yplib.c revision 1.21 1 1.21 jtc /* $NetBSD: yplib.c,v 1.21 1996/05/15 05:27:53 jtc Exp $ */
2 1.14 cgd
3 1.3 deraadt /*
4 1.8 deraadt * Copyright (c) 1992, 1993 Theo de Raadt <deraadt (at) fsa.ca>
5 1.3 deraadt * All rights reserved.
6 1.3 deraadt *
7 1.3 deraadt * Redistribution and use in source and binary forms, with or without
8 1.3 deraadt * modification, are permitted provided that the following conditions
9 1.3 deraadt * are met:
10 1.3 deraadt * 1. Redistributions of source code must retain the above copyright
11 1.3 deraadt * notice, this list of conditions and the following disclaimer.
12 1.3 deraadt * 2. Redistributions in binary form must reproduce the above copyright
13 1.3 deraadt * notice, this list of conditions and the following disclaimer in the
14 1.3 deraadt * documentation and/or other materials provided with the distribution.
15 1.8 deraadt * 3. All advertising materials mentioning features or use of this software
16 1.8 deraadt * must display the following acknowledgement:
17 1.8 deraadt * This product includes software developed by Theo de Raadt.
18 1.8 deraadt * 4. The name of the author may not be used to endorse or promote products
19 1.8 deraadt * derived from this software without specific prior written permission.
20 1.3 deraadt *
21 1.3 deraadt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 1.3 deraadt * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 1.3 deraadt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.3 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 1.3 deraadt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.3 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.3 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.3 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.3 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.3 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.3 deraadt * SUCH DAMAGE.
32 1.3 deraadt */
33 1.3 deraadt
34 1.17 jtc #if defined(LIBC_SCCS) && !defined(lint)
35 1.21 jtc static char rcsid[] = "$NetBSD: yplib.c,v 1.21 1996/05/15 05:27:53 jtc Exp $";
36 1.3 deraadt #endif
37 1.3 deraadt
38 1.1 deraadt #include <sys/param.h>
39 1.1 deraadt #include <sys/types.h>
40 1.1 deraadt #include <sys/socket.h>
41 1.1 deraadt #include <sys/file.h>
42 1.7 deraadt #include <sys/uio.h>
43 1.1 deraadt #include <errno.h>
44 1.1 deraadt #include <stdio.h>
45 1.9 jtc #include <stdlib.h>
46 1.1 deraadt #include <string.h>
47 1.9 jtc #include <unistd.h>
48 1.1 deraadt #include <rpc/rpc.h>
49 1.1 deraadt #include <rpc/xdr.h>
50 1.1 deraadt #include <rpcsvc/yp_prot.h>
51 1.1 deraadt #include <rpcsvc/ypclnt.h>
52 1.1 deraadt
53 1.13 deraadt #define BINDINGDIR "/var/yp/binding"
54 1.13 deraadt #define YPBINDLOCK "/var/run/ypbind.lock"
55 1.1 deraadt #define YPMATCHCACHE
56 1.1 deraadt
57 1.1 deraadt struct dom_binding *_ypbindlist;
58 1.21 jtc char _yp_domain[MAXHOSTNAMELEN];
59 1.1 deraadt int _yplib_timeout = 10;
60 1.1 deraadt
61 1.16 christos static bool_t ypmatch_add __P((const char *, const char *, int, char *, int));
62 1.16 christos static bool_t ypmatch_find __P((const char *, const char *, int, const char **,
63 1.16 christos int *));
64 1.20 jtc void _yp_unbind __P((struct dom_binding *));
65 1.16 christos
66 1.1 deraadt int
67 1.1 deraadt _yp_dobind(dom, ypdb)
68 1.16 christos const char *dom;
69 1.16 christos struct dom_binding **ypdb;
70 1.1 deraadt {
71 1.16 christos static int pid = -1;
72 1.16 christos char path[MAXPATHLEN];
73 1.1 deraadt struct dom_binding *ysd, *ysd2;
74 1.1 deraadt struct ypbind_resp ypbr;
75 1.16 christos struct timeval tv;
76 1.1 deraadt struct sockaddr_in clnt_sin;
77 1.16 christos int clnt_sock, fd, gpid;
78 1.16 christos CLIENT *client;
79 1.16 christos int new = 0, r;
80 1.16 christos int count = 0;
81 1.1 deraadt
82 1.13 deraadt /*
83 1.13 deraadt * test if YP is running or not
84 1.13 deraadt */
85 1.16 christos if ((fd = open(YPBINDLOCK, O_RDONLY)) == -1)
86 1.13 deraadt return YPERR_YPBIND;
87 1.16 christos if (!(flock(fd, LOCK_EX | LOCK_NB) == -1 && errno == EWOULDBLOCK)) {
88 1.16 christos (void)close(fd);
89 1.13 deraadt return YPERR_YPBIND;
90 1.13 deraadt }
91 1.16 christos (void)close(fd);
92 1.13 deraadt
93 1.1 deraadt gpid = getpid();
94 1.16 christos if (!(pid == -1 || pid == gpid)) {
95 1.1 deraadt ysd = _ypbindlist;
96 1.16 christos while (ysd) {
97 1.16 christos if (ysd->dom_client)
98 1.1 deraadt clnt_destroy(ysd->dom_client);
99 1.1 deraadt ysd2 = ysd->dom_pnext;
100 1.1 deraadt free(ysd);
101 1.1 deraadt ysd = ysd2;
102 1.1 deraadt }
103 1.1 deraadt _ypbindlist = NULL;
104 1.1 deraadt }
105 1.1 deraadt pid = gpid;
106 1.1 deraadt
107 1.16 christos if (ypdb != NULL)
108 1.1 deraadt *ypdb = NULL;
109 1.1 deraadt
110 1.16 christos if (dom == NULL || strlen(dom) == 0)
111 1.1 deraadt return YPERR_BADARGS;
112 1.1 deraadt
113 1.16 christos for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext)
114 1.16 christos if (strcmp(dom, ysd->dom_domain) == 0)
115 1.1 deraadt break;
116 1.16 christos if (ysd == NULL) {
117 1.16 christos if ((ysd = malloc(sizeof *ysd)) == NULL)
118 1.16 christos return YPERR_YPERR;
119 1.16 christos (void)memset(ysd, 0, sizeof *ysd);
120 1.1 deraadt ysd->dom_socket = -1;
121 1.1 deraadt ysd->dom_vers = 0;
122 1.1 deraadt new = 1;
123 1.1 deraadt }
124 1.1 deraadt again:
125 1.16 christos if (ysd->dom_vers == 0) {
126 1.16 christos (void) snprintf(path, sizeof(path), "%s/%s.%d",
127 1.16 christos BINDINGDIR, dom, 2);
128 1.16 christos if ((fd = open(path, O_RDONLY)) == -1) {
129 1.16 christos /*
130 1.16 christos * no binding file, YP is dead, or not yet fully
131 1.16 christos * alive.
132 1.16 christos */
133 1.11 deraadt goto trynet;
134 1.1 deraadt }
135 1.16 christos if (flock(fd, LOCK_EX | LOCK_NB) == -1 &&
136 1.16 christos errno == EWOULDBLOCK) {
137 1.16 christos struct iovec iov[2];
138 1.7 deraadt struct ypbind_resp ybr;
139 1.16 christos u_short ypb_port;
140 1.16 christos struct ypbind_binding *bn;
141 1.7 deraadt
142 1.16 christos iov[0].iov_base = (caddr_t) & ypb_port;
143 1.7 deraadt iov[0].iov_len = sizeof ypb_port;
144 1.16 christos iov[1].iov_base = (caddr_t) & ybr;
145 1.7 deraadt iov[1].iov_len = sizeof ybr;
146 1.7 deraadt
147 1.7 deraadt r = readv(fd, iov, 2);
148 1.16 christos if (r != iov[0].iov_len + iov[1].iov_len) {
149 1.16 christos (void)close(fd);
150 1.1 deraadt ysd->dom_vers = -1;
151 1.1 deraadt goto again;
152 1.1 deraadt }
153 1.16 christos (void)memset(&ysd->dom_server_addr, 0,
154 1.16 christos sizeof ysd->dom_server_addr);
155 1.16 christos ysd->dom_server_addr.sin_len =
156 1.16 christos sizeof(struct sockaddr_in);
157 1.7 deraadt ysd->dom_server_addr.sin_family = AF_INET;
158 1.16 christos bn = &ybr.ypbind_respbody.ypbind_bindinfo;
159 1.15 mycroft ysd->dom_server_addr.sin_port =
160 1.16 christos bn->ypbind_binding_port;
161 1.16 christos
162 1.7 deraadt ysd->dom_server_addr.sin_addr =
163 1.16 christos bn->ypbind_binding_addr;
164 1.7 deraadt
165 1.1 deraadt ysd->dom_server_port = ysd->dom_server_addr.sin_port;
166 1.16 christos (void)close(fd);
167 1.1 deraadt goto gotit;
168 1.1 deraadt } else {
169 1.1 deraadt /* no lock on binding file, YP is dead. */
170 1.16 christos (void)close(fd);
171 1.16 christos if (new)
172 1.1 deraadt free(ysd);
173 1.1 deraadt return YPERR_YPBIND;
174 1.1 deraadt }
175 1.1 deraadt }
176 1.11 deraadt trynet:
177 1.16 christos if (ysd->dom_vers == -1 || ysd->dom_vers == 0) {
178 1.16 christos struct ypbind_binding *bn;
179 1.16 christos (void)memset(&clnt_sin, 0, sizeof clnt_sin);
180 1.15 mycroft clnt_sin.sin_len = sizeof(struct sockaddr_in);
181 1.1 deraadt clnt_sin.sin_family = AF_INET;
182 1.1 deraadt clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
183 1.1 deraadt
184 1.1 deraadt clnt_sock = RPC_ANYSOCK;
185 1.16 christos client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS,
186 1.16 christos &clnt_sock, 0, 0);
187 1.16 christos if (client == NULL) {
188 1.1 deraadt clnt_pcreateerror("clnttcp_create");
189 1.16 christos if (new)
190 1.1 deraadt free(ysd);
191 1.1 deraadt return YPERR_YPBIND;
192 1.1 deraadt }
193 1.1 deraadt tv.tv_sec = _yplib_timeout;
194 1.1 deraadt tv.tv_usec = 0;
195 1.16 christos r = clnt_call(client, YPBINDPROC_DOMAIN, xdr_domainname,
196 1.16 christos dom, xdr_ypbind_resp, &ypbr, tv);
197 1.16 christos if (r != RPC_SUCCESS) {
198 1.16 christos if (new == 0 || count)
199 1.12 deraadt fprintf(stderr,
200 1.16 christos "YP server for domain %s not responding, still trying\n",
201 1.16 christos dom);
202 1.12 deraadt count++;
203 1.1 deraadt clnt_destroy(client);
204 1.1 deraadt ysd->dom_vers = -1;
205 1.1 deraadt goto again;
206 1.1 deraadt }
207 1.1 deraadt clnt_destroy(client);
208 1.1 deraadt
209 1.16 christos (void)memset(&ysd->dom_server_addr, 0,
210 1.16 christos sizeof ysd->dom_server_addr);
211 1.15 mycroft ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in);
212 1.1 deraadt ysd->dom_server_addr.sin_family = AF_INET;
213 1.16 christos bn = &ypbr.ypbind_respbody.ypbind_bindinfo;
214 1.1 deraadt ysd->dom_server_addr.sin_port =
215 1.16 christos bn->ypbind_binding_port;
216 1.1 deraadt ysd->dom_server_addr.sin_addr.s_addr =
217 1.16 christos bn->ypbind_binding_addr.s_addr;
218 1.1 deraadt ysd->dom_server_port =
219 1.16 christos bn->ypbind_binding_port;
220 1.1 deraadt gotit:
221 1.1 deraadt ysd->dom_vers = YPVERS;
222 1.16 christos (void)strcpy(ysd->dom_domain, dom);
223 1.1 deraadt }
224 1.16 christos tv.tv_sec = _yplib_timeout / 2;
225 1.1 deraadt tv.tv_usec = 0;
226 1.16 christos if (ysd->dom_client)
227 1.1 deraadt clnt_destroy(ysd->dom_client);
228 1.1 deraadt ysd->dom_socket = RPC_ANYSOCK;
229 1.1 deraadt ysd->dom_client = clntudp_create(&ysd->dom_server_addr,
230 1.16 christos YPPROG, YPVERS, tv, &ysd->dom_socket);
231 1.16 christos if (ysd->dom_client == NULL) {
232 1.1 deraadt clnt_pcreateerror("clntudp_create");
233 1.1 deraadt ysd->dom_vers = -1;
234 1.1 deraadt goto again;
235 1.1 deraadt }
236 1.16 christos if (fcntl(ysd->dom_socket, F_SETFD, 1) == -1)
237 1.1 deraadt perror("fcntl: F_SETFD");
238 1.1 deraadt
239 1.16 christos if (new) {
240 1.1 deraadt ysd->dom_pnext = _ypbindlist;
241 1.1 deraadt _ypbindlist = ysd;
242 1.1 deraadt }
243 1.16 christos if (ypdb != NULL)
244 1.1 deraadt *ypdb = ysd;
245 1.1 deraadt return 0;
246 1.1 deraadt }
247 1.1 deraadt
248 1.20 jtc void
249 1.1 deraadt _yp_unbind(ypb)
250 1.16 christos struct dom_binding *ypb;
251 1.1 deraadt {
252 1.1 deraadt clnt_destroy(ypb->dom_client);
253 1.1 deraadt ypb->dom_client = NULL;
254 1.1 deraadt ypb->dom_socket = -1;
255 1.1 deraadt }
256 1.1 deraadt
257 1.1 deraadt int
258 1.1 deraadt yp_bind(dom)
259 1.16 christos const char *dom;
260 1.1 deraadt {
261 1.1 deraadt return _yp_dobind(dom, NULL);
262 1.1 deraadt }
263 1.1 deraadt
264 1.1 deraadt void
265 1.1 deraadt yp_unbind(dom)
266 1.16 christos const char *dom;
267 1.1 deraadt {
268 1.1 deraadt struct dom_binding *ypb, *ypbp;
269 1.1 deraadt
270 1.1 deraadt ypbp = NULL;
271 1.16 christos for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) {
272 1.16 christos if (strcmp(dom, ypb->dom_domain) == 0) {
273 1.1 deraadt clnt_destroy(ypb->dom_client);
274 1.16 christos if (ypbp)
275 1.1 deraadt ypbp->dom_pnext = ypb->dom_pnext;
276 1.1 deraadt else
277 1.1 deraadt _ypbindlist = ypb->dom_pnext;
278 1.1 deraadt free(ypb);
279 1.1 deraadt return;
280 1.1 deraadt }
281 1.1 deraadt ypbp = ypb;
282 1.1 deraadt }
283 1.1 deraadt return;
284 1.1 deraadt }
285 1.1 deraadt
286 1.1 deraadt int
287 1.1 deraadt yp_get_default_domain(domp)
288 1.16 christos char **domp;
289 1.1 deraadt {
290 1.1 deraadt *domp = NULL;
291 1.16 christos if (_yp_domain[0] == '\0')
292 1.16 christos if (getdomainname(_yp_domain, sizeof _yp_domain))
293 1.1 deraadt return YPERR_NODOM;
294 1.1 deraadt *domp = _yp_domain;
295 1.1 deraadt return 0;
296 1.1 deraadt }
297 1.1 deraadt
298 1.1 deraadt int
299 1.1 deraadt yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
300 1.16 christos const char *indomain;
301 1.16 christos const char *inmap;
302 1.16 christos char **outkey;
303 1.16 christos int *outkeylen;
304 1.16 christos char **outval;
305 1.16 christos int *outvallen;
306 1.1 deraadt {
307 1.1 deraadt struct ypresp_key_val yprkv;
308 1.1 deraadt struct ypreq_nokey yprnk;
309 1.1 deraadt struct dom_binding *ysd;
310 1.16 christos struct timeval tv;
311 1.16 christos int r;
312 1.1 deraadt
313 1.1 deraadt *outkey = *outval = NULL;
314 1.1 deraadt *outkeylen = *outvallen = 0;
315 1.1 deraadt
316 1.1 deraadt again:
317 1.16 christos if (_yp_dobind(indomain, &ysd) != 0)
318 1.1 deraadt return YPERR_DOMAIN;
319 1.1 deraadt
320 1.1 deraadt tv.tv_sec = _yplib_timeout;
321 1.1 deraadt tv.tv_usec = 0;
322 1.1 deraadt
323 1.1 deraadt yprnk.domain = indomain;
324 1.1 deraadt yprnk.map = inmap;
325 1.16 christos (void)memset(&yprkv, 0, sizeof yprkv);
326 1.1 deraadt
327 1.1 deraadt r = clnt_call(ysd->dom_client, YPPROC_FIRST,
328 1.16 christos xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv);
329 1.16 christos if (r != RPC_SUCCESS) {
330 1.1 deraadt clnt_perror(ysd->dom_client, "yp_first: clnt_call");
331 1.1 deraadt ysd->dom_vers = -1;
332 1.1 deraadt goto again;
333 1.1 deraadt }
334 1.16 christos if (!(r = ypprot_err(yprkv.status))) {
335 1.1 deraadt *outkeylen = yprkv.keydat.dsize;
336 1.16 christos if ((*outkey = malloc(*outkeylen + 1)) == NULL)
337 1.16 christos r = RPC_SYSTEMERROR;
338 1.16 christos else {
339 1.16 christos (void)memcpy(*outkey, yprkv.keydat.dptr, *outkeylen);
340 1.16 christos (*outkey)[*outkeylen] = '\0';
341 1.16 christos }
342 1.1 deraadt *outvallen = yprkv.valdat.dsize;
343 1.16 christos if ((*outval = malloc(*outvallen + 1)) == NULL)
344 1.16 christos r = RPC_SYSTEMERROR;
345 1.16 christos else {
346 1.16 christos (void)memcpy(*outval, yprkv.valdat.dptr, *outvallen);
347 1.16 christos (*outval)[*outvallen] = '\0';
348 1.16 christos }
349 1.1 deraadt }
350 1.16 christos xdr_free(xdr_ypresp_key_val, (char *) &yprkv);
351 1.1 deraadt _yp_unbind(ysd);
352 1.1 deraadt return r;
353 1.1 deraadt }
354 1.1 deraadt
355 1.1 deraadt int
356 1.1 deraadt yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
357 1.16 christos const char *indomain;
358 1.16 christos const char *inmap;
359 1.16 christos const char *inkey;
360 1.16 christos int inkeylen;
361 1.16 christos char **outkey;
362 1.16 christos int *outkeylen;
363 1.16 christos char **outval;
364 1.16 christos int *outvallen;
365 1.1 deraadt {
366 1.1 deraadt struct ypresp_key_val yprkv;
367 1.1 deraadt struct ypreq_key yprk;
368 1.1 deraadt struct dom_binding *ysd;
369 1.16 christos struct timeval tv;
370 1.16 christos int r;
371 1.1 deraadt
372 1.1 deraadt *outkey = *outval = NULL;
373 1.1 deraadt *outkeylen = *outvallen = 0;
374 1.1 deraadt
375 1.1 deraadt again:
376 1.16 christos if (_yp_dobind(indomain, &ysd) != 0)
377 1.1 deraadt return YPERR_DOMAIN;
378 1.1 deraadt
379 1.1 deraadt tv.tv_sec = _yplib_timeout;
380 1.1 deraadt tv.tv_usec = 0;
381 1.1 deraadt
382 1.1 deraadt yprk.domain = indomain;
383 1.1 deraadt yprk.map = inmap;
384 1.1 deraadt yprk.keydat.dptr = inkey;
385 1.1 deraadt yprk.keydat.dsize = inkeylen;
386 1.16 christos (void)memset(&yprkv, 0, sizeof yprkv);
387 1.1 deraadt
388 1.1 deraadt r = clnt_call(ysd->dom_client, YPPROC_NEXT,
389 1.16 christos xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv, tv);
390 1.16 christos if (r != RPC_SUCCESS) {
391 1.1 deraadt clnt_perror(ysd->dom_client, "yp_next: clnt_call");
392 1.1 deraadt ysd->dom_vers = -1;
393 1.1 deraadt goto again;
394 1.1 deraadt }
395 1.16 christos if (!(r = ypprot_err(yprkv.status))) {
396 1.1 deraadt *outkeylen = yprkv.keydat.dsize;
397 1.16 christos if ((*outkey = malloc(*outkeylen + 1)) == NULL)
398 1.16 christos r = RPC_SYSTEMERROR;
399 1.16 christos else {
400 1.16 christos (void)memcpy(*outkey, yprkv.keydat.dptr, *outkeylen);
401 1.16 christos (*outkey)[*outkeylen] = '\0';
402 1.16 christos }
403 1.1 deraadt *outvallen = yprkv.valdat.dsize;
404 1.16 christos if ((*outval = malloc(*outvallen + 1)) == NULL)
405 1.16 christos r = RPC_SYSTEMERROR;
406 1.16 christos else {
407 1.16 christos (void)memcpy(*outval, yprkv.valdat.dptr, *outvallen);
408 1.16 christos (*outval)[*outvallen] = '\0';
409 1.16 christos }
410 1.1 deraadt }
411 1.16 christos xdr_free(xdr_ypresp_key_val, (char *) &yprkv);
412 1.1 deraadt _yp_unbind(ysd);
413 1.1 deraadt return r;
414 1.1 deraadt }
415 1.1 deraadt
416 1.16 christos int
417 1.1 deraadt yp_maplist(indomain, outmaplist)
418 1.16 christos const char *indomain;
419 1.16 christos struct ypmaplist **outmaplist;
420 1.1 deraadt {
421 1.1 deraadt struct dom_binding *ysd;
422 1.1 deraadt struct ypresp_maplist ypml;
423 1.16 christos struct timeval tv;
424 1.16 christos int r;
425 1.1 deraadt
426 1.1 deraadt again:
427 1.16 christos if (_yp_dobind(indomain, &ysd) != 0)
428 1.1 deraadt return YPERR_DOMAIN;
429 1.1 deraadt
430 1.1 deraadt tv.tv_sec = _yplib_timeout;
431 1.1 deraadt tv.tv_usec = 0;
432 1.1 deraadt
433 1.9 jtc memset(&ypml, 0, sizeof ypml);
434 1.1 deraadt
435 1.1 deraadt r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
436 1.16 christos xdr_domainname, indomain, xdr_ypresp_maplist, &ypml, tv);
437 1.1 deraadt if (r != RPC_SUCCESS) {
438 1.1 deraadt clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
439 1.1 deraadt ysd->dom_vers = -1;
440 1.1 deraadt goto again;
441 1.1 deraadt }
442 1.1 deraadt *outmaplist = ypml.list;
443 1.16 christos /* NO: xdr_free(xdr_ypresp_maplist, &ypml); */
444 1.1 deraadt _yp_unbind(ysd);
445 1.1 deraadt return ypprot_err(ypml.status);
446 1.1 deraadt }
447 1.1 deraadt
448 1.1 deraadt int
449 1.1 deraadt ypprot_err(incode)
450 1.16 christos unsigned int incode;
451 1.1 deraadt {
452 1.16 christos switch (incode) {
453 1.1 deraadt case YP_TRUE:
454 1.1 deraadt return 0;
455 1.1 deraadt case YP_FALSE:
456 1.1 deraadt return YPERR_YPBIND;
457 1.1 deraadt case YP_NOMORE:
458 1.1 deraadt return YPERR_NOMORE;
459 1.1 deraadt case YP_NOMAP:
460 1.1 deraadt return YPERR_MAP;
461 1.1 deraadt case YP_NODOM:
462 1.1 deraadt return YPERR_NODOM;
463 1.1 deraadt case YP_NOKEY:
464 1.1 deraadt return YPERR_KEY;
465 1.1 deraadt case YP_BADOP:
466 1.1 deraadt return YPERR_YPERR;
467 1.1 deraadt case YP_BADDB:
468 1.1 deraadt return YPERR_BADDB;
469 1.1 deraadt case YP_YPERR:
470 1.1 deraadt return YPERR_YPERR;
471 1.1 deraadt case YP_BADARGS:
472 1.1 deraadt return YPERR_BADARGS;
473 1.1 deraadt case YP_VERS:
474 1.1 deraadt return YPERR_VERS;
475 1.1 deraadt }
476 1.1 deraadt return YPERR_YPERR;
477 1.1 deraadt }
478 1.1 deraadt
479 1.1 deraadt int
480 1.1 deraadt _yp_check(dom)
481 1.16 christos char **dom;
482 1.1 deraadt {
483 1.16 christos char *unused;
484 1.1 deraadt
485 1.16 christos if (_yp_domain[0] == '\0')
486 1.16 christos if (yp_get_default_domain(&unused))
487 1.1 deraadt return 0;
488 1.1 deraadt
489 1.16 christos if (dom)
490 1.1 deraadt *dom = _yp_domain;
491 1.1 deraadt
492 1.16 christos if (yp_bind(_yp_domain) == 0)
493 1.1 deraadt return 1;
494 1.1 deraadt return 0;
495 1.1 deraadt }
496