2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3 * Copyright (c) 1998 Bill Paul <wpaul@ctr.columbia.edu>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * $FreeBSD: src/lib/libc/yp/yplib.c,v 1.34.2.2 2002/02/15 00:46:53 des Exp $
31 * $DragonFly: src/lib/libcr/yp/Attic/yplib.c,v 1.2 2003/06/17 04:26:47 dillon Exp $
34 #include <sys/param.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
46 #include <rpcsvc/yp.h>
49 * We have to define these here due to clashes between yp_prot.h and
61 struct ypmatch_ent *ypc_next;
63 #define YPLIB_MAXCACHE 5 /* At most 5 entries */
64 #define YPLIB_EXPIRE 5 /* Expire after 5 seconds */
68 struct dom_binding *dom_pnext;
69 char dom_domain[YPMAXDOMAIN + 1];
70 struct sockaddr_in dom_server_addr;
71 u_short dom_server_port;
74 u_short dom_local_port; /* now I finally know what this is for. */
77 struct ypmatch_ent *cache;
82 #include <rpcsvc/ypclnt.h>
85 #define BINDINGDIR "/var/yp/binding"
87 #define MAX_RETRIES 20
89 extern bool_t xdr_domainname(), xdr_ypbind_resp();
90 extern bool_t xdr_ypreq_key(), xdr_ypresp_val();
91 extern bool_t xdr_ypreq_nokey(), xdr_ypresp_key_val();
92 extern bool_t xdr_ypresp_all(), xdr_ypresp_all_seq();
93 extern bool_t xdr_ypresp_master();
95 int (*ypresp_allfn)();
98 static void _yp_unbind(struct dom_binding *);
99 struct dom_binding *_ypbindlist;
100 static char _yp_domain[MAXHOSTNAMELEN];
101 int _yplib_timeout = 10;
104 static void ypmatch_cache_delete(ypdb, prev, cur)
105 struct dom_binding *ypdb;
106 struct ypmatch_ent *prev;
107 struct ypmatch_ent *cur;
110 ypdb->cache = cur->ypc_next;
112 prev->ypc_next = cur->ypc_next;
115 free(cur->ypc_key.keydat_val);
116 free(cur->ypc_val.valdat_val);
119 ypdb->ypmatch_cachecnt--;
124 static void ypmatch_cache_flush(ypdb)
125 struct dom_binding *ypdb;
127 struct ypmatch_ent *n, *c = ypdb->cache;
131 ypmatch_cache_delete(ypdb, NULL, c);
138 static void ypmatch_cache_expire(ypdb)
139 struct dom_binding *ypdb;
141 struct ypmatch_ent *c = ypdb->cache;
142 struct ypmatch_ent *n, *p = NULL;
148 if (t >= c->ypc_expire_t) {
150 ypmatch_cache_delete(ypdb, p, c);
161 static void ypmatch_cache_insert(ypdb, map, key, val)
162 struct dom_binding *ypdb;
167 struct ypmatch_ent *new;
169 /* Do an expire run to maybe open up a slot. */
170 if (ypdb->ypmatch_cachecnt)
171 ypmatch_cache_expire(ypdb);
174 * If there are no slots free, then force an expire of
175 * the least recently used entry.
177 if (ypdb->ypmatch_cachecnt >= YPLIB_MAXCACHE) {
178 struct ypmatch_ent *o = NULL, *c = ypdb->cache;
184 if (c->ypc_expire_t < oldest) {
185 oldest = c->ypc_expire_t;
194 ypmatch_cache_expire(ypdb);
197 new = malloc(sizeof(struct ypmatch_ent));
201 new->ypc_map = strdup(map);
202 if (new->ypc_map == NULL) {
206 new->ypc_key.keydat_val = malloc(key->keydat_len);
207 if (new->ypc_key.keydat_val == NULL) {
212 new->ypc_val.valdat_val = malloc(val->valdat_len);
213 if (new->ypc_val.valdat_val == NULL) {
214 free(new->ypc_val.valdat_val);
220 new->ypc_expire_t = time(NULL) + YPLIB_EXPIRE;
221 new->ypc_key.keydat_len = key->keydat_len;
222 new->ypc_val.valdat_len = val->valdat_len;
223 bcopy(key->keydat_val, new->ypc_key.keydat_val, key->keydat_len);
224 bcopy(val->valdat_val, new->ypc_val.valdat_val, val->valdat_len);
226 new->ypc_next = ypdb->cache;
229 ypdb->ypmatch_cachecnt++;
234 static bool_t ypmatch_cache_lookup(ypdb, map, key, val)
235 struct dom_binding *ypdb;
240 struct ypmatch_ent *c = ypdb->cache;
242 ypmatch_cache_expire(ypdb);
244 for (c = ypdb->cache; c != NULL; c = c->ypc_next) {
245 if (strcmp(map, c->ypc_map))
247 if (key->keydat_len != c->ypc_key.keydat_len)
249 if (bcmp(key->keydat_val, c->ypc_key.keydat_val,
257 val->valdat_len = c->ypc_val.valdat_len;
258 val->valdat_val = c->ypc_val.valdat_val;
265 ypbinderr_string(incode)
273 return ("Internal ypbind error");
274 case YPBIND_ERR_NOSERV:
275 return ("Domain not bound");
276 case YPBIND_ERR_RESC:
277 return ("System resource allocation failure");
279 sprintf(err, "Unknown ypbind error: #%d\n", incode);
284 _yp_dobind(dom, ypdb)
286 struct dom_binding **ypdb;
288 static pid_t pid = -1;
289 char path[MAXPATHLEN];
290 struct dom_binding *ysd, *ysd2;
291 struct ypbind_resp ypbr;
293 struct sockaddr_in clnt_sin;
299 struct sockaddr_in check;
300 int checklen = sizeof(struct sockaddr_in);
302 /* Not allowed; bad doggie. Bad. */
303 if (strchr(dom, '/') != NULL)
304 return(YPERR_BADARGS);
307 if (!(pid == -1 || pid == gpid)) {
310 if (ysd->dom_client != NULL)
312 ysd2 = ysd->dom_pnext;
323 if (dom == NULL || strlen(dom) == 0)
324 return (YPERR_BADARGS);
326 for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext)
327 if (strcmp(dom, ysd->dom_domain) == 0)
332 ysd = (struct dom_binding *)malloc(sizeof *ysd);
333 bzero((char *)ysd, sizeof *ysd);
334 ysd->dom_socket = -1;
338 /* Check the socket -- may have been hosed by the caller. */
339 if (getsockname(ysd->dom_socket, (struct sockaddr *)&check,
340 &checklen) == -1 || check.sin_family != AF_INET ||
341 check.sin_port != ysd->dom_local_port) {
342 /* Socket became bogus somehow... need to rebind. */
345 sock = ysd->dom_socket;
346 save = dup(ysd->dom_socket);
347 if (ysd->dom_client != NULL)
348 clnt_destroy(ysd->dom_client);
350 ysd->dom_client = NULL;
351 sock = dup2(save, sock);
358 if (retries > MAX_RETRIES) {
361 return(YPERR_YPBIND);
364 if (ysd->dom_vers == 0) {
366 * We're trying to make a new binding: zorch the
367 * existing handle now (if any).
369 if (ysd->dom_client != NULL) {
370 clnt_destroy(ysd->dom_client);
371 ysd->dom_client = NULL;
372 ysd->dom_socket = -1;
374 snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2);
375 if ((fd = _open(path, O_RDONLY)) == -1) {
376 /* no binding file, YP is dead. */
377 /* Try to bring it back to life. */
381 if (flock(fd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
383 struct ypbind_resp ybr;
386 iov[0].iov_base = (caddr_t)&ypb_port;
387 iov[0].iov_len = sizeof ypb_port;
388 iov[1].iov_base = (caddr_t)&ybr;
389 iov[1].iov_len = sizeof ybr;
391 r = readv(fd, iov, 2);
392 if (r != iov[0].iov_len + iov[1].iov_len) {
398 bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
399 ysd->dom_server_addr.sin_family = AF_INET;
400 ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in);
401 ysd->dom_server_addr.sin_addr.s_addr =
402 *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
403 ysd->dom_server_addr.sin_port =
404 *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
406 ysd->dom_server_port = ysd->dom_server_addr.sin_port;
410 /* no lock on binding file, YP is dead. */
411 /* Try to bring it back to life. */
418 if (ysd->dom_vers == -1 || ysd->dom_vers == 0) {
420 * We're trying to make a new binding: zorch the
421 * existing handle now (if any).
423 if (ysd->dom_client != NULL) {
424 clnt_destroy(ysd->dom_client);
425 ysd->dom_client = NULL;
426 ysd->dom_socket = -1;
428 bzero((char *)&clnt_sin, sizeof clnt_sin);
429 clnt_sin.sin_family = AF_INET;
430 clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
432 clnt_sock = RPC_ANYSOCK;
433 client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, &clnt_sock,
435 if (client == NULL) {
437 * These conditions indicate ypbind just isn't
438 * alive -- we probably don't want to shoot our
439 * mouth off in this case; instead generate error
440 * messages only for really exotic problems.
442 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
443 (rpc_createerr.cf_stat != RPC_SYSTEMERROR &&
444 rpc_createerr.cf_error.re_errno == ECONNREFUSED))
445 clnt_pcreateerror("clnttcp_create");
448 return (YPERR_YPBIND);
452 * Check the port number -- should be < IPPORT_RESERVED.
453 * If not, it's possible someone has registered a bogus
454 * ypbind with the portmapper and is trying to trick us.
456 if (ntohs(clnt_sin.sin_port) >= IPPORT_RESERVED) {
458 clnt_destroy(client);
461 return(YPERR_YPBIND);
463 tv.tv_sec = _yplib_timeout/2;
465 r = clnt_call(client, YPBINDPROC_DOMAIN,
466 xdr_domainname, (char *)&dom, xdr_ypbind_resp, &ypbr, tv);
467 if (r != RPC_SUCCESS) {
468 clnt_destroy(client);
470 if (r == RPC_PROGUNAVAIL || r == RPC_PROCUNAVAIL) {
473 return(YPERR_YPBIND);
476 "YP: server for domain %s not responding, retrying\n", dom);
479 if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
480 struct timespec time_to_sleep, time_remaining;
482 clnt_destroy(client);
485 time_to_sleep.tv_sec = _yplib_timeout/2;
486 time_to_sleep.tv_nsec = 0;
487 _nanosleep(&time_to_sleep,
492 clnt_destroy(client);
494 bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
495 ysd->dom_server_addr.sin_family = AF_INET;
496 ysd->dom_server_addr.sin_port =
497 *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
498 ysd->dom_server_addr.sin_addr.s_addr =
499 *(u_long *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
502 * We could do a reserved port check here too, but this
503 * could pose compatibility problems. The local ypbind is
504 * supposed to decide whether or not to trust yp servers
505 * on insecure ports. For now, we trust its judgement.
507 ysd->dom_server_port =
508 *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
510 ysd->dom_vers = YPVERS;
511 strlcpy(ysd->dom_domain, dom, sizeof(ysd->dom_domain));
514 /* Don't rebuild the connection to the server unless we have to. */
515 if (ysd->dom_client == NULL) {
516 tv.tv_sec = _yplib_timeout/2;
518 ysd->dom_socket = RPC_ANYSOCK;
519 ysd->dom_client = clntudp_bufcreate(&ysd->dom_server_addr,
520 YPPROG, YPVERS, tv, &ysd->dom_socket, 1280, 2304);
521 if (ysd->dom_client == NULL) {
522 clnt_pcreateerror("clntudp_create");
526 if (_fcntl(ysd->dom_socket, F_SETFD, 1) == -1)
527 perror("fcntl: F_SETFD");
529 * We want a port number associated with this socket
530 * so that we can check its authenticity later.
532 checklen = sizeof(struct sockaddr_in);
533 bzero((char *)&check, checklen);
534 bind(ysd->dom_socket, (struct sockaddr *)&check, checklen);
535 check.sin_family = AF_INET;
536 if (!getsockname(ysd->dom_socket,
537 (struct sockaddr *)&check, &checklen)) {
538 ysd->dom_local_port = check.sin_port;
540 clnt_destroy(ysd->dom_client);
543 return(YPERR_YPBIND);
548 ysd->dom_pnext = _ypbindlist;
559 struct dom_binding *ypb;
561 struct sockaddr_in check;
562 int checklen = sizeof(struct sockaddr_in);
564 if (ypb->dom_client != NULL) {
565 /* Check the socket -- may have been hosed by the caller. */
566 if (getsockname(ypb->dom_socket, (struct sockaddr *)&check,
567 &checklen) == -1 || check.sin_family != AF_INET ||
568 check.sin_port != ypb->dom_local_port) {
571 sock = ypb->dom_socket;
572 save = dup(ypb->dom_socket);
573 clnt_destroy(ypb->dom_client);
574 sock = dup2(save, sock);
577 clnt_destroy(ypb->dom_client);
580 ypb->dom_client = NULL;
581 ypb->dom_socket = -1;
584 ypmatch_cache_flush(ypb);
592 return (_yp_dobind(dom, NULL));
599 struct dom_binding *ypb, *ypbp;
602 for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) {
603 if (strcmp(dom, ypb->dom_domain) == 0) {
606 ypbp->dom_pnext = ypb->dom_pnext;
608 _ypbindlist = ypb->dom_pnext;
618 yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
626 struct dom_binding *ysd;
627 struct ypresp_val yprv;
629 struct ypreq_key yprk;
637 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
638 inmap == NULL || !strlen(inmap) ||
639 indomain == NULL || !strlen(indomain))
640 return (YPERR_BADARGS);
642 if (_yp_dobind(indomain, &ysd) != 0)
643 return(YPERR_DOMAIN);
645 yprk.domain = indomain;
647 yprk.key.keydat_val = (char *)inkey;
648 yprk.key.keydat_len = inkeylen;
651 if (ypmatch_cache_lookup(ysd, yprk.map, &yprk.key, &yprv.val) == TRUE) {
653 if (!strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey,
654 inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) {
656 *outvallen = yprv.val.valdat_len;
657 *outval = (char *)malloc(*outvallen+1);
658 bcopy(yprv.val.valdat_val, *outval, *outvallen);
659 (*outval)[*outvallen] = '\0';
665 if (_yp_dobind(indomain, &ysd) != 0)
666 return (YPERR_DOMAIN);
668 tv.tv_sec = _yplib_timeout;
671 bzero((char *)&yprv, sizeof yprv);
673 r = clnt_call(ysd->dom_client, YPPROC_MATCH,
674 xdr_ypreq_key, &yprk, xdr_ypresp_val, &yprv, tv);
675 if (r != RPC_SUCCESS) {
676 clnt_perror(ysd->dom_client, "yp_match: clnt_call");
681 if (!(r = ypprot_err(yprv.stat))) {
682 *outvallen = yprv.val.valdat_len;
683 *outval = (char *)malloc(*outvallen+1);
684 bcopy(yprv.val.valdat_val, *outval, *outvallen);
685 (*outval)[*outvallen] = '\0';
687 ypmatch_cache_insert(ysd, yprk.map, &yprk.key, &yprv.val);
691 xdr_free(xdr_ypresp_val, (char *)&yprv);
696 yp_get_default_domain(domp)
700 if (_yp_domain[0] == '\0')
701 if (getdomainname(_yp_domain, sizeof _yp_domain))
702 return (YPERR_NODOM);
708 yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
716 struct ypresp_key_val yprkv;
717 struct ypreq_nokey yprnk;
718 struct dom_binding *ysd;
724 if (indomain == NULL || !strlen(indomain) ||
725 inmap == NULL || !strlen(inmap))
726 return (YPERR_BADARGS);
728 *outkey = *outval = NULL;
729 *outkeylen = *outvallen = 0;
732 if (_yp_dobind(indomain, &ysd) != 0)
733 return (YPERR_DOMAIN);
735 tv.tv_sec = _yplib_timeout;
738 yprnk.domain = indomain;
740 bzero((char *)&yprkv, sizeof yprkv);
742 r = clnt_call(ysd->dom_client, YPPROC_FIRST,
743 xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv);
744 if (r != RPC_SUCCESS) {
745 clnt_perror(ysd->dom_client, "yp_first: clnt_call");
749 if (!(r = ypprot_err(yprkv.stat))) {
750 *outkeylen = yprkv.key.keydat_len;
751 *outkey = (char *)malloc(*outkeylen+1);
752 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
753 (*outkey)[*outkeylen] = '\0';
754 *outvallen = yprkv.val.valdat_len;
755 *outval = (char *)malloc(*outvallen+1);
756 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
757 (*outval)[*outvallen] = '\0';
760 xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
765 yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
775 struct ypresp_key_val yprkv;
776 struct ypreq_key yprk;
777 struct dom_binding *ysd;
783 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
784 inmap == NULL || !strlen(inmap) ||
785 indomain == NULL || !strlen(indomain))
786 return (YPERR_BADARGS);
788 *outkey = *outval = NULL;
789 *outkeylen = *outvallen = 0;
792 if (_yp_dobind(indomain, &ysd) != 0)
793 return (YPERR_DOMAIN);
795 tv.tv_sec = _yplib_timeout;
798 yprk.domain = indomain;
800 yprk.key.keydat_val = inkey;
801 yprk.key.keydat_len = inkeylen;
802 bzero((char *)&yprkv, sizeof yprkv);
804 r = clnt_call(ysd->dom_client, YPPROC_NEXT,
805 xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv, tv);
806 if (r != RPC_SUCCESS) {
807 clnt_perror(ysd->dom_client, "yp_next: clnt_call");
811 if (!(r = ypprot_err(yprkv.stat))) {
812 *outkeylen = yprkv.key.keydat_len;
813 *outkey = (char *)malloc(*outkeylen+1);
814 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
815 (*outkey)[*outkeylen] = '\0';
816 *outvallen = yprkv.val.valdat_len;
817 *outval = (char *)malloc(*outvallen+1);
818 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
819 (*outval)[*outvallen] = '\0';
822 xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
827 yp_all(indomain, inmap, incallback)
830 struct ypall_callback *incallback;
832 struct ypreq_nokey yprnk;
833 struct dom_binding *ysd;
835 struct sockaddr_in clnt_sin;
837 u_long status, savstat;
842 if (indomain == NULL || !strlen(indomain) ||
843 inmap == NULL || !strlen(inmap))
844 return (YPERR_BADARGS);
848 if (_yp_dobind(indomain, &ysd) != 0)
849 return (YPERR_DOMAIN);
851 tv.tv_sec = _yplib_timeout;
854 /* YPPROC_ALL manufactures its own channel to ypserv using TCP */
856 clnt_sock = RPC_ANYSOCK;
857 clnt_sin = ysd->dom_server_addr;
858 clnt_sin.sin_port = 0;
859 clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0);
861 printf("clnttcp_create failed\n");
865 yprnk.domain = indomain;
867 ypresp_allfn = incallback->foreach;
868 ypresp_data = (void *)incallback->data;
870 if (clnt_call(clnt, YPPROC_ALL,
871 xdr_ypreq_nokey, &yprnk,
872 xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) {
873 clnt_perror(ysd->dom_client, "yp_all: clnt_call");
881 xdr_free(xdr_ypresp_all_seq, (char *)&status); /* not really needed... */
882 if (savstat != YP_NOMORE)
883 return (ypprot_err(savstat));
888 yp_order(indomain, inmap, outorder)
893 struct dom_binding *ysd;
894 struct ypresp_order ypro;
895 struct ypreq_nokey yprnk;
901 if (indomain == NULL || !strlen(indomain) ||
902 inmap == NULL || !strlen(inmap))
903 return (YPERR_BADARGS);
906 if (_yp_dobind(indomain, &ysd) != 0)
907 return (YPERR_DOMAIN);
909 tv.tv_sec = _yplib_timeout;
912 yprnk.domain = indomain;
915 bzero((char *)(char *)&ypro, sizeof ypro);
917 r = clnt_call(ysd->dom_client, YPPROC_ORDER,
918 xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv);
921 * NIS+ in YP compat mode doesn't support the YPPROC_ORDER
924 if (r == RPC_PROCUNAVAIL) {
928 if (r != RPC_SUCCESS) {
929 clnt_perror(ysd->dom_client, "yp_order: clnt_call");
934 if (!(r = ypprot_err(ypro.stat))) {
935 *outorder = ypro.ordernum;
938 xdr_free(xdr_ypresp_order, (char *)&ypro);
943 yp_master(indomain, inmap, outname)
948 struct dom_binding *ysd;
949 struct ypresp_master yprm;
950 struct ypreq_nokey yprnk;
956 if (indomain == NULL || !strlen(indomain) ||
957 inmap == NULL || !strlen(inmap))
958 return (YPERR_BADARGS);
960 if (_yp_dobind(indomain, &ysd) != 0)
961 return (YPERR_DOMAIN);
963 tv.tv_sec = _yplib_timeout;
966 yprnk.domain = indomain;
969 bzero((char *)&yprm, sizeof yprm);
971 r = clnt_call(ysd->dom_client, YPPROC_MASTER,
972 xdr_ypreq_nokey, &yprnk, xdr_ypresp_master, &yprm, tv);
973 if (r != RPC_SUCCESS) {
974 clnt_perror(ysd->dom_client, "yp_master: clnt_call");
979 if (!(r = ypprot_err(yprm.stat))) {
980 *outname = (char *)strdup(yprm.peer);
983 xdr_free(xdr_ypresp_master, (char *)&yprm);
987 yp_maplist(indomain, outmaplist)
989 struct ypmaplist **outmaplist;
991 struct dom_binding *ysd;
992 struct ypresp_maplist ypml;
998 if (indomain == NULL || !strlen(indomain))
999 return (YPERR_BADARGS);
1002 if (_yp_dobind(indomain, &ysd) != 0)
1003 return (YPERR_DOMAIN);
1005 tv.tv_sec = _yplib_timeout;
1008 bzero((char *)&ypml, sizeof ypml);
1010 r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
1011 xdr_domainname,(char *)&indomain,xdr_ypresp_maplist,&ypml,tv);
1012 if (r != RPC_SUCCESS) {
1013 clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
1017 if (!(r = ypprot_err(ypml.stat))) {
1018 *outmaplist = ypml.maps;
1021 /* NO: xdr_free(xdr_ypresp_maplist, &ypml);*/
1026 yperr_string(incode)
1029 static char err[80];
1035 return ("Request arguments bad");
1037 return ("RPC failure");
1039 return ("Can't bind to server which serves this domain");
1041 return ("No such map in server's domain");
1043 return ("No such key in map");
1045 return ("YP server error");
1047 return ("Local resource allocation failure");
1049 return ("No more records in map database");
1051 return ("Can't communicate with portmapper");
1053 return ("Can't communicate with ypbind");
1055 return ("Can't communicate with ypserv");
1057 return ("Local domain name not set");
1059 return ("Server data base is bad");
1061 return ("YP server version mismatch - server can't supply service.");
1063 return ("Access violation");
1065 return ("Database is busy");
1067 sprintf(err, "YP unknown error %d\n", incode);
1073 unsigned int incode;
1079 return (YPERR_YPBIND);
1081 return (YPERR_NOMORE);
1085 return (YPERR_DOMAIN);
1089 return (YPERR_YPERR);
1091 return (YPERR_BADDB);
1093 return (YPERR_YPERR);
1095 return (YPERR_BADARGS);
1097 return (YPERR_VERS);
1099 return (YPERR_YPERR);
1108 if (_yp_domain[0]=='\0')
1109 if (yp_get_default_domain(&unused))
1115 if (yp_bind(_yp_domain) == 0) {
1116 yp_unbind(_yp_domain);