[BACK]Return to xdryp.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / yp

Annotation of src/lib/libc/yp/xdryp.c, Revision 1.19.2.1

1.19.2.1! thorpej     1: /*     $NetBSD: xdryp.c,v 1.19 1997/10/20 22:05:38 thorpej Exp $       */
1.8       cgd         2:
1.3       deraadt     3: /*
1.12      thorpej     4:  * Copyright (c) 1996 Jason R. Thorpe <thorpej@NetBSD.ORG>.
                      5:  * All rights reserved.
                      6:  *
1.6       deraadt     7:  * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
1.3       deraadt     8:  * All rights reserved.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
1.6       deraadt    18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed by Theo de Raadt.
1.12      thorpej    21:  *     This product includes software developed for the NetBSD Project
                     22:  *     by Jason R. Thorpe.
1.6       deraadt    23:  * 4. The name of the author may not be used to endorse or promote products
                     24:  *    derived from this software without specific prior written permission.
1.3       deraadt    25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
                     27:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                     28:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     29:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
                     30:  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     31:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     32:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     33:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     34:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     35:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     36:  * SUCH DAMAGE.
                     37:  */
                     38:
1.16      christos   39: #include <sys/cdefs.h>
1.10      jtc        40: #if defined(LIBC_SCCS) && !defined(lint)
1.19.2.1! thorpej    41: __RCSID("$NetBSD: xdryp.c,v 1.19 1997/10/20 22:05:38 thorpej Exp $");
1.3       deraadt    42: #endif
                     43:
1.12      thorpej    44: /*
                     45:  * XDR routines used by the YP protocol.  Note that these routines do
                     46:  * not strictly conform to the RPC definition in yp.x.  This file
                     47:  * replicates the functions exported by the Sun YP API; reality is
                     48:  * often inaccurate.
                     49:  */
                     50:
1.17      jtc        51: #include "namespace.h"
1.1       deraadt    52: #include <sys/param.h>
                     53: #include <sys/types.h>
                     54: #include <sys/socket.h>
                     55: #include <stdio.h>
1.7       jtc        56: #include <stdlib.h>
                     57: #include <string.h>
1.1       deraadt    58: #include <ctype.h>
                     59: #include <rpc/rpc.h>
                     60: #include <rpc/xdr.h>
                     61: #include <rpcsvc/yp_prot.h>
                     62: #include <rpcsvc/ypclnt.h>
1.17      jtc        63:
                     64: #ifdef __weak_alias
                     65: __weak_alias(xdr_datum,_xdr_datum);
                     66: __weak_alias(xdr_domainname,_xdr_domainname);
                     67: __weak_alias(xdr_mapname,_xdr_mapname);
                     68: __weak_alias(xdr_peername,_xdr_peername);
                     69: __weak_alias(xdr_yp_inaddr,_xdr_yp_inaddr);
                     70: __weak_alias(xdr_ypall,_xdr_ypall);
                     71: __weak_alias(xdr_ypbind_resp,_xdr_ypbind_resp);
                     72: __weak_alias(xdr_ypbind_setdom,_xdr_ypbind_setdom);
                     73: __weak_alias(xdr_ypdomain_wrap_string,_xdr_ypdomain_wrap_string);
                     74: __weak_alias(xdr_ypmap_parms,_xdr_ypmap_parms);
                     75: __weak_alias(xdr_ypmap_wrap_string,_xdr_ypmap_wrap_string);
                     76: __weak_alias(xdr_ypmaplist,_xdr_ypmaplist);
                     77: __weak_alias(xdr_ypowner_wrap_string,_xdr_ypowner_wrap_string);
                     78: __weak_alias(xdr_yppushresp_xfr,_xdr_yppushresp_xfr);
                     79: __weak_alias(xdr_ypreq_key,_xdr_ypreq_key);
                     80: __weak_alias(xdr_ypreq_nokey,_xdr_ypreq_nokey);
                     81: __weak_alias(xdr_ypreq_xfr,_xdr_ypreq_xfr);
                     82: __weak_alias(xdr_ypresp_key_val,_xdr_ypresp_key_val);
                     83: __weak_alias(xdr_ypresp_maplist,_xdr_ypresp_maplist);
                     84: __weak_alias(xdr_ypresp_master,_xdr_ypresp_master);
                     85: __weak_alias(xdr_ypresp_order,_xdr_ypresp_order);
                     86: __weak_alias(xdr_ypresp_val,_xdr_ypresp_val);
                     87: #endif
