c183a93033
This is a ported/modified version of the ypxfr program from the yps-0.21 package from the NYS project. This program is normally invoked by ypserv when it receives a yppush command from an NIS master. It can also be run from the command line to grab copies of maps when initializing a slave server. This program has been hacked in the following ways: - rpcgen'ed new yp_xdr.c, yp_svc.c and yp_clnt.c files. The old ones were rather grody. - Changed certain function names (prefended a _ to them) to avoid conflicts with certain functions lurking within libc. One major problem here is that ypxfr needs to bind to a YP master in order to work correctly, but it can't use the _yp_bind function inside libc because that function only lets you bind to a domain, not a specific host. Lots of head scratching here. - Converted from GDBM to DB at gunpoint. - Removed lots of really nasty looking DEBUG code to try to reduce clutter. - Incorporated some of the library code supplied with yps-0.21 on which ypxfr was dependent. This program still needs to be cleaned up just as a matter of principle: I get all icky just looking at it sometimes.
235 lines
5.3 KiB
C
235 lines
5.3 KiB
C
#include <rpc/rpc.h>
|
|
#include "yp.h"
|
|
#ifndef lint
|
|
/*static char sccsid[] = "from: @(#)yp.x 2.1 88/08/01 4.0 RPCSRC";*/
|
|
static char rcsid[] = "yp.x,v 1.1 1994/08/04 19:01:55 wollman Exp";
|
|
#endif /* not lint */
|
|
|
|
struct {
|
|
union {
|
|
int (*encoder)(char *, int, char **, int *, char **, int *);
|
|
int (*decoder)(int, char *, int, char *, int, char *);
|
|
} foreach;
|
|
char *data;
|
|
} *xdr_ypall_callback;
|
|
|
|
bool_t
|
|
__xdr_ypstat(XDR *xdrs, ypstat *objp)
|
|
{
|
|
|
|
if (!xdr_enum(xdrs, (enum_t *)objp)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
bool_t
|
|
__xdr_valdat(XDR *xdrs, valdat *objp)
|
|
{
|
|
|
|
if (!xdr_bytes(xdrs, (char **)&objp->valdat_val, (u_int *)&objp->valdat_len, YPMAXRECORD)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
bool_t
|
|
__xdr_keydat(XDR *xdrs, keydat *objp)
|
|
{
|
|
|
|
if (!xdr_bytes(xdrs, (char **)&objp->keydat_val, (u_int *)&objp->keydat_len, YPMAXRECORD)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
bool_t
|
|
__xdr_ypresp_key_val(XDR *xdrs, ypresp_key_val *objp)
|
|
{
|
|
|
|
if (!__xdr_ypstat(xdrs, &objp->stat)) {
|
|
return (FALSE);
|
|
}
|
|
if (!__xdr_valdat(xdrs, &objp->val)) {
|
|
return (FALSE);
|
|
}
|
|
if (!__xdr_keydat(xdrs, &objp->key)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
bool_t
|
|
xdr_ypxfrstat(xdrs, objp)
|
|
XDR *xdrs;
|
|
ypxfrstat *objp;
|
|
{
|
|
if (!xdr_enum(xdrs, (enum_t *)objp)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
|
|
bool_t
|
|
xdr_ypmap_parms(xdrs, objp)
|
|
XDR *xdrs;
|
|
ypmap_parms *objp;
|
|
{
|
|
if (!xdr_domainname(xdrs, &objp->domain)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_mapname(xdrs, &objp->map)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_u_int(xdrs, &objp->ordernum)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_peername(xdrs, &objp->peer)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
bool_t
|
|
xdr_ypreq_xfr(xdrs, objp)
|
|
XDR *xdrs;
|
|
ypreq_xfr *objp;
|
|
{
|
|
if (!xdr_ypmap_parms(xdrs, &objp->map_parms)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_u_int(xdrs, &objp->transid)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_u_int(xdrs, &objp->prog)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_u_int(xdrs, &objp->port)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
bool_t
|
|
xdr_ypresp_xfr(xdrs, objp)
|
|
XDR *xdrs;
|
|
ypresp_xfr *objp;
|
|
{
|
|
if (!xdr_u_int(xdrs, &objp->transid)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_ypxfrstat(xdrs, &objp->xfrstat)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
bool_t
|
|
xdr_yppush_status(xdrs, objp)
|
|
XDR *xdrs;
|
|
yppush_status *objp;
|
|
{
|
|
if (!xdr_enum(xdrs, (enum_t *)objp)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
|
|
bool_t
|
|
xdr_yppushresp_xfr(xdrs, objp)
|
|
XDR *xdrs;
|
|
yppushresp_xfr *objp;
|
|
{
|
|
if (!xdr_u_int(xdrs, &objp->transid)) {
|
|
return (FALSE);
|
|
}
|
|
if (!xdr_yppush_status(xdrs, &objp->status)) {
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
bool_t
|
|
__xdr_ypresp_all(XDR *xdrs, ypresp_all *objp)
|
|
{
|
|
int CallAgain = 0;
|
|
if (xdrs->x_op == XDR_DECODE) {
|
|
while(1) {
|
|
#if 1
|
|
int s=objp->ypresp_all_u.val.stat;
|
|
bzero((char *)objp, sizeof (*objp));
|
|
objp->ypresp_all_u.val.stat=s;
|
|
#endif
|
|
if (!xdr_bool(xdrs, &objp->more)) {
|
|
return (FALSE);
|
|
}
|
|
switch (objp->more) {
|
|
case TRUE:
|
|
if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) {
|
|
return (FALSE);
|
|
}
|
|
if (CallAgain==0) {
|
|
CallAgain=(*(xdr_ypall_callback->foreach.decoder))(
|
|
objp->ypresp_all_u.val.stat,
|
|
objp->ypresp_all_u.val.key.keydat_val,
|
|
objp->ypresp_all_u.val.key.keydat_len,
|
|
objp->ypresp_all_u.val.val.valdat_val,
|
|
objp->ypresp_all_u.val.val.valdat_len,
|
|
xdr_ypall_callback->data);
|
|
}
|
|
break;
|
|
case FALSE:
|
|
return TRUE;
|
|
}
|
|
#if 0
|
|
xdrs->x_op=XDR_FREE;
|
|
if (!__xdr_ypresp_all(xdrs, objp)) {
|
|
return FALSE;
|
|
}
|
|
xdrs->x_op=XDR_DECODE;
|
|
#else
|
|
xdr_free(__xdr_ypresp_all, (char *)objp);
|
|
#endif
|
|
}
|
|
} else if (xdrs->x_op == XDR_ENCODE) {
|
|
while(1) {
|
|
if (!xdr_bool(xdrs, &(objp->more))) {
|
|
return (FALSE);
|
|
}
|
|
if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) {
|
|
printf("__xdr_ypresp_key_val failed\n");
|
|
return (FALSE);
|
|
}
|
|
if (objp->ypresp_all_u.val.stat!=YP_TRUE) {
|
|
objp->more=FALSE;
|
|
if (!xdr_bool(xdrs, &(objp->more))) {
|
|
return (FALSE);
|
|
}
|
|
return(TRUE);
|
|
}
|
|
objp->ypresp_all_u.val.stat =
|
|
(enum ypstat)(*(xdr_ypall_callback->foreach.encoder))(
|
|
objp->ypresp_all_u.val.key.keydat_val,
|
|
objp->ypresp_all_u.val.key.keydat_len,
|
|
&(objp->ypresp_all_u.val.key.keydat_val),
|
|
&(objp->ypresp_all_u.val.key.keydat_len),
|
|
&(objp->ypresp_all_u.val.val.valdat_val),
|
|
&(objp->ypresp_all_u.val.val.valdat_len));
|
|
}
|
|
} else {
|
|
#if 0
|
|
bool_t more=objp->more;
|
|
if (more==TRUE) {
|
|
if (!xdr_bool(xdrs, &objp->more)) {
|
|
return FALSE;
|
|
}
|
|
if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) {
|
|
return (FALSE);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return(TRUE);
|
|
}
|
|
}
|