1/* $NetBSD: yplib.c,v 1.5 2003/12/10 12:06:25 agc Exp $ */ 2 3/* 4 * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29/* 30 * This file provides "stubs" for all the YP library functions. 31 * It is not needed unless you pull in things that call YP, and 32 * if you use all the get* files here then the YP stuff should 33 * not get dragged in. But if it does, one can use this. 34 * 35 * This was copied from: 36 * lib/libc/yp/yplib.c 37 * (and then completely gutted! 8^) 38 */ 39#include <sys/cdefs.h> 40 41#ifdef __weak_alias 42#define yp_all _yp_all 43#define yp_bind _yp_bind 44#define yp_first _yp_first 45#define yp_get_default_domain _yp_get_default_domain 46#define yp_maplist _yp_maplist 47#define yp_master _yp_master 48#define yp_match _yp_match 49#define yp_next _yp_next 50#define yp_order _yp_order 51#define yp_unbind _yp_unbind 52#define yperr_string _yperr_string 53#define ypprot_err _ypprot_err 54#endif 55 56#include <sys/types.h> 57 58#include <errno.h> 59#include <stdio.h> 60#include <stdlib.h> 61#include <string.h> 62#include <unistd.h> 63 64#include <rpc/rpc.h> 65#include <rpc/xdr.h> 66#include <rpcsvc/yp_prot.h> 67#include <rpcsvc/ypclnt.h> 68 69struct dom_binding *_ypbindlist; 70char _yp_domain[256]; 71 72#define YPLIB_TIMEOUT 10 73#define YPLIB_RPC_RETRIES 4 74 75struct timeval _yplib_timeout = { YPLIB_TIMEOUT, 0 }; 76struct timeval _yplib_rpc_timeout = { YPLIB_TIMEOUT / YPLIB_RPC_RETRIES, 77 1000000 * (YPLIB_TIMEOUT % YPLIB_RPC_RETRIES) / YPLIB_RPC_RETRIES }; 78int _yplib_nerrs = 5; 79 80 81#ifdef __weak_alias 82__weak_alias(yp_all,_yp_all); 83__weak_alias(yp_bind, _yp_bind); 84__weak_alias(yp_first,_yp_first); 85__weak_alias(yp_get_default_domain, _yp_get_default_domain); 86__weak_alias(yp_maplist,_yp_maplist); 87__weak_alias(yp_master,_yp_master); 88__weak_alias(yp_match,_yp_match); 89__weak_alias(yp_next,_yp_next); 90__weak_alias(yp_order,_yp_order); 91__weak_alias(yp_unbind, _yp_unbind); 92__weak_alias(yperr_string,_yperr_string); 93__weak_alias(ypprot_err,_ypprot_err); 94#endif 95 96void __yp_unbind __P((struct dom_binding *)); 97int _yp_invalid_domain __P((const char *)); 98 99int 100_yp_dobind(dom, ypdb) 101 const char *dom; 102 struct dom_binding **ypdb; 103{ 104 return YPERR_YPBIND; 105} 106 107void 108__yp_unbind(ypb) 109 struct dom_binding *ypb; 110{ 111} 112 113int 114yp_bind(dom) 115 const char *dom; 116{ 117 return _yp_dobind(dom, NULL); 118} 119 120void 121yp_unbind(dom) 122 const char *dom; 123{ 124} 125 126int 127yp_get_default_domain(domp) 128 char **domp; 129{ 130 *domp = NULL; 131 if (_yp_domain[0] == '\0') 132 if (getdomainname(_yp_domain, sizeof(_yp_domain))) 133 return YPERR_NODOM; 134 *domp = _yp_domain; 135 return 0; 136} 137 138int 139_yp_check(dom) 140 char **dom; 141{ 142 char *unused; 143 144 if (_yp_domain[0] == '\0') 145 if (yp_get_default_domain(&unused)) 146 return 0; 147 148 if (dom) 149 *dom = _yp_domain; 150 151 if (yp_bind(_yp_domain) == 0) 152 return 1; 153 return 0; 154} 155 156int 157_yp_invalid_domain(dom) 158 const char *dom; 159{ 160 if (dom == NULL || *dom == '\0') 161 return 1; 162 163 if (strlen(dom) > YPMAXDOMAIN) 164 return 1; 165 166 if (strchr(dom, '/') != NULL) 167 return 1; 168 169 return 0; 170} 171 172int 173yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen) 174 const char *indomain; 175 const char *inmap; 176 const char *inkey; 177 int inkeylen; 178 char **outval; 179 int *outvallen; 180{ 181 *outval = NULL; 182 *outvallen = 0; 183 184 return YPERR_DOMAIN; 185} 186 187int 188yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen) 189 const char *indomain; 190 const char *inmap; 191 char **outkey; 192 int *outkeylen; 193 char **outval; 194 int *outvallen; 195{ 196 197 *outkey = *outval = NULL; 198 *outkeylen = *outvallen = 0; 199 200 return YPERR_DOMAIN; 201} 202 203int 204yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen) 205 const char *indomain; 206 const char *inmap; 207 const char *inkey; 208 int inkeylen; 209 char **outkey; 210 int *outkeylen; 211 char **outval; 212 int *outvallen; 213{ 214 *outkey = *outval = NULL; 215 *outkeylen = *outvallen = 0; 216 217 return YPERR_DOMAIN; 218} 219 220int 221yp_all(indomain, inmap, incallback) 222 const char *indomain; 223 const char *inmap; 224 struct ypall_callback *incallback; 225{ 226 return YPERR_DOMAIN; 227} 228 229int 230yp_order(indomain, inmap, outorder) 231 const char *indomain; 232 const char *inmap; 233 int *outorder; 234{ 235 return YPERR_DOMAIN; 236} 237 238int 239yp_master(indomain, inmap, outname) 240 const char *indomain; 241 const char *inmap; 242 char **outname; 243{ 244 return YPERR_DOMAIN; 245} 246 247int 248yp_maplist(indomain, outmaplist) 249 const char *indomain; 250 struct ypmaplist **outmaplist; 251{ 252 return YPERR_DOMAIN; 253} 254 255char * 256yperr_string(incode) 257 int incode; 258{ 259 static char err[80]; 260 261 if (incode == 0) 262 return "Success"; 263 264 snprintf(err, sizeof(err), "YP FAKE error %d\n", incode); 265 return err; 266} 267 268int 269ypprot_err(incode) 270 unsigned int incode; 271{ 272 switch (incode) { 273 case YP_TRUE: /* success */ 274 return 0; 275 case YP_FALSE: /* failure */ 276 return YPERR_YPBIND; 277 } 278 return YPERR_YPERR; 279} 280 281