1.1       deraadt    88:
1.12      thorpej    89: /*
                     90:  * Functions used only within this file.
                     91:  */
                     92: static bool_t xdr_ypbind_binding __P((XDR *, struct ypbind_binding *));
                     93: static bool_t xdr_ypbind_resptype __P((XDR *, enum ypbind_resptype *));
                     94: static bool_t xdr_ypstat __P((XDR *, enum ypbind_resptype *));
                     95: static bool_t xdr_ypmaplist_str __P((XDR *, char *));
                     96:
1.19      thorpej    97: __warn_references(xdr_domainname,
1.19.2.1! thorpej    98:     "warning: this program uses xdr_domainname(), which is deprecated and buggy.")
1.19      thorpej    99:
                    100: bool_t
                    101: xdr_domainname(xdrs, objp)
                    102:        XDR *xdrs;
                    103:        char *objp;
                    104: {
                    105:        return xdr_string(xdrs, &objp, YPMAXDOMAIN);
                    106: }
                    107:
                    108: __warn_references(xdr_peername,
1.19.2.1! thorpej   109:     "warning: this program uses xdr_peername(), which is deprecated and buggy.")
1.19      thorpej   110:
                    111: bool_t
                    112: xdr_peername(xdrs, objp)
                    113:        XDR *xdrs;
                    114:        char *objp;
                    115: {
                    116:        return xdr_string(xdrs, &objp, YPMAXPEER);
                    117: }
                    118:
                    119: __warn_references(xdr_mapname,
1.19.2.1! thorpej   120:     "warning: this program uses xdr_mapname(), which is deprecated and buggy.")
1.19      thorpej   121:
                    122: bool_t
                    123: xdr_mapname(xdrs, objp)
                    124:        XDR *xdrs;
                    125:        char *objp;
                    126: {
                    127:        return xdr_string(xdrs, &objp, YPMAXMAP);
                    128: }
                    129:
1.12      thorpej   130: bool_t
                    131: xdr_ypdomain_wrap_string(xdrs, objp)
                    132:        XDR *xdrs;
                    133:        char **objp;
                    134: {
                    135:        return xdr_string(xdrs, objp, YPMAXDOMAIN);
                    136: }
                    137:
                    138: bool_t
                    139: xdr_ypmap_wrap_string(xdrs, objp)
                    140:        XDR *xdrs;
                    141:        char **objp;
                    142: {
                    143:        return xdr_string(xdrs, objp, YPMAXMAP);
                    144: }
                    145:
1.1       deraadt   146: bool_t
1.12      thorpej   147: xdr_ypowner_wrap_string(xdrs, objp)
                    148:        XDR *xdrs;
                    149:        char **objp;
1.1       deraadt   150: {
1.12      thorpej   151:        return xdr_string(xdrs, objp, YPMAXPEER);
1.1       deraadt   152: }
                    153:
                    154: bool_t
1.12      thorpej   155: xdr_datum(xdrs, objp)
                    156:        XDR *xdrs;
                    157:        datum *objp;
1.1       deraadt   158: {
1.12      thorpej   159:        return xdr_bytes(xdrs, (char **)&objp->dptr,
                    160:            (u_int *)&objp->dsize, YPMAXRECORD);
1.1       deraadt   161: }
                    162:
                    163: bool_t
                    164: xdr_ypreq_key(xdrs, objp)
1.12      thorpej   165:        XDR *xdrs;
                    166:        struct ypreq_key *objp;
1.1       deraadt   167: {
1.13      christos  168:        if (!xdr_ypdomain_wrap_string(xdrs, (char **)&objp->domain))
1.9       christos  169:                return FALSE;
1.12      thorpej   170:
1.13      christos  171:        if (!xdr_ypmap_wrap_string(xdrs, (char **)&objp->map))
1.9       christos  172:                return FALSE;
1.12      thorpej   173:
1.13      christos  174:        if (!xdr_datum(xdrs, &objp->keydat))
                    175:                return FALSE;
                    176:
                    177:        return TRUE;
1.1       deraadt   178: }
                    179:
                    180: bool_t
                    181: xdr_ypreq_nokey(xdrs, objp)
