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
32 static char *rcsid = "$FreeBSD: src/lib/libc/yp/yplib.c,v 1.34.2.2 2002/02/15 00:46:53 des Exp $";
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
47 #include <rpcsvc/yp.h>
50 * We have to define these here due to clashes between yp_prot.h and
62 struct ypmatch_ent *ypc_next;
64 #define YPLIB_MAXCACHE 5 /* At most 5 entries */
65 #define YPLIB_EXPIRE 5 /* Expire after 5 seconds */
69 struct dom_binding *dom_pnext;
70 char dom_domain[YPMAXDOMAIN + 1];
71 struct sockaddr_in dom_server_addr;
72 u_short dom_server_port;
75 u_short dom_local_port; /* now I finally know what this is for. */
78 struct ypmatch_ent *cache;
83 #include <rpcsvc/ypclnt.h>
86 #define BINDINGDIR "/var/yp/binding"
88 #define MAX_RETRIES 20
90 extern bool_t xdr_domainname(), xdr_ypbind_resp();
91 extern bool_t xdr_ypreq_key(), xdr_ypresp_val();
92 extern bool_t xdr_ypreq_nokey(), xdr_ypresp_key_val();
93 extern bool_t xdr_ypresp_all(), xdr_ypresp_all_seq();
94 extern bool_t xdr_ypresp_master();
96 int (*ypresp_allfn)();
99 static void _yp_unbind(struct dom_binding *);
100 struct dom_binding *_ypbindlist;
101 static char _yp_domain[MAXHOSTNAMELEN];
102 int _yplib_timeout = 10;
105 static void ypmatch_cache_delete(ypdb, prev, cur)
106 struct dom_binding *ypdb;
107 struct ypmatch_ent *prev;
108 struct ypmatch_ent *cur;
111 ypdb->cache = cur->ypc_next;
113 prev->ypc_next = cur->ypc_next;
116 free(cur->ypc_key.keydat_val);
117 free(cur->ypc_val.valdat_val);
120 ypdb->ypmatch_cachecnt--;
125 static void ypmatch_cache_flush(ypdb)
126 struct dom_binding *ypdb;
128 struct ypmatch_ent *n, *c = ypdb->cache;
132 ypmatch_cache_delete(ypdb, NULL, c);
139 static void ypmatch_cache_expire(ypdb)
140 struct dom_binding *ypdb;
142 struct ypmatch_ent *c = ypdb->cache;
143 struct ypmatch_ent *n, *p = NULL;
149 if (t >= c->ypc_expire_t) {
151 ypmatch_cache_delete(ypdb, p, c);
162 static void ypmatch_cache_insert(ypdb, map, key, val)
163 struct dom_binding *ypdb;
168 struct ypmatch_ent *new;
170 /* Do an expire run to maybe open up a slot. */
171 if (ypdb->ypmatch_cachecnt)
172 ypmatch_cache_expire(ypdb);
175 * If there are no slots free, then force an expire of
176 * the least recently used entry.
178 if (ypdb->ypmatch_cachecnt >= YPLIB_MAXCACHE) {
179 struct ypmatch_ent *o = NULL, *c = ypdb->cache;
185 if (c->ypc_expire_t < oldest) {
186 oldest = c->ypc_expire_t;
195 ypmatch_cache_expire(ypdb);
198 new = malloc(sizeof(struct ypmatch_ent));
202 new->ypc_map = strdup(map);
203 if (new->ypc_map == NULL) {
207 new->ypc_key.keydat_val = malloc(key->keydat_len);
208 if (new->ypc_key.keydat_val == NULL) {
213 new->ypc_val.valdat_val = malloc(val->valdat_len);
214 if (new->ypc_val.valdat_val == NULL) {
215 free(new->ypc_val.valdat_val);
221 new->ypc_expire_t = time(NULL) + YPLIB_EXPIRE;
222 new->ypc_key.keydat_len = key->keydat_len;
223 new->ypc_val.valdat_len = val->valdat_len;
224 bcopy(key->keydat_val, new->ypc_key.keydat_val, key->keydat_len);
225 bcopy(val->valdat_val, new->ypc_val.valdat_val, val->valdat_len);
227 new->ypc_next = ypdb->cache;
230 ypdb->ypmatch_cachecnt++;
235 static bool_t ypmatch_cache_lookup(ypdb, map, key, val)
236 struct dom_binding *ypdb;
241 struct ypmatch_ent *c = ypdb->cache;
243 ypmatch_cache_expire(ypdb);
245 for (c = ypdb->cache; c != NULL; c = c->ypc_next) {
246 if (strcmp(map, c->ypc_map))
248 if (key->keydat_len != c->ypc_key.keydat_len)
250 if (bcmp(key->keydat_val, c->ypc_key.keydat_val,
258 val->valdat_len = c->ypc_val.valdat_len;
259 val->valdat_val = c->ypc_val.valdat_val;
266 ypbinderr_string(incode)
274 return ("Internal ypbind error");
275 case YPBIND_ERR_NOSERV:
276 return ("Domain not bound");
277 case YPBIND_ERR_RESC:
278 return ("System resource allocation failure");
280 sprintf(err, "Unknown ypbind error: #%d\n", incode);
285 _yp_dobind(dom, ypdb)
287 struct dom_binding **ypdb;
289 static pid_t pid = -1;
290 char path[MAXPATHLEN];
291 struct dom_binding *ysd, *ysd2;
292 struct ypbind_resp ypbr;
294 struct sockaddr_in clnt_sin;
300 struct sockaddr_in check;
301 int checklen = sizeof(struct sockaddr_in);
303 /* Not allowed; bad doggie. Bad. */
304 if (strchr(dom, '/') != NULL)
305 return(YPERR_BADARGS);
308 if (!(pid == -1 || pid == gpid)) {
311 if (ysd->dom_client != NULL)
313 ysd2 = ysd->dom_pnext;
324 if (dom == NULL || strlen(dom) == 0)
325 return (YPERR_BADARGS);
327 for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext)
328 if (strcmp(dom, ysd->dom_domain) == 0)
333 ysd = (struct dom_binding *)malloc(sizeof *ysd);
334 bzero((char *)ysd, sizeof *ysd);
335 ysd->dom_socket = -1;
339 /* Check the socket -- may have been hosed by the caller. */
340 if (getsockname(ysd->dom_socket, (struct sockaddr *)&check,
341 &checklen) == -1 || check.sin_family != AF_INET ||
342 check.sin_port != ysd->dom_local_port) {
343 /* Socket became bogus somehow... need to rebind. */
346 sock = ysd->dom_socket;
347 save = dup(ysd->dom_socket);
348 if (ysd->dom_client != NULL)
349 clnt_destroy(ysd->dom_client);
351 ysd->dom_client = NULL;
352 sock = dup2(save, sock);
359 if (retries > MAX_RETRIES) {
362 return(YPERR_YPBIND);
365 if (ysd->dom_vers == 0) {
367 * We're trying to make a new binding: zorch the
368 * existing handle now (if any).
370 if (ysd->dom_client != NULL) {
371 clnt_destroy(ysd->dom_client);
372 ysd->dom_client = NULL;
373 ysd->dom_socket = -1;
375 snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2);
376 if ((fd = _open(path, O_RDONLY)) == -1) {
377 /* no binding file, YP is dead. */
378 /* Try to bring it back to life. */
382 if (flock(fd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
384 struct ypbind_resp ybr;
387 iov[0].iov_base = (caddr_t)&ypb_port;
388 iov[0].iov_len = sizeof ypb_port;
389 iov[1].iov_base = (caddr_t)&ybr;
390 iov[1].iov_len = sizeof ybr;
392 r = readv(fd, iov, 2);
393 if (r != iov[0].iov_len + iov[1].iov_len) {
399 bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
400 ysd->dom_server_addr.sin_family = AF_INET;
401 ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in);
402 ysd->dom_server_addr.sin_addr.s_addr =
403 *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
404 ysd->dom_server_addr.sin_port =
405 *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
407 ysd->dom_server_port = ysd->dom_server_addr.sin_port;
411 /* no lock on binding file, YP is dead. */
412 /* Try to bring it back to life. */
419 if (ysd->dom_vers == -1 || ysd->dom_vers == 0) {
421 * We're trying to make a new binding: zorch the
422 * existing handle now (if any).
424 if (ysd->dom_client != NULL) {
425 clnt_destroy(ysd->dom_client);
426 ysd->dom_client = NULL;
427 ysd->dom_socket = -1;
429 bzero((char *)&clnt_sin, sizeof clnt_sin);
430 clnt_sin.sin_family = AF_INET;
431 clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
433 clnt_sock = RPC_ANYSOCK;
434 client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, &clnt_sock,
436 if (client == NULL) {
438 * These conditions indicate ypbind just isn't
439 * alive -- we probably don't want to shoot our
440 * mouth off in this case; instead generate error
441 * messages only for really exotic problems.
443 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
444 (rpc_createerr.cf_stat != RPC_SYSTEMERROR &&
445 rpc_createerr.cf_error.re_errno == ECONNREFUSED))
446 clnt_pcreateerror("clnttcp_create");
449 return (YPERR_YPBIND);
453 * Check the port number -- should be < IPPORT_RESERVED.
454 * If not, it's possible someone has registered a bogus
455 * ypbind with the portmapper and is trying to trick us.
457 if (ntohs(clnt_sin.sin_port) >= IPPORT_RESERVED) {
459 clnt_destroy(client);
462 return(YPERR_YPBIND);
464 tv.tv_sec = _yplib_timeout/2;
466 r = clnt_call(client, YPBINDPROC_DOMAIN,
467 xdr_domainname, (char *)&dom, xdr_ypbind_resp, &ypbr, tv);
468 if (r != RPC_SUCCESS) {
469 clnt_destroy(client);
471 if (r == RPC_PROGUNAVAIL || r == RPC_PROCUNAVAIL) {
474 return(YPERR_YPBIND);
477 "YP: server for domain %s not responding, retrying\n", dom);
480 if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
481 struct timespec time_to_sleep, time_remaining;
483 clnt_destroy(client);
486 time_to_sleep.tv_sec = _yplib_timeout/2;
487 time_to_sleep.tv_nsec = 0;
488 _nanosleep(&time_to_sleep,
493 clnt_destroy(client);
495 bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
496 ysd->dom_server_addr.sin_family = AF_INET;
497 ysd->dom_server_addr.sin_port =
498 *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
499 ysd->dom_server_addr.sin_addr.s_addr =
500 *(u_long *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
503 * We could do a reserved port check here too, but this
504 * could pose compatibility problems. The local ypbind is
505 * supposed to decide whether or not to trust yp servers
506 * on insecure ports. For now, we trust its judgement.
508 ysd->dom_server_port =
509 *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
511 ysd->dom_vers = YPVERS;
512 strlcpy(ysd->dom_domain, dom, sizeof(ysd->dom_domain));
515 /* Don't rebuild the connection to the server unless we have to. */
516 if (ysd->dom_client == NULL) {
517 tv.tv_sec = _yplib_timeout/2;
519 ysd->dom_socket = RPC_ANYSOCK;
520 ysd->dom_client = clntudp_bufcreate(&ysd->dom_server_addr,
521 YPPROG, YPVERS, tv, &ysd->dom_socket, 1280, 2304);
522 if (ysd->dom_client == NULL) {
523 clnt_pcreateerror("clntudp_create");
527 if (_fcntl(ysd->dom_socket, F_SETFD, 1) == -1)
528 perror("fcntl: F_SETFD");
530 * We want a port number associated with this socket
531 * so that we can check its authenticity later.
533 checklen = sizeof(struct sockaddr_in);
534 bzero((char *)&check, checklen);
535 bind(ysd->dom_socket, (struct sockaddr *)&check, checklen);
536 check.sin_family = AF_INET;
537 if (!getsockname(ysd->dom_socket,
538 (struct sockaddr *)&check, &checklen)) {
539 ysd->dom_local_port = check.sin_port;
541 clnt_destroy(ysd->dom_client);
544 return(YPERR_YPBIND);
549 ysd->dom_pnext = _ypbindlist;
560 struct dom_binding *ypb;
562 struct sockaddr_in check;
563 int checklen = sizeof(struct sockaddr_in);
565 if (ypb->dom_client != NULL) {
566 /* Check the socket -- may have been hosed by the caller. */
567 if (getsockname(ypb->dom_socket, (struct sockaddr *)&check,
568 &checklen) == -1 || check.sin_family != AF_INET ||
569 check.sin_port != ypb->dom_local_port) {
572 sock = ypb->dom_socket;
573 save = dup(ypb->dom_socket);
574 clnt_destroy(ypb->dom_client);
575 sock = dup2(save, sock);
578 clnt_destroy(ypb->dom_client);
581 ypb->dom_client = NULL;
582 ypb->dom_socket = -1;
585 ypmatch_cache_flush(ypb);
593 return (_yp_dobind(dom, NULL));
600 struct dom_binding *ypb, *ypbp;
603 for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) {
604 if (strcmp(dom, ypb->dom_domain) == 0) {
607 ypbp->dom_pnext = ypb->dom_pnext;
609 _ypbindlist = ypb->dom_pnext;
619 yp_match(indomain, inmap, inkey, inkeylen, outval, outvallen)
627 struct dom_binding *ysd;
628 struct ypresp_val yprv;
630 struct ypreq_key yprk;
638 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
639 inmap == NULL || !strlen(inmap) ||
640 indomain == NULL || !strlen(indomain))
641 return (YPERR_BADARGS);
643 if (_yp_dobind(indomain, &ysd) != 0)
644 return(YPERR_DOMAIN);
646 yprk.domain = indomain;
648 yprk.key.keydat_val = (char *)inkey;
649 yprk.key.keydat_len = inkeylen;
652 if (ypmatch_cache_lookup(ysd, yprk.map, &yprk.key, &yprv.val) == TRUE) {
654 if (!strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey,
655 inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) {
657 *outvallen = yprv.val.valdat_len;
658 *outval = (char *)malloc(*outvallen+1);
659 bcopy(yprv.val.valdat_val, *outval, *outvallen);
660 (*outval)[*outvallen] = '\0';
666 if (_yp_dobind(indomain, &ysd) != 0)
667 return (YPERR_DOMAIN);
669 tv.tv_sec = _yplib_timeout;
672 bzero((char *)&yprv, sizeof yprv);
674 r = clnt_call(ysd->dom_client, YPPROC_MATCH,
675 xdr_ypreq_key, &yprk, xdr_ypresp_val, &yprv, tv);
676 if (r != RPC_SUCCESS) {
677 clnt_perror(ysd->dom_client, "yp_match: clnt_call");
682 if (!(r = ypprot_err(yprv.stat))) {
683 *outvallen = yprv.val.valdat_len;
684 *outval = (char *)malloc(*outvallen+1);
685 bcopy(yprv.val.valdat_val, *outval, *outvallen);
686 (*outval)[*outvallen] = '\0';
688 ypmatch_cache_insert(ysd, yprk.map, &yprk.key, &yprv.val);
692 xdr_free(xdr_ypresp_val, (char *)&yprv);
697 yp_get_default_domain(domp)
701 if (_yp_domain[0] == '\0')
702 if (getdomainname(_yp_domain, sizeof _yp_domain))
703 return (YPERR_NODOM);
709 yp_first(indomain, inmap, outkey, outkeylen, outval, outvallen)
717 struct ypresp_key_val yprkv;
718 struct ypreq_nokey yprnk;
719 struct dom_binding *ysd;
725 if (indomain == NULL || !strlen(indomain) ||
726 inmap == NULL || !strlen(inmap))
727 return (YPERR_BADARGS);
729 *outkey = *outval = NULL;
730 *outkeylen = *outvallen = 0;
733 if (_yp_dobind(indomain, &ysd) != 0)
734 return (YPERR_DOMAIN);
736 tv.tv_sec = _yplib_timeout;
739 yprnk.domain = indomain;
741 bzero((char *)&yprkv, sizeof yprkv);
743 r = clnt_call(ysd->dom_client, YPPROC_FIRST,
744 xdr_ypreq_nokey, &yprnk, xdr_ypresp_key_val, &yprkv, tv);
745 if (r != RPC_SUCCESS) {
746 clnt_perror(ysd->dom_client, "yp_first: clnt_call");
750 if (!(r = ypprot_err(yprkv.stat))) {
751 *outkeylen = yprkv.key.keydat_len;
752 *outkey = (char *)malloc(*outkeylen+1);
753 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
754 (*outkey)[*outkeylen] = '\0';
755 *outvallen = yprkv.val.valdat_len;
756 *outval = (char *)malloc(*outvallen+1);
757 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
758 (*outval)[*outvallen] = '\0';
761 xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
766 yp_next(indomain, inmap, inkey, inkeylen, outkey, outkeylen, outval, outvallen)
776 struct ypresp_key_val yprkv;
777 struct ypreq_key yprk;
778 struct dom_binding *ysd;
784 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
785 inmap == NULL || !strlen(inmap) ||
786 indomain == NULL || !strlen(indomain))
787 return (YPERR_BADARGS);
789 *outkey = *outval = NULL;
790 *outkeylen = *outvallen = 0;
793 if (_yp_dobind(indomain, &ysd) != 0)
794 return (YPERR_DOMAIN);
796 tv.tv_sec = _yplib_timeout;
799 yprk.domain = indomain;
801 yprk.key.keydat_val = inkey;
802 yprk.key.keydat_len = inkeylen;
803 bzero((char *)&yprkv, sizeof yprkv);
805 r = clnt_call(ysd->dom_client, YPPROC_NEXT,
806 xdr_ypreq_key, &yprk, xdr_ypresp_key_val, &yprkv, tv);
807 if (r != RPC_SUCCESS) {
808 clnt_perror(ysd->dom_client, "yp_next: clnt_call");
812 if (!(r = ypprot_err(yprkv.stat))) {
813 *outkeylen = yprkv.key.keydat_len;
814 *outkey = (char *)malloc(*outkeylen+1);
815 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
816 (*outkey)[*outkeylen] = '\0';
817 *outvallen = yprkv.val.valdat_len;
818 *outval = (char *)malloc(*outvallen+1);
819 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
820 (*outval)[*outvallen] = '\0';
823 xdr_free(xdr_ypresp_key_val, (char *)&yprkv);
828 yp_all(indomain, inmap, incallback)
831 struct ypall_callback *incallback;
833 struct ypreq_nokey yprnk;
834 struct dom_binding *ysd;
836 struct sockaddr_in clnt_sin;
838 u_long status, savstat;
843 if (indomain == NULL || !strlen(indomain) ||
844 inmap == NULL || !strlen(inmap))
845 return (YPERR_BADARGS);
849 if (_yp_dobind(indomain, &ysd) != 0)
850 return (YPERR_DOMAIN);
852 tv.tv_sec = _yplib_timeout;
855 /* YPPROC_ALL manufactures its own channel to ypserv using TCP */
857 clnt_sock = RPC_ANYSOCK;
858 clnt_sin = ysd->dom_server_addr;
859 clnt_sin.sin_port = 0;
860 clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0);
862 printf("clnttcp_create failed\n");
866 yprnk.domain = indomain;
868 ypresp_allfn = incallback->foreach;
869 ypresp_data = (void *)incallback->data;
871 if (clnt_call(clnt, YPPROC_ALL,
872 xdr_ypreq_nokey, &yprnk,
873 xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) {
874 clnt_perror(ysd->dom_client, "yp_all: clnt_call");
882 xdr_free(xdr_ypresp_all_seq, (char *)&status); /* not really needed... */
883 if (savstat != YP_NOMORE)
884 return (ypprot_err(savstat));
889 yp_order(indomain, inmap, outorder)
894 struct dom_binding *ysd;
895 struct ypresp_order ypro;
896 struct ypreq_nokey yprnk;
902 if (indomain == NULL || !strlen(indomain) ||
903 inmap == NULL || !strlen(inmap))
904 return (YPERR_BADARGS);
907 if (_yp_dobind(indomain, &ysd) != 0)
908 return (YPERR_DOMAIN);
910 tv.tv_sec = _yplib_timeout;
913 yprnk.domain = indomain;
916 bzero((char *)(char *)&ypro, sizeof ypro);
918 r = clnt_call(ysd->dom_client, YPPROC_ORDER,
919 xdr_ypreq_nokey, &yprnk, xdr_ypresp_order, &ypro, tv);
922 * NIS+ in YP compat mode doesn't support the YPPROC_ORDER
925 if (r == RPC_PROCUNAVAIL) {
929 if (r != RPC_SUCCESS) {
930 clnt_perror(ysd->dom_client, "yp_order: clnt_call");
935 if (!(r = ypprot_err(ypro.stat))) {
936 *outorder = ypro.ordernum;
939 xdr_free(xdr_ypresp_order, (char *)&ypro);
944 yp_master(indomain, inmap, outname)
949 struct dom_binding *ysd;
950 struct ypresp_master yprm;
951 struct ypreq_nokey yprnk;
957 if (indomain == NULL || !strlen(indomain) ||
958 inmap == NULL || !strlen(inmap))
959 return (YPERR_BADARGS);
961 if (_yp_dobind(indomain, &ysd) != 0)
962 return (YPERR_DOMAIN);
964 tv.tv_sec = _yplib_timeout;
967 yprnk.domain = indomain;
970 bzero((char *)&yprm, sizeof yprm);
972 r = clnt_call(ysd->dom_client, YPPROC_MASTER,
973 xdr_ypreq_nokey, &yprnk, xdr_ypresp_master, &yprm, tv);
974 if (r != RPC_SUCCESS) {
975 clnt_perror(ysd->dom_client, "yp_master: clnt_call");
980 if (!(r = ypprot_err(yprm.stat))) {
981 *outname = (char *)strdup(yprm.peer);
984 xdr_free(xdr_ypresp_master, (char *)&yprm);
988 yp_maplist(indomain, outmaplist)
990 struct ypmaplist **outmaplist;
992 struct dom_binding *ysd;
993 struct ypresp_maplist ypml;
999 if (indomain == NULL || !strlen(indomain))
1000 return (YPERR_BADARGS);
1003 if (_yp_dobind(indomain, &ysd) != 0)
1004 return (YPERR_DOMAIN);
1006 tv.tv_sec = _yplib_timeout;
1009 bzero((char *)&ypml, sizeof ypml);
1011 r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
1012 xdr_domainname,(char *)&indomain,xdr_ypresp_maplist,&ypml,tv);
1013 if (r != RPC_SUCCESS) {
1014 clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
1018 if (!(r = ypprot_err(ypml.stat))) {
1019 *outmaplist = ypml.maps;
1022 /* NO: xdr_free(xdr_ypresp_maplist, &ypml);*/
1027 yperr_string(incode)
1030 static char err[80];
1036 return ("Request arguments bad");
1038 return ("RPC failure");
1040 return ("Can't bind to server which serves this domain");
1042 return ("No such map in server's domain");
1044 return ("No such key in map");
1046 return ("YP server error");
1048 return ("Local resource allocation failure");
1050 return ("No more records in map database");
1052 return ("Can't communicate with portmapper");
1054 return ("Can't communicate with ypbind");
1056 return ("Can't communicate with ypserv");
1058 return ("Local domain name not set");
1060 return ("Server data base is bad");
1062 return ("YP server version mismatch - server can't supply service.");
1064 return ("Access violation");
1066 return ("Database is busy");
1068 sprintf(err, "YP unknown error %d\n", incode);
1074 unsigned int incode;
1080 return (YPERR_YPBIND);
1082 return (YPERR_NOMORE);
1086 return (YPERR_DOMAIN);
1090 return (YPERR_YPERR);
1092 return (YPERR_BADDB);
1094 return (YPERR_YPERR);
1096 return (YPERR_BADARGS);
1098 return (YPERR_VERS);
1100 return (YPERR_YPERR);
1109 if (_yp_domain[0]=='\0')
1110 if (yp_get_default_domain(&unused))
1116 if (yp_bind(_yp_domain) == 0) {
1117 yp_unbind(_yp_domain);