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
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include "namespace.h"
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
40 #include <arpa/inet.h>
48 #include <rpcsvc/yp.h>
49 #include "un-namespace.h"
50 #include "libc_private.h"
53 * We have to define these here due to clashes between yp_prot.h and
65 struct ypmatch_ent *ypc_next;
67 #define YPLIB_MAXCACHE 5 /* At most 5 entries */
68 #define YPLIB_EXPIRE 5 /* Expire after 5 seconds */
72 struct dom_binding *dom_pnext;
73 char dom_domain[YPMAXDOMAIN + 1];
74 struct sockaddr_in dom_server_addr;
75 u_short dom_server_port;
78 u_short dom_local_port; /* now I finally know what this is for. */
81 struct ypmatch_ent *cache;
86 #include <rpcsvc/ypclnt.h>
89 #define BINDINGDIR "/var/yp/binding"
91 #define MAX_RETRIES 20
93 extern bool_t xdr_domainname(), xdr_ypbind_resp();
94 extern bool_t xdr_ypreq_key(), xdr_ypresp_val();
95 extern bool_t xdr_ypreq_nokey(), xdr_ypresp_key_val();
96 extern bool_t xdr_ypresp_all(), xdr_ypresp_all_seq();
97 extern bool_t xdr_ypresp_master();
99 int (*ypresp_allfn)();
102 static void _yp_unbind(struct dom_binding *);
103 struct dom_binding *_ypbindlist;
104 static char _yp_domain[MAXHOSTNAMELEN];
105 int _yplib_timeout = 10;
109 ypmatch_cache_delete(struct dom_binding *ypdb, struct ypmatch_ent *prev,
110 struct ypmatch_ent *cur)
113 ypdb->cache = cur->ypc_next;
115 prev->ypc_next = cur->ypc_next;
118 free(cur->ypc_key.keydat_val);
119 free(cur->ypc_val.valdat_val);
122 ypdb->ypmatch_cachecnt--;
128 ypmatch_cache_flush(struct dom_binding *ypdb)
130 struct ypmatch_ent *n, *c = ypdb->cache;
134 ypmatch_cache_delete(ypdb, NULL, c);
142 ypmatch_cache_expire(struct dom_binding *ypdb)
144 struct ypmatch_ent *c = ypdb->cache;
145 struct ypmatch_ent *n, *p = NULL;
151 if (t >= c->ypc_expire_t) {
153 ypmatch_cache_delete(ypdb, p, c);
165 ypmatch_cache_insert(struct dom_binding *ypdb, char *map, keydat *key,
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++;
236 ypmatch_cache_lookup(struct dom_binding *ypdb, char *map, keydat *key,
239 struct ypmatch_ent *c = ypdb->cache;
241 ypmatch_cache_expire(ypdb);
243 for (c = ypdb->cache; c != NULL; c = c->ypc_next) {
244 if (strcmp(map, c->ypc_map))
246 if (key->keydat_len != c->ypc_key.keydat_len)
248 if (bcmp(key->keydat_val, c->ypc_key.keydat_val,
256 val->valdat_len = c->ypc_val.valdat_len;
257 val->valdat_val = c->ypc_val.valdat_val;
264 ypbinderr_string(int incode)
271 return ("Internal ypbind error");
272 case YPBIND_ERR_NOSERV:
273 return ("Domain not bound");
274 case YPBIND_ERR_RESC:
275 return ("System resource allocation failure");
277 sprintf(err, "Unknown ypbind error: #%d\n", incode);
282 _yp_dobind(char *dom, struct dom_binding **ypdb)
284 static pid_t pid = -1;
285 char path[MAXPATHLEN];
286 struct dom_binding *ysd, *ysd2;
287 struct ypbind_resp ypbr;
289 struct sockaddr_in clnt_sin;
295 struct sockaddr_in check;
296 int checklen = sizeof(struct sockaddr_in);
298 /* Not allowed; bad doggie. Bad. */
299 if (strchr(dom, '/') != NULL)
300 return(YPERR_BADARGS);
303 if (!(pid == -1 || pid == gpid)) {
306 if (ysd->dom_client != NULL)
308 ysd2 = ysd->dom_pnext;
319 if (dom == NULL || strlen(dom) == 0)
320 return (YPERR_BADARGS);
322 for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext)
323 if (strcmp(dom, ysd->dom_domain) == 0)
328 ysd = (struct dom_binding *)malloc(sizeof *ysd);
329 bzero((char *)ysd, sizeof *ysd);
330 ysd->dom_socket = -1;
334 /* Check the socket -- may have been hosed by the caller. */
335 if (_getsockname(ysd->dom_socket, (struct sockaddr *)&check,
336 &checklen) == -1 || check.sin_family != AF_INET ||
337 check.sin_port != ysd->dom_local_port) {
338 /* Socket became bogus somehow... need to rebind. */
341 sock = ysd->dom_socket;
342 save = _dup(ysd->dom_socket);
343 if (ysd->dom_client != NULL)
344 clnt_destroy(ysd->dom_client);
346 ysd->dom_client = NULL;
347 sock = _dup2(save, sock);
354 if (retries > MAX_RETRIES) {
357 return(YPERR_YPBIND);
360 if (ysd->dom_vers == 0) {
362 * We're trying to make a new binding: zorch the
363 * existing handle now (if any).
365 if (ysd->dom_client != NULL) {
366 clnt_destroy(ysd->dom_client);
367 ysd->dom_client = NULL;
368 ysd->dom_socket = -1;
370 snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2);
371 if ((fd = _open(path, O_RDONLY)) == -1) {
372 /* no binding file, YP is dead. */
373 /* Try to bring it back to life. */
377 if (_flock(fd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
379 struct ypbind_resp ybr;
382 iov[0].iov_base = (caddr_t)&ypb_port;
383 iov[0].iov_len = sizeof ypb_port;
384 iov[1].iov_base = (caddr_t)&ybr;
385 iov[1].iov_len = sizeof ybr;
387 r = _readv(fd, iov, 2);
388 if (r != iov[0].iov_len + iov[1].iov_len) {
394 bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
395 ysd->dom_server_addr.sin_family = AF_INET;
396 ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in);
397 bcopy(&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,
398 &ysd->dom_server_addr.sin_addr.s_addr,
399 sizeof(ysd->dom_server_addr.sin_addr.s_addr));
400 bcopy(&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,
401 &ysd->dom_server_addr.sin_port,
402 sizeof(ysd->dom_server_addr.sin_port));
404 ysd->dom_server_port = ysd->dom_server_addr.sin_port;
408 /* no lock on binding file, YP is dead. */
409 /* Try to bring it back to life. */
416 if (ysd->dom_vers == -1 || ysd->dom_vers == 0) {
418 * We're trying to make a new binding: zorch the
419 * existing handle now (if any).
421 if (ysd->dom_client != NULL) {
422 clnt_destroy(ysd->dom_client);
423 ysd->dom_client = NULL;
424 ysd->dom_socket = -1;
426 bzero((char *)&clnt_sin, sizeof clnt_sin);
427 clnt_sin.sin_family = AF_INET;
428 clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
430 clnt_sock = RPC_ANYSOCK;
431 client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, &clnt_sock,
433 if (client == NULL) {
435 * These conditions indicate ypbind just isn't
436 * alive -- we probably don't want to shoot our
437 * mouth off in this case; instead generate error
438 * messages only for really exotic problems.
440 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
441 (rpc_createerr.cf_stat != RPC_SYSTEMERROR &&
442 rpc_createerr.cf_error.re_errno == ECONNREFUSED))
443 clnt_pcreateerror("clnttcp_create");
446 return (YPERR_YPBIND);
450 * Check the port number -- should be < IPPORT_RESERVED.
451 * If not, it's possible someone has registered a bogus
452 * ypbind with the portmapper and is trying to trick us.
454 if (ntohs(clnt_sin.sin_port) >= IPPORT_RESERVED) {
456 clnt_destroy(client);
459 return(YPERR_YPBIND);
461 tv.tv_sec = _yplib_timeout/2;
463 r = clnt_call(client, YPBINDPROC_DOMAIN,
464 (xdrproc_t)xdr_domainname, &dom,
465 (xdrproc_t)xdr_ypbind_resp, &ypbr, tv);
466 if (r != RPC_SUCCESS) {
467 clnt_destroy(client);
469 if (r == RPC_PROGUNAVAIL || r == RPC_PROCUNAVAIL) {
472 return(YPERR_YPBIND);
475 "YP: server for domain %s not responding, retrying\n", dom);
478 if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
479 struct timespec time_to_sleep, time_remaining;
481 clnt_destroy(client);
484 time_to_sleep.tv_sec = _yplib_timeout/2;
485 time_to_sleep.tv_nsec = 0;
486 _nanosleep(&time_to_sleep,
491 clnt_destroy(client);
493 bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
494 ysd->dom_server_addr.sin_family = AF_INET;
495 bcopy(&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,
496 &ysd->dom_server_addr.sin_port,
497 sizeof(ysd->dom_server_addr.sin_port));
498 bcopy(&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,
499 &ysd->dom_server_addr.sin_addr.s_addr,
500 sizeof(ysd->dom_server_addr.sin_addr.s_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;
559 _yp_unbind(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);
591 return (_yp_dobind(dom, NULL));
597 struct dom_binding *ypb, *ypbp;
600 for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) {
601 if (strcmp(dom, ypb->dom_domain) == 0) {
604 ypbp->dom_pnext = ypb->dom_pnext;
606 _ypbindlist = ypb->dom_pnext;
616 yp_match(char *indomain, char *inmap, const char *inkey, int inkeylen,
617 char **outval, int *outvallen)
619 struct dom_binding *ysd;
620 struct ypresp_val yprv;
622 struct ypreq_key yprk;
630 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
631 inmap == NULL || !strlen(inmap) ||
632 indomain == NULL || !strlen(indomain))
633 return (YPERR_BADARGS);
635 if (_yp_dobind(indomain, &ysd) != 0)
636 return(YPERR_DOMAIN);
638 yprk.domain = indomain;
640 yprk.key.keydat_val = (char *)inkey;
641 yprk.key.keydat_len = inkeylen;
644 if (ypmatch_cache_lookup(ysd, yprk.map, &yprk.key, &yprv.val) == TRUE) {
646 if (!strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey,
647 inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) {
649 *outvallen = yprv.val.valdat_len;
650 *outval = (char *)malloc(*outvallen+1);
651 bcopy(yprv.val.valdat_val, *outval, *outvallen);
652 (*outval)[*outvallen] = '\0';
658 if (_yp_dobind(indomain, &ysd) != 0)
659 return (YPERR_DOMAIN);
661 tv.tv_sec = _yplib_timeout;
664 bzero((char *)&yprv, sizeof yprv);
666 r = clnt_call(ysd->dom_client, YPPROC_MATCH,
667 (xdrproc_t)xdr_ypreq_key, &yprk,
668 (xdrproc_t)xdr_ypresp_val, &yprv, tv);
669 if (r != RPC_SUCCESS) {
670 clnt_perror(ysd->dom_client, "yp_match: clnt_call");
675 if (!(r = ypprot_err(yprv.stat))) {
676 *outvallen = yprv.val.valdat_len;
677 *outval = (char *)malloc(*outvallen+1);
678 bcopy(yprv.val.valdat_val, *outval, *outvallen);
679 (*outval)[*outvallen] = '\0';
681 ypmatch_cache_insert(ysd, yprk.map, &yprk.key, &yprv.val);
685 xdr_free((xdrproc_t)xdr_ypresp_val, &yprv);
690 yp_get_default_domain(char **domp)
693 if (_yp_domain[0] == '\0')
694 if (getdomainname(_yp_domain, sizeof _yp_domain))
695 return (YPERR_NODOM);
701 yp_first(char *indomain, char *inmap, char **outkey, int *outkeylen,
702 char **outval, int *outvallen)
704 struct ypresp_key_val yprkv;
705 struct ypreq_nokey yprnk;
706 struct dom_binding *ysd;
712 if (indomain == NULL || !strlen(indomain) ||
713 inmap == NULL || !strlen(inmap))
714 return (YPERR_BADARGS);
716 *outkey = *outval = NULL;
717 *outkeylen = *outvallen = 0;
720 if (_yp_dobind(indomain, &ysd) != 0)
721 return (YPERR_DOMAIN);
723 tv.tv_sec = _yplib_timeout;
726 yprnk.domain = indomain;
728 bzero((char *)&yprkv, sizeof yprkv);
730 r = clnt_call(ysd->dom_client, YPPROC_FIRST,
731 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
732 (xdrproc_t)xdr_ypresp_key_val, &yprkv, tv);
733 if (r != RPC_SUCCESS) {
734 clnt_perror(ysd->dom_client, "yp_first: clnt_call");
738 if (!(r = ypprot_err(yprkv.stat))) {
739 *outkeylen = yprkv.key.keydat_len;
740 *outkey = (char *)malloc(*outkeylen+1);
741 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
742 (*outkey)[*outkeylen] = '\0';
743 *outvallen = yprkv.val.valdat_len;
744 *outval = (char *)malloc(*outvallen+1);
745 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
746 (*outval)[*outvallen] = '\0';
749 xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
754 yp_next(char *indomain, char *inmap, char *inkey, int inkeylen,
755 char **outkey, int *outkeylen, char **outval, int *outvallen)
757 struct ypresp_key_val yprkv;
758 struct ypreq_key yprk;
759 struct dom_binding *ysd;
765 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
766 inmap == NULL || !strlen(inmap) ||
767 indomain == NULL || !strlen(indomain))
768 return (YPERR_BADARGS);
770 *outkey = *outval = NULL;
771 *outkeylen = *outvallen = 0;
774 if (_yp_dobind(indomain, &ysd) != 0)
775 return (YPERR_DOMAIN);
777 tv.tv_sec = _yplib_timeout;
780 yprk.domain = indomain;
782 yprk.key.keydat_val = inkey;
783 yprk.key.keydat_len = inkeylen;
784 bzero((char *)&yprkv, sizeof yprkv);
786 r = clnt_call(ysd->dom_client, YPPROC_NEXT,
787 (xdrproc_t)xdr_ypreq_key, &yprk,
788 (xdrproc_t)xdr_ypresp_key_val, &yprkv, tv);
789 if (r != RPC_SUCCESS) {
790 clnt_perror(ysd->dom_client, "yp_next: clnt_call");
794 if (!(r = ypprot_err(yprkv.stat))) {
795 *outkeylen = yprkv.key.keydat_len;
796 *outkey = (char *)malloc(*outkeylen+1);
797 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
798 (*outkey)[*outkeylen] = '\0';
799 *outvallen = yprkv.val.valdat_len;
800 *outval = (char *)malloc(*outvallen+1);
801 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
802 (*outval)[*outvallen] = '\0';
805 xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
810 yp_all(char *indomain, char *inmap, struct ypall_callback *incallback)
812 struct ypreq_nokey yprnk;
813 struct dom_binding *ysd;
815 struct sockaddr_in clnt_sin;
817 u_long status, savstat;
822 if (indomain == NULL || !strlen(indomain) ||
823 inmap == NULL || !strlen(inmap))
824 return (YPERR_BADARGS);
828 if (_yp_dobind(indomain, &ysd) != 0)
829 return (YPERR_DOMAIN);
831 tv.tv_sec = _yplib_timeout;
834 /* YPPROC_ALL manufactures its own channel to ypserv using TCP */
836 clnt_sock = RPC_ANYSOCK;
837 clnt_sin = ysd->dom_server_addr;
838 clnt_sin.sin_port = 0;
839 clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0);
841 printf("clnttcp_create failed\n");
845 yprnk.domain = indomain;
847 ypresp_allfn = incallback->foreach;
848 ypresp_data = (void *)incallback->data;
850 if (clnt_call(clnt, YPPROC_ALL,
851 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
852 (xdrproc_t)xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) {
853 clnt_perror(ysd->dom_client, "yp_all: clnt_call");
861 xdr_free((xdrproc_t)xdr_ypresp_all_seq, &status); /* not really needed... */
862 if (savstat != YP_NOMORE)
863 return (ypprot_err(savstat));
868 yp_order(char *indomain, char *inmap, int *outorder)
870 struct dom_binding *ysd;
871 struct ypresp_order ypro;
872 struct ypreq_nokey yprnk;
878 if (indomain == NULL || !strlen(indomain) ||
879 inmap == NULL || !strlen(inmap))
880 return (YPERR_BADARGS);
883 if (_yp_dobind(indomain, &ysd) != 0)
884 return (YPERR_DOMAIN);
886 tv.tv_sec = _yplib_timeout;
889 yprnk.domain = indomain;
892 bzero((char *)(char *)&ypro, sizeof ypro);
894 r = clnt_call(ysd->dom_client, YPPROC_ORDER,
895 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
896 (xdrproc_t)xdr_ypresp_order, &ypro, tv);
899 * NIS+ in YP compat mode doesn't support the YPPROC_ORDER
902 if (r == RPC_PROCUNAVAIL) {
906 if (r != RPC_SUCCESS) {
907 clnt_perror(ysd->dom_client, "yp_order: clnt_call");
912 if (!(r = ypprot_err(ypro.stat))) {
913 *outorder = ypro.ordernum;
916 xdr_free((xdrproc_t)xdr_ypresp_order, &ypro);
921 yp_master(char *indomain, char *inmap, char **outname)
923 struct dom_binding *ysd;
924 struct ypresp_master yprm;
925 struct ypreq_nokey yprnk;
931 if (indomain == NULL || !strlen(indomain) ||
932 inmap == NULL || !strlen(inmap))
933 return (YPERR_BADARGS);
935 if (_yp_dobind(indomain, &ysd) != 0)
936 return (YPERR_DOMAIN);
938 tv.tv_sec = _yplib_timeout;
941 yprnk.domain = indomain;
944 bzero((char *)&yprm, sizeof yprm);
946 r = clnt_call(ysd->dom_client, YPPROC_MASTER,
947 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
948 (xdrproc_t)xdr_ypresp_master, &yprm, tv);
949 if (r != RPC_SUCCESS) {
950 clnt_perror(ysd->dom_client, "yp_master: clnt_call");
955 if (!(r = ypprot_err(yprm.stat))) {
956 *outname = (char *)strdup(yprm.peer);
959 xdr_free((xdrproc_t)xdr_ypresp_master, &yprm);
964 yp_maplist(char *indomain, struct ypmaplist **outmaplist)
966 struct dom_binding *ysd;
967 struct ypresp_maplist ypml;
973 if (indomain == NULL || !strlen(indomain))
974 return (YPERR_BADARGS);
977 if (_yp_dobind(indomain, &ysd) != 0)
978 return (YPERR_DOMAIN);
980 tv.tv_sec = _yplib_timeout;
983 bzero((char *)&ypml, sizeof ypml);
985 r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
986 (xdrproc_t)xdr_domainname, &indomain,
987 (xdrproc_t)xdr_ypresp_maplist, &ypml,tv);
988 if (r != RPC_SUCCESS) {
989 clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
993 if (!(r = ypprot_err(ypml.stat))) {
994 *outmaplist = ypml.maps;
997 /* NO: xdr_free((xdrproc_t)xdr_ypresp_maplist, &ypml);*/
1002 yperr_string(int incode)
1004 static char err[80];
1010 return ("Request arguments bad");
1012 return ("RPC failure");
1014 return ("Can't bind to server which serves this domain");
1016 return ("No such map in server's domain");
1018 return ("No such key in map");
1020 return ("YP server error");
1022 return ("Local resource allocation failure");
1024 return ("No more records in map database");
1026 return ("Can't communicate with portmapper");
1028 return ("Can't communicate with ypbind");
1030 return ("Can't communicate with ypserv");
1032 return ("Local domain name not set");
1034 return ("Server data base is bad");
1036 return ("YP server version mismatch - server can't supply service.");
1038 return ("Access violation");
1040 return ("Database is busy");
1042 sprintf(err, "YP unknown error %d\n", incode);
1047 ypprot_err(unsigned int incode)
1053 return (YPERR_YPBIND);
1055 return (YPERR_NOMORE);
1059 return (YPERR_DOMAIN);
1063 return (YPERR_YPERR);
1065 return (YPERR_BADDB);
1067 return (YPERR_YPERR);
1069 return (YPERR_BADARGS);
1071 return (YPERR_VERS);
1073 return (YPERR_YPERR);
1077 _yp_check(char **dom)
1081 if (_yp_domain[0]=='\0')
1082 if (yp_get_default_domain(&unused))
1088 if (yp_bind(_yp_domain) == 0) {
1089 yp_unbind(_yp_domain);