1.12      thorpej   182:        XDR *xdrs;
                    183:        struct ypreq_nokey *objp;
1.1       deraadt   184: {
1.13      christos  185:        if (!xdr_ypdomain_wrap_string(xdrs, (char **)&objp->domain))
                    186:                return FALSE;
                    187:
                    188:        if (!xdr_ypmap_wrap_string(xdrs, (char **)&objp->map))
1.9       christos  189:                return FALSE;
1.12      thorpej   190:
1.13      christos  191:        return TRUE;
1.1       deraadt   192: }
                    193:
                    194: bool_t
                    195: xdr_yp_inaddr(xdrs, objp)
1.12      thorpej   196:        XDR *xdrs;
                    197:        struct in_addr *objp;
1.1       deraadt   198: {
1.7       jtc       199:        return xdr_opaque(xdrs, (caddr_t)&objp->s_addr, sizeof objp->s_addr);
1.1       deraadt   200: }
                    201:
1.12      thorpej   202: static bool_t
1.1       deraadt   203: xdr_ypbind_binding(xdrs, objp)
1.12      thorpej   204:        XDR *xdrs;
                    205:        struct ypbind_binding *objp;
1.1       deraadt   206: {
1.12      thorpej   207:        if (!xdr_yp_inaddr(xdrs, &objp->ypbind_binding_addr))
1.9       christos  208:                return FALSE;
1.12      thorpej   209:
1.13      christos  210:        if (!xdr_opaque(xdrs, (void *)&objp->ypbind_binding_port,
                    211:            sizeof objp->ypbind_binding_port))
                    212:                return FALSE;
                    213:
                    214:        return TRUE;
1.1       deraadt   215: }
                    216:
1.12      thorpej   217: static bool_t
1.1       deraadt   218: xdr_ypbind_resptype(xdrs, objp)
1.12      thorpej   219:        XDR *xdrs;
                    220:        enum ypbind_resptype *objp;
1.1       deraadt   221: {
1.7       jtc       222:        return xdr_enum(xdrs, (enum_t *)objp);
1.1       deraadt   223: }
                    224:
1.12      thorpej   225: static bool_t
1.1       deraadt   226: xdr_ypstat(xdrs, objp)
1.12      thorpej   227:        XDR *xdrs;
                    228:        enum ypbind_resptype *objp;
1.1       deraadt   229: {
1.7       jtc       230:        return xdr_enum(xdrs, (enum_t *)objp);
1.1       deraadt   231: }
                    232:
                    233: bool_t
                    234: xdr_ypbind_resp(xdrs, objp)
1.12      thorpej   235:        XDR *xdrs;
                    236:        struct ypbind_resp *objp;
1.1       deraadt   237: {
1.12      thorpej   238:        if (!xdr_ypbind_resptype(xdrs, &objp->ypbind_status))
1.9       christos  239:                return FALSE;
                    240:
1.1       deraadt   241:        switch (objp->ypbind_status) {
                    242:        case YPBIND_FAIL_VAL:
1.9       christos  243:                return xdr_u_int(xdrs,
1.12      thorpej   244:                    (u_int *)&objp->ypbind_respbody.ypbind_error);
                    245:
1.1       deraadt   246:        case YPBIND_SUCC_VAL:
1.12      thorpej   247:                return xdr_ypbind_binding(xdrs,
                    248:                    &objp->ypbind_respbody.ypbind_bindinfo);
                    249:
1.1       deraadt   250:        default:
1.9       christos  251:                return FALSE;
1.1       deraadt   252:        }
1.7       jtc       253:        /* NOTREACHED */
1.1       deraadt   254: }
                    255:
                    256: bool_t
                    257: xdr_ypresp_val(xdrs, objp)
1.12      thorpej   258:        XDR *xdrs;
                    259:        struct ypresp_val *objp;
1.1       deraadt   260: {
1.12      thorpej   261:        if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status))
1.9       christos  262:                return FALSE;
1.12      thorpej   263:
1.13      christos  264:        if (!xdr_datum(xdrs, &objp->valdat))
                    265:                return FALSE;
                    266:
                    267:        return TRUE;
1.1       deraadt   268: }
                    269:
                    270: bool_t
                    271: xdr_ypbind_setdom(xdrs, objp)
1.12      thorpej   272:        XDR *xdrs;
                    273:        struct ypbind_setdom *objp;
