xdryp.c revision 22993
10Sduke/* 22362Sohair * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 30Sduke * All rights reserved. 40Sduke * 50Sduke * Redistribution and use in source and binary forms, with or without 60Sduke * modification, are permitted provided that the following conditions 70Sduke * are met: 80Sduke * 1. Redistributions of source code must retain the above copyright 90Sduke * notice, this list of conditions and the following disclaimer. 100Sduke * 2. Redistributions in binary form must reproduce the above copyright 110Sduke * notice, this list of conditions and the following disclaimer in the 120Sduke * documentation and/or other materials provided with the distribution. 130Sduke * 3. The name of the author may not be used to endorse or promote 140Sduke * products derived from this software without specific prior written 150Sduke * permission. 160Sduke * 170Sduke * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 180Sduke * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 192362Sohair * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 202362Sohair * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 212362Sohair * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 220Sduke * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 230Sduke * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 240Sduke * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 250Sduke * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 260Sduke * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 270Sduke * SUCH DAMAGE. 280Sduke */ 290Sduke 300Sduke#ifndef LINT 310Sdukestatic char *rcsid = "$Id$"; 320Sduke#endif 330Sduke 340Sduke#include <rpc/rpc.h> 350Sduke#include <rpcsvc/yp.h> 360Sduke#include <stdlib.h> 370Sduke#include <string.h> 380Sduke 390Sdukeextern int (*ypresp_allfn)(); 400Sdukeextern void *ypresp_data; 410Sduke 420Sduke/* 430Sduke * I'm leaving the xdr_datum() function in purely for backwards 440Sduke * compatibility. yplib.c doesn't actually use it, but it's listed 450Sduke * in yp_prot.h as being available, so it's probably a good idea to 460Sduke * leave it in in case somebody goes looking for it. 470Sduke */ 480Sduketypedef struct { 490Sduke char *dptr; 500Sduke int dsize; 510Sduke} datum; 520Sduke 530Sdukebool_t 540Sdukexdr_datum(xdrs, objp) 550SdukeXDR *xdrs; 560Sdukedatum *objp; 570Sduke{ 580Sduke if (!xdr_bytes(xdrs, (char **)&objp->dptr, (u_int *)&objp->dsize, YPMAXRECORD)) { 590Sduke return (FALSE); 600Sduke } 610Sduke return (TRUE); 620Sduke} 630Sduke 640Sdukebool_t 650Sdukexdr_ypresp_all_seq(xdrs, objp) 66XDR *xdrs; 67u_long *objp; 68{ 69 struct ypresp_all out; 70 u_long status; 71 char *key, *val; 72 int r; 73 74 bzero(&out, sizeof out); 75 while(1) { 76 if( !xdr_ypresp_all(xdrs, &out)) { 77 xdr_free(xdr_ypresp_all, (char *)&out); 78 *objp = YP_YPERR; 79 return FALSE; 80 } 81 if(out.more == 0) { 82 xdr_free(xdr_ypresp_all, (char *)&out); 83 *objp = YP_NOMORE; 84 return TRUE; 85 } 86 status = out.ypresp_all_u.val.stat; 87 switch(status) { 88 case YP_TRUE: 89 key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1); 90 bcopy(out.ypresp_all_u.val.key.keydat_val, key, 91 out.ypresp_all_u.val.key.keydat_len); 92 key[out.ypresp_all_u.val.key.keydat_len] = '\0'; 93 val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1); 94 bcopy(out.ypresp_all_u.val.val.valdat_val, val, 95 out.ypresp_all_u.val.val.valdat_len); 96 val[out.ypresp_all_u.val.val.valdat_len] = '\0'; 97 xdr_free(xdr_ypresp_all, (char *)&out); 98 99 r = (*ypresp_allfn)(status, 100 key, out.ypresp_all_u.val.key.keydat_len, 101 val, out.ypresp_all_u.val.val.valdat_len, 102 ypresp_data); 103 *objp = status; 104 free(key); 105 free(val); 106 if(r) 107 return TRUE; 108 break; 109 case YP_NOMORE: 110 xdr_free(xdr_ypresp_all, (char *)&out); 111 *objp = YP_NOMORE; 112 return TRUE; 113 default: 114 xdr_free(xdr_ypresp_all, (char *)&out); 115 *objp = status; 116 return TRUE; 117 } 118 } 119} 120