xdryp.c revision 12816
11919Swollman/* 21919Swollman * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 31919Swollman * All rights reserved. 41919Swollman * 51919Swollman * Redistribution and use in source and binary forms, with or without 61919Swollman * modification, are permitted provided that the following conditions 71919Swollman * are met: 81919Swollman * 1. Redistributions of source code must retain the above copyright 91919Swollman * notice, this list of conditions and the following disclaimer. 101919Swollman * 2. Redistributions in binary form must reproduce the above copyright 111919Swollman * notice, this list of conditions and the following disclaimer in the 121919Swollman * documentation and/or other materials provided with the distribution. 131919Swollman * 3. The name of the author may not be used to endorse or promote 141919Swollman * products derived from this software without specific prior written 151919Swollman * permission. 161919Swollman * 171919Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 181919Swollman * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 191919Swollman * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201919Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 211919Swollman * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221919Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231919Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241919Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251919Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261919Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271919Swollman * SUCH DAMAGE. 281919Swollman */ 291919Swollman 301919Swollman#ifndef LINT 3112816Swpaulstatic char *rcsid = "$Id: xdryp.c,v 1.3 1995/04/02 19:58:29 wpaul Exp $"; 321919Swollman#endif 331919Swollman 341919Swollman#include <rpc/rpc.h> 3512816Swpaul#include <rpcsvc/yp.h> 361919Swollman 371919Swollmanextern int (*ypresp_allfn)(); 381919Swollmanextern void *ypresp_data; 391919Swollman 4012816Swpaul/* 4112816Swpaul * I'm leaving the xdr_datum() function in purely for backwards 4212816Swpaul * compatibility. yplib.c doesn't actually use it, but it's listed 4312816Swpaul * in yp_prot.h as being available, so it's probably a good idea to 4412816Swpaul * leave it in in case somebody goes looking for it. 4512816Swpaul */ 4612816Swpaultypedef struct { 4712816Swpaul char *dptr; 4812816Swpaul int dsize; 4912816Swpaul} datum; 501919Swollman 511919Swollmanbool_t 521919Swollmanxdr_datum(xdrs, objp) 531919SwollmanXDR *xdrs; 541919Swollmandatum *objp; 551919Swollman{ 561919Swollman if (!xdr_bytes(xdrs, (char **)&objp->dptr, (u_int *)&objp->dsize, YPMAXRECORD)) { 571919Swollman return (FALSE); 581919Swollman } 591919Swollman return (TRUE); 601919Swollman} 611919Swollman 621919Swollmanbool_t 631919Swollmanxdr_ypresp_all_seq(xdrs, objp) 641919SwollmanXDR *xdrs; 651919Swollmanu_long *objp; 661919Swollman{ 671919Swollman struct ypresp_all out; 681919Swollman u_long status; 691919Swollman char *key, *val; 701919Swollman int r; 711919Swollman 721919Swollman bzero(&out, sizeof out); 731919Swollman while(1) { 741919Swollman if( !xdr_ypresp_all(xdrs, &out)) { 751919Swollman xdr_free(xdr_ypresp_all, (char *)&out); 761919Swollman *objp = YP_YPERR; 771919Swollman return FALSE; 781919Swollman } 791919Swollman if(out.more == 0) { 801919Swollman xdr_free(xdr_ypresp_all, (char *)&out); 811919Swollman return FALSE; 821919Swollman } 8312816Swpaul status = out.ypresp_all_u.val.stat; 841919Swollman switch(status) { 851919Swollman case YP_TRUE: 8612816Swpaul key = (char *)malloc(out.ypresp_all_u.val.key.keydat_len + 1); 8712816Swpaul bcopy(out.ypresp_all_u.val.key.keydat_val, key, 8812816Swpaul out.ypresp_all_u.val.key.keydat_len); 8912816Swpaul key[out.ypresp_all_u.val.key.keydat_len] = '\0'; 9012816Swpaul val = (char *)malloc(out.ypresp_all_u.val.val.valdat_len + 1); 9112816Swpaul bcopy(out.ypresp_all_u.val.val.valdat_val, val, 9212816Swpaul out.ypresp_all_u.val.val.valdat_len); 9312816Swpaul val[out.ypresp_all_u.val.val.valdat_len] = '\0'; 941919Swollman xdr_free(xdr_ypresp_all, (char *)&out); 951919Swollman 961919Swollman r = (*ypresp_allfn)(status, 9712816Swpaul key, out.ypresp_all_u.val.key.keydat_len, 9812816Swpaul val, out.ypresp_all_u.val.val.valdat_len, 991919Swollman ypresp_data); 1001919Swollman *objp = status; 1011919Swollman free(key); 1021919Swollman free(val); 1031919Swollman if(r) 1041919Swollman return TRUE; 1051919Swollman break; 1061919Swollman case YP_NOMORE: 1071919Swollman xdr_free(xdr_ypresp_all, (char *)&out); 1081919Swollman return TRUE; 1091919Swollman default: 1101919Swollman xdr_free(xdr_ypresp_all, (char *)&out); 1111919Swollman *objp = status; 1121919Swollman return TRUE; 1131919Swollman } 1141919Swollman } 1151919Swollman} 116