1.1       deraadt   274: {
1.12      thorpej   275:        char *cp = objp->ypsetdom_domain;
                    276:
1.13      christos  277:        if (!xdr_ypdomain_wrap_string(xdrs, &cp))
1.9       christos  278:                return FALSE;
1.12      thorpej   279:
                    280:        if (!xdr_ypbind_binding(xdrs, &objp->ypsetdom_binding))
1.9       christos  281:                return FALSE;
1.12      thorpej   282:
1.14      thorpej   283:        if (!xdr_u_int(xdrs, &objp->ypsetdom_vers))
1.13      christos  284:                return FALSE;
                    285:
                    286:        return TRUE;
1.1       deraadt   287: }
                    288:
                    289: bool_t
                    290: xdr_ypresp_key_val(xdrs, objp)
1.12      thorpej   291:        XDR *xdrs;
                    292:        struct ypresp_key_val *objp;
1.1       deraadt   293: {
1.12      thorpej   294:        if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status))
1.9       christos  295:                return FALSE;
1.12      thorpej   296:
                    297:        if (!xdr_datum(xdrs, &objp->valdat))
1.9       christos  298:                return FALSE;
1.12      thorpej   299:
1.13      christos  300:        if (!xdr_datum(xdrs, &objp->keydat))
                    301:                return FALSE;
                    302:
                    303:        return TRUE;
1.1       deraadt   304: }
                    305:
                    306: bool_t
1.12      thorpej   307: xdr_ypall(xdrs, incallback)
                    308:        XDR *xdrs;
                    309:        struct ypall_callback *incallback;
                    310: {
                    311:        struct ypresp_key_val out;
                    312:        char key[YPMAXRECORD], val[YPMAXRECORD];
                    313:        bool_t more, status;
1.1       deraadt   314:
1.12      thorpej   315:        /*
                    316:         * Set up key/val struct to be used during the transaction.
                    317:         */
1.7       jtc       318:        memset(&out, 0, sizeof out);
1.12      thorpej   319:        out.keydat.dptr = key;
                    320:        out.keydat.dsize = sizeof(key);
                    321:        out.valdat.dptr = val;
                    322:        out.valdat.dsize = sizeof(val);
                    323:
                    324:        for (;;) {
                    325:                /* Values pending? */
                    326:                if (!xdr_bool(xdrs, &more))
                    327:                        return FALSE;           /* can't tell! */
1.13      christos  328:                if (!more)
1.12      thorpej   329:                        return TRUE;            /* no more */
                    330:
                    331:                /* Transfer key/value pair. */
                    332:                status = xdr_ypresp_key_val(xdrs, &out);
                    333:
                    334:                /*
                    335:                 * If we succeeded, call the callback function.
                    336:                 * The callback will return TRUE when it wants
                    337:                 * no more values.  If we fail, indicate the
                    338:                 * error.
                    339:                 */
1.13      christos  340:                if (status) {
1.12      thorpej   341:                        if ((*incallback->foreach)(out.status,
                    342:                            (char *)out.keydat.dptr, out.keydat.dsize,
                    343:                            (char *)out.valdat.dptr, out.valdat.dsize,
                    344:                            incallback->data))
                    345:                                return TRUE;
                    346:                } else
1.1       deraadt   347:                        return FALSE;
                    348:        }
                    349: }
                    350:
                    351: bool_t
                    352: xdr_ypresp_master(xdrs, objp)
1.12      thorpej   353:        XDR *xdrs;
                    354:        struct ypresp_master *objp;
1.1       deraadt   355: {
1.12      thorpej   356:        if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status))
1.9       christos  357:                return FALSE;
1.12      thorpej   358:
1.13      christos  359:        if (!xdr_string(xdrs, &objp->master, YPMAXPEER))
                    360:                return FALSE;
                    361:
                    362:        return TRUE;
1.1       deraadt   363: }
                    364:
1.12      thorpej   365: static bool_t
1.1       deraadt   366: xdr_ypmaplist_str(xdrs, objp)
1.12      thorpej   367:        XDR *xdrs;
                    368:        char *objp;
1.1       deraadt   369: {
1.7       jtc       370:        return xdr_string(xdrs, &objp, YPMAXMAP+1);
1.1       deraadt   371: }
                    372:
                    373: bool_t
                    374: xdr_ypmaplist(xdrs, objp)
