1 /* $NetBSD: yplib.c,v 1.1.1.1 1995/10/08 23:08:48 gwr 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 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Theo de Raadt. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34 /* 35 * This file provides "stubs" for all the YP library functions. 36 * It is not needed unless you pull in things that call YP, and 37 * if you use all the get* files here then the YP stuff should 38 * not get dragged in. But if it does, one can use this. 39 * 40 * This was copied from: 41 * lib/libc/yp/yplib.c 42 * (and then completely gutted! 8^) 43 */ 44 45 #include <sys/types.h> 46 47 /* #include <rpcsvc/yp_prot.h> */ 48 #define YP_TRUE ((long)1) /* general purpose success code */ 49 #define YP_FALSE ((long)0) /* general purpose failure code */ 50 51 /* #include <rpcsvc/ypclnt.h> */ 52 #define YPERR_DOMAIN 3 /* can't bind to a server for domain */ 53 #define YPERR_YPERR 6 /* some internal YP server or client error */ 54 #define YPERR_YPBIND 10 /* can't communicate with ypbind */ 55 #define YPERR_NODOM 12 /* local domain name not set */ 56 57 #ifndef NULL 58 #define NULL (void*)0 59 #endif 60 61 62 static char _yp_domain[256]; 63 64 int 65 _yp_dobind(dom, ypdb) 66 const char *dom; 67 void **ypdb; 68 { 69 return YPERR_YPBIND; 70 } 71 72 int 73 yp_bind(dom) 74 const char *dom; 75 { 76 return _yp_dobind(dom, NULL); 77 } 78 79 void 80 yp_unbind(dom) 81 const char *dom; 82 { 83 } 84 85 int 86 yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen) 87 const char *indomain; 88 const char *inmap; 89 const char *inkey; 90 int inkeylen; 91 char **outval; 92 int *outvallen; 93 { 94 *outval = NULL; 95 *outvallen = 0; 96 97 return YPERR_DOMAIN; 98 } 99 100 int 101 yp_get_default_domain(domp) 102 char **domp; 103 { 104 *domp = NULL; 105 if (_yp_domain[0] == '\0') 106 if (getdomainname(_yp_domain, sizeof(_yp_domain))) 107 return YPERR_NODOM; 108 *domp = _yp_domain; 109 return 0; 110 } 111 112 int 113 yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen) 114 const char *indomain; 115 const char *inmap; 116 char **outkey; 117 int *outkeylen; 118 char **outval; 119 int *outvallen; 120 { 121 122 *outkey = *outval = NULL; 123 *outkeylen = *outvallen = 0; 124 125 return YPERR_DOMAIN; 126 } 127 128 int 129 yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen) 130 const char *indomain; 131 const char *inmap; 132 const char *inkey; 133 int inkeylen; 134 char **outkey; 135 int *outkeylen; 136 char **outval; 137 int *outvallen; 138 { 139 *outkey = *outval = NULL; 140 *outkeylen = *outvallen = 0; 141 142 return YPERR_DOMAIN; 143 } 144 145 int 146 yp_all(indomain, inmap, incallback) 147 const char *indomain; 148 const char *inmap; 149 void *incallback; 150 { 151 return YPERR_DOMAIN; 152 } 153 154 int 155 yp_order(indomain, inmap, outorder) 156 const char *indomain; 157 const char *inmap; 158 int *outorder; 159 { 160 return YPERR_DOMAIN; 161 } 162 163 int 164 yp_master(indomain, inmap, outname) 165 const char *indomain; 166 const char *inmap; 167 char **outname; 168 { 169 return YPERR_DOMAIN; 170 } 171 172 int 173 yp_maplist(indomain, outmaplist) 174 const char *indomain; 175 struct ypmaplist **outmaplist; 176 { 177 return YPERR_DOMAIN; 178 } 179 180 char * 181 yperr_string(incode) 182 int incode; 183 { 184 static char err[80]; 185 186 if (incode == 0) 187 return "Success"; 188 189 sprintf(err, "YP FAKE error %d\n", incode); 190 return err; 191 } 192 193 int 194 ypprot_err(incode) 195 unsigned int incode; 196 { 197 switch (incode) { 198 case YP_TRUE: /* success */ 199 return 0; 200 case YP_FALSE: /* failure */ 201 return YPERR_YPBIND; 202 } 203 return YPERR_YPERR; 204 } 205 206 int 207 _yp_check(dom) 208 char **dom; 209 { 210 char *unused; 211 212 if (_yp_domain[0] == '\0') 213 if (yp_get_default_domain(&unused)) 214 return 0; 215 216 if (dom) 217 *dom = _yp_domain; 218 219 if (yp_bind(_yp_domain) == 0) 220 return 1; 221 return 0; 222 } 223