aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/yp
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/yp')
-rw-r--r--usr.sbin/yp/Makefile10
-rw-r--r--usr.sbin/yp/yp.873
-rw-r--r--usr.sbin/yp/ypbind/Makefile9
-rw-r--r--usr.sbin/yp/ypbind/ypbind.c672
-rw-r--r--usr.sbin/yp/ypcat/Makefile7
-rw-r--r--usr.sbin/yp/ypcat/ypcat.170
-rw-r--r--usr.sbin/yp/ypcat/ypcat.c143
-rw-r--r--usr.sbin/yp/ypmatch/Makefile7
-rw-r--r--usr.sbin/yp/ypmatch/ypmatch.171
-rw-r--r--usr.sbin/yp/ypmatch/ypmatch.c134
-rw-r--r--usr.sbin/yp/yppoll/Makefile8
-rw-r--r--usr.sbin/yp/yppoll/yppoll.c101
-rw-r--r--usr.sbin/yp/ypset/Makefile8
-rw-r--r--usr.sbin/yp/ypset/ypset.c154
-rw-r--r--usr.sbin/yp/ypwhich/Makefile8
-rw-r--r--usr.sbin/yp/ypwhich/ypwhich.c249
16 files changed, 1724 insertions, 0 deletions
diff --git a/usr.sbin/yp/Makefile b/usr.sbin/yp/Makefile
new file mode 100644
index 000000000000..5728c48fe1a2
--- /dev/null
+++ b/usr.sbin/yp/Makefile
@@ -0,0 +1,10 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# Makefile,v 1.4 1993/07/30 11:11:03 mycroft Exp
+
+NOPROG=
+MAN8= yp.8
+
+CFLAGS+=-DYP
+SUBDIR= ypbind ypwhich ypcat ypmatch ypset yppoll # yppasswd
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/yp/yp.8 b/usr.sbin/yp/yp.8
new file mode 100644
index 000000000000..f25f3868325a
--- /dev/null
+++ b/usr.sbin/yp/yp.8
@@ -0,0 +1,73 @@
+.\" Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. The name of the author may not be used to endorse or promote
+.\" products derived from this software without specific prior written
+.\" permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" from: @(#)yp.8 1.0 (deraadt) 4/26/93
+.\" $Id: yp.8,v 1.2 1994/01/11 19:01:20 nate Exp $
+.\"
+.Dd April 5, 1993
+.Dt YP 8
+.Os BSD 4.2
+.Sh NAME
+.Nm yp
+.Nd description of the YP system
+.Sh SYNOPSIS
+.Nm yp
+.Sh DESCRIPTION
+The
+.Nm YP
+subsystem allows network management of passwd and group file
+entries through the functions getpwent(3) and getgrent(3).
+The
+.Nm YP
+subsystem is started automatically in
+.Nm /etc/netstart
+if the directory
+.Nm /var/yp
+exists.
+.Sh BUGS
+Only
+.Nm YP
+client functionality exists -- the server code has not yet been
+written. Brave folk can contact the author.
+
+.Nm /etc/passwd
+and
+.Nm /etc/group only supports "+" entries.
+
+Many more manual pages should be written, especially ypclnt(3).
+For the time being, seek out a local Sun machine and read the
+manuals for there.
+
+Neither Sun nor this author have found a clean way to handle
+the problems that occur when ypbind cannot find its server
+upon bootup.
+.Sh HISTORY
+The
+.Nm YP
+subsystem was written from the ground up by Theo de Raadt
+to be compatible to Sun's implimentation. No Sun code was
+referenced.
diff --git a/usr.sbin/yp/ypbind/Makefile b/usr.sbin/yp/ypbind/Makefile
new file mode 100644
index 000000000000..03cd158903d8
--- /dev/null
+++ b/usr.sbin/yp/ypbind/Makefile
@@ -0,0 +1,9 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.2 1994/02/17 07:06:06 rgrimes Exp $
+
+PROG= ypbind
+NOMAN=
+CFLAGS+=-DDAEMON
+
+.include <bsd.prog.mk>
+.include "../../Makefile.inc"
diff --git a/usr.sbin/yp/ypbind/ypbind.c b/usr.sbin/yp/ypbind/ypbind.c
new file mode 100644
index 000000000000..18cfd642861a
--- /dev/null
+++ b/usr.sbin/yp/ypbind/ypbind.c
@@ -0,0 +1,672 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: ypbind.c,v 1.2 1994/01/11 19:01:23 nate Exp $";
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/signal.h>
+#include <sys/socket.h>
+#include <sys/file.h>
+#include <sys/fcntl.h>
+#include <sys/uio.h>
+#include <sys/syslog.h>
+#include <stdio.h>
+#include <errno.h>
+#include <ctype.h>
+#include <dirent.h>
+#include <netdb.h>
+#include <string.h>
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <net/if.h>
+#include <arpa/inet.h>
+#include <rpc/pmap_clnt.h>
+#include <rpc/pmap_prot.h>
+#include <rpc/pmap_rmt.h>
+#include <unistd.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+#ifndef BINDINGDIR
+#define BINDINGDIR "/var/yp/binding"
+#endif
+
+struct _dom_binding {
+ struct _dom_binding *dom_pnext;
+ char dom_domain[YPMAXDOMAIN + 1];
+ struct sockaddr_in dom_server_addr;
+ unsigned short int dom_server_port;
+ int dom_socket;
+ CLIENT *dom_client;
+ long int dom_vers;
+ time_t dom_check_t;
+ int dom_lockfd;
+ int dom_alive;
+};
+
+extern bool_t xdr_domainname(), xdr_ypbind_resp();
+extern bool_t xdr_ypreq_key(), xdr_ypresp_val();
+extern bool_t xdr_ypbind_setdom();
+
+char *domainname;
+
+struct _dom_binding *ypbindlist;
+int check;
+
+#define YPSET_NO 0
+#define YPSET_LOCAL 1
+#define YPSET_ALL 2
+int ypsetmode = YPSET_NO;
+
+int rpcsock;
+struct rmtcallargs rmtca;
+struct rmtcallres rmtcr;
+char rmtcr_outval;
+u_long rmtcr_port;
+SVCXPRT *udptransp, *tcptransp;
+
+void *
+ypbindproc_null_2(transp, argp, clnt)
+SVCXPRT *transp;
+void *argp;
+CLIENT *clnt;
+{
+ static char res;
+
+ bzero((char *)&res, sizeof(res));
+ return (void *)&res;
+}
+
+struct ypbind_resp *
+ypbindproc_domain_2(transp, argp, clnt)
+SVCXPRT *transp;
+char *argp;
+CLIENT *clnt;
+{
+ static struct ypbind_resp res;
+ struct _dom_binding *ypdb;
+ char path[MAXPATHLEN];
+
+ bzero((char *)&res, sizeof res);
+ res.ypbind_status = YPBIND_FAIL_VAL;
+
+ for(ypdb=ypbindlist; ypdb; ypdb=ypdb->dom_pnext)
+ if( strcmp(ypdb->dom_domain, argp) == 0)
+ break;
+
+ if(ypdb==NULL) {
+ ypdb = (struct _dom_binding *)malloc(sizeof *ypdb);
+ bzero((char *)ypdb, sizeof *ypdb);
+ strncpy(ypdb->dom_domain, argp, sizeof ypdb->dom_domain);
+ ypdb->dom_vers = YPVERS;
+ ypdb->dom_alive = 0;
+ ypdb->dom_lockfd = -1;
+ sprintf(path, "%s/%s.%d", BINDINGDIR, ypdb->dom_domain, ypdb->dom_vers);
+ unlink(path);
+ ypdb->dom_pnext = ypbindlist;
+ ypbindlist = ypdb;
+ check++;
+ return NULL;
+ }
+
+ if(ypdb->dom_alive==0)
+ return NULL;
+
+#if 0
+ delta = ypdb->dom_check_t - ypdb->dom_ask_t;
+ if( !(ypdb->dom_ask_t==0 || delta > 5)) {
+ ypdb->dom_ask_t = time(NULL);
+ /*
+ * Hmm. More than 2 requests in 5 seconds have indicated that my
+ * binding is possibly incorrect. Ok, make myself unalive, and
+ * find out what the actual state is.
+ */
+ if(ypdb->dom_lockfd!=-1)
+ close(ypdb->dom_lockfd);
+ ypdb->dom_lockfd = -1;
+ ypdb->dom_alive = 0;
+ ypdb->dom_lockfd = -1;
+ sprintf(path, "%s/%s.%d", BINDINGDIR, ypdb->dom_domain, ypdb->dom_vers);
+ unlink(path);
+ check++;
+ return NULL;
+ }
+#endif
+
+answer:
+ res.ypbind_status = YPBIND_SUCC_VAL;
+ res.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr.s_addr =
+ ypdb->dom_server_addr.sin_addr.s_addr;
+ res.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port =
+ ypdb->dom_server_port;
+ /*printf("domain %s at %s/%d\n", ypdb->dom_domain,
+ inet_ntoa(ypdb->dom_server_addr.sin_addr),
+ ntohs(ypdb->dom_server_addr.sin_port));*/
+ return &res;
+}
+
+bool_t *
+ypbindproc_setdom_2(transp, argp, clnt)
+SVCXPRT *transp;
+struct ypbind_setdom *argp;
+CLIENT *clnt;
+{
+ struct sockaddr_in *fromsin, bindsin;
+ char res;
+
+ bzero((char *)&res, sizeof(res));
+ fromsin = svc_getcaller(transp);
+
+ switch(ypsetmode) {
+ case YPSET_LOCAL:
+ if( fromsin->sin_addr.s_addr != htonl(INADDR_LOOPBACK))
+ return (void *)NULL;
+ break;
+ case YPSET_ALL:
+ break;
+ case YPSET_NO:
+ default:
+ return (void *)NULL;
+ }
+
+ if(ntohs(fromsin->sin_port) >= IPPORT_RESERVED)
+ return (void *)&res;
+
+ if(argp->ypsetdom_vers != YPVERS)
+ return (void *)&res;
+
+ bzero((char *)&bindsin, sizeof bindsin);
+ bindsin.sin_family = AF_INET;
+ bindsin.sin_addr.s_addr = argp->ypsetdom_addr.s_addr;
+ bindsin.sin_port = argp->ypsetdom_port;
+ rpc_received(argp->ypsetdom_domain, &bindsin, 1);
+
+ res = 1;
+ return (void *)&res;
+}
+
+static void
+ypbindprog_2(rqstp, transp)
+struct svc_req *rqstp;
+register SVCXPRT *transp;
+{
+ union {
+ char ypbindproc_domain_2_arg[MAXHOSTNAMELEN];
+ struct ypbind_setdom ypbindproc_setdom_2_arg;
+ } argument;
+ struct authunix_parms *creds;
+ char *result;
+ bool_t (*xdr_argument)(), (*xdr_result)();
+ char *(*local)();
+
+ switch (rqstp->rq_proc) {
+ case YPBINDPROC_NULL:
+ xdr_argument = xdr_void;
+ xdr_result = xdr_void;
+ local = (char *(*)()) ypbindproc_null_2;
+ break;
+
+ case YPBINDPROC_DOMAIN:
+ xdr_argument = xdr_domainname;
+ xdr_result = xdr_ypbind_resp;
+ local = (char *(*)()) ypbindproc_domain_2;
+ break;
+
+ case YPBINDPROC_SETDOM:
+ switch(rqstp->rq_cred.oa_flavor) {
+ case AUTH_UNIX:
+ creds = (struct authunix_parms *)rqstp->rq_clntcred;
+ if( creds->aup_uid != 0) {
+ svcerr_auth(transp, AUTH_BADCRED);
+ return;
+ }
+ break;
+ default:
+ svcerr_auth(transp, AUTH_TOOWEAK);
+ return;
+ }
+
+ xdr_argument = xdr_ypbind_setdom;
+ xdr_result = xdr_void;
+ local = (char *(*)()) ypbindproc_setdom_2;
+ break;
+
+ default:
+ svcerr_noproc(transp);
+ return;
+ }
+ bzero((char *)&argument, sizeof(argument));
+ if (!svc_getargs(transp, xdr_argument, &argument)) {
+ svcerr_decode(transp);
+ return;
+ }
+ result = (*local)(transp, &argument, rqstp);
+ if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
+ svcerr_systemerr(transp);
+ }
+ return;
+}
+
+main(argc, argv)
+char **argv;
+{
+ char path[MAXPATHLEN];
+ struct timeval tv;
+ fd_set fdsr;
+ int width;
+ int i;
+
+ yp_get_default_domain(&domainname);
+ if( domainname[0] == '\0') {
+ fprintf(stderr, "domainname not set. Aborting.\n");
+ exit(1);
+ }
+
+ for(i=1; i<argc; i++) {
+ if( strcmp("-ypset", argv[i]) == 0)
+ ypsetmode = YPSET_ALL;
+ else if (strcmp("-ypsetme", argv[i]) == 0)
+ ypsetmode = YPSET_LOCAL;
+ }
+
+ /* blow away everything in BINDINGDIR */
+
+
+
+#ifdef DAEMON
+ switch(fork()) {
+ case 0:
+ break;
+ case -1:
+ perror("fork");
+ exit(1);
+ default:
+ exit(0);
+ }
+ setsid();
+#endif
+
+ pmap_unset(YPBINDPROG, YPBINDVERS);
+
+ udptransp = svcudp_create(RPC_ANYSOCK);
+ if (udptransp == NULL) {
+ fprintf(stderr, "cannot create udp service.");
+ exit(1);
+ }
+ if (!svc_register(udptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
+ IPPROTO_UDP)) {
+ fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, udp).");
+ exit(1);
+ }
+
+ tcptransp = svctcp_create(RPC_ANYSOCK, 0, 0);
+ if (tcptransp == NULL) {
+ fprintf(stderr, "cannot create tcp service.");
+ exit(1);
+ }
+
+ if (!svc_register(tcptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2,
+ IPPROTO_TCP)) {
+ fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, tcp).");
+ exit(1);
+ }
+
+ if( (rpcsock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("socket");
+ return -1;
+ }
+
+ fcntl(rpcsock, F_SETFL, fcntl(rpcsock, F_GETFL, 0) | FNDELAY);
+ i = 1;
+ setsockopt(rpcsock, SOL_SOCKET, SO_BROADCAST, &i, sizeof(i));
+ rmtca.prog = YPPROG;
+ rmtca.vers = YPVERS;
+ rmtca.proc = YPPROC_DOMAIN_NONACK;
+ rmtca.xdr_args = NULL; /* set at call time */
+ rmtca.args_ptr = NULL; /* set at call time */
+ rmtcr.port_ptr = &rmtcr_port;
+ rmtcr.xdr_results = xdr_bool;
+ rmtcr.results_ptr = (caddr_t)&rmtcr_outval;
+
+ /* build initial domain binding, make it "unsuccessful" */
+ ypbindlist = (struct _dom_binding *)malloc(sizeof *ypbindlist);
+ bzero((char *)ypbindlist, sizeof *ypbindlist);
+ strncpy(ypbindlist->dom_domain, domainname, sizeof ypbindlist->dom_domain);
+ ypbindlist->dom_vers = YPVERS;
+ ypbindlist->dom_alive = 0;
+ ypbindlist->dom_lockfd = -1;
+ sprintf(path, "%s/%s.%d", BINDINGDIR, ypbindlist->dom_domain,
+ ypbindlist->dom_vers);
+ (void)unlink(path);
+
+ width = getdtablesize();
+ while(1) {
+ fdsr = svc_fdset;
+ FD_SET(rpcsock, &fdsr);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+
+ switch(select(width, &fdsr, NULL, NULL, &tv)) {
+ case 0:
+ checkwork();
+ break;
+ case -1:
+ perror("select\n");
+ break;
+ default:
+ if(FD_ISSET(rpcsock, &fdsr)) {
+ FD_CLR(rpcsock, &fdsr);
+ handle_replies();
+ }
+ svc_getreqset(&fdsr);
+ if(check)
+ checkwork();
+ break;
+ }
+ }
+}
+
+/*
+ * change to do something like this:
+ *
+ * STATE TIME ACTION NEWTIME NEWSTATE
+ * no binding t==* broadcast t=2 no binding
+ * binding t==60 check server t=10 binding
+ * binding t=10 broadcast t=2 no binding
+ */
+checkwork()
+{
+ struct _dom_binding *ypdb;
+ time_t t;
+
+ check = 0;
+
+ time(&t);
+ for(ypdb=ypbindlist; ypdb; ypdb=ypdb->dom_pnext) {
+ if(ypdb->dom_alive==0 || ypdb->dom_check_t < t) {
+ broadcast(ypdb->dom_domain);
+ time(&t);
+ ypdb->dom_check_t = t + 5;
+ }
+ }
+}
+
+broadcast(dom)
+char *dom;
+{
+ struct rpc_msg rpcmsg;
+ char buf[1400], inbuf[8192];
+ enum clnt_stat st;
+ struct timeval tv;
+ int outlen, i, sock, len;
+ struct sockaddr_in bsin;
+ struct ifconf ifc;
+ struct ifreq ifreq, *ifr;
+ struct in_addr in;
+ AUTH *rpcua;
+ XDR rpcxdr;
+
+ rmtca.xdr_args = xdr_domainname;
+ rmtca.args_ptr = dom;
+
+ bzero((char *)&bsin, sizeof bsin);
+ bsin.sin_family = AF_INET;
+ bsin.sin_port = htons(PMAPPORT);
+
+ bzero((char *)&rpcxdr, sizeof rpcxdr);
+ bzero((char *)&rpcmsg, sizeof rpcmsg);
+
+ rpcua = authunix_create_default();
+ if( rpcua == (AUTH *)NULL) {
+ /*printf("cannot get unix auth\n");*/
+ return RPC_SYSTEMERROR;
+ }
+ rpcmsg.rm_direction = CALL;
+ rpcmsg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+ rpcmsg.rm_call.cb_prog = PMAPPROG;
+ rpcmsg.rm_call.cb_vers = PMAPVERS;
+ rpcmsg.rm_call.cb_proc = PMAPPROC_CALLIT;
+ rpcmsg.rm_call.cb_cred = rpcua->ah_cred;
+ rpcmsg.rm_call.cb_verf = rpcua->ah_verf;
+
+ gettimeofday(&tv, (struct timezone *)0);
+ rpcmsg.rm_xid = (int)dom;
+ tv.tv_usec = 0;
+ xdrmem_create(&rpcxdr, buf, sizeof buf, XDR_ENCODE);
+ if( (!xdr_callmsg(&rpcxdr, &rpcmsg)) ) {
+ st = RPC_CANTENCODEARGS;
+ AUTH_DESTROY(rpcua);
+ return st;
+ }
+ if( (!xdr_rmtcall_args(&rpcxdr, &rmtca)) ) {
+ st = RPC_CANTENCODEARGS;
+ AUTH_DESTROY(rpcua);
+ return st;
+ }
+ outlen = (int)xdr_getpos(&rpcxdr);
+ xdr_destroy(&rpcxdr);
+ if(outlen<1) {
+ AUTH_DESTROY(rpcua);
+ return st;
+ }
+ AUTH_DESTROY(rpcua);
+
+ /* find all networks and send the RPC packet out them all */
+ if( (sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("socket");
+ return -1;
+ }
+
+ ifc.ifc_len = sizeof inbuf;
+ ifc.ifc_buf = inbuf;
+ if( ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
+ close(sock);
+ perror("ioctl(SIOCGIFCONF)");
+ return -1;
+ }
+ ifr = ifc.ifc_req;
+ ifreq.ifr_name[0] = '\0';
+ for(i=0; i<ifc.ifc_len; i+=len, ifr=(struct ifreq *)((caddr_t)ifr+len)) {
+#if defined(BSD) && BSD >= 199103
+ len = sizeof ifr->ifr_name + ifr->ifr_addr.sa_len;
+#else
+ len = sizeof ifc.ifc_len / sizeof(struct ifreq);
+#endif
+ ifreq = *ifr;
+ if( ifreq.ifr_addr.sa_family != AF_INET)
+ continue;
+ if( ioctl(sock, SIOCGIFFLAGS, &ifreq) < 0) {
+ perror("ioctl(SIOCGIFFLAGS)");
+ continue;
+ }
+ if( (ifreq.ifr_flags & IFF_UP) == 0)
+ continue;
+
+ ifreq.ifr_flags &= (IFF_LOOPBACK | IFF_BROADCAST);
+ if( ifreq.ifr_flags==IFF_BROADCAST ) {
+ if( ioctl(sock, SIOCGIFBRDADDR, &ifreq) < 0 ) {
+ perror("ioctl(SIOCGIFBRDADDR)");
+ continue;
+ }
+ } else if( ifreq.ifr_flags==IFF_LOOPBACK ) {
+ if( ioctl(sock, SIOCGIFADDR, &ifreq) < 0 ) {
+ perror("ioctl(SIOCGIFADDR)");
+ continue;
+ }
+ } else
+ continue;
+
+ in = ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr;
+ bsin.sin_addr = in;
+ if( sendto(rpcsock, buf, outlen, 0, (struct sockaddr *)&bsin,
+ sizeof bsin) < 0 )
+ perror("sendto");
+ }
+ close(sock);
+ return 0;
+}
+
+/*enum clnt_stat*/
+handle_replies()
+{
+ char buf[1400];
+ int fromlen, inlen;
+ struct sockaddr_in raddr;
+ struct rpc_msg msg;
+ XDR xdr;
+
+recv_again:
+ bzero((char *)&xdr, sizeof(xdr));
+ bzero((char *)&msg, sizeof(msg));
+ msg.acpted_rply.ar_verf = _null_auth;
+ msg.acpted_rply.ar_results.where = (caddr_t)&rmtcr;
+ msg.acpted_rply.ar_results.proc = xdr_rmtcallres;
+
+try_again:
+ fromlen = sizeof (struct sockaddr);
+ inlen = recvfrom(rpcsock, buf, sizeof buf, 0,
+ (struct sockaddr *)&raddr, &fromlen);
+ if(inlen<0) {
+ if(errno==EINTR)
+ goto try_again;
+ return RPC_CANTRECV;
+ }
+ if(inlen<sizeof(u_long))
+ goto recv_again;
+
+ /*
+ * see if reply transaction id matches sent id.
+ * If so, decode the results.
+ */
+ xdrmem_create(&xdr, buf, (u_int)inlen, XDR_DECODE);
+ if( xdr_replymsg(&xdr, &msg)) {
+ if( (msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
+ (msg.acpted_rply.ar_stat == SUCCESS)) {
+ raddr.sin_port = htons((u_short)rmtcr_port);
+ rpc_received(msg.rm_xid, &raddr, 0);
+ }
+ }
+ xdr.x_op = XDR_FREE;
+ msg.acpted_rply.ar_results.proc = xdr_void;
+ xdr_destroy(&xdr);
+
+ return RPC_SUCCESS;
+}
+
+/*
+ * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
+ */
+rpc_received(dom, raddrp, force)
+char *dom;
+struct sockaddr_in *raddrp;
+int force;
+{
+ struct _dom_binding *ypdb;
+ struct iovec iov[2];
+ struct ypbind_resp ybr;
+ char path[MAXPATHLEN];
+ int fd;
+
+ /*printf("returned from %s about %s\n", inet_ntoa(raddrp->sin_addr), dom);*/
+
+ if(dom==NULL)
+ return;
+
+ for(ypdb=ypbindlist; ypdb; ypdb=ypdb->dom_pnext)
+ if( strcmp(ypdb->dom_domain, dom) == 0)
+ break;
+
+ if(ypdb==NULL) {
+ if(force==0)
+ return;
+ ypdb = (struct _dom_binding *)malloc(sizeof *ypdb);
+ bzero((char *)ypdb, sizeof *ypdb);
+ strncpy(ypdb->dom_domain, dom, sizeof ypdb->dom_domain);
+ ypdb->dom_lockfd = -1;
+ ypdb->dom_pnext = ypbindlist;
+ ypbindlist = ypdb;
+ }
+
+ /* soft update, alive, less than 30 seconds old */
+ if(ypdb->dom_alive==1 && force==0 && ypdb->dom_check_t<time(NULL)+30)
+ return;
+
+ bcopy((char *)raddrp, (char *)&ypdb->dom_server_addr,
+ sizeof ypdb->dom_server_addr);
+ ypdb->dom_check_t = time(NULL) + 60; /* recheck binding in 60 seconds */
+ ypdb->dom_vers = YPVERS;
+ ypdb->dom_alive = 1;
+
+ if(ypdb->dom_lockfd != -1)
+ close(ypdb->dom_lockfd);
+
+ sprintf(path, "%s/%s.%d", BINDINGDIR,
+ ypdb->dom_domain, ypdb->dom_vers);
+#ifdef O_SHLOCK
+ if( (fd=open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1) {
+ (void)mkdir(BINDINGDIR, 0755);
+ if( (fd=open(path, O_CREAT|O_SHLOCK|O_RDWR|O_TRUNC, 0644)) == -1)
+ return;
+ }
+#else
+ if( (fd=open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1) {
+ (void)mkdir(BINDINGDIR, 0755);
+ if( (fd=open(path, O_CREAT|O_RDWR|O_TRUNC, 0644)) == -1)
+ return;
+ }
+ flock(fd, LOCK_SH);
+#endif
+
+ /*
+ * ok, if BINDINGDIR exists, and we can create the binding file,
+ * then write to it..
+ */
+ ypdb->dom_lockfd = fd;
+
+ iov[0].iov_base = (caddr_t)&(udptransp->xp_port);
+ iov[0].iov_len = sizeof udptransp->xp_port;
+ iov[1].iov_base = (caddr_t)&ybr;
+ iov[1].iov_len = sizeof ybr;
+
+ bzero(&ybr, sizeof ybr);
+ ybr.ypbind_status = YPBIND_SUCC_VAL;
+ ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr = raddrp->sin_addr;
+ ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port = raddrp->sin_port;
+
+ if( writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) {
+ perror("write");
+ close(ypdb->dom_lockfd);
+ ypdb->dom_lockfd = -1;
+ return;
+ }
+}
diff --git a/usr.sbin/yp/ypcat/Makefile b/usr.sbin/yp/ypcat/Makefile
new file mode 100644
index 000000000000..db0121aeaec7
--- /dev/null
+++ b/usr.sbin/yp/ypcat/Makefile
@@ -0,0 +1,7 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.3 1994/02/17 07:06:10 rgrimes Exp $
+
+PROG= ypcat
+BINDIR=/usr/bin
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/yp/ypcat/ypcat.1 b/usr.sbin/yp/ypcat/ypcat.1
new file mode 100644
index 000000000000..99321b496c3c
--- /dev/null
+++ b/usr.sbin/yp/ypcat/ypcat.1
@@ -0,0 +1,70 @@
+.\" Copyright (c) 1993 Winning Strategies, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Winning Strategies, Inc.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software withough specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $Id: ypcat.1,v 1.1 1994/01/11 19:01:27 nate Exp $
+.\"
+.Dd December 3, 1993
+.Dt YPCAT 1
+.Os
+.Sh NAME
+.Nm ypcat
+.Nd "print the values of all keys in a YP database"
+.Sh SYNOPSIS
+.Nm ypcat
+.Op Fl kt
+.Op Fl d Ar domainname
+.Ar mapname
+.Nm ypcat
+.Fl x
+.Sh DESCRIPTION
+.Nm Ypcat
+prints out the values of all keys from the
+.Tn YP
+database specified by
+.Ar mapname,
+which may be a map name or a map nickname.
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl d Ar domainname
+Specify a domain other than the default domain.
+.It Fl k
+Display map keys.
+This option is useful with maps in which the values are null or the key
+is not part of the value.
+.It Fl t
+Inhibit translation of map nicknames
+to their corresponding map names.
+.It Fl x
+Display the map nickname table.
+.El
+.Sh SEE ALSO
+.Xr ypmatch 1 ,
+.Xr yp 8
+.Sh AUTHOR
+Theo De Raadt
diff --git a/usr.sbin/yp/ypcat/ypcat.c b/usr.sbin/yp/ypcat/ypcat.c
new file mode 100644
index 000000000000..85158a34d341
--- /dev/null
+++ b/usr.sbin/yp/ypcat/ypcat.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LINT
+static char rcsid[] = "ypcat.c,v 1.2 1993/05/16 02:49:01 deraadt Exp";
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+struct ypalias {
+ char *alias, *name;
+} ypaliases[] = {
+ { "passwd", "passwd.byname" },
+ { "group", "group.byname" },
+ { "networks", "networks.byaddr" },
+ { "hosts", "hosts.byaddr" },
+ { "protocols", "protocols.bynumber" },
+ { "services", "services.byname" },
+ { "aliases", "mail.aliases" },
+ { "ethers", "ethers.byname" },
+};
+
+int key;
+
+usage()
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\typcat [-k] [-d domainname] [-t] mapname\n");
+ fprintf(stderr, "\typcat -x\n");
+ exit(1);
+}
+
+printit(instatus, inkey, inkeylen, inval, invallen, indata)
+int instatus;
+char *inkey;
+int inkeylen;
+char *inval;
+int invallen;
+char *indata;
+{
+ if(instatus != YP_TRUE)
+ return instatus;
+ if(key)
+ printf("%*.*s ", inkeylen, inkeylen, inkey);
+ printf("%*.*s\n", invallen, invallen, inval);
+ return 0;
+}
+
+int
+main(argc, argv)
+char **argv;
+{
+ char *domainname;
+ struct ypall_callback ypcb;
+ char *inmap;
+ extern char *optarg;
+ extern int optind;
+ int notrans;
+ int c, r, i;
+
+ notrans = key = 0;
+ yp_get_default_domain(&domainname);
+
+ while( (c=getopt(argc, argv, "xd:kt")) != -1)
+ switch(c) {
+ case 'x':
+ for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ printf("Use \"%s\" for \"%s\"\n",
+ ypaliases[i].alias,
+ ypaliases[i].name);
+ exit(0);
+ case 'd':
+ domainname = optarg;
+ break;
+ case 't':
+ notrans++;
+ break;
+ case 'k':
+ key++;
+ break;
+ default:
+ usage();
+ }
+
+ if(optind + 1 != argc )
+ usage();
+
+ inmap = argv[optind];
+ for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ if( strcmp(inmap, ypaliases[i].alias) == 0)
+ inmap = ypaliases[i].name;
+ ypcb.foreach = printit;
+ ypcb.data = NULL;
+
+ r = yp_all(domainname, inmap, &ypcb);
+ switch(r) {
+ case 0:
+ break;
+ case YPERR_YPBIND:
+ fprintf(stderr, "ypcat: not running ypbind\n");
+ exit(1);
+ default:
+ fprintf(stderr, "No such map %s. Reason: %s\n",
+ inmap, yperr_string(r));
+ exit(1);
+ }
+ exit(0);
+}
diff --git a/usr.sbin/yp/ypmatch/Makefile b/usr.sbin/yp/ypmatch/Makefile
new file mode 100644
index 000000000000..fa08b29ad249
--- /dev/null
+++ b/usr.sbin/yp/ypmatch/Makefile
@@ -0,0 +1,7 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.3 1994/02/17 07:06:13 rgrimes Exp $
+
+PROG= ypmatch
+BINDIR=/usr/bin
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/yp/ypmatch/ypmatch.1 b/usr.sbin/yp/ypmatch/ypmatch.1
new file mode 100644
index 000000000000..0b7ac89cd86b
--- /dev/null
+++ b/usr.sbin/yp/ypmatch/ypmatch.1
@@ -0,0 +1,71 @@
+.\" Copyright (c) 1993 Winning Strategies, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Winning Strategies, Inc.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software withough specific prior written permission
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\" $Id: ypmatch.1,v 1.1 1994/01/11 19:01:30 nate Exp $
+.\"
+.Dd December 3, 1993
+.Dt YPMATCH 1
+.Os
+.Sh NAME
+.Nm ypmatch
+.Nd "print the values of one or more keys in a YP database"
+.Sh SYNOPSIS
+.Nm ypmatch
+.Op Fl kt
+.Op Fl d Ar domainname
+.Ar key ...
+.Ar mapname
+.Nm ypmatch
+.Fl x
+.Sh DESCRIPTION
+.Nm Ypmatch
+prints out the values of one or more keys from the
+.Tn YP
+database specified by
+.Ar mapname,
+which may be a map name or a map nickname.
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl d Ar domainname
+Specify a domain other than the default domain.
+.It Fl k
+Display map keys.
+This option is useful with maps in which the values are null or the key
+is not part of the value.
+.It Fl t
+Inhibit translation of map nicknames
+to their corresponding map names.
+.It Fl x
+Display the map nickname table.
+.El
+.Sh SEE ALSO
+.Xr ypcat 1 ,
+.Xr yp 8
+.Sh AUTHOR
+Theo De Raadt
diff --git a/usr.sbin/yp/ypmatch/ypmatch.c b/usr.sbin/yp/ypmatch/ypmatch.c
new file mode 100644
index 000000000000..7370e94d3d63
--- /dev/null
+++ b/usr.sbin/yp/ypmatch/ypmatch.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LINT
+static char rcsid[] = "ypmatch.c,v 1.2 1993/05/16 02:49:03 deraadt Exp";
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <ctype.h>
+
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+struct ypalias {
+ char *alias, *name;
+} ypaliases[] = {
+ { "passwd", "passwd.byname" },
+ { "group", "group.byname" },
+ { "networks", "networks.byaddr" },
+ { "hosts", "hosts.byaddr" },
+ { "protocols", "protocols.bynumber" },
+ { "services", "services.byname" },
+ { "aliases", "mail.aliases" },
+ { "ethers", "ethers.byname" },
+};
+
+usage()
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\typmatch [-d domain] [-t] [-k] key [key ...] mname\n");
+ fprintf(stderr, "\typmatch -x\n");
+ fprintf(stderr, "where\n");
+ fprintf(stderr, "\tmname may be either a mapname or a nickname for a map\n");
+ fprintf(stderr, "\t-t inhibits map nickname translation\n");
+ fprintf(stderr, "\t-k prints keys as well as values.\n");
+ fprintf(stderr, "\t-x dumps the map nickname translation table.\n");
+ exit(1);
+}
+
+int
+main(argc, argv)
+char **argv;
+{
+ char *domainname;
+ char *inkey, *inmap, *outbuf;
+ extern char *optarg;
+ extern int optind;
+ int outbuflen, key, notrans;
+ int c, r, i;
+
+ notrans = key = 0;
+ yp_get_default_domain(&domainname);
+
+ while( (c=getopt(argc, argv, "xd:kt")) != -1)
+ switch(c) {
+ case 'x':
+ for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ printf("Use \"%s\" for \"%s\"\n",
+ ypaliases[i].alias,
+ ypaliases[i].name);
+ exit(0);
+ case 'd':
+ domainname = optarg;
+ break;
+ case 't':
+ notrans++;
+ break;
+ case 'k':
+ key++;
+ break;
+ default:
+ usage();
+ }
+
+ if( (argc-optind) < 2 )
+ usage();
+
+ inmap = argv[argc-1];
+ for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ if( strcmp(inmap, ypaliases[i].alias) == 0)
+ inmap = ypaliases[i].name;
+ for(; optind < argc-1; optind++) {
+ inkey = argv[optind];
+
+ r = yp_match(domainname, inmap, inkey,
+ strlen(inkey), &outbuf, &outbuflen);
+ switch(r) {
+ case 0:
+ if(key)
+ printf("%s ", inkey);
+ printf("%*.*s\n", outbuflen, outbuflen, outbuf);
+ break;
+ case YPERR_YPBIND:
+ fprintf(stderr, "yp_match: not running ypbind\n");
+ exit(1);
+ default:
+ fprintf(stderr, "Can't match key %s in map %s. Reason: %s\n",
+ inkey, inmap, yperr_string(r));
+ break;
+ }
+ }
+ exit(0);
+}
diff --git a/usr.sbin/yp/yppoll/Makefile b/usr.sbin/yp/yppoll/Makefile
new file mode 100644
index 000000000000..d24b2d81b364
--- /dev/null
+++ b/usr.sbin/yp/yppoll/Makefile
@@ -0,0 +1,8 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.2 1994/02/17 07:06:17 rgrimes Exp $
+
+PROG= yppoll
+NOMAN=
+
+.include <bsd.prog.mk>
+.include "../../Makefile.inc"
diff --git a/usr.sbin/yp/yppoll/yppoll.c b/usr.sbin/yp/yppoll/yppoll.c
new file mode 100644
index 000000000000..525e564d6d45
--- /dev/null
+++ b/usr.sbin/yp/yppoll/yppoll.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * Copyright (c) 1992/3 John Brezak
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] = "yppoll.c,v 1.2 1993/08/02 17:57:20 mycroft Exp";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <time.h>
+
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+usage()
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\typpoll [-h host] [-d domainname] mapname\n");
+ exit(1);
+}
+
+int
+main(argc, argv)
+char **argv;
+{
+ char *domainname;
+ char *hostname = "localhost";
+ char *inmap, *master;
+ int order;
+ extern char *optarg;
+ extern int optind;
+ int c, r;
+
+ yp_get_default_domain(&domainname);
+
+ while( (c=getopt(argc, argv, "h:d:?")) != -1)
+ switch(c) {
+ case 'd':
+ domainname = optarg;
+ break;
+ case 'h':
+ hostname = optarg;
+ break;
+ case '?':
+ usage();
+ /*NOTREACHED*/
+ }
+
+ if(optind + 1 != argc )
+ usage();
+
+ inmap = argv[optind];
+
+ r = yp_order(domainname, inmap, &order);
+ if (r != 0) {
+ fprintf(stderr, "No such map %s. Reason: %s\n",
+ inmap, yperr_string(r));
+ exit(1);
+ }
+ printf("Map %s has order number %d. %s", inmap, order, ctime((time_t *)&order));
+ r = yp_master(domainname, inmap, &master);
+ if (r != 0) {
+ fprintf(stderr, "No such map %s. Reason: %s\n",
+ inmap, yperr_string(r));
+ exit(1);
+ }
+ printf("The master server is %s.\n", master);
+
+ exit(0);
+}
diff --git a/usr.sbin/yp/ypset/Makefile b/usr.sbin/yp/ypset/Makefile
new file mode 100644
index 000000000000..147b045c5a3d
--- /dev/null
+++ b/usr.sbin/yp/ypset/Makefile
@@ -0,0 +1,8 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.2 1994/02/17 07:06:19 rgrimes Exp $
+
+PROG= ypset
+NOMAN=
+
+.include <bsd.prog.mk>
+.include "../../Makefile.inc"
diff --git a/usr.sbin/yp/ypset/ypset.c b/usr.sbin/yp/ypset/ypset.c
new file mode 100644
index 000000000000..6a25a97c917b
--- /dev/null
+++ b/usr.sbin/yp/ypset/ypset.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LINT
+static char rcsid[] = "ypset.c,v 1.3 1993/06/12 00:02:37 deraadt Exp";
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+#include <arpa/inet.h>
+
+extern bool_t xdr_domainname();
+
+usage()
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\typset [-h host ] [-d domain] server\n");
+ exit(1);
+}
+
+bind_tohost(sin, dom, server)
+struct sockaddr_in *sin;
+char *dom, *server;
+{
+ struct ypbind_setdom ypsd;
+ struct timeval tv;
+ struct hostent *hp;
+ CLIENT *client;
+ int sock, port;
+ int r;
+ unsigned long server_addr;
+
+ if( (port=htons(getrpcport(server, YPPROG, YPPROC_NULL, IPPROTO_UDP))) == 0) {
+ fprintf(stderr, "%s not running ypserv.\n", server);
+ exit(1);
+ }
+
+ bzero(&ypsd, sizeof ypsd);
+
+ if( (hp = gethostbyname (server)) != NULL ) {
+ /* is this the most compatible way?? */
+ bcopy (hp->h_addr_list[0], &ypsd.ypsetdom_addr,
+ sizeof (ypsd.ypsetdom_addr));
+ } else if( (long)(server_addr = inet_addr (server)) == -1) {
+ fprintf(stderr, "can't find address for %s\n", server);
+ exit(1);
+ } else
+ bcopy (&server_addr, &ypsd.ypsetdom_addr,
+ sizeof (server_addr));
+
+ strncpy(ypsd.ypsetdom_domain, dom, sizeof ypsd.ypsetdom_domain);
+ ypsd.ypsetdom_port = port;
+ ypsd.ypsetdom_vers = YPVERS;
+
+ tv.tv_sec = 15;
+ tv.tv_usec = 0;
+ sock = RPC_ANYSOCK;
+ client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
+ if (client==NULL) {
+ fprintf(stderr, "can't yp_bind: Reason: %s\n",
+ yperr_string(YPERR_YPBIND));
+ return YPERR_YPBIND;
+ }
+ client->cl_auth = authunix_create_default();
+
+ r = clnt_call(client, YPBINDPROC_SETDOM,
+ xdr_ypbind_setdom, &ypsd, xdr_void, NULL, tv);
+ if(r) {
+ fprintf(stderr, "Sorry, cannot ypset for domain %s on host.\n", dom);
+ clnt_destroy(client);
+ return YPERR_YPBIND;
+ }
+ clnt_destroy(client);
+ return 0;
+}
+
+int
+main(argc, argv)
+char **argv;
+{
+ struct sockaddr_in sin;
+ struct hostent *hent;
+ extern char *optarg;
+ extern int optind;
+ char *domainname;
+ int c;
+
+ yp_get_default_domain(&domainname);
+
+ bzero(&sin, sizeof sin);
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = htonl(0x7f000001);
+
+ while( (c=getopt(argc, argv, "h:d:")) != -1)
+ switch(c) {
+ case 'd':
+ domainname = optarg;
+ break;
+ case 'h':
+ if( (sin.sin_addr.s_addr=inet_addr(optarg)) == -1) {
+ hent = gethostbyname(optarg);
+ if(hent==NULL) {
+ fprintf(stderr, "ypset: host %s unknown\n",
+ optarg);
+ exit(1);
+ }
+ bcopy(&hent->h_addr_list[0], &sin.sin_addr,
+ sizeof sin.sin_addr);
+ }
+ break;
+ default:
+ usage();
+ }
+
+ if(optind + 1 != argc )
+ usage();
+
+ if (bind_tohost(&sin, domainname, argv[optind]))
+ exit(1);
+ exit(0);
+}
diff --git a/usr.sbin/yp/ypwhich/Makefile b/usr.sbin/yp/ypwhich/Makefile
new file mode 100644
index 000000000000..604aba8af929
--- /dev/null
+++ b/usr.sbin/yp/ypwhich/Makefile
@@ -0,0 +1,8 @@
+# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
+# $Id: Makefile,v 1.2 1994/02/17 07:06:22 rgrimes Exp $
+
+PROG= ypwhich
+NOMAN=
+BINDIR=/usr/bin
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/yp/ypwhich/ypwhich.c b/usr.sbin/yp/ypwhich/ypwhich.c
new file mode 100644
index 000000000000..cefac38ffa79
--- /dev/null
+++ b/usr.sbin/yp/ypwhich/ypwhich.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LINT
+static char rcsid[] = "ypwhich.c,v 1.2 1993/05/16 02:49:10 deraadt Exp";
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <rpc/rpc.h>
+#include <rpc/xdr.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+
+extern bool_t xdr_domainname();
+
+struct ypalias {
+ char *alias, *name;
+} ypaliases[] = {
+ { "passwd", "passwd.byname" },
+ { "group", "group.byname" },
+ { "networks", "networks.byaddr" },
+ { "hosts", "hosts.byaddr" },
+ { "protocols", "protocols.bynumber" },
+ { "services", "services.byname" },
+ { "aliases", "mail.aliases" },
+ { "ethers", "ethers.byname" },
+};
+
+usage()
+{
+ fprintf(stderr, "Usage:\n");
+ fprintf(stderr, "\typwhich [-d domain] [[-t] -m [mname] | host]\n");
+ fprintf(stderr, "\typwhich -x\n");
+ exit(1);
+}
+
+
+/*
+ * Like yp_bind except can query a specific host
+ */
+bind_host(dom, sin)
+char *dom;
+struct sockaddr_in *sin;
+{
+ struct hostent *hent = NULL;
+ struct ypbind_resp ypbr;
+ struct dom_binding *ysd;
+ struct timeval tv;
+ CLIENT *client;
+ int sock, r;
+ u_long ss_addr;
+
+ sock = RPC_ANYSOCK;
+ tv.tv_sec = 15;
+ tv.tv_usec = 0;
+ client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
+ if(client==NULL) {
+ fprintf(stderr, "can't clntudp_create: %s\n",
+ yperr_string(YPERR_YPBIND));
+ return YPERR_YPBIND;
+ }
+
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ r = clnt_call(client, YPBINDPROC_DOMAIN,
+ xdr_domainname, dom, xdr_ypbind_resp, &ypbr, tv);
+ if( r != RPC_SUCCESS) {
+ fprintf(stderr, "can't clnt_call: %s\n",
+ yperr_string(YPERR_YPBIND));
+ clnt_destroy(client);
+ return YPERR_YPBIND;
+ } else {
+ if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
+ fprintf(stderr, "can't yp_bind: Reason: %s\n",
+ yperr_string(ypbr.ypbind_status));
+ clnt_destroy(client);
+ return r;
+ }
+ }
+ clnt_destroy(client);
+
+ ss_addr = ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr.s_addr;
+ /*printf("%08x\n", ss_addr);*/
+ hent = gethostbyaddr((char *)&ss_addr, sizeof(ss_addr), AF_INET);
+ if (hent)
+ printf("%s\n", hent->h_name);
+ else
+ printf("%s\n", inet_ntoa(ss_addr));
+ return 0;
+}
+
+int
+main(argc, argv)
+char **argv;
+{
+ char *domainname, *master, *map;
+ struct ypmaplist *ypml, *y;
+ extern char *optarg;
+ extern int optind;
+ struct hostent *hent;
+ struct sockaddr_in sin;
+ int notrans, mode, getmap;
+ int c, r, i;
+
+ yp_get_default_domain(&domainname);
+
+ map = NULL;
+ getmap = notrans = mode = 0;
+ while( (c=getopt(argc, argv, "xd:mt")) != -1)
+ switch(c) {
+ case 'x':
+ for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ printf("Use \"%s\" for \"%s\"\n",
+ ypaliases[i].alias,
+ ypaliases[i].name);
+ exit(0);
+ case 'd':
+ domainname = optarg;
+ break;
+ case 't':
+ notrans++;
+ break;
+ case 'm':
+ mode++;
+ break;
+ default:
+ usage();
+ }
+
+ if(mode==0) {
+ switch(argc-optind) {
+ case 0:
+ bzero(&sin, sizeof sin);
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ if(bind_host(domainname, &sin))
+ exit(1);
+ break;
+ case 1:
+ bzero(&sin, sizeof sin);
+ sin.sin_family = AF_INET;
+ if( (sin.sin_addr.s_addr=inet_addr(argv[optind]))==-1) {
+ hent = gethostbyname(argv[optind]);
+ if(!hent) {
+ fprintf(stderr, "ypwhich: host %s unknown\n",
+ argv[optind]);
+ exit(1);
+ }
+ bcopy((char *)hent->h_addr_list[0],
+ (char *)&sin.sin_addr, sizeof sin.sin_addr);
+ }
+ if(bind_host(domainname, &sin))
+ exit(1);
+ break;
+ default:
+ usage();
+ }
+ exit(0);
+ }
+
+ if( argc-optind > 1)
+ usage();
+
+ if(argv[optind]) {
+ map = argv[optind];
+ for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
+ if( strcmp(map, ypaliases[i].alias) == 0)
+ map = ypaliases[i].name;
+ r = yp_master(domainname, map, &master);
+ switch(r) {
+ case 0:
+ printf("%s\n", master);
+ free(master);
+ break;
+ case YPERR_YPBIND:
+ fprintf(stderr, "ypwhich: not running ypbind\n");
+ exit(1);
+ default:
+ fprintf(stderr, "Can't find master for map %s. Reason: %s\n",
+ map, yperr_string(r));
+ exit(1);
+ }
+ exit(0);
+ }
+
+ ypml = NULL;
+ r = yp_maplist(domainname, &ypml);
+ switch(r) {
+ case 0:
+ for(y=ypml; y; ) {
+ ypml = y;
+ r = yp_master(domainname, ypml->ypml_name, &master);
+ switch(r) {
+ case 0:
+ printf("%s %s\n", ypml->ypml_name, master);
+ free(master);
+ break;
+ default:
+ fprintf(stderr,
+ "YP: can't find the master of %s: Reason: %s\n",
+ ypml->ypml_name, yperr_string(r));
+ break;
+ }
+ y = ypml->ypml_next;
+ free(ypml);
+ }
+ break;
+ case YPERR_YPBIND:
+ fprintf(stderr, "ypwhich: not running ypbind\n");
+ exit(1);
+ default:
+ fprintf(stderr, "Can't get map list for domain %s. Reason: %s\n",
+ domainname, yperr_string(r));
+ exit(1);
+ }
+ exit(0);
+}