1.12      thorpej   375:        XDR *xdrs;
                    376:        struct ypmaplist *objp;
1.1       deraadt   377: {
1.12      thorpej   378:        if (!xdr_ypmaplist_str(xdrs, objp->ypml_name))
1.9       christos  379:                return FALSE;
1.12      thorpej   380:
1.13      christos  381:        if (!xdr_pointer(xdrs, (caddr_t *)&objp->ypml_next,
                    382:            sizeof(struct ypmaplist), xdr_ypmaplist))
                    383:                return FALSE;
                    384:
                    385:        return TRUE;
1.1       deraadt   386: }
                    387:
                    388: bool_t
                    389: xdr_ypresp_maplist(xdrs, objp)
1.12      thorpej   390:        XDR *xdrs;
                    391:        struct ypresp_maplist *objp;
1.1       deraadt   392: {
1.12      thorpej   393:        if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status))
1.9       christos  394:                return FALSE;
1.12      thorpej   395:
1.13      christos  396:        if (!xdr_pointer(xdrs, (caddr_t *)&objp->list,
                    397:            sizeof(struct ypmaplist), xdr_ypmaplist))
                    398:                return FALSE;
                    399:
                    400:        return TRUE;
1.1       deraadt   401: }
                    402:
                    403: bool_t
                    404: xdr_ypresp_order(xdrs, objp)
1.12      thorpej   405:        XDR *xdrs;
                    406:        struct ypresp_order *objp;
1.1       deraadt   407: {
1.12      thorpej   408:        if (!xdr_ypstat(xdrs, (enum ypbind_resptype *)&objp->status))
1.9       christos  409:                return FALSE;
1.12      thorpej   410:
1.14      thorpej   411:        if (!xdr_u_int(xdrs, &objp->ordernum))
1.13      christos  412:                return FALSE;
                    413:
                    414:        return TRUE;
1.12      thorpej   415: }
                    416:
                    417: bool_t
                    418: xdr_ypreq_xfr(xdrs, objp)
                    419:        XDR *xdrs;
                    420:        struct ypreq_xfr *objp;
                    421: {
1.13      christos  422:        if (!xdr_ypmap_parms(xdrs, &objp->map_parms))
1.12      thorpej   423:                return FALSE;
                    424:
1.14      thorpej   425:        if (!xdr_u_int(xdrs, &objp->transid))
1.12      thorpej   426:                return FALSE;
                    427:
1.14      thorpej   428:        if (!xdr_u_int(xdrs, &objp->proto))
1.12      thorpej   429:                return FALSE;
                    430:
1.14      thorpej   431:        if (!xdr_u_int(xdrs, &objp->port))
1.12      thorpej   432:                return FALSE;
                    433:
                    434:        return TRUE;
                    435: }
                    436:
                    437: bool_t
                    438: xdr_ypmap_parms(xdrs, objp)
                    439:        XDR *xdrs;
                    440:        struct ypmap_parms *objp;
                    441: {
1.15      chuck     442:        if (!xdr_ypdomain_wrap_string(xdrs, (char **)&objp->domain))
1.12      thorpej   443:                return FALSE;
                    444:
1.15      chuck     445:        if (!xdr_ypmap_wrap_string(xdrs, (char **)&objp->map))
1.12      thorpej   446:                return FALSE;
                    447:
1.14      thorpej   448:        if (!xdr_u_int(xdrs, &objp->ordernum))
1.12      thorpej   449:                return FALSE;
                    450:
1.13      christos  451:        if (!xdr_ypowner_wrap_string(xdrs, &objp->owner))
1.12      thorpej   452:                return FALSE;
                    453:
                    454:        return TRUE;
                    455: }
                    456:
                    457: bool_t
                    458: xdr_yppushresp_xfr(xdrs, objp)
                    459:        XDR *xdrs;
                    460:        struct yppushresp_xfr *objp;
                    461: {
1.14      thorpej   462:        if (!xdr_u_int(xdrs, &objp->transid))
1.12      thorpej   463:                return FALSE;
                    464:
1.14      thorpej   465:        if (!xdr_enum(xdrs, (enum_t *)&objp->status))
1.12      thorpej   466:                return FALSE;
                    467:
                    468:        return TRUE;
1.1       deraadt   469: }

CVSweb <webmaster@jp.NetBSD.org>