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/libc/yp/yplib.c,v 1.9 2006/08/03 16:40:46 swildner Exp $
34 #include "namespace.h"
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
47 #include <rpcsvc/yp.h>
48 #include "un-namespace.h"
50 bool_t xdr_ypresp_all_seq(XDR *, u_long *);
51 int _yp_check(char **);
53 int (*ypresp_allfn)(unsigned long, char *, int, char *, int, void *);
56 * We have to define these here due to clashes between yp_prot.h and
68 struct ypmatch_ent *ypc_next;
70 #define YPLIB_MAXCACHE 5 /* At most 5 entries */
71 #define YPLIB_EXPIRE 5 /* Expire after 5 seconds */
75 struct dom_binding *dom_pnext;
76 char dom_domain[YPMAXDOMAIN + 1];
77 struct sockaddr_in dom_server_addr;
78 u_short dom_server_port;
81 u_short dom_local_port; /* now I finally know what this is for. */
84 struct ypmatch_ent *cache;
89 #include <rpcsvc/yp.h>
90 #include <rpcsvc/ypclnt.h>
93 #define BINDINGDIR "/var/yp/binding"
95 #define MAX_RETRIES 20
99 static void _yp_unbind(struct dom_binding *);
100 struct dom_binding *_ypbindlist;
101 static char _yp_domain[MAXHOSTNAMELEN];
102 int _yplib_timeout = 10;
106 ypmatch_cache_delete(struct dom_binding *ypdb, 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--;
125 ypmatch_cache_flush(struct dom_binding *ypdb)
127 struct ypmatch_ent *n, *c = ypdb->cache;
131 ypmatch_cache_delete(ypdb, NULL, c);
139 ypmatch_cache_expire(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);
162 ypmatch_cache_insert(struct dom_binding *ypdb, char *map, keydat *key,
165 struct ypmatch_ent *new;
167 /* Do an expire run to maybe open up a slot. */
168 if (ypdb->ypmatch_cachecnt)
169 ypmatch_cache_expire(ypdb);
172 * If there are no slots free, then force an expire of
173 * the least recently used entry.
175 if (ypdb->ypmatch_cachecnt >= YPLIB_MAXCACHE) {
176 struct ypmatch_ent *o = NULL, *c = ypdb->cache;
182 if (c->ypc_expire_t < oldest) {
183 oldest = c->ypc_expire_t;
192 ypmatch_cache_expire(ypdb);
195 new = malloc(sizeof(struct ypmatch_ent));
199 new->ypc_map = strdup(map);
200 if (new->ypc_map == NULL) {
204 new->ypc_key.keydat_val = malloc(key->keydat_len);
205 if (new->ypc_key.keydat_val == NULL) {
210 new->ypc_val.valdat_val = malloc(val->valdat_len);
211 if (new->ypc_val.valdat_val == NULL) {
212 free(new->ypc_val.valdat_val);
218 new->ypc_expire_t = time(NULL) + YPLIB_EXPIRE;
219 new->ypc_key.keydat_len = key->keydat_len;
220 new->ypc_val.valdat_len = val->valdat_len;
221 bcopy(key->keydat_val, new->ypc_key.keydat_val, key->keydat_len);
222 bcopy(val->valdat_val, new->ypc_val.valdat_val, val->valdat_len);
224 new->ypc_next = ypdb->cache;
227 ypdb->ypmatch_cachecnt++;
233 ypmatch_cache_lookup(struct dom_binding *ypdb, char *map, keydat *key,
236 struct ypmatch_ent *c = ypdb->cache;
238 ypmatch_cache_expire(ypdb);
240 for (c = ypdb->cache; c != NULL; c = c->ypc_next) {
241 if (strcmp(map, c->ypc_map))
243 if (key->keydat_len != c->ypc_key.keydat_len)
245 if (bcmp(key->keydat_val, c->ypc_key.keydat_val,
253 val->valdat_len = c->ypc_val.valdat_len;
254 val->valdat_val = c->ypc_val.valdat_val;
261 ypbinderr_string(int incode)
270 errstr = "Internal ypbind error";
272 case YPBIND_ERR_NOSERV:
273 errstr = "Domain not bound";
275 case YPBIND_ERR_RESC:
276 errstr = "System resource allocation failure";
283 strlcpy(err, errstr, sizeof(err));
285 snprintf(err, sizeof(err), "Unknown ypbind error: #%d\n", incode);
290 _yp_dobind(const char *dom, struct dom_binding **ypdb)
292 static pid_t pid = -1;
293 char path[MAXPATHLEN];
294 struct dom_binding *ysd, *ysd2;
295 struct ypbind_resp ypbr;
297 struct sockaddr_in clnt_sin;
304 struct sockaddr_in check;
305 int checklen = sizeof(struct sockaddr_in);
307 /* Not allowed; bad doggie. Bad. */
308 if (strchr(dom, '/') != NULL)
309 return(YPERR_BADARGS);
312 if (!(pid == -1 || pid == gpid)) {
315 if (ysd->dom_client != NULL)
317 ysd2 = ysd->dom_pnext;
328 if (dom == NULL || strlen(dom) == 0)
329 return (YPERR_BADARGS);
331 for (ysd = _ypbindlist; ysd; ysd = ysd->dom_pnext)
332 if (strcmp(dom, ysd->dom_domain) == 0)
337 ysd = (struct dom_binding *)malloc(sizeof *ysd);
338 bzero((char *)ysd, sizeof *ysd);
339 ysd->dom_socket = -1;
343 /* Check the socket -- may have been hosed by the caller. */
344 if (_getsockname(ysd->dom_socket, (struct sockaddr *)&check,
345 &checklen) == -1 || check.sin_family != AF_INET ||
346 check.sin_port != ysd->dom_local_port) {
347 /* Socket became bogus somehow... need to rebind. */
350 sock = ysd->dom_socket;
351 save = _dup(ysd->dom_socket);
352 if (ysd->dom_client != NULL)
353 clnt_destroy(ysd->dom_client);
355 ysd->dom_client = NULL;
356 sock = _dup2(save, sock);
363 if (retries > MAX_RETRIES) {
366 return(YPERR_YPBIND);
369 if (ysd->dom_vers == 0) {
371 * We're trying to make a new binding: zorch the
372 * existing handle now (if any).
374 if (ysd->dom_client != NULL) {
375 clnt_destroy(ysd->dom_client);
376 ysd->dom_client = NULL;
377 ysd->dom_socket = -1;
379 snprintf(path, sizeof(path), "%s/%s.%d", BINDINGDIR, dom, 2);
380 if ((fd = _open(path, O_RDONLY)) == -1) {
381 /* no binding file, YP is dead. */
382 /* Try to bring it back to life. */
386 if (_flock(fd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
388 struct ypbind_resp ybr;
391 iov[0].iov_base = (caddr_t)&ypb_port;
392 iov[0].iov_len = sizeof ypb_port;
393 iov[1].iov_base = (caddr_t)&ybr;
394 iov[1].iov_len = sizeof ybr;
396 r = _readv(fd, iov, 2);
397 if (r != (ssize_t)(iov[0].iov_len + iov[1].iov_len)) {
403 bzero(&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
404 ysd->dom_server_addr.sin_family = AF_INET;
405 ysd->dom_server_addr.sin_len = sizeof(struct sockaddr_in);
406 ysd->dom_server_addr.sin_addr.s_addr =
407 *(u_long *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
408 ysd->dom_server_addr.sin_port =
409 *(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
411 ysd->dom_server_port = ysd->dom_server_addr.sin_port;
415 /* no lock on binding file, YP is dead. */
416 /* Try to bring it back to life. */
423 if (ysd->dom_vers == -1 || ysd->dom_vers == 0) {
425 * We're trying to make a new binding: zorch the
426 * existing handle now (if any).
428 if (ysd->dom_client != NULL) {
429 clnt_destroy(ysd->dom_client);
430 ysd->dom_client = NULL;
431 ysd->dom_socket = -1;
433 bzero((char *)&clnt_sin, sizeof clnt_sin);
434 clnt_sin.sin_family = AF_INET;
435 clnt_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
437 clnt_sock = RPC_ANYSOCK;
438 client = clnttcp_create(&clnt_sin, YPBINDPROG, YPBINDVERS, &clnt_sock,
440 if (client == NULL) {
442 * These conditions indicate ypbind just isn't
443 * alive -- we probably don't want to shoot our
444 * mouth off in this case; instead generate error
445 * messages only for really exotic problems.
447 if (rpc_createerr.cf_stat != RPC_PROGNOTREGISTERED &&
448 (rpc_createerr.cf_stat != RPC_SYSTEMERROR &&
449 rpc_createerr.cf_error.re_errno == ECONNREFUSED))
450 clnt_pcreateerror("clnttcp_create");
453 return (YPERR_YPBIND);
457 * Check the port number -- should be < IPPORT_RESERVED.
458 * If not, it's possible someone has registered a bogus
459 * ypbind with the portmapper and is trying to trick us.
461 if (ntohs(clnt_sin.sin_port) >= IPPORT_RESERVED) {
463 clnt_destroy(client);
466 return(YPERR_YPBIND);
468 tv.tv_sec = _yplib_timeout/2;
470 r = clnt_call(client, YPBINDPROC_DOMAIN,
471 (xdrproc_t)xdr_domainname, (char *)&dom,
472 (xdrproc_t)xdr_ypbind_resp, &ypbr, tv);
473 if (r != RPC_SUCCESS) {
474 clnt_destroy(client);
476 if (r == RPC_PROGUNAVAIL || r == RPC_PROCUNAVAIL) {
479 return(YPERR_YPBIND);
482 "YP: server for domain %s not responding, retrying\n", dom);
485 if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
486 struct timespec time_to_sleep, time_remaining;
488 clnt_destroy(client);
491 time_to_sleep.tv_sec = _yplib_timeout/2;
492 time_to_sleep.tv_nsec = 0;
493 _nanosleep(&time_to_sleep,
498 clnt_destroy(client);
500 bzero((char *)&ysd->dom_server_addr, sizeof ysd->dom_server_addr);
501 ysd->dom_server_addr.sin_family = AF_INET;
502 ysd->dom_server_addr.sin_port =
503 *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
504 ysd->dom_server_addr.sin_addr.s_addr =
505 *(u_long *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr;
508 * We could do a reserved port check here too, but this
509 * could pose compatibility problems. The local ypbind is
510 * supposed to decide whether or not to trust yp servers
511 * on insecure ports. For now, we trust its judgement.
513 ysd->dom_server_port =
514 *(u_short *)&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port;
516 ysd->dom_vers = YPVERS;
517 strlcpy(ysd->dom_domain, dom, sizeof(ysd->dom_domain));
520 /* Don't rebuild the connection to the server unless we have to. */
521 if (ysd->dom_client == NULL) {
522 tv.tv_sec = _yplib_timeout/2;
524 ysd->dom_socket = RPC_ANYSOCK;
525 ysd->dom_client = clntudp_bufcreate(&ysd->dom_server_addr,
526 YPPROG, YPVERS, tv, &ysd->dom_socket, 1280, 2304);
527 if (ysd->dom_client == NULL) {
528 clnt_pcreateerror("clntudp_create");
532 if (_fcntl(ysd->dom_socket, F_SETFD, 1) == -1)
533 perror("fcntl: F_SETFD");
535 * We want a port number associated with this socket
536 * so that we can check its authenticity later.
538 checklen = sizeof(struct sockaddr_in);
539 bzero((char *)&check, checklen);
540 _bind(ysd->dom_socket, (struct sockaddr *)&check, checklen);
541 check.sin_family = AF_INET;
542 if (!_getsockname(ysd->dom_socket,
543 (struct sockaddr *)&check, &checklen)) {
544 ysd->dom_local_port = check.sin_port;
546 clnt_destroy(ysd->dom_client);
549 return(YPERR_YPBIND);
554 ysd->dom_pnext = _ypbindlist;
564 _yp_unbind(struct dom_binding *ypb)
566 struct sockaddr_in check;
567 int checklen = sizeof(struct sockaddr_in);
569 if (ypb->dom_client != NULL) {
570 /* Check the socket -- may have been hosed by the caller. */
571 if (_getsockname(ypb->dom_socket, (struct sockaddr *)&check,
572 &checklen) == -1 || check.sin_family != AF_INET ||
573 check.sin_port != ypb->dom_local_port) {
576 sock = ypb->dom_socket;
577 save = _dup(ypb->dom_socket);
578 clnt_destroy(ypb->dom_client);
579 sock = _dup2(save, sock);
582 clnt_destroy(ypb->dom_client);
585 ypb->dom_client = NULL;
586 ypb->dom_socket = -1;
589 ypmatch_cache_flush(ypb);
596 return (_yp_dobind(dom, NULL));
602 struct dom_binding *ypb, *ypbp;
605 for (ypb = _ypbindlist; ypb; ypb = ypb->dom_pnext) {
606 if (strcmp(dom, ypb->dom_domain) == 0) {
609 ypbp->dom_pnext = ypb->dom_pnext;
611 _ypbindlist = ypb->dom_pnext;
621 yp_match(char *indomain, char *inmap, const char *inkey, int inkeylen,
622 char **outval, int *outvallen)
624 struct dom_binding *ysd;
625 struct ypresp_val yprv;
627 struct ypreq_key yprk;
635 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
636 inmap == NULL || !strlen(inmap) ||
637 indomain == NULL || !strlen(indomain))
638 return (YPERR_BADARGS);
640 if (_yp_dobind(indomain, &ysd) != 0)
641 return(YPERR_DOMAIN);
643 yprk.domain = indomain;
645 yprk.key.keydat_val = (char *)inkey;
646 yprk.key.keydat_len = inkeylen;
649 if (ypmatch_cache_lookup(ysd, yprk.map, &yprk.key, &yprv.val) == TRUE) {
651 if (!strcmp(_yp_domain, indomain) && ypmatch_find(inmap, inkey,
652 inkeylen, &yprv.val.valdat_val, &yprv.val.valdat_len)) {
654 *outvallen = yprv.val.valdat_len;
655 *outval = (char *)malloc(*outvallen+1);
656 bcopy(yprv.val.valdat_val, *outval, *outvallen);
657 (*outval)[*outvallen] = '\0';
663 if (_yp_dobind(indomain, &ysd) != 0)
664 return (YPERR_DOMAIN);
666 tv.tv_sec = _yplib_timeout;
669 bzero((char *)&yprv, sizeof yprv);
671 r = clnt_call(ysd->dom_client, YPPROC_MATCH,
672 (xdrproc_t)xdr_ypreq_key, &yprk,
673 (xdrproc_t)xdr_ypresp_val, &yprv, tv);
674 if (r != RPC_SUCCESS) {
675 clnt_perror(ysd->dom_client, "yp_match: clnt_call");
680 if (!(r = ypprot_err(yprv.stat))) {
681 *outvallen = yprv.val.valdat_len;
682 *outval = (char *)malloc(*outvallen+1);
683 bcopy(yprv.val.valdat_val, *outval, *outvallen);
684 (*outval)[*outvallen] = '\0';
686 ypmatch_cache_insert(ysd, yprk.map, &yprk.key, &yprv.val);
690 xdr_free((xdrproc_t)xdr_ypresp_val, &yprv);
695 yp_get_default_domain(char **domp)
698 if (_yp_domain[0] == '\0')
699 if (getdomainname(_yp_domain, sizeof _yp_domain))
700 return (YPERR_NODOM);
706 yp_first(char *indomain, char *inmap, char **outkey, size_t *outkeylen,
707 char **outval, size_t *outvallen)
709 struct ypresp_key_val yprkv;
710 struct ypreq_nokey yprnk;
711 struct dom_binding *ysd;
717 if (indomain == NULL || !strlen(indomain) ||
718 inmap == NULL || !strlen(inmap))
719 return (YPERR_BADARGS);
721 *outkey = *outval = NULL;
722 *outkeylen = *outvallen = 0;
725 if (_yp_dobind(indomain, &ysd) != 0)
726 return (YPERR_DOMAIN);
728 tv.tv_sec = _yplib_timeout;
731 yprnk.domain = indomain;
733 bzero((char *)&yprkv, sizeof yprkv);
735 r = clnt_call(ysd->dom_client, YPPROC_FIRST,
736 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
737 (xdrproc_t)xdr_ypresp_key_val, &yprkv, tv);
738 if (r != RPC_SUCCESS) {
739 clnt_perror(ysd->dom_client, "yp_first: clnt_call");
743 if (!(r = ypprot_err(yprkv.stat))) {
744 *outkeylen = yprkv.key.keydat_len;
745 *outkey = (char *)malloc(*outkeylen+1);
746 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
747 (*outkey)[*outkeylen] = '\0';
748 *outvallen = yprkv.val.valdat_len;
749 *outval = (char *)malloc(*outvallen+1);
750 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
751 (*outval)[*outvallen] = '\0';
754 xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
759 yp_next(char *indomain, char *inmap, char *inkey, size_t inkeylen,
760 char **outkey, size_t *outkeylen, char **outval, size_t *outvallen)
762 struct ypresp_key_val yprkv;
763 struct ypreq_key yprk;
764 struct dom_binding *ysd;
770 if (inkey == NULL || !strlen(inkey) || inkeylen <= 0 ||
771 inmap == NULL || !strlen(inmap) ||
772 indomain == NULL || !strlen(indomain))
773 return (YPERR_BADARGS);
775 *outkey = *outval = NULL;
776 *outkeylen = *outvallen = 0;
779 if (_yp_dobind(indomain, &ysd) != 0)
780 return (YPERR_DOMAIN);
782 tv.tv_sec = _yplib_timeout;
785 yprk.domain = indomain;
787 yprk.key.keydat_val = inkey;
788 yprk.key.keydat_len = inkeylen;
789 bzero((char *)&yprkv, sizeof yprkv);
791 r = clnt_call(ysd->dom_client, YPPROC_NEXT,
792 (xdrproc_t)xdr_ypreq_key, &yprk,
793 (xdrproc_t)xdr_ypresp_key_val, &yprkv, tv);
794 if (r != RPC_SUCCESS) {
795 clnt_perror(ysd->dom_client, "yp_next: clnt_call");
799 if (!(r = ypprot_err(yprkv.stat))) {
800 *outkeylen = yprkv.key.keydat_len;
801 *outkey = (char *)malloc(*outkeylen+1);
802 bcopy(yprkv.key.keydat_val, *outkey, *outkeylen);
803 (*outkey)[*outkeylen] = '\0';
804 *outvallen = yprkv.val.valdat_len;
805 *outval = (char *)malloc(*outvallen+1);
806 bcopy(yprkv.val.valdat_val, *outval, *outvallen);
807 (*outval)[*outvallen] = '\0';
810 xdr_free((xdrproc_t)xdr_ypresp_key_val, &yprkv);
815 yp_all(char *indomain, char *inmap, struct ypall_callback *incallback)
817 struct ypreq_nokey yprnk;
818 struct dom_binding *ysd;
820 struct sockaddr_in clnt_sin;
822 u_long status, savstat;
827 if (indomain == NULL || !strlen(indomain) ||
828 inmap == NULL || !strlen(inmap))
829 return (YPERR_BADARGS);
833 if (_yp_dobind(indomain, &ysd) != 0)
834 return (YPERR_DOMAIN);
836 tv.tv_sec = _yplib_timeout;
839 /* YPPROC_ALL manufactures its own channel to ypserv using TCP */
841 clnt_sock = RPC_ANYSOCK;
842 clnt_sin = ysd->dom_server_addr;
843 clnt_sin.sin_port = 0;
844 clnt = clnttcp_create(&clnt_sin, YPPROG, YPVERS, &clnt_sock, 0, 0);
846 printf("clnttcp_create failed\n");
850 yprnk.domain = indomain;
852 ypresp_allfn = incallback->foreach;
853 ypresp_data = (void *)incallback->data;
855 if (clnt_call(clnt, YPPROC_ALL,
856 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
857 (xdrproc_t)xdr_ypresp_all_seq, &status, tv) != RPC_SUCCESS) {
858 clnt_perror(ysd->dom_client, "yp_all: clnt_call");
866 xdr_free((xdrproc_t)xdr_ypresp_all_seq, &status); /* not really needed... */
867 if (savstat != YP_NOMORE)
868 return (ypprot_err(savstat));
873 yp_order(char *indomain, char *inmap, int *outorder)
875 struct dom_binding *ysd;
876 struct ypresp_order ypro;
877 struct ypreq_nokey yprnk;
883 if (indomain == NULL || !strlen(indomain) ||
884 inmap == NULL || !strlen(inmap))
885 return (YPERR_BADARGS);
888 if (_yp_dobind(indomain, &ysd) != 0)
889 return (YPERR_DOMAIN);
891 tv.tv_sec = _yplib_timeout;
894 yprnk.domain = indomain;
897 bzero((char *)(char *)&ypro, sizeof ypro);
899 r = clnt_call(ysd->dom_client, YPPROC_ORDER,
900 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
901 (xdrproc_t)xdr_ypresp_order, &ypro, tv);
904 * NIS+ in YP compat mode doesn't support the YPPROC_ORDER
907 if (r == RPC_PROCUNAVAIL) {
911 if (r != RPC_SUCCESS) {
912 clnt_perror(ysd->dom_client, "yp_order: clnt_call");
917 if (!(r = ypprot_err(ypro.stat))) {
918 *outorder = ypro.ordernum;
921 xdr_free((xdrproc_t)xdr_ypresp_order, &ypro);
926 yp_master(char *indomain, char *inmap, char **outname)
928 struct dom_binding *ysd;
929 struct ypresp_master yprm;
930 struct ypreq_nokey yprnk;
936 if (indomain == NULL || !strlen(indomain) ||
937 inmap == NULL || !strlen(inmap))
938 return (YPERR_BADARGS);
940 if (_yp_dobind(indomain, &ysd) != 0)
941 return (YPERR_DOMAIN);
943 tv.tv_sec = _yplib_timeout;
946 yprnk.domain = indomain;
949 bzero((char *)&yprm, sizeof yprm);
951 r = clnt_call(ysd->dom_client, YPPROC_MASTER,
952 (xdrproc_t)xdr_ypreq_nokey, &yprnk,
953 (xdrproc_t)xdr_ypresp_master, &yprm, tv);
954 if (r != RPC_SUCCESS) {
955 clnt_perror(ysd->dom_client, "yp_master: clnt_call");
960 if (!(r = ypprot_err(yprm.stat))) {
961 *outname = (char *)strdup(yprm.peer);
964 xdr_free((xdrproc_t)xdr_ypresp_master, &yprm);
969 yp_maplist(char *indomain, struct ypmaplist **outmaplist)
971 struct dom_binding *ysd;
972 struct ypresp_maplist ypml;
978 if (indomain == NULL || !strlen(indomain))
979 return (YPERR_BADARGS);
982 if (_yp_dobind(indomain, &ysd) != 0)
983 return (YPERR_DOMAIN);
985 tv.tv_sec = _yplib_timeout;
988 bzero((char *)&ypml, sizeof ypml);
990 r = clnt_call(ysd->dom_client, YPPROC_MAPLIST,
991 (xdrproc_t)xdr_domainname, (char *)&indomain,
992 (xdrproc_t)xdr_ypresp_maplist, &ypml, tv);
993 if (r != RPC_SUCCESS) {
994 clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
998 if (!(r = ypprot_err(ypml.stat))) {
999 *outmaplist = ypml.maps;
1002 /* NO: xdr_free(xdr_ypresp_maplist, &ypml);*/
1007 yperr_string(int incode)
1010 static char err[80];
1017 errstr = "Request arguments bad";
1020 errstr = "RPC failure";
1023 errstr = "Can't bind to server which serves this domain";
1026 errstr = "No such map in server's domain";
1029 errstr = "No such key in map";
1032 errstr = "YP server error";
1035 errstr = "Local resource allocation failure";
1038 errstr = "No more records in map database";
1041 errstr = "Can't communicate with portmapper";
1044 errstr = "Can't communicate with ypbind";
1047 errstr = "Can't communicate with ypserv";
1050 errstr = "Local domain name not set";
1053 errstr = "Server data base is bad";
1056 errstr = "YP server version mismatch - server can't supply service.";
1059 errstr = "Access violation";
1062 errstr = "Database is busy";
1069 strlcpy(err, errstr, sizeof(err));
1071 snprintf(err, sizeof(err), "YP unknown error %d\n", incode);
1076 ypprot_err(unsigned int incode)
1082 return (YPERR_YPBIND);
1084 return (YPERR_NOMORE);
1088 return (YPERR_DOMAIN);
1092 return (YPERR_YPERR);
1094 return (YPERR_BADDB);
1096 return (YPERR_YPERR);
1098 return (YPERR_BADARGS);
1100 return (YPERR_VERS);
1102 return (YPERR_YPERR);
1106 _yp_check(char **dom)
1110 if (_yp_domain[0]=='\0')
1111 if (yp_get_default_domain(&unused))
1117 if (yp_bind(_yp_domain) == 0) {
1118 yp_unbind(_yp_domain);