From 4c65cdeaf90bb3e5dc095270b746b620a7336594 Mon Sep 17 00:00:00 2001 From: wpaul Date: Thu, 14 Dec 1995 05:16:45 +0000 Subject: Now that rpcgen is squared away, arrange to have all the NIS XDR routines rpcgen-erated on the fly (just like librpcsvc). Makefile: Add rule for generating yp_xdr.c and yp.h. xdryp.c: gut everything except the special ypresp_all XDR function needed to to handle yp_all() (this one can't be created on the fly), and xdr_datum(), which isn't used internally by libc, but which as documented as being there in yp_prot.h, so what the hell. We now get everything else from yp_xdr.c. yplib.c: change a few structure member names to match those found in yp.h instead of those declared in yp_prot.h. --- lib/libc/yp/Makefile.inc | 13 +- lib/libc/yp/xdryp.c | 440 +++-------------------------------------------- lib/libc/yp/yplib.c | 88 ++++++---- 3 files changed, 93 insertions(+), 448 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/yp/Makefile.inc b/lib/libc/yp/Makefile.inc index 9afbedf..529de75 100644 --- a/lib/libc/yp/Makefile.inc +++ b/lib/libc/yp/Makefile.inc @@ -1,8 +1,17 @@ # from: @(#)Makefile.inc 5.3 (Berkeley) 2/20/91 -# $Id: Makefile.inc,v 1.1 1993/11/01 23:56:27 paul Exp $ +# $Id: Makefile.inc,v 1.1 1994/08/07 23:04:53 wollman Exp $ # yp sources .PATH: ${.CURDIR}/yp -SRCS+= xdryp.c yplib.c +SRCS+= xdryp.c yp_xdr.c yplib.c +CLEANFILES+= yp_xdr.c yp.h +RPCSRC= ${.DESTDIR}/usr/include/rpcsvc/yp.x +RPCGEN= rpcgen + +yp_xdr.c: ${RPCSRC} yp.h + ${RPCGEN} -c -o ${.TARGET} ${RPCSRC} + +yp.h: ${RPCSRC} + ${RPCGEN} -h -o ${.TARGET} ${RPCSRC} diff --git a/lib/libc/yp/xdryp.c b/lib/libc/yp/xdryp.c index c12250b..51a3878 100644 --- a/lib/libc/yp/xdryp.c +++ b/lib/libc/yp/xdryp.c @@ -28,76 +28,25 @@ */ #ifndef LINT -static char *rcsid = "$Id: xdryp.c,v 1.2 1995/04/02 01:02:17 wpaul Exp $"; +static char *rcsid = "$Id: xdryp.c,v 1.3 1995/04/02 19:58:29 wpaul Exp $"; #endif -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include extern int (*ypresp_allfn)(); extern void *ypresp_data; -struct ypresp_all { - bool_t more; - union { - struct ypresp_key_val val; - } ypresp_all_u; -}; - -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, -}; - -struct ypresp_xfr { - u_int transid; - enum ypxfrstat xfrstat; -}; - -bool_t -xdr_domainname(xdrs, objp) -XDR *xdrs; -char *objp; -{ - if (!xdr_string(xdrs, &objp, YPMAXDOMAIN)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_peername(xdrs, objp) -XDR *xdrs; -char *objp; -{ - if (!xdr_string(xdrs, &objp, YPMAXPEER)) { - return (FALSE); - } - return (TRUE); -} +/* + * I'm leaving the xdr_datum() function in purely for backwards + * compatibility. yplib.c doesn't actually use it, but it's listed + * in yp_prot.h as being available, so it's probably a good idea to + * leave it in in case somebody goes looking for it. + */ +typedef struct { + char *dptr; + int dsize; +} datum; bool_t xdr_datum(xdrs, objp) @@ -111,191 +60,6 @@ datum *objp; } bool_t -xdr_mapname(xdrs, objp) -XDR *xdrs; -char *objp; -{ - if (!xdr_string(xdrs, &objp, YPMAXMAP)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypreq_key(xdrs, objp) -XDR *xdrs; -struct ypreq_key *objp; -{ - if (!xdr_domainname(xdrs, objp->domain)) { - return (FALSE); - } - if (!xdr_mapname(xdrs, objp->map)) { - return (FALSE); - } - if (!xdr_datum(xdrs, &objp->keydat)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypreq_nokey(xdrs, objp) -XDR *xdrs; -struct ypreq_nokey *objp; -{ - if (!xdr_domainname(xdrs, objp->domain)) { - return (FALSE); - } - if (!xdr_mapname(xdrs, objp->map)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_yp_inaddr(xdrs, objp) -XDR *xdrs; -struct in_addr *objp; -{ - if (!xdr_opaque(xdrs, (caddr_t)&objp->s_addr, sizeof objp->s_addr)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypbind_binding(xdrs, objp) -XDR *xdrs; -struct ypbind_binding *objp; -{ - if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr)) { - return (FALSE); - } - if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port, - sizeof objp->ypbind_binding_port)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypbind_resptype(xdrs, objp) -XDR *xdrs; -enum ypbind_resptype *objp; -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypstat(xdrs, objp) -XDR *xdrs; -enum ypbind_resptype *objp; -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypbind_resp(xdrs, objp) -XDR *xdrs; -struct ypbind_resp *objp; -{ - if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status)) { - return (FALSE); - } - switch (objp->ypbind_status) { - case YPBIND_FAIL_VAL: - if (!xdr_u_int(xdrs, (u_int *)&objp->ypbind_respbody.ypbind_error)) { - return (FALSE); - } - break; - case YPBIND_SUCC_VAL: - if (!xdr_ypbind_binding(xdrs, &objp->ypbind_respbody.ypbind_bindinfo)) { - return (FALSE); - } - break; - default: - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypresp_val(xdrs, objp) -XDR *xdrs; -struct ypresp_val *objp; -{ - if (!xdr_ypstat(xdrs, &objp->status)) { - return (FALSE); - } - if (!xdr_datum(xdrs, &objp->valdat)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypbind_setdom(xdrs, objp) -XDR *xdrs; -struct ypbind_setdom *objp; -{ - if (!xdr_domainname(xdrs, objp->ypsetdom_domain)) { - return (FALSE); - } - if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding)) { - return (FALSE); - } - if (!xdr_u_short(xdrs, &objp->ypsetdom_vers)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypresp_key_val(xdrs, objp) -XDR *xdrs; -struct ypresp_key_val *objp; -{ - if (!xdr_ypstat(xdrs, &objp->status)) { - return (FALSE); - } - if (!xdr_datum(xdrs, &objp->valdat)) { - return (FALSE); - } - if (!xdr_datum(xdrs, &objp->keydat)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypresp_all(xdrs, objp) -XDR *xdrs; -struct ypresp_all *objp; -{ - 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); - } - break; - case FALSE: - break; - default: - return (FALSE); - } - return (TRUE); -} - -bool_t xdr_ypresp_all_seq(xdrs, objp) XDR *xdrs; u_long *objp; @@ -316,22 +80,22 @@ u_long *objp; xdr_free(xdr_ypresp_all, (char *)&out); return FALSE; } - status = out.ypresp_all_u.val.status; + status = out.ypresp_all_u.val.stat; switch(status) { case YP_TRUE: - key = (char *)malloc(out.ypresp_all_u.val.keydat.dsize + 1); - bcopy(out.ypresp_all_u.val.keydat.dptr, key, - out.ypresp_all_u.val.keydat.dsize); - key[out.ypresp_all_u.val.keydat.dsize] = '\0'; - val = (char *)malloc(out.ypresp_all_u.val.valdat.dsize + 1); - bcopy(out.ypresp_all_u.val.valdat.dptr, val, - out.ypresp_all_u.val.valdat.dsize); - val[out.ypresp_all_u.val.valdat.dsize] = '\0'; + key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1); + bcopy(out.ypresp_all_u.val.key.keydat_val, key, + out.ypresp_all_u.val.key.keydat_len); + key[out.ypresp_all_u.val.key.keydat_len] = '\0'; + val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1); + bcopy(out.ypresp_all_u.val.val.valdat_val, val, + out.ypresp_all_u.val.val.valdat_len); + val[out.ypresp_all_u.val.val.valdat_len] = '\0'; xdr_free(xdr_ypresp_all, (char *)&out); r = (*ypresp_allfn)(status, - key, out.ypresp_all_u.val.keydat.dsize, - val, out.ypresp_all_u.val.valdat.dsize, + key, out.ypresp_all_u.val.key.keydat_len, + val, out.ypresp_all_u.val.val.valdat_len, ypresp_data); *objp = status; free(key); @@ -349,161 +113,3 @@ u_long *objp; } } } - -bool_t -xdr_ypresp_master(xdrs, objp) -XDR *xdrs; -struct ypresp_master *objp; -{ - if (!xdr_ypstat(xdrs, &objp->status)) { - return (FALSE); - } - if (!xdr_string(xdrs, &objp->master, YPMAXPEER)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypmaplist_str(xdrs, objp) -XDR *xdrs; -char *objp; -{ - if (!xdr_string(xdrs, &objp, YPMAXMAP+1)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypmaplist(xdrs, objp) -XDR *xdrs; -struct ypmaplist *objp; -{ - if (!xdr_ypmaplist_str(xdrs, objp->ypml_name)) { - return (FALSE); - } - if (!xdr_pointer(xdrs, (caddr_t *)&objp->ypml_next, - sizeof(struct ypmaplist), xdr_ypmaplist)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypresp_maplist(xdrs, objp) -XDR *xdrs; -struct ypresp_maplist *objp; -{ - if (!xdr_ypstat(xdrs, &objp->status)) { - return (FALSE); - } - if (!xdr_pointer(xdrs, (caddr_t *)&objp->list, - sizeof(struct ypmaplist), xdr_ypmaplist)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypresp_order(xdrs, objp) -XDR *xdrs; -struct ypresp_order *objp; -{ - if (!xdr_ypstat(xdrs, &objp->status)) { - return (FALSE); - } - if (!xdr_u_long(xdrs, &objp->ordernum)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypxfrstat(xdrs, objp) -XDR *xdrs; -enum ypxfrstat *objp; -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_ypresp_xfr(xdrs, objp) -XDR *xdrs; -struct 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_ypmap_parms(xdrs, objp) -XDR *xdrs; -struct ypmap_parms *objp; -{ - if (!xdr_domainname(xdrs, objp->domain)) { - return (FALSE); - } - if (!xdr_mapname(xdrs, objp->map)) { - return (FALSE); - } - if (!xdr_u_long(xdrs, &objp->ordernum)) { - return (FALSE); - } - if (!xdr_peername(xdrs, objp->owner)) { - return (FALSE); - } -} - -bool_t -xdr_ypreq_xfr(xdrs, objp) -XDR *xdrs; -struct ypreq_xfr *objp; -{ - if (!xdr_ypmap_parms(xdrs, &objp->map_parms)) { - return (FALSE); - } - if (!xdr_u_long(xdrs, &objp->transid)) { - return (FALSE); - } - if (!xdr_u_long(xdrs, &objp->proto)) { - return (FALSE); - } - if (!xdr_u_short(xdrs, &objp->port)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_yppush_status(xdrs, objp) -XDR *xdrs; -enum yppush_status *objp; -{ - if (!xdr_enum(xdrs, (enum_t *)objp)) { - return (FALSE); - } - return (TRUE); -} - -bool_t -xdr_yppushresp_xfr(xdrs, objp) -XDR *xdrs; -struct yppushresp_xfr *objp; -{ - if (!xdr_u_long(xdrs, &objp->transid)) { - return (FALSE); - } - if (!xdr_yppush_status(xdrs, &objp->status)) { - return (FALSE); - } - return (TRUE); -} diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index 2765a9b..0e11353 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -28,7 +28,7 @@ */ #ifndef LINT -static char *rcsid = "$Id: yplib.c,v 1.12 1995/09/02 04:16:21 wpaul Exp $"; +static char *rcsid = "$Id: yplib.c,v 1.13 1995/11/05 05:39:04 wpaul Exp $"; #endif #include @@ -43,7 +43,37 @@ static char *rcsid = "$Id: yplib.c,v 1.12 1995/09/02 04:16:21 wpaul Exp $"; #include #include #include -#include +#include + + +/* + * We have to define these here due to clashes between yp_prot.h and + * yp.h. + */ + +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; +}; + +struct _ypbind_binding { + struct in_addr ypbind_binding_addr; /* In network order */ + unsigned short int ypbind_binding_port; /* In network order */ +}; +struct _ypbind_resp { + enum ypbind_resptype ypbind_status; + union { + unsigned long ypbind_error; + struct _ypbind_binding ypbind_bindinfo; + } ypbind_respbody; +}; + #include #ifndef YPBINDLOCK @@ -200,7 +230,7 @@ struct dom_binding **ypdb; static int pid = -1; char path[MAXPATHLEN]; struct dom_binding *ysd, *ysd2; - struct ypbind_resp ypbr; + struct _ypbind_resp ypbr; struct timeval tv; struct sockaddr_in clnt_sin; int clnt_sock, lfd, fd, gpid; @@ -271,7 +301,7 @@ again: } if( flock(fd, LOCK_EX|LOCK_NB) == -1 && errno==EWOULDBLOCK) { struct iovec iov[2]; - struct ypbind_resp ybr; + struct _ypbind_resp ybr; u_short ypb_port; iov[0].iov_base = (caddr_t)&ypb_port; @@ -444,10 +474,10 @@ int *outvallen; #ifdef YPMATCHCACHE if( !strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey, - inkeylen, &yprv.valdat.dptr, &yprv.valdat.dsize)) { - *outvallen = yprv.valdat.dsize; + inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) { + *outvallen = yprv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); - bcopy(yprv.valdat.dptr, *outval, *outvallen); + bcopy(yprv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; return 0; } @@ -462,8 +492,8 @@ again: yprk.domain = indomain; yprk.map = inmap; - yprk.keydat.dptr = (char *)inkey; - yprk.keydat.dsize = inkeylen; + yprk.key.keydat_val = (char *)inkey; + yprk.key.keydat_len = inkeylen; bzero((char *)&yprv, sizeof yprv); @@ -474,10 +504,10 @@ again: ysd->dom_vers = -1; goto again; } - if( !(r=ypprot_err(yprv.status)) ) { - *outvallen = yprv.valdat.dsize; + if( !(r=ypprot_err(yprv.stat)) ) { + *outvallen = yprv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); - bcopy(yprv.valdat.dptr, *outval, *outvallen); + bcopy(yprv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; #ifdef YPMATCHCACHE if( strcmp(_yp_domain, indomain)==0 ) @@ -543,14 +573,14 @@ again: ysd->dom_vers = 0; goto again; } - if( !(r=ypprot_err(yprkv.status)) ) { - *outkeylen = yprkv.keydat.dsize; + if( !(r=ypprot_err(yprkv.stat)) ) { + *outkeylen = yprkv.key.keydat_len; *outkey = (char *)malloc(*outkeylen+1); - bcopy(yprkv.keydat.dptr, *outkey, *outkeylen); + bcopy(yprkv.key.keydat_val, *outkey, *outkeylen); (*outkey)[*outkeylen] = '\0'; - *outvallen = yprkv.valdat.dsize; + *outvallen = yprkv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); - bcopy(yprkv.valdat.dptr, *outval, *outvallen); + bcopy(yprkv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; } xdr_free(xdr_ypresp_key_val, (char *)&yprkv); @@ -594,8 +624,8 @@ again: yprk.domain = indomain; yprk.map = inmap; - yprk.keydat.dptr = inkey; - yprk.keydat.dsize = inkeylen; + yprk.key.keydat_val = inkey; + yprk.key.keydat_len = inkeylen; bzero((char *)&yprkv, sizeof yprkv); r = clnt_call(ysd->dom_client, YPPROC_NEXT, @@ -605,14 +635,14 @@ again: ysd->dom_vers = -1; goto again; } - if( !(r=ypprot_err(yprkv.status)) ) { - *outkeylen = yprkv.keydat.dsize; + if( !(r=ypprot_err(yprkv.stat)) ) { + *outkeylen = yprkv.key.keydat_len; *outkey = (char *)malloc(*outkeylen+1); - bcopy(yprkv.keydat.dptr, *outkey, *outkeylen); + bcopy(yprkv.key.keydat_val, *outkey, *outkeylen); (*outkey)[*outkeylen] = '\0'; - *outvallen = yprkv.valdat.dsize; + *outvallen = yprkv.val.valdat_len; *outval = (char *)malloc(*outvallen+1); - bcopy(yprkv.valdat.dptr, *outval, *outvallen); + bcopy(yprkv.val.valdat_val, *outval, *outvallen); (*outval)[*outvallen] = '\0'; } xdr_free(xdr_ypresp_key_val, (char *)&yprkv); @@ -711,7 +741,7 @@ again: *outorder = ypro.ordernum; xdr_free(xdr_ypresp_order, (char *)&ypro); _yp_unbind(ysd); - return ypprot_err(ypro.status); + return ypprot_err(ypro.stat); } int @@ -750,8 +780,8 @@ again: ysd->dom_vers = -1; goto again; } - if( !(r=ypprot_err(yprm.status)) ) { - *outname = (char *)strdup(yprm.master); + if( !(r=ypprot_err(yprm.stat)) ) { + *outname = (char *)strdup(yprm.peer); } xdr_free(xdr_ypresp_master, (char *)&yprm); _yp_unbind(ysd); @@ -788,10 +818,10 @@ again: ysd->dom_vers = -1; goto again; } - *outmaplist = ypml.list; + *outmaplist = ypml.maps; /* NO: xdr_free(xdr_ypresp_maplist, &ypml);*/ _yp_unbind(ysd); - return ypprot_err(ypml.status); + return ypprot_err(ypml.stat); } char * -- cgit v1.1