Module Name: src
Committed By: christos
Date: Sat Jun 20 19:27:26 UTC 2009
Modified Files:
src/usr.bin/ypcat: Makefile ypcat.1 ypcat.c
src/usr.bin/ypmatch: Makefile ypmatch.1 ypmatch.c
src/usr.bin/ypwhich: Makefile ypwhich.1 ypwhich.c
Added Files:
src/usr.bin/ypcat: nicknames nicknames.5 ypalias_init.c ypalias_init.h
Log Message:
PR/22627: Greywolf: Support for yp nicknames map.
To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/ypcat/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/ypcat/nicknames \
src/usr.bin/ypcat/nicknames.5 src/usr.bin/ypcat/ypalias_init.c \
src/usr.bin/ypcat/ypalias_init.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/ypcat/ypcat.1
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/ypcat/ypcat.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/ypmatch/Makefile
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/ypmatch/ypmatch.1
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/ypmatch/ypmatch.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/ypwhich/Makefile
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/ypwhich/ypwhich.1 \
src/usr.bin/ypwhich/ypwhich.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/ypcat/Makefile
diff -u src/usr.bin/ypcat/Makefile:1.11 src/usr.bin/ypcat/Makefile:1.12
--- src/usr.bin/ypcat/Makefile:1.11 Mon May 28 08:06:33 2007
+++ src/usr.bin/ypcat/Makefile Sat Jun 20 15:27:26 2009
@@ -1,8 +1,11 @@
-# $NetBSD: Makefile,v 1.11 2007/05/28 12:06:33 tls Exp $
+# $NetBSD: Makefile,v 1.12 2009/06/20 19:27:26 christos Exp $
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
USE_FORT?= yes # network client
-PROG= ypcat
-
+PROG= ypcat
+SRCS= ypalias_init.c ypcat.c
+FILES= nicknames
+FILESDIR= /var/yp
+MAN= ypcat.1 nicknames.5
.include <bsd.prog.mk>
Index: src/usr.bin/ypcat/ypcat.1
diff -u src/usr.bin/ypcat/ypcat.1:1.14 src/usr.bin/ypcat/ypcat.1:1.15
--- src/usr.bin/ypcat/ypcat.1:1.14 Sat Feb 26 11:21:05 2005
+++ src/usr.bin/ypcat/ypcat.1 Sat Jun 20 15:27:26 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: ypcat.1,v 1.14 2005/02/26 16:21:05 wiz Exp $
+.\" $NetBSD: ypcat.1,v 1.15 2009/06/20 19:27:26 christos Exp $
.\"
.\" Copyright (c) 1993 Winning Strategies, Inc.
.\" All rights reserved.
@@ -28,7 +28,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 26, 2005
+.Dd June 20, 2009
.Dt YPCAT 1
.Os
.Sh NAME
@@ -61,15 +61,21 @@
Inhibit translation of map nicknames
to their corresponding map names.
.It Fl x
-Display the map nickname table.
+Display the map nickname table, found in /var/yp/nicknames.
+A built-in default translation table is used if /var/yp/nicknames
+does not exist (see
+.Xr nicknames 5
+for details).
.El
.Sh SEE ALSO
.Xr domainname 1 ,
.Xr ypmatch 1 ,
.Xr ypwhich 1 ,
+.Xr nicknames 5 ,
.Xr nis 8 ,
.Xr ypbind 8 ,
.Xr yppoll 8 ,
.Xr ypset 8
.Sh AUTHORS
.An Theo De Raadt
+.An Greywolf
Index: src/usr.bin/ypcat/ypcat.c
diff -u src/usr.bin/ypcat/ypcat.c:1.12 src/usr.bin/ypcat/ypcat.c:1.13
--- src/usr.bin/ypcat/ypcat.c:1.12 Tue Apr 14 05:55:07 2009
+++ src/usr.bin/ypcat/ypcat.c Sat Jun 20 15:27:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: ypcat.c,v 1.12 2009/04/14 09:55:07 lukem Exp $ */
+/* $NetBSD: ypcat.c,v 1.13 2009/06/20 19:27:26 christos Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <[email protected]>
@@ -28,12 +28,13 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ypcat.c,v 1.12 2009/04/14 09:55:07 lukem Exp $");
+__RCSID("$NetBSD: ypcat.c,v 1.13 2009/06/20 19:27:26 christos Exp $");
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/errno.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
@@ -46,29 +47,14 @@
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
-const struct ypalias {
- const 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 main __P((int, char *[]));
-int printit __P((int, char *, int, char *, int, char *));
-void usage __P((void));
+#include "ypalias_init.h"
+
+static int printit(int, char *, int, char *, int, char *);
+static void usage(void) __attribute__((__noreturn__));
-int key;
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
char *domainname;
struct ypall_callback ypcb;
@@ -76,18 +62,21 @@
int notrans;
int c, r;
size_t i;
+ const struct ypalias *ypaliases;
+ int key;
+ setprogname(*argv);
domainname = NULL;
notrans = key = 0;
+ ypaliases = ypalias_init();
while((c = getopt(argc, argv, "xd:kt")) != -1) {
switch (c) {
case 'x':
- for (i = 0;
- i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
+ for (i = 0; ypaliases[i].alias; i++)
printf("Use \"%s\" for \"%s\"\n",
- ypaliases[i].alias,
- ypaliases[i].name);
- exit(0);
+ ypaliases[i].alias,
+ ypaliases[i].name);
+ return 0;
case 'd':
domainname = optarg;
@@ -117,13 +106,13 @@
inmap = argv[0];
if (notrans == 0) {
- for (i = 0; i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
+ for (i = 0; ypaliases[i].alias; i++)
if (strcmp(inmap, ypaliases[i].alias) == 0)
inmap = ypaliases[i].name;
}
ypcb.foreach = printit;
- ypcb.data = NULL;
+ ypcb.data = key ? (void *)&key : NULL;
r = yp_all(domainname, inmap, &ypcb);
switch (r) {
@@ -136,35 +125,31 @@
default:
errx(1, "no such map %s. Reason: %s", inmap, yperr_string(r));
}
- exit(0);
+ return 0;
}
-int
-printit(instatus, inkey, inkeylen, inval, invallen, indata)
- int instatus;
- char *inkey;
- int inkeylen;
- char *inval;
- int invallen;
- char *indata;
+static int
+printit(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);
+ if (indata)
+ (void)printf("%*.*s", inkeylen, inkeylen, inkey);
if (invallen)
- printf("%s%*.*s", (key ? " " : ""), invallen, invallen, inval);
- printf("\n");
+ (void)printf("%s%*.*s", (indata ? " " : ""), invallen, invallen,
+ inval);
+ (void)printf("\n");
return 0;
}
-void
-usage()
+static void
+usage(void)
{
- fprintf(stderr, "usage: %s [-k] [-d domainname] [-t] mapname\n",
+ (void)fprintf(stderr, "Usage: %s [-k] [-d domainname] [-t] mapname\n",
getprogname());
- fprintf(stderr, " %s -x\n", getprogname());
+ (void)fprintf(stderr, " %s -x\n", getprogname());
exit(1);
}
Index: src/usr.bin/ypmatch/Makefile
diff -u src/usr.bin/ypmatch/Makefile:1.11 src/usr.bin/ypmatch/Makefile:1.12
--- src/usr.bin/ypmatch/Makefile:1.11 Mon May 28 08:06:33 2007
+++ src/usr.bin/ypmatch/Makefile Sat Jun 20 15:27:26 2009
@@ -1,8 +1,11 @@
-# $NetBSD: Makefile,v 1.11 2007/05/28 12:06:33 tls Exp $
+# $NetBSD: Makefile,v 1.12 2009/06/20 19:27:26 christos Exp $
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
USE_FORT?= yes # network client
+.PATH.c: ${.CURDIR}/../ypcat
+CPPFLAGS+= -I${.CURDIR}/../ypcat
PROG= ypmatch
+SRCS= ypmatch.c ypalias_init.c
.include <bsd.prog.mk>
Index: src/usr.bin/ypmatch/ypmatch.1
diff -u src/usr.bin/ypmatch/ypmatch.1:1.14 src/usr.bin/ypmatch/ypmatch.1:1.15
--- src/usr.bin/ypmatch/ypmatch.1:1.14 Sat Feb 26 11:21:44 2005
+++ src/usr.bin/ypmatch/ypmatch.1 Sat Jun 20 15:27:26 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: ypmatch.1,v 1.14 2005/02/26 16:21:44 wiz Exp $
+.\" $NetBSD: ypmatch.1,v 1.15 2009/06/20 19:27:26 christos Exp $
.\"
.\" Copyright (c) 1993 Winning Strategies, Inc.
.\" All rights reserved.
@@ -28,7 +28,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 26, 2005
+.Dd June 20, 2009
.Dt YPMATCH 1
.Os
.Sh NAME
@@ -62,7 +62,11 @@
Inhibit translation of map nicknames
to their corresponding map names.
.It Fl x
-Display the map nickname table.
+Display the map nickname table, found in /var/yp/nicknames.
+A built-in default translation table is used if /var/yp/nicknames
+does not exist (see
+.Xr nicknames 5
+for details).
.It Fl z
Append a NUL character at the end of the key when doing the lookup.
This is useful for mail.aliases maps, which include a trailing NUL in
@@ -72,9 +76,11 @@
.Xr domainname 1 ,
.Xr ypcat 1 ,
.Xr ypwhich 1 ,
+.Xr nicknames 5 ,
.Xr nis 8 ,
.Xr ypbind 8 ,
.Xr yppoll 8 ,
.Xr ypset 8
.Sh AUTHORS
.An Theo De Raadt
+.An Greywolf
Index: src/usr.bin/ypmatch/ypmatch.c
diff -u src/usr.bin/ypmatch/ypmatch.c:1.17 src/usr.bin/ypmatch/ypmatch.c:1.18
--- src/usr.bin/ypmatch/ypmatch.c:1.17 Tue Apr 14 05:57:38 2009
+++ src/usr.bin/ypmatch/ypmatch.c Sat Jun 20 15:27:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: ypmatch.c,v 1.17 2009/04/14 09:57:38 lukem Exp $ */
+/* $NetBSD: ypmatch.c,v 1.18 2009/06/20 19:27:26 christos Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <[email protected]>
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ypmatch.c,v 1.17 2009/04/14 09:57:38 lukem Exp $");
+__RCSID("$NetBSD: ypmatch.c,v 1.18 2009/06/20 19:27:26 christos Exp $");
#endif
#include <sys/param.h>
@@ -46,26 +46,12 @@
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
-const struct ypalias {
- const char *alias, *name;
-} ypaliases[] = {
- { "passwd", "passwd.byname" },
- { "group", "group.byname" },
- { "networks", "networks.byaddr" },
- { "hosts", "hosts.byname" },
- { "protocols", "protocols.bynumber" },
- { "services", "services.byname" },
- { "aliases", "mail.aliases" },
- { "ethers", "ethers.byname" },
-};
+#include "ypalias_init.h"
-int main __P((int, char *[]));
-void usage __P((void));
+static void usage(void) __attribute__((__noreturn__));
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
char *domainname;
char *inkey, *outbuf;
@@ -74,18 +60,20 @@
int c, r, len;
size_t i;
int rval;
+ const struct ypalias *ypaliases;
+ setprogname(*argv);
domainname = NULL;
notrans = key = null = 0;
+ ypaliases = ypalias_init();
while ((c = getopt(argc, argv, "xd:ktz")) != -1) {
switch (c) {
case 'x':
- for(i = 0;
- i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
+ for(i = 0; ypaliases[i].alias; i++)
printf("Use \"%s\" for \"%s\"\n",
ypaliases[i].alias,
ypaliases[i].name);
- exit(0);
+ return 0;
case 'd':
domainname = optarg;
@@ -119,7 +107,7 @@
inmap = argv[argc - 1];
if (notrans == 0) {
- for (i = 0 ; i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
+ for (i = 0; ypaliases[i].alias; i++)
if (strcmp(inmap, ypaliases[i].alias) == 0)
inmap = ypaliases[i].name;
}
@@ -152,15 +140,15 @@
}
}
- exit(rval);
+ return rval;
}
-void
-usage()
+static void
+usage(void)
{
- fprintf(stderr, "usage: %s [-d domain] [-tkz] key [key ...] "
+ (void)fprintf(stderr, "Usage: %s [-d domain] [-tkz] key [key ...] "
"mapname\n", getprogname());
- fprintf(stderr, " %s -x\n", getprogname());
+ (void)fprintf(stderr, " %s -x\n", getprogname());
exit(1);
}
Index: src/usr.bin/ypwhich/Makefile
diff -u src/usr.bin/ypwhich/Makefile:1.11 src/usr.bin/ypwhich/Makefile:1.12
--- src/usr.bin/ypwhich/Makefile:1.11 Mon May 28 08:06:33 2007
+++ src/usr.bin/ypwhich/Makefile Sat Jun 20 15:27:26 2009
@@ -1,8 +1,11 @@
-# $NetBSD: Makefile,v 1.11 2007/05/28 12:06:33 tls Exp $
+# $NetBSD: Makefile,v 1.12 2009/06/20 19:27:26 christos Exp $
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
USE_FORT?=yes # network client
+.PATH.c: ${.CURDIR}/../ypcat
+CPPFLAGS+=-I${.CURDIR}/../ypcat
PROG= ypwhich
+SRCS= ypwhich.c ypalias_init.c
.include <bsd.prog.mk>
Index: src/usr.bin/ypwhich/ypwhich.1
diff -u src/usr.bin/ypwhich/ypwhich.1:1.15 src/usr.bin/ypwhich/ypwhich.1:1.16
--- src/usr.bin/ypwhich/ypwhich.1:1.15 Thu Jan 24 18:56:55 2008
+++ src/usr.bin/ypwhich/ypwhich.1 Sat Jun 20 15:27:26 2009
@@ -1,4 +1,4 @@
-.\" $NetBSD: ypwhich.1,v 1.15 2008/01/24 23:56:55 christos Exp $
+.\" $NetBSD: ypwhich.1,v 1.16 2009/06/20 19:27:26 christos Exp $
.\"
.\" Copyright (c) 1994 Christopher G. Demetriou
.\" All rights reserved.
@@ -99,7 +99,11 @@
.Nm
will produce a list of available maps.
.It Fl x
-Display the map nickname table.
+Display the map nickname table, found in /var/yp/nicknames.
+A built-in default translation table is used if /var/yp/nicknames
+does not exist (see
+.Xr nicknames 5
+for details).
.El
.Pp
.Nm
@@ -110,9 +114,11 @@
.Xr domainname 1 ,
.Xr ypcat 1 ,
.Xr ypmatch 1 ,
+.Xr nicknames 5 ,
.Xr nis 8 ,
.Xr ypbind 8 ,
.Xr yppoll 8 ,
.Xr ypset 8
.Sh AUTHORS
.An Charles D. Cranor
+.An Greywolf
Index: src/usr.bin/ypwhich/ypwhich.c
diff -u src/usr.bin/ypwhich/ypwhich.c:1.15 src/usr.bin/ypwhich/ypwhich.c:1.16
--- src/usr.bin/ypwhich/ypwhich.c:1.15 Fri Jan 25 14:54:40 2008
+++ src/usr.bin/ypwhich/ypwhich.c Sat Jun 20 15:27:26 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: ypwhich.c,v 1.15 2008/01/25 19:54:40 christos Exp $ */
+/* $NetBSD: ypwhich.c,v 1.16 2009/06/20 19:27:26 christos Exp $ */
/*
*
@@ -56,6 +56,7 @@
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
+#include "ypalias_init.h"
/*
* ypwhich: query a host about its yp service
@@ -78,25 +79,12 @@
* -x: print list of yp map aliases and exit
*/
-static const char *ypnicknames[] = {
- "aliases", "mail.aliases",
- "ethers", "ethers.byname",
- "group", "group.byname",
- "hosts", "hosts.byaddr",
- "networks", "networks.byaddr",
- "passwd", "passwd.byname",
- "protocols", "protocols.bynumber",
- "services", "services.byname",
- 0, 0,
-};
-
-
/*
* prototypes
*/
static void find_mapmaster(const char *, const char *, const char *,
- int, int, int);
+ int, int, int, const struct ypalias *);
static struct in_addr *find_server(const char *, const char *, int);
static CLIENT *mkclient(struct sockaddr_in *, unsigned long, unsigned long,
int);
@@ -113,14 +101,17 @@
char *ourdomain;
int inhibit = 0, force = 0, tcp = 0;
char *targmap = NULL;
- int ch, saw_m, lcv;
+ int ch, saw_m;
struct in_addr *inaddr;
struct hostent *he;
+ size_t i;
+ const struct ypalias *ypaliases;
/*
* get default domainname and parse options
*/
+ ypaliases = ypalias_init();
(void)yp_get_default_domain(&ourdomain);
saw_m = 0;
while ((ch = getopt(argc, argv, "h:d:xtTfm")) != -1) {
@@ -132,9 +123,9 @@
ourdomain = optarg;
break;
case 'x':
- for (lcv = 0; ypnicknames[lcv]; lcv += 2)
+ for (i = 0; ypaliases[i].alias; i++)
(void)printf("Use \"%s\" for map \"%s\"\n",
- ypnicknames[lcv], ypnicknames[lcv + 1]);
+ ypaliases[i].alias, ypaliases[i].name);
return 0;
case 'f':
force = 1;
@@ -180,7 +171,7 @@
*/
if (saw_m)
find_mapmaster(targhost, ourdomain, targmap, inhibit, force,
- tcp);
+ tcp, ypaliases);
else {
inaddr = find_server(targhost, ourdomain, tcp);
he = gethostbyaddr((void *)&inaddr->s_addr,
@@ -282,11 +273,10 @@
*/
static void
find_mapmaster(const char *host, const char *domain, const char *map,
- int inhibit, int force, int tcp)
+ int inhibit, int force, int tcp, const struct ypalias *ypaliases)
{
struct in_addr *inaddr, faddr;
struct hostent *he;
- int lcv;
struct sockaddr_in sin;
CLIENT *ypserv;
int yperr;
@@ -296,6 +286,7 @@
struct ypmaplist fakelist, *ypml;
struct ypresp_master yprespmaster;
struct ypreq_nokey ypreqkey;
+ size_t i;
/*
* we can either ask the hosts ypbind where it's ypserv is located,
@@ -318,9 +309,12 @@
* now translate nicknames [unless inhibited]
*/
if (map && !inhibit) {
- for (lcv = 0; ypnicknames[lcv]; lcv += 2) {
- if (strcmp(map, ypnicknames[lcv]) == 0) {
- map = ypnicknames[lcv + 1];
+/*###325 [cc] error: 'i' undeclared (first use in this function)%%%*/
+/*###325 [cc] error: (Each undeclared identifier is reported only once%%%*/
+/*###325 [cc] error: for each function it appears in.)%%%*/
+ for (i = 0; ypaliases[i].alias; i++) {
+ if (strcmp(map, ypaliases[i].alias) == 0) {
+ map = ypaliases[i].name;
break;
}
}
Added files:
Index: src/usr.bin/ypcat/nicknames
diff -u /dev/null src/usr.bin/ypcat/nicknames:1.1
--- /dev/null Sat Jun 20 15:27:26 2009
+++ src/usr.bin/ypcat/nicknames Sat Jun 20 15:27:26 2009
@@ -0,0 +1,9 @@
+passwd passwd.byname
+group group.byname
+networks networks.byaddr
+hosts hosts.byaddr
+protocols protocols.bynumber
+services services.byname
+aliases mail.aliases
+ethers ethers.byname
+master.passwd master.passwd.byname
Index: src/usr.bin/ypcat/nicknames.5
diff -u /dev/null src/usr.bin/ypcat/nicknames.5:1.1
--- /dev/null Sat Jun 20 15:27:26 2009
+++ src/usr.bin/ypcat/nicknames.5 Sat Jun 20 15:27:26 2009
@@ -0,0 +1,90 @@
+.\" $NetBSD: nicknames.5,v 1.1 2009/06/20 19:27:26 christos Exp $
+.\"
+.\"
+.\" Copyright (c) 2003 The NetBSD Foundation
+.\" 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.
+.\"
+.Dd 28 August, 2003
+.Dt NICKNAMES 5
+.Os
+.Sh NAME
+.Nm nicknames
+.Nd map nickname translation file for NIS (YP)
+.Sh DESCRIPTION
+The
+.Xr ypcat 1 ,
+.Xr ypmatch 1 ,
+and
+.Xr ypwhich 1
+commands reference NIS (YP) maps as specified by the user. Occasionally
+it is desirable to use a shorthand reference for a longer map name, hence
+the
+.Nm
+file, kept in
+.Dq /var/yp/nicknames.
+.Pp
+The format of the file is
+.Pp
+.Dl nickname map
+.Pp
+one pair per line. The default installed nickname map is as follows:
+.Pp
+.Bl -tag -width protocols -offset indent -compact
+.It passwd
+passwd.byname
+.It group
+group.byname
+.It networks
+networks.byaddr
+.It hosts
+hosts.byname
+.It protocols
+protocols.bynumber
+.It services
+services.byname
+.It aliases
+aliases.byname
+.It ethers
+ethers.byname
+.It master.passwd
+master.passwd.byname
+.El
+.Pp
+A blank or incomplete
+.Nm
+file will affect any scripts which use nicknames for map lookup,
+whereas if the file is simply missing, the default compiled-in list
+will be used.
+.Pp
+.Sh SEE ALSO
+.Xr ypcat 1 ,
+.Xr ypmatch 1 ,
+.Xr ypwhich 1
+.Sh HISTORY
+The
+.Nm
+file first appeared in Solaris 2.4.
Index: src/usr.bin/ypcat/ypalias_init.c
diff -u /dev/null src/usr.bin/ypcat/ypalias_init.c:1.1
--- /dev/null Sat Jun 20 15:27:26 2009
+++ src/usr.bin/ypcat/ypalias_init.c Sat Jun 20 15:27:26 2009
@@ -0,0 +1,120 @@
+/* $NetBSD: ypalias_init.c,v 1.1 2009/06/20 19:27:26 christos Exp $ */
+
+/*
+ * Copyright (c) 2009 The NetBSD Foundation
+ * 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.
+ */
+
+/* Code contributed by Greywolf <[email protected]>
+ * 28 August 2003. All rights released to The NetBSD Foundation.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: ypalias_init.c,v 1.1 2009/06/20 19:27:26 christos Exp $");
+#endif
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <paths.h>
+#include <errno.h>
+
+#include "ypalias_init.h"
+
+#ifndef _PATH_YPNICKNAMES
+#define _PATH_YPNICKNAMES "/var/yp/nicknames"
+#endif
+
+const struct ypalias def_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" },
+ { NULL, NULL },
+};
+
+const struct ypalias *
+ypalias_init(void)
+{
+ FILE *fp;
+ char *cp, *line;
+ struct ypalias *ypa, *nypa;
+ size_t nypalias = 50;
+ size_t i, len, lineno;
+
+ if ((fp = fopen(_PATH_YPNICKNAMES, "r")) == NULL)
+ return &def_ypaliases[0];
+
+ if ((ypa = calloc(sizeof(*ypa), nypalias)) == NULL)
+ goto out;
+
+ lineno = 1;
+ for (i = 0; (line = fparseln(fp, &len, &lineno, NULL,
+ FPARSELN_UNESCALL));) {
+ cp = line;
+ /* Ignore malformed lines */
+ if ((ypa[i].alias = strsep(&line, " \t\n")) == NULL ||
+ (ypa[i].name = strsep(&line, " \t\n")) == NULL ||
+ ypa[i].alias != cp) {
+ warnx("%s, %zu: syntax error, ignored",
+ _PATH_YPNICKNAMES, lineno);
+ free(cp);
+ } else
+ i++;
+ if (i == nypalias) {
+ nypalias <<= 1;
+ nypa = realloc(ypa, sizeof(*ypa) * nypalias);
+ if (nypa == NULL)
+ goto out;
+ ypa = nypa;
+ }
+ }
+ ypa[i].alias = ypa[i].name = NULL;
+ i++;
+
+ (void)fclose(fp);
+ if ((nypa = realloc(ypa, sizeof(*ypa) * i)) != NULL)
+ return nypa;
+out:
+ warn("Cannot alllocate alias space, returning default list");
+ if (ypa) {
+ do
+ free(__UNCONST(ypa[--i].alias));
+ while (i != 0);
+ free(ypa);
+ }
+ (void)fclose(fp);
+ return def_ypaliases;
+ return ypa;
+}
Index: src/usr.bin/ypcat/ypalias_init.h
diff -u /dev/null src/usr.bin/ypcat/ypalias_init.h:1.1
--- /dev/null Sat Jun 20 15:27:26 2009
+++ src/usr.bin/ypcat/ypalias_init.h Sat Jun 20 15:27:26 2009
@@ -0,0 +1,6 @@
+
+struct ypalias {
+ const char *alias, *name;
+};
+
+const struct ypalias *ypalias_init(void);