Home | History | Annotate | Line # | Download | only in libhack
yplib.c revision 1.2
      1 /*	$NetBSD: yplib.c,v 1.2 1999/03/13 19:08:44 sommerfe Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1992, 1993 Theo de Raadt <deraadt (at) 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 <errno.h>
     48 #include <stdio.h>
     49 #include <stdlib.h>
     50 #include <string.h>
     51 #include <unistd.h>
     52 
     53 #include <rpc/rpc.h>
     54 #include <rpc/xdr.h>
     55 #include <rpcsvc/yp_prot.h>
     56 #include <rpcsvc/ypclnt.h>
     57 
     58 static char _yp_domain[256];
     59 
     60 int
     61 _yp_dobind(dom, ypdb)
     62 	const char *dom;
     63 	struct dom_binding **ypdb;
     64 {
     65 	return YPERR_YPBIND;
     66 }
     67 
     68 int
     69 yp_bind(dom)
     70 	const char     *dom;
     71 {
     72 	return _yp_dobind(dom, NULL);
     73 }
     74 
     75 void
     76 yp_unbind(dom)
     77 	const char     *dom;
     78 {
     79 }
     80 
     81 int
     82 yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
     83 	const char     *indomain;
     84 	const char     *inmap;
     85 	const char     *inkey;
     86 	int             inkeylen;
     87 	char          **outval;
     88 	int            *outvallen;
     89 {
     90 	*outval = NULL;
     91 	*outvallen = 0;
     92 
     93 	return YPERR_DOMAIN;
     94 }
     95 
     96 int
     97 yp_get_default_domain(domp)
     98 	char **domp;
     99 {
    100 	*domp = NULL;
    101 	if (_yp_domain[0] == '\0')
    102 		if (getdomainname(_yp_domain, sizeof(_yp_domain)))
    103 			return YPERR_NODOM;
    104 	*domp = _yp_domain;
    105 	return 0;
    106 }
    107 
    108 int
    109 yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
    110 	const char     *indomain;
    111 	const char     *inmap;
    112 	char          **outkey;
    113 	int            *outkeylen;
    114 	char          **outval;
    115 	int            *outvallen;
    116 {
    117 
    118 	*outkey = *outval = NULL;
    119 	*outkeylen = *outvallen = 0;
    120 
    121 	return YPERR_DOMAIN;
    122 }
    123 
    124 int
    125 yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
    126 	const char     *indomain;
    127 	const char     *inmap;
    128 	const char     *inkey;
    129 	int             inkeylen;
    130 	char          **outkey;
    131 	int            *outkeylen;
    132 	char          **outval;
    133 	int            *outvallen;
    134 {
    135 	*outkey = *outval = NULL;
    136 	*outkeylen = *outvallen = 0;
    137 
    138 	return YPERR_DOMAIN;
    139 }
    140 
    141 int
    142 yp_all(indomain, inmap, incallback)
    143 	const char     *indomain;
    144 	const char     *inmap;
    145 	struct ypall_callback *incallback;
    146 {
    147 	return YPERR_DOMAIN;
    148 }
    149 
    150 int
    151 yp_order(indomain, inmap, outorder)
    152 	const char     *indomain;
    153 	const char     *inmap;
    154 	int            *outorder;
    155 {
    156 	return YPERR_DOMAIN;
    157 }
    158 
    159 int
    160 yp_master(indomain, inmap, outname)
    161 	const char     *indomain;
    162 	const char     *inmap;
    163 	char          **outname;
    164 {
    165 	return YPERR_DOMAIN;
    166 }
    167 
    168 int
    169 yp_maplist(indomain, outmaplist)
    170 	const char     *indomain;
    171 	struct ypmaplist **outmaplist;
    172 {
    173 	return YPERR_DOMAIN;
    174 }
    175 
    176 char *
    177 yperr_string(incode)
    178 	int             incode;
    179 {
    180 	static char     err[80];
    181 
    182 	if (incode == 0)
    183 		return "Success";
    184 
    185 	sprintf(err, "YP FAKE error %d\n", incode);
    186 	return err;
    187 }
    188 
    189 int
    190 ypprot_err(incode)
    191 	unsigned int    incode;
    192 {
    193 	switch (incode) {
    194 	case YP_TRUE:	/* success */
    195 		return 0;
    196 	case YP_FALSE:	/* failure */
    197 		return YPERR_YPBIND;
    198 	}
    199 	return YPERR_YPERR;
    200 }
    201 
    202 int
    203 _yp_check(dom)
    204 	char          **dom;
    205 {
    206 	char           *unused;
    207 
    208 	if (_yp_domain[0] == '\0')
    209 		if (yp_get_default_domain(&unused))
    210 			return 0;
    211 
    212 	if (dom)
    213 		*dom = _yp_domain;
    214 
    215 	if (yp_bind(_yp_domain) == 0)
    216 		return 1;
    217 	return 0;
    218 }
    219