From 73407b3433708f5eed5603eeee6c79bc7d23068e Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Mon, 8 Aug 1994 01:13:35 +0000 Subject: [PATCH] Move more YP user programs over. --- usr.bin/Makefile | 6 +- usr.bin/ypcat/Makefile | 6 + usr.bin/ypcat/ypcat.1 | 70 +++++++++++ usr.bin/ypcat/ypcat.c | 143 ++++++++++++++++++++++ usr.bin/ypmatch/Makefile | 6 + usr.bin/ypmatch/ypmatch.1 | 71 +++++++++++ usr.bin/ypmatch/ypmatch.c | 134 ++++++++++++++++++++ usr.bin/ypwhich/Makefile | 7 ++ usr.bin/ypwhich/ypwhich.c | 249 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 690 insertions(+), 2 deletions(-) create mode 100644 usr.bin/ypcat/Makefile create mode 100644 usr.bin/ypcat/ypcat.1 create mode 100644 usr.bin/ypcat/ypcat.c create mode 100644 usr.bin/ypmatch/Makefile create mode 100644 usr.bin/ypmatch/ypmatch.1 create mode 100644 usr.bin/ypmatch/ypmatch.c create mode 100644 usr.bin/ypwhich/Makefile create mode 100644 usr.bin/ypwhich/ypwhich.c diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 66e14e3deca2..98c28462333b 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -5,7 +5,9 @@ # XXX MISSING SOURCES: file grep sort # XXX MISSING Makefile: uucp # XXX Use GNU versions: ld man apropos whatis patch -SUBDIR= apply ar banner basename bdes biff cal calendar \ +# Moved to secure: bdes +# +SUBDIR= apply ar banner basename biff cal calendar \ cap_mkdb checknr chflags chpass cksum col colcrt colrm column \ comm compress cpp ctags cut dirname du \ env error expand false find finger fmt fold fpr from \ @@ -20,7 +22,7 @@ SUBDIR= apply ar banner basename bdes biff cal calendar \ tn3270 touch tput tr true tset tsort tty ul uname unexpand \ unifdef uniq unvis users uudecode uuencode vacation \ vgrind vis w wall wc what whereis who whois window write \ - xargs xinstall xstr yacc yes + xargs xinstall xstr yacc yes ypcat ypmatch ypwhich # Cmp, look and tail all use mmap, so new-VM only. # F77 and pascal are VAX/Tahoe only. diff --git a/usr.bin/ypcat/Makefile b/usr.bin/ypcat/Makefile new file mode 100644 index 000000000000..c133eb52a80e --- /dev/null +++ b/usr.bin/ypcat/Makefile @@ -0,0 +1,6 @@ +# from: @(#)Makefile 5.8 (Berkeley) 7/28/90 +# $Id: Makefile,v 1.3 1994/02/17 07:06:10 rgrimes Exp $ + +PROG= ypcat + +.include diff --git a/usr.bin/ypcat/ypcat.1 b/usr.bin/ypcat/ypcat.1 new file mode 100644 index 000000000000..99321b496c3c --- /dev/null +++ b/usr.bin/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.bin/ypcat/ypcat.c b/usr.bin/ypcat/ypcat.c new file mode 100644 index 000000000000..85158a34d341 --- /dev/null +++ b/usr.bin/ypcat/ypcat.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 1992/3 Theo de Raadt + * 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 +#include +#include +#include +#include + +#include +#include +#include +#include + +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 diff --git a/usr.bin/ypmatch/ypmatch.1 b/usr.bin/ypmatch/ypmatch.1 new file mode 100644 index 000000000000..0b7ac89cd86b --- /dev/null +++ b/usr.bin/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.bin/ypmatch/ypmatch.c b/usr.bin/ypmatch/ypmatch.c new file mode 100644 index 000000000000..7370e94d3d63 --- /dev/null +++ b/usr.bin/ypmatch/ypmatch.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 1992/3 Theo de Raadt + * 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 +#include +#include +#include +#include + +#include +#include +#include +#include + +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 diff --git a/usr.bin/ypwhich/ypwhich.c b/usr.bin/ypwhich/ypwhich.c new file mode 100644 index 000000000000..cefac38ffa79 --- /dev/null +++ b/usr.bin/ypwhich/ypwhich.c @@ -0,0 +1,249 @@ +/* + * Copyright (c) 1992/3 Theo de Raadt + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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; ih_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) && iypml_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); +}