mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-23 11:18:54 +00:00
Move more YP user programs over.
This commit is contained in:
parent
d832d69165
commit
73407b3433
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=1930
@ -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.
|
||||
|
6
usr.bin/ypcat/Makefile
Normal file
6
usr.bin/ypcat/Makefile
Normal file
@ -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 <bsd.prog.mk>
|
70
usr.bin/ypcat/ypcat.1
Normal file
70
usr.bin/ypcat/ypcat.1
Normal file
@ -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
|
143
usr.bin/ypcat/ypcat.c
Normal file
143
usr.bin/ypcat/ypcat.c
Normal file
@ -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);
|
||||
}
|
6
usr.bin/ypmatch/Makefile
Normal file
6
usr.bin/ypmatch/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
|
||||
# $Id: Makefile,v 1.3 1994/02/17 07:06:13 rgrimes Exp $
|
||||
|
||||
PROG= ypmatch
|
||||
|
||||
.include <bsd.prog.mk>
|
71
usr.bin/ypmatch/ypmatch.1
Normal file
71
usr.bin/ypmatch/ypmatch.1
Normal file
@ -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
|
134
usr.bin/ypmatch/ypmatch.c
Normal file
134
usr.bin/ypmatch/ypmatch.c
Normal file
@ -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);
|
||||
}
|
7
usr.bin/ypwhich/Makefile
Normal file
7
usr.bin/ypwhich/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
|
||||
# $Id: Makefile,v 1.2 1994/02/17 07:06:22 rgrimes Exp $
|
||||
|
||||
PROG= ypwhich
|
||||
NOMAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
249
usr.bin/ypwhich/ypwhich.c
Normal file
249
usr.bin/ypwhich/ypwhich.c
Normal file
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user