From e5b131e6ec525c31d4917642b06e9024a8f9839c Mon Sep 17 00:00:00 2001 From: wpaul Date: Tue, 31 Jan 1995 09:28:47 +0000 Subject: Obtained from: The NYS project 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. --- gnu/libexec/ypxfr/Makefile | 11 ++ gnu/libexec/ypxfr/yp.h | 288 ++++++++++++++++++++++++++++++++++ gnu/libexec/ypxfr/yp_clnt.c | 264 +++++++++++++++++++++++++++++++ gnu/libexec/ypxfr/yp_svc.c | 270 ++++++++++++++++++++++++++++++++ gnu/libexec/ypxfr/yp_xdr.c | 234 ++++++++++++++++++++++++++++ gnu/libexec/ypxfr/ypclnt.c | 255 ++++++++++++++++++++++++++++++ gnu/libexec/ypxfr/ypxfr.c | 372 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1694 insertions(+) create mode 100644 gnu/libexec/ypxfr/Makefile create mode 100644 gnu/libexec/ypxfr/yp.h create mode 100644 gnu/libexec/ypxfr/yp_clnt.c create mode 100644 gnu/libexec/ypxfr/yp_svc.c create mode 100644 gnu/libexec/ypxfr/yp_xdr.c create mode 100644 gnu/libexec/ypxfr/ypclnt.c create mode 100644 gnu/libexec/ypxfr/ypxfr.c (limited to 'gnu/libexec') diff --git a/gnu/libexec/ypxfr/Makefile b/gnu/libexec/ypxfr/Makefile new file mode 100644 index 0000000..9b8d88c --- /dev/null +++ b/gnu/libexec/ypxfr/Makefile @@ -0,0 +1,11 @@ +# $Id$ + +PROG= ypxfr +MAN8= + +SRCS= ypxfr.c ypclnt.c yp_clnt.c yp_xdr.c + +BINOWN= bin +BINMODE=555 + +.include diff --git a/gnu/libexec/ypxfr/yp.h b/gnu/libexec/ypxfr/yp.h new file mode 100644 index 0000000..899a1ab --- /dev/null +++ b/gnu/libexec/ypxfr/yp.h @@ -0,0 +1,288 @@ +#define YPMAXRECORD 1024 +#define YPMAXDOMAIN 64 +#define YPMAXMAP 64 +#define YPMAXPEER 64 + +enum ypstat { + YP_TRUE = 1, + YP_NOMORE = 2, + YP_FALSE = 0, + YP_NOMAP = -1, + YP_NODOM = -2, + YP_NOKEY = -3, + YP_BADOP = -4, + YP_BADDB = -5, + YP_YPERR = -6, + YP_BADARGS = -7, + YP_VERS = -8, +}; +typedef enum ypstat ypstat; +bool_t xdr_ypstat(); + + +enum ypxfrstat { + YPXFR_SUCC = 1, + YPXFR_AGE = 2, + YPXFR_NOMAP = -1, + YPXFR_NODOM = -2, + YPXFR_RSRC = -3, + YPXFR_RPC = -4, + YPXFR_MADDR = -5, + YPXFR_YPERR = -6, + YPXFR_BADARGS = -7, + YPXFR_DBM = -8, + YPXFR_FILE = -9, + YPXFR_SKEW = -10, + YPXFR_CLEAR = -11, + YPXFR_FORCE = -12, + YPXFR_XFRERR = -13, + YPXFR_REFUSED = -14, +}; +typedef enum ypxfrstat ypxfrstat; +bool_t xdr_ypxfrstat(); + + +typedef char *domainname; +bool_t xdr_domainname(); + + +typedef char *mapname; +bool_t xdr_mapname(); + + +typedef char *peername; +bool_t xdr_peername(); + + +typedef struct { + u_int keydat_len; + char *keydat_val; +} keydat; +bool_t xdr_keydat(); + + +typedef struct { + u_int valdat_len; + char *valdat_val; +} valdat; +bool_t xdr_valdat(); + + +struct ypmap_parms { + domainname domain; + mapname map; + u_int ordernum; + peername peer; +}; +typedef struct ypmap_parms ypmap_parms; +bool_t xdr_ypmap_parms(); + + +struct ypreq_key { + domainname domain; + mapname map; + keydat key; +}; +typedef struct ypreq_key ypreq_key; +bool_t xdr_ypreq_key(); + + +struct ypreq_nokey { + domainname domain; + mapname map; +}; +typedef struct ypreq_nokey ypreq_nokey; +bool_t xdr_ypreq_nokey(); + + +struct ypreq_xfr { + ypmap_parms map_parms; + u_int transid; + u_int prog; + u_int port; +}; +typedef struct ypreq_xfr ypreq_xfr; +bool_t xdr_ypreq_xfr(); + + +struct ypresp_val { + ypstat stat; + valdat val; +}; +typedef struct ypresp_val ypresp_val; +bool_t xdr_ypresp_val(); + + +struct ypresp_key_val { + ypstat stat; + keydat key; + valdat val; +}; +typedef struct ypresp_key_val ypresp_key_val; +bool_t xdr_ypresp_key_val(); + + +struct ypresp_master { + ypstat stat; + peername peer; +}; +typedef struct ypresp_master ypresp_master; +bool_t xdr_ypresp_master(); + + +struct ypresp_order { + ypstat stat; + u_int ordernum; +}; +typedef struct ypresp_order ypresp_order; +bool_t xdr_ypresp_order(); + + +struct ypresp_all { + bool_t more; + union { + ypresp_key_val val; + } ypresp_all_u; +}; +typedef struct ypresp_all ypresp_all; +bool_t __xdr_ypresp_all(); + + +struct ypresp_xfr { + u_int transid; + ypxfrstat xfrstat; +}; +typedef struct ypresp_xfr ypresp_xfr; +bool_t xdr_ypresp_xfr(); + + +struct ypmaplist { + mapname map; + struct ypmaplist *next; +}; +typedef struct ypmaplist ypmaplist; +bool_t xdr_ypmaplist(); + + +struct ypresp_maplist { + ypstat stat; + ypmaplist *maps; +}; +typedef struct ypresp_maplist ypresp_maplist; +bool_t xdr_ypresp_maplist(); + + +enum yppush_status { + YPPUSH_SUCC = 1, + YPPUSH_AGE = 2, + YPPUSH_NOMAP = -1, + YPPUSH_NODOM = -2, + YPPUSH_RSRC = -3, + YPPUSH_RPC = -4, + YPPUSH_MADDR = -5, + YPPUSH_YPERR = -6, + YPPUSH_BADARGS = -7, + YPPUSH_DBM = -8, + YPPUSH_FILE = -9, + YPPUSH_SKEW = -10, + YPPUSH_CLEAR = -11, + YPPUSH_FORCE = -12, + YPPUSH_XFRERR = -13, + YPPUSH_REFUSED = -14, +}; +typedef enum yppush_status yppush_status; +bool_t xdr_yppush_status(); + + +struct yppushresp_xfr { + u_int transid; + yppush_status status; +}; +typedef struct yppushresp_xfr yppushresp_xfr; +bool_t xdr_yppushresp_xfr(); + + +enum ypbind_resptype { + YPBIND_SUCC_VAL = 1, + YPBIND_FAIL_VAL = 2, +}; +typedef enum ypbind_resptype ypbind_resptype; +bool_t xdr_ypbind_resptype(); + + +struct ypbind_binding { + char ypbind_binding_addr[4]; + char ypbind_binding_port[2]; +}; +typedef struct ypbind_binding ypbind_binding; +bool_t xdr_ypbind_binding(); + + +struct ypbind_resp { + ypbind_resptype ypbind_status; + union { + u_int ypbind_error; + ypbind_binding ypbind_bindinfo; + } ypbind_resp_u; +}; +typedef struct ypbind_resp ypbind_resp; +bool_t xdr_ypbind_resp(); + +#define YPBIND_ERR_ERR 1 +#define YPBIND_ERR_NOSERV 2 +#define YPBIND_ERR_RESC 3 + +struct ypbind_setdom { + domainname ypsetdom_domain; + ypbind_binding ypsetdom_binding; + u_int ypsetdom_vers; +}; +typedef struct ypbind_setdom ypbind_setdom; +bool_t xdr_ypbind_setdom(); + + +#define YPPROG ((u_long)100004) +#define YPVERS ((u_long)2) +#define YPPROC_NULL ((u_long)0) +extern void *ypproc_null_2(); +#define YPPROC_DOMAIN ((u_long)1) +extern bool_t *ypproc_domain_2(); +#define YPPROC_DOMAIN_NONACK ((u_long)2) +extern bool_t *ypproc_domain_nonack_2(); +#define YPPROC_MATCH ((u_long)3) +extern ypresp_val *ypproc_match_2(); +#define YPPROC_FIRST ((u_long)4) +extern ypresp_key_val *ypproc_first_2(); +#define YPPROC_NEXT ((u_long)5) +extern ypresp_key_val *ypproc_next_2(); +#define YPPROC_XFR ((u_long)6) +extern ypresp_xfr *ypproc_xfr_2(); +#define YPPROC_CLEAR ((u_long)7) +extern void *ypproc_clear_2(); +#define YPPROC_ALL ((u_long)8) +extern ypresp_all *ypproc_all_2(); +#define YPPROC_MASTER ((u_long)9) +extern ypresp_master *ypproc_master_2(); +#define YPPROC_ORDER ((u_long)10) +extern ypresp_order *ypproc_order_2(); +#define YPPROC_MAPLIST ((u_long)11) +extern ypresp_maplist *ypproc_maplist_2(); + + +#define YPPUSH_XFRRESPPROG ((u_long)0x40000000) +#define YPPUSH_XFRRESPVERS ((u_long)1) +#define YPPUSHPROC_NULL ((u_long)0) +extern void *yppushproc_null_1(); +#define YPPUSHPROC_XFRRESP ((u_long)1) +extern yppushresp_xfr *yppushproc_xfrresp_1(); + + +#define YPBINDPROG ((u_long)100007) +#define YPBINDVERS ((u_long)2) +#define YPBINDPROC_NULL ((u_long)0) +extern void *ypbindproc_null_2(); +#define YPBINDPROC_DOMAIN ((u_long)1) +extern ypbind_resp *ypbindproc_domain_2(); +#define YPBINDPROC_SETDOM ((u_long)2) +extern void *ypbindproc_setdom_2(); + diff --git a/gnu/libexec/ypxfr/yp_clnt.c b/gnu/libexec/ypxfr/yp_clnt.c new file mode 100644 index 0000000..290a5f7 --- /dev/null +++ b/gnu/libexec/ypxfr/yp_clnt.c @@ -0,0 +1,264 @@ +#include +#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 */ + +/* Default timeout can be changed using clnt_control() */ +static struct timeval TIMEOUT = { 25, 0 }; + +void * +ypproc_null_2(argp, clnt) + void *argp; + CLIENT *clnt; +{ + static char res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_NULL, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return ((void *)&res); +} + + +bool_t * +ypproc_domain_2(argp, clnt) + domainname *argp; + CLIENT *clnt; +{ + static bool_t res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_DOMAIN, xdr_domainname, argp, xdr_bool, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +bool_t * +ypproc_domain_nonack_2(argp, clnt) + domainname *argp; + CLIENT *clnt; +{ + static bool_t res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_DOMAIN_NONACK, xdr_domainname, argp, xdr_bool, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_val * +ypproc_match_2(argp, clnt) + ypreq_key *argp; + CLIENT *clnt; +{ + static ypresp_val res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_MATCH, xdr_ypreq_key, argp, xdr_ypresp_val, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_key_val * +ypproc_first_2(argp, clnt) + ypreq_key *argp; + CLIENT *clnt; +{ + static ypresp_key_val res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_FIRST, xdr_ypreq_key, argp, xdr_ypresp_key_val, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_key_val * +ypproc_next_2(argp, clnt) + ypreq_key *argp; + CLIENT *clnt; +{ + static ypresp_key_val res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_NEXT, xdr_ypreq_key, argp, xdr_ypresp_key_val, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_xfr * +ypproc_xfr_2(argp, clnt) + ypreq_xfr *argp; + CLIENT *clnt; +{ + static ypresp_xfr res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_XFR, xdr_ypreq_xfr, argp, xdr_ypresp_xfr, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +void * +ypproc_clear_2(argp, clnt) + void *argp; + CLIENT *clnt; +{ + static char res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_CLEAR, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return ((void *)&res); +} + + +ypresp_all * +ypproc_all_2(argp, clnt) + ypreq_nokey *argp; + CLIENT *clnt; +{ + static ypresp_all res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_ALL, xdr_ypreq_nokey, argp, __xdr_ypresp_all, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_master * +ypproc_master_2(argp, clnt) + ypreq_nokey *argp; + CLIENT *clnt; +{ + static ypresp_master res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_MASTER, xdr_ypreq_nokey, argp, xdr_ypresp_master, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_order * +ypproc_order_2(argp, clnt) + ypreq_nokey *argp; + CLIENT *clnt; +{ + static ypresp_order res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_ORDER, xdr_ypreq_nokey, argp, xdr_ypresp_order, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +ypresp_maplist * +ypproc_maplist_2(argp, clnt) + domainname *argp; + CLIENT *clnt; +{ + static ypresp_maplist res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPROC_MAPLIST, xdr_domainname, argp, xdr_ypresp_maplist, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +void * +yppushproc_null_1(argp, clnt) + void *argp; + CLIENT *clnt; +{ + static char res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPUSHPROC_NULL, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return ((void *)&res); +} + + +yppushresp_xfr * +yppushproc_xfrresp_1(argp, clnt) + void *argp; + CLIENT *clnt; +{ + static yppushresp_xfr res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPPUSHPROC_XFRRESP, xdr_void, argp, xdr_yppushresp_xfr, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +void * +ypbindproc_null_2(argp, clnt) + void *argp; + CLIENT *clnt; +{ + static char res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPBINDPROC_NULL, xdr_void, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return ((void *)&res); +} + + +ypbind_resp * +ypbindproc_domain_2(argp, clnt) + domainname *argp; + CLIENT *clnt; +{ + static ypbind_resp res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPBINDPROC_DOMAIN, xdr_domainname, argp, xdr_ypbind_resp, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return (&res); +} + + +void * +ypbindproc_setdom_2(argp, clnt) + ypbind_setdom *argp; + CLIENT *clnt; +{ + static char res; + + bzero((char *)&res, sizeof(res)); + if (clnt_call(clnt, YPBINDPROC_SETDOM, xdr_ypbind_setdom, argp, xdr_void, &res, TIMEOUT) != RPC_SUCCESS) { + return (NULL); + } + return ((void *)&res); +} + diff --git a/gnu/libexec/ypxfr/yp_svc.c b/gnu/libexec/ypxfr/yp_svc.c new file mode 100644 index 0000000..12f26c9 --- /dev/null +++ b/gnu/libexec/ypxfr/yp_svc.c @@ -0,0 +1,270 @@ +#include +#include +#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 */ + +static void ypprog_2(); +static void yppush_xfrrespprog_1(); +static void ypbindprog_2(); + +main() +{ + SVCXPRT *transp; + + (void)pmap_unset(YPPROG, YPVERS); + (void)pmap_unset(YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS); + (void)pmap_unset(YPBINDPROG, YPBINDVERS); + + transp = svcudp_create(RPC_ANYSOCK); + if (transp == NULL) { + (void)fprintf(stderr, "cannot create udp service.\n"); + exit(1); + } + if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_UDP)) { + (void)fprintf(stderr, "unable to register (YPPROG, YPVERS, udp).\n"); + exit(1); + } + if (!svc_register(transp, YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, yppush_xfrrespprog_1, IPPROTO_UDP)) { + (void)fprintf(stderr, "unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, udp).\n"); + exit(1); + } + if (!svc_register(transp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_UDP)) { + (void)fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, udp).\n"); + exit(1); + } + + transp = svctcp_create(RPC_ANYSOCK, 0, 0); + if (transp == NULL) { + (void)fprintf(stderr, "cannot create tcp service.\n"); + exit(1); + } + if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_TCP)) { + (void)fprintf(stderr, "unable to register (YPPROG, YPVERS, tcp).\n"); + exit(1); + } + if (!svc_register(transp, YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, yppush_xfrrespprog_1, IPPROTO_TCP)) { + (void)fprintf(stderr, "unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, tcp).\n"); + exit(1); + } + if (!svc_register(transp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_TCP)) { + (void)fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, tcp).\n"); + exit(1); + } + svc_run(); + (void)fprintf(stderr, "svc_run returned\n"); + exit(1); +} + +static void +ypprog_2(rqstp, transp) + struct svc_req *rqstp; + SVCXPRT *transp; +{ + union { + domainname ypproc_domain_2_arg; + domainname ypproc_domain_nonack_2_arg; + ypreq_key ypproc_match_2_arg; + ypreq_key ypproc_first_2_arg; + ypreq_key ypproc_next_2_arg; + ypreq_xfr ypproc_xfr_2_arg; + ypreq_nokey ypproc_all_2_arg; + ypreq_nokey ypproc_master_2_arg; + ypreq_nokey ypproc_order_2_arg; + domainname ypproc_maplist_2_arg; + } argument; + char *result; + bool_t (*xdr_argument)(), (*xdr_result)(); + char *(*local)(); + + switch (rqstp->rq_proc) { + case YPPROC_NULL: + xdr_argument = xdr_void; + xdr_result = xdr_void; + local = (char *(*)()) ypproc_null_2; + break; + + case YPPROC_DOMAIN: + xdr_argument = xdr_domainname; + xdr_result = xdr_bool; + local = (char *(*)()) ypproc_domain_2; + break; + + case YPPROC_DOMAIN_NONACK: + xdr_argument = xdr_domainname; + xdr_result = xdr_bool; + local = (char *(*)()) ypproc_domain_nonack_2; + break; + + case YPPROC_MATCH: + xdr_argument = xdr_ypreq_key; + xdr_result = xdr_ypresp_val; + local = (char *(*)()) ypproc_match_2; + break; + + case YPPROC_FIRST: + xdr_argument = xdr_ypreq_key; + xdr_result = xdr_ypresp_key_val; + local = (char *(*)()) ypproc_first_2; + break; + + case YPPROC_NEXT: + xdr_argument = xdr_ypreq_key; + xdr_result = xdr_ypresp_key_val; + local = (char *(*)()) ypproc_next_2; + break; + + case YPPROC_XFR: + xdr_argument = xdr_ypreq_xfr; + xdr_result = xdr_ypresp_xfr; + local = (char *(*)()) ypproc_xfr_2; + break; + + case YPPROC_CLEAR: + xdr_argument = xdr_void; + xdr_result = xdr_void; + local = (char *(*)()) ypproc_clear_2; + break; + + case YPPROC_ALL: + xdr_argument = xdr_ypreq_nokey; + xdr_result = __xdr_ypresp_all; + local = (char *(*)()) ypproc_all_2; + break; + + case YPPROC_MASTER: + xdr_argument = xdr_ypreq_nokey; + xdr_result = xdr_ypresp_master; + local = (char *(*)()) ypproc_master_2; + break; + + case YPPROC_ORDER: + xdr_argument = xdr_ypreq_nokey; + xdr_result = xdr_ypresp_order; + local = (char *(*)()) ypproc_order_2; + break; + + case YPPROC_MAPLIST: + xdr_argument = xdr_domainname; + xdr_result = xdr_ypresp_maplist; + local = (char *(*)()) ypproc_maplist_2; + break; + + default: + svcerr_noproc(transp); + return; + } + bzero((char *)&argument, sizeof(argument)); + if (!svc_getargs(transp, xdr_argument, &argument)) { + svcerr_decode(transp); + return; + } + result = (*local)(&argument, rqstp); + if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { + svcerr_systemerr(transp); + } + if (!svc_freeargs(transp, xdr_argument, &argument)) { + (void)fprintf(stderr, "unable to free arguments\n"); + exit(1); + } +} + + +static void +yppush_xfrrespprog_1(rqstp, transp) + struct svc_req *rqstp; + SVCXPRT *transp; +{ + union { + int fill; + } argument; + char *result; + bool_t (*xdr_argument)(), (*xdr_result)(); + char *(*local)(); + + switch (rqstp->rq_proc) { + case YPPUSHPROC_NULL: + xdr_argument = xdr_void; + xdr_result = xdr_void; + local = (char *(*)()) yppushproc_null_1; + break; + + case YPPUSHPROC_XFRRESP: + xdr_argument = xdr_void; + xdr_result = xdr_yppushresp_xfr; + local = (char *(*)()) yppushproc_xfrresp_1; + break; + + default: + svcerr_noproc(transp); + return; + } + bzero((char *)&argument, sizeof(argument)); + if (!svc_getargs(transp, xdr_argument, &argument)) { + svcerr_decode(transp); + return; + } + result = (*local)(&argument, rqstp); + if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { + svcerr_systemerr(transp); + } + if (!svc_freeargs(transp, xdr_argument, &argument)) { + (void)fprintf(stderr, "unable to free arguments\n"); + exit(1); + } +} + + +static void +ypbindprog_2(rqstp, transp) + struct svc_req *rqstp; + SVCXPRT *transp; +{ + union { + domainname ypbindproc_domain_2_arg; + ypbind_setdom ypbindproc_setdom_2_arg; + } argument; + char *result; + bool_t (*xdr_argument)(), (*xdr_result)(); + char *(*local)(); + + switch (rqstp->rq_proc) { + case YPBINDPROC_NULL: + xdr_argument = xdr_void; + xdr_result = xdr_void; + local = (char *(*)()) ypbindproc_null_2; + break; + + case YPBINDPROC_DOMAIN: + xdr_argument = xdr_domainname; + xdr_result = xdr_ypbind_resp; + local = (char *(*)()) ypbindproc_domain_2; + break; + + case YPBINDPROC_SETDOM: + xdr_argument = xdr_ypbind_setdom; + xdr_result = xdr_void; + local = (char *(*)()) ypbindproc_setdom_2; + break; + + default: + svcerr_noproc(transp); + return; + } + bzero((char *)&argument, sizeof(argument)); + if (!svc_getargs(transp, xdr_argument, &argument)) { + svcerr_decode(transp); + return; + } + result = (*local)(&argument, rqstp); + if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { + svcerr_systemerr(transp); + } + if (!svc_freeargs(transp, xdr_argument, &argument)) { + (void)fprintf(stderr, "unable to free arguments\n"); + exit(1); + } +} + diff --git a/gnu/libexec/ypxfr/yp_xdr.c b/gnu/libexec/ypxfr/yp_xdr.c new file mode 100644 index 0000000..a39acae --- /dev/null +++ b/gnu/libexec/ypxfr/yp_xdr.c @@ -0,0 +1,234 @@ +#include +#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); + } +} diff --git a/gnu/libexec/ypxfr/ypclnt.c b/gnu/libexec/ypxfr/ypclnt.c new file mode 100644 index 0000000..3ad43e9 --- /dev/null +++ b/gnu/libexec/ypxfr/ypclnt.c @@ -0,0 +1,255 @@ +/* + YPS-0.2, NIS-Server for Linux + Copyright (C) 1994 Tobias Reber + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) + + $Id$ +*/ + +/* + * $Author: root $ + * $Log: ypclnt.c,v $ + * Revision 2.0 1994/01/06 16:58:48 root + * Version 2.0 + * + * Revision 0.17 1994/01/02 22:48:22 root + * Added strict prototypes + * + * Revision 0.16 1994/01/02 20:09:39 root + * Added GPL notice + * + * Revision 0.15 1993/12/30 22:34:57 root + * *** empty log message *** + * + * Revision 0.14 1993/12/19 12:42:32 root + * *** empty log message *** + * + * Revision 0.13 1993/06/12 09:39:30 root + * Align with include-4.4 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* + * ypclnt.h does not have a definition for struct dom_binding, + * although it is used there. It is defined in yp_prot.h, but + * we cannot use it here. + */ +struct dom_binding { + void * m; +}; +#include + +static struct sockaddr_in ServerAddress; +static CLIENT *UdpClient=NULL, *TcpClient=NULL; + +#ifdef YPBROADCAST +static bool_t +eachresult( caddr_t resultsp, struct sockaddr_in *raddr) +{ + bcopy(raddr, &ServerAddress, sizeof(ServerAddress)); + return((bool_t) TRUE); +} +#endif + +static struct sockaddr_in * +__do_ypbind(domainname d) +{ + static struct sockaddr_in resp; + int rc; + ypbind_resp r; + CLIENT *localBindClient; + struct sockaddr_in localAddr; + int s; + struct timeval t={5,0}, tott={25,0}; + + s=RPC_ANYSOCK; + bzero(&localAddr, sizeof localAddr); + localAddr.sin_addr.s_addr=htonl(INADDR_LOOPBACK); + localBindClient=clntudp_create(&localAddr, YPBINDPROG, YPBINDVERS, tott, &s); + if (!localBindClient) { + clnt_pcreateerror(""); + return NULL; + } + + rc=clnt_call(localBindClient, YPBINDPROC_DOMAIN, + xdr_domainname, (char *)&d, xdr_ypbind_resp, (char *)&r, t); + if (rc) { + clnt_perrno(rc); + return NULL; + } + + switch (r.ypbind_status) { + case YPBIND_FAIL_VAL: + switch(r.ypbind_resp_u.ypbind_error) { + case YPBIND_ERR_ERR: + fprintf(stderr, "YPBINDPROC_DOMAIN: Internal error\n"); + break; + case YPBIND_ERR_NOSERV: + fprintf(stderr, "YPBINDPROC_DOMAIN: No bound server for passed domain\n"); + break; + case YPBIND_ERR_RESC: + fprintf(stderr, "YPBINDPROC_DOMAIN: System resource allocation failure\n"); + break; + default: + fprintf(stderr, "YPBINDPROC_DOMAIN: Unknown error\n"); + break; + } + return NULL; + case YPBIND_SUCC_VAL: + { + struct ypbind_binding *y=&r.ypbind_resp_u.ypbind_bindinfo; + bzero(&resp, sizeof resp); + resp.sin_family=AF_INET; + resp.sin_addr=*(struct in_addr *)(y->ypbind_binding_addr); + return &resp; + } + } + return NULL; +} + +void +__yp_unbind(char *DomainName) +{ + if (UdpClient) clnt_destroy(UdpClient); + UdpClient=NULL; + if (TcpClient) clnt_destroy(TcpClient); + TcpClient=NULL; +} + +int +_yp_bind(struct sockaddr_in *ServerAddress, char *DomainName) +{ + struct sockaddr_in UdpServerAddress, TcpServerAddress; + int UdpSockp, TcpSockp; + static struct timeval Wait = { 5, 0 }; + + if (UdpClient || TcpClient) __yp_unbind(DomainName); + + bcopy(ServerAddress, &UdpServerAddress, sizeof(*ServerAddress)); + UdpServerAddress.sin_port=0; + UdpSockp=(RPC_ANYSOCK); + bcopy(ServerAddress, &TcpServerAddress, sizeof(*ServerAddress)); + TcpServerAddress.sin_port=0; + TcpSockp=(RPC_ANYSOCK); + if ((UdpClient=clntudp_create(&UdpServerAddress, YPPROG, YPVERS, + Wait, &UdpSockp))==NULL) { + clnt_pcreateerror("UdpClient"); + return(YPERR_RPC); + } + if ((TcpClient=clnttcp_create(&TcpServerAddress, YPPROG, YPVERS, + &TcpSockp, 0, 0))==NULL) { + clnt_pcreateerror("TcpClient"); + return(YPERR_RPC); + } + return(0); + +} + +int +__yp_bind(char *DomainName) +{ +# ifdef YPBROADCAST + enum clnt_stat clnt_stat; + static bool_t res; +# endif + static domainname domain; + + domain=DomainName; +# ifndef SOCKSERVER +# ifdef YPBROADCAST + bzero(&ServerAddress, sizeof ServerAddress); + if ((clnt_stat=clnt_broadcast(YPPROG, YPVERS, + YPPROC_DOMAIN_NONACK, xdr_domainname, (char *)&domain, xdr_bool, + (char *)&res, eachresult))!=RPC_SUCCESS) { + clnt_perrno(clnt_stat); + return(YPERR_DOMAIN); + } +# else + { + struct sockaddr_in *s=__do_ypbind(DomainName); + if (!s) return(YPERR_DOMAIN); + ServerAddress=*s; + } +# endif +# else + bzero(&ServerAddress, sizeof ServerAddress); + ServerAddress.sin_family=AF_INET; + ServerAddress.sin_addr.s_addr=htonl(SOCKSERVER); +# endif SOCKSERVER + return (_yp_bind(&ServerAddress, DomainName)); +} + +int +__yp_all( char *DomainName, char *MapName, struct ypall_callback *CallBack) +{ + static ypreq_nokey req; + ypresp_all *resp; + extern struct ypall_callback *xdr_ypall_callback; + int Status; + + do { + if (TcpClient==NULL) + if ((Status=__yp_bind(DomainName))) return(Status); + + req.domain=DomainName; + req.map=MapName; + xdr_ypall_callback=CallBack; + if ((resp=ypproc_all_2(&req, TcpClient))==NULL) { + clnt_perror(TcpClient, "ypall"); + __yp_unbind(DomainName); + } + } while(resp==NULL); + switch (resp->ypresp_all_u.val.stat) { + case YP_TRUE: + case YP_NOMORE: + Status=0; + break; + default: + Status=ypprot_err(resp->ypresp_all_u.val.stat); + } + clnt_freeres(TcpClient, xdr_ypresp_all, resp); + return(Status); +} + +int +_yp_clear(char *DomainName) +{ + void *resp; + int Status; + + do { + if (UdpClient==NULL) + if ((Status=yp_bind(DomainName))) return(Status); + if ((resp=ypproc_clear_2(NULL, UdpClient))==NULL) { + clnt_perror(UdpClient, "_yp_clear"); + __yp_unbind(DomainName); + } + } while(resp==NULL); + return 0; +} + diff --git a/gnu/libexec/ypxfr/ypxfr.c b/gnu/libexec/ypxfr/ypxfr.c new file mode 100644 index 0000000..3d06431 --- /dev/null +++ b/gnu/libexec/ypxfr/ypxfr.c @@ -0,0 +1,372 @@ +/* + YPS-0.2, NIS-Server for Linux + Copyright (C) 1994 Tobias Reber + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) + + $Id$ +*/ + +/* + * $Author: root $ + * $Log: ypxfr.c,v $ + * Revision 2.0 1994/01/06 16:58:08 root + * Version 2.0 + * + * Revision 0.20 1994/01/02 21:59:08 root + * Strict prototypes + * + * Revision 0.19 1994/01/02 20:10:08 root + * Added GPL notice + * + * Revision 0.18 1994/01/02 18:00:38 root + * New arguments for -C flag. + * + * Revision 0.17 1993/12/30 22:21:49 root + * Switch to GDBM + * + * Revision 0.16 1993/12/27 23:43:26 root + * Use dbm directly instead of makedbm + * + * Revision 0.15 1993/12/27 21:21:00 root + * This host should be the default master + * + * Revision 0.14 1993/12/19 12:41:55 root + * *** empty log message *** + * + * Revision 0.13 1993/06/12 10:49:35 root + * Align with include-4.4 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DB *db; + +#define PERM_SECURE (S_IRUSR|S_IWUSR) +HASHINFO openinfo = { + 4096, /* bsize */ + 32, /* ffactor */ + 256, /* nelem */ + 2048 * 1024, /* cachesize */ + NULL, /* hash */ + 0 /* lorder */ +}; + +#include + +struct dom_binding { + struct dom_binding *dom_pnext; + char dom_domain[YPMAXDOMAIN + 1]; + struct sockaddr_in dom_server_addr; + u_short dom_server_port; + int dom_socket; + CLIENT *dom_client; + u_short dom_local_port; + long dom_vers; +}; + +#define DATUM /* Otherwise ypclnt.h redefines datum */ +#include +/* + * These are hooks to the ypclnt library in ../lib + */ +extern int _yp_bind(struct sockaddr_in *, char *); +extern int _yp_clear( char *); +#include +#include +#include +#include + +extern int optind; +extern char *optarg; + +static char *SourceHost=NULL, *TargetDomain=NULL, *SourceDomain=NULL; +static struct in_addr IpAddress; +static int Force=0, NoClear=0, TaskId=0, ProgramNumber=0, + PortNumber=0, Secure=0; + +static char * +ypxfr_err_string(enum ypxfrstat y) { + switch(y) { + case YPXFR_SUCC: return "Success"; + case YPXFR_AGE: return "Master's version not newer"; + case YPXFR_NOMAP: return "Can't find server for map"; + case YPXFR_NODOM: return "Domain not supported"; + case YPXFR_RSRC: return "Local resource alloc failure"; + case YPXFR_RPC: return "RPC failure talking to server"; + case YPXFR_MADDR: return "Can't get master address"; + case YPXFR_YPERR: return "YP server/map db error"; + case YPXFR_BADARGS: return "Request arguments bad"; + case YPXFR_DBM: return "Local dbm operation failed"; + case YPXFR_FILE: return "Local file I/O operation failed"; + case YPXFR_SKEW: return "Map version skew during transfer"; + case YPXFR_CLEAR: return "Can't send \"Clear\" req to local ypserv"; + case YPXFR_FORCE: return "No local order number in map use -f flag."; + case YPXFR_XFRERR: return "ypxfr error"; + case YPXFR_REFUSED: return "Transfer request refused by ypserv"; + } +} + +ypxfr_foreach(int status, char *key, int keylen, char *val, int vallen, + int *data) +{ + + DBT outKey, outData; + + if (status==YP_NOMORE) + return 0; + if (status!=YP_TRUE) { + int s=ypprot_err(status); + fprintf(stderr, "%s\n", yperr_string(s)); + return 1; + } + + outKey.data=key; outKey.size=(size_t)keylen; + outData.data=val; outData.size=(size_t)vallen; + (db->put)(db,&outKey,&outData,0); + + return 0; +} + +static enum ypxfrstat +ypxfr(char *mapName) { + + int localOrderNum=0; + int masterOrderNum=0; + char *masterName; + struct sockaddr_in localHost; + struct sockaddr_in masterHost; + struct ypall_callback callback; + char dbName[1024]; + char dbName2[1024]; + int y, masterSock; + CLIENT *masterClient; + + memset(&localHost, '\0', sizeof localHost); + localHost.sin_family=AF_INET; + localHost.sin_addr.s_addr=htonl(INADDR_LOOPBACK); + + + if (!SourceHost) { + if ((y=yp_master(SourceDomain, mapName, &masterName))) + return YPXFR_MADDR; + SourceHost=masterName; + } + + memset(&masterHost, '\0', sizeof masterHost); + masterHost.sin_family=AF_INET; + { + struct hostent *h=gethostbyname(SourceHost); + if (!h) { + return YPXFR_MADDR; + } + memcpy(&masterHost.sin_addr, h->h_addr, + sizeof masterHost.sin_addr); + } + + if ((y=_yp_bind(&masterHost, SourceDomain))) return YPXFR_RPC; + + masterSock=RPC_ANYSOCK; + masterClient=clnttcp_create(&masterHost, YPPROG, YPVERS, &masterSock, 0, 0); + if (masterClient==NULL) { + clnt_pcreateerror(""); + return YPXFR_RPC; + } + { + static struct timeval tv = { 25, 0 }; + struct ypreq_nokey req; + struct ypresp_order resp; + int y; + + req.domain=SourceDomain; + req.map=mapName; + y=clnt_call(masterClient, YPPROC_ORDER, xdr_ypreq_nokey, + &req, xdr_ypresp_order, &resp, tv); + if (y!=RPC_SUCCESS) { + clnt_perror(masterClient, "masterOrderNum"); + masterOrderNum=0x7fffffff; + } else { + masterOrderNum=resp.ordernum; + } + xdr_free(xdr_ypresp_order, (char *)&resp); + } + + if (!Force) { + DBT inKey, inVal; + sprintf(dbName, "%s/%s/%s", _PATH_YP, TargetDomain, mapName); + if ((db = dbopen(dbName,O_RDWR|O_EXCL, PERM_SECURE, + DB_HASH, &openinfo)) == NULL) { + perror("dbopen"); + fprintf(stderr, "%s: cannot open - ignored.\n", dbName); + localOrderNum=0; + } else { + inKey.data="YP_LAST_MODIFIED"; inKey.size=strlen(inKey.data); + (db->get)(db,&inKey,&inVal,0); + if (inVal.data) { + int i; + char *d=inVal.data; + for (i=0; iclose)(db); + return YPXFR_SKEW; + } + } + localOrderNum=atoi(inVal.data); + } + (void)(db->close)(db); + } + if (localOrderNum>=masterOrderNum) return YPXFR_AGE; + } + + sprintf(dbName, "%s/%s/%s~", _PATH_YP, TargetDomain, mapName); + if ((db = dbopen(dbName,O_RDWR|O_EXCL|O_CREAT, PERM_SECURE, DB_HASH, + &openinfo)) == NULL) { + fprintf(stderr, "%s: Cannot open\n", dbName); + return YPXFR_DBM; + } + + { + DBT outKey, outData; + char orderNum[12]; + outKey.data="YP_MASTER_NAME"; outKey.size=strlen(outKey.data); + outData.data=SourceHost; outData.size=strlen(outData.data); + (db->put)(db,&outKey,&outData,0); + sprintf(orderNum, "%d", masterOrderNum); + outKey.data="YP_LAST_MODIFIED"; outKey.size=strlen(outKey.data); + outData.data=orderNum; outData.size=strlen(outData.data); + (db->put)(db,&outKey,&outData,0); + } + + + callback.foreach = ypxfr_foreach; + callback.data = NULL; + y=__yp_all(SourceDomain, mapName, &callback); + + (void)(db->close)(db); + sprintf(dbName, "%s/%s/%s~", _PATH_YP, TargetDomain, mapName); + sprintf(dbName2, "%s/%s/%s", _PATH_YP, TargetDomain, mapName); + unlink(dbName2); + rename(dbName, dbName2); + + if (!NoClear) { + memset(&localHost, '\0', sizeof localHost); + localHost.sin_family=AF_INET; + localHost.sin_addr.s_addr=htonl(INADDR_LOOPBACK); + if (_yp_bind(&localHost, TargetDomain) || + _yp_clear(TargetDomain)) return YPXFR_CLEAR; + } + return y==0?YPXFR_SUCC:YPXFR_YPERR; +} + +void +main (int argc, char **argv) +{ + while(1) { + int c=getopt(argc, argv, "fcd:h:s:C:S"); + if (c==EOF) break; + switch (c) { + case 'f': + Force++; + break; + case 'c': + NoClear++; + break; + case 'd': + TargetDomain=optarg; + break; + case 'h': + SourceHost=optarg; + break; + case 's': + SourceDomain=optarg; + break; + case 'C': + TaskId=atoi(optarg); + ProgramNumber=atoi(argv[optind++]); + IpAddress.s_addr=inet_addr(argv[optind++]); + PortNumber=atoi(argv[optind++]); + break; + case 'S': + Secure++; + break; + } + } + argc-=optind; + argv+=optind; + + if (!TargetDomain) { + yp_get_default_domain(&TargetDomain); + } + if (!SourceDomain) { + SourceDomain=TargetDomain; + } + + for (; *argv; argv++) { + enum ypxfrstat y; + if ((y=ypxfr(*argv))!=YPXFR_SUCC) { + fprintf(stderr, "%s\n", ypxfr_err_string(y)); + } + if (TaskId) { + struct sockaddr_in addr; + struct timeval wait; + CLIENT *clnt; + int s; + ypresp_xfr resp; + static struct timeval tv={0,0}; + + memset(&addr, '\0', sizeof addr); + addr.sin_addr=IpAddress; + addr.sin_port=htons(PortNumber); + addr.sin_family=AF_INET; + wait.tv_sec=25; wait.tv_usec=0; + s=RPC_ANYSOCK; + + clnt=clntudp_create(&addr, ProgramNumber, 1, wait, &s); + if (!clnt) { + clnt_pcreateerror("ypxfr_callback"); + continue; + } + + resp.transid=TaskId; + resp.xfrstat=y; + switch (clnt_call(clnt, 1, xdr_ypresp_xfr, &resp, + xdr_void, NULL, tv)) { + case RPC_SUCCESS: + case RPC_TIMEDOUT: + break; + default: + clnt_perror(clnt, "ypxfr_callback"); + } + + clnt_destroy(clnt); + } + } + + exit(0); + +} -- cgit v1.1