[prev in list] [next in list] [prev in thread] [next in thread]
List: netbsd-bugs
Subject: bin/22627: ypcat, ypmatch and ypwhich depend on archaic hardcoded maps
From: Greywolf <greywolf () starwolf ! com>
Date: 2003-08-28 23:16:53
[Download RAW message or body]
> Number: 22627
> Category: bin
> Synopsis: ypcat, ypmatch and ypwhich depend on archaic hardcoded maps
> Confidential: no
> Severity: serious
> Priority: high
> Responsible: bin-bug-people
> State: open
> Class: change-request
> Submitter-Id: net
> Arrival-Date: Thu Aug 28 23:17:00 UTC 2003
> Closed-Date:
> Last-Modified:
> Originator:
> Release: NetBSD 1.6U
> Organization:
Star Wolf Innovations
> Environment:
System: NetBSD rivendell.starwolf.com 1.6U NetBSD 1.6U (RIVENDELL) #14: Mon Jul 28 \
21:12:25 PDT 2003 root@:/.../src/sys/arch/i386/compile/RIVENDELL i386
Architecture: i386
Machine: i386
> Description:
ypcat, ypwhich and ypmatch depend on archaic hardcoded maps being
compiled in. This is, to put it succinctly, inflexible.
It would be more desirable to use /var/yp/nicknames, if present.
> How-To-Repeat:
# { domainname && ypwhich } || echo "enable YP first"
# ypcat -x;
# ypcat master.passwd
# ypcat -x | awk -F\" '{print $2, $4}' > /tmp/p
# mv /tmp/p /var/yp/nicknames
# echo "master.passwd master.passwd.byname" >> var/yp/nicknames
# ypcat master.passwd
[ Note that no translation happens. ]
> Fix:
Please find enclosed the requisite diffs for:
ypcat/Makefile
ypcat/ypcat.c
ypmatch/Makefile
ypmatch/ypmatch.c
ypwhich/Makefile
ypwhich/ypwhich.c
And the following files
ypcat/ypalias_init.c
ypcat/nicknames (to be installed in /var/yp)
I leave final judgment whence to install them up to you;
likewise, my coding style might suck -- if you can rewrite
this better, by all means, please do.
#### diffs follow ####
--- ypcat/Makefile.new 2003-08-28 16:12:51.000000000 -0700
+++ ypcat/Makefile 1997-10-20 07:54:27.000000000 -0700
@@ -2,8 +2,5 @@
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
PROG= ypcat
-SRCS+= ypalias_init.c
-FILES= nicknames
-FILESDIR= /var/yp
.include <bsd.prog.mk>
--- ypcat/ypcat.c.new 2003-08-28 15:52:22.000000000 -0700
+++ ypcat/ypcat.c 2001-02-20 03:34:26.000000000 -0800
@@ -1,4 +1,4 @@
-/* $NetBSD: ypcat.c,v 1.10 2001/02/19 23:03:54 cgd Exp $ */
+/* $NetBSD: ypcat.c,v 1.10 2001/02/19 23:03:54 cgd Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
@@ -40,7 +40,6 @@
#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>
@@ -53,18 +52,22 @@
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
-extern int errno;
-
-struct ypalias {
+const 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" },
};
-struct ypalias *ypaliases;
-
int main __P((int, char *[]));
int printit __P((int, char *, int, char *, int, char *));
void usage __P((void));
-extern struct ypalias *ypalias_init __P((void));
int key;
@@ -76,19 +79,19 @@
char *domainname;
struct ypall_callback ypcb;
char *inmap;
- struct ypalias *ypa;
int notrans;
int c, r, i;
domainname = NULL;
notrans = key = 0;
- ypaliases = ypalias_init();
while((c = getopt(argc, argv, "xd:kt")) != -1) {
switch (c) {
case 'x':
- for (ypa = ypaliases; ypa->alias; ypa++)
+ for (i = 0;
+ i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
printf("Use \"%s\" for \"%s\"\n",
- ypa->alias, ypa->name);
+ ypaliases[i].alias,
+ ypaliases[i].name);
exit(0);
case 'd':
@@ -119,9 +122,9 @@
inmap = argv[0];
if (notrans == 0) {
- for (ypa = ypaliases; ypa->alias; ypa++)
- if (strcmp(inmap, ypa->alias) == 0)
- inmap = ypa->name;
+ for (i = 0; i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
+ if (strcmp(inmap, ypaliases[i].alias) == 0)
+ inmap = ypaliases[i].name;
}
ypcb.foreach = printit;
@@ -140,7 +143,7 @@
}
exit(0);
}
-
+
int
printit(instatus, inkey, inkeylen, inval, invallen, indata)
int instatus;
--- ypmatch/Makefile.new 2003-08-28 15:25:40.000000000 -0700
+++ ypmatch/Makefile 1997-10-20 07:54:31.000000000 -0700
@@ -2,6 +2,5 @@
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
PROG= ypmatch
-SRCS+= ../ypcat/ypalias_init.c
.include <bsd.prog.mk>
--- ypmatch/ypmatch.c.new 2003-08-28 15:52:34.000000000 -0700
+++ ypmatch/ypmatch.c 2003-04-12 03:04:01.000000000 -0700
@@ -52,15 +52,21 @@
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
-struct ypalias {
+const struct ypalias {
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" },
};
-struct ypalias *ypaliases;
-
int main __P((int, char *[]));
void usage __P((void));
-extern struct ypalias *ypalias_init __P((void));
int
main(argc, argv)
@@ -69,20 +75,20 @@
{
char *domainname;
char *inkey, *inmap, *outbuf;
- struct ypalias *ypa;
int outbuflen, key, null, notrans;
int c, r, i, len;
int rval;
domainname = NULL;
notrans = key = null = 0;
- ypaliases = ypalias_init();
while ((c = getopt(argc, argv, "xd:ktz")) != -1) {
switch (c) {
case 'x':
- for(ypa = ypaliases; ypa->alias; ypa++)
+ for(i = 0;
+ i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
printf("Use \"%s\" for \"%s\"\n",
- ypa->alias, ypa->name);
+ ypaliases[i].alias,
+ ypaliases[i].name);
exit(0);
case 'd':
@@ -117,9 +123,9 @@
inmap = argv[argc - 1];
if (notrans == 0) {
- for (ypa = ypaliases; ypa->alias; ypa++)
- if (strcmp(inmap, ypa->alias) == 0)
- inmap = ypa->name;
+ for (i = 0 ; i < sizeof(ypaliases)/sizeof(ypaliases[0]); i++)
+ if (strcmp(inmap, ypaliases[i].alias) == 0)
+ inmap = ypaliases[i].name;
}
rval = 0;
--- ypwhich/ypwhich.c.new 2003-08-28 15:52:44.000000000 -0700
+++ ypwhich/ypwhich.c 2003-07-13 03:08:54.000000000 -0700
@@ -77,12 +77,18 @@
* -x: print list of yp map aliases and exit
*/
-struct ypalias {
- char *alias;
- char *name;
+static 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,
};
-struct ypalias *ypaliases;
/*
* prototypes
@@ -93,7 +99,6 @@
struct in_addr *find_server __P((const char *, const char *));
int main __P((int, char *[]));
void usage __P((void));
-extern struct ypalias *ypalias_init __P((void));
/*
* main
@@ -109,7 +114,6 @@
int inhibit = 0, force = 0;
char *targmap = NULL;
int ch, saw_m, lcv;
- struct ypalias *ypa;
struct in_addr *inaddr;
struct hostent *he;
@@ -119,7 +123,6 @@
yp_get_default_domain(&ourdomain);
saw_m = 0;
- ypaliases = ypalias_init();
while ((ch = getopt(argc, argv, "h:d:xtfm")) != -1) {
switch (ch) {
case 'h':
@@ -129,9 +132,9 @@
ourdomain = optarg;
break;
case 'x':
- for (ypa = ypaliases; ypa->alias; ypa++)
+ for (lcv = 0; ypnicknames[lcv]; lcv += 2)
printf("Use \"%s\" for map \"%s\"\n",
- ypa->alias, ypa->name);
+ ypnicknames[lcv], ypnicknames[lcv + 1]);
exit(0);
case 'f':
force = 1;
@@ -281,7 +284,6 @@
struct ypmaplist fakelist, *ypml;
struct ypresp_master yprespmaster;
struct ypreq_nokey ypreqkey;
- struct ypalias *ypa;
/*
* we can either ask the hosts ypbind where it's ypserv is located,
@@ -304,9 +306,9 @@
* now translate nicknames [unless inhibited]
*/
if (map && !inhibit) {
- for (ypa = ypaliases; ypa->alias; ypa++) {
- if (strcmp(map, ypa->alias) == 0) {
- map = ypa->name;
+ for (lcv = 0; ypnicknames[lcv]; lcv += 2) {
+ if (strcmp(map, ypnicknames[lcv]) == 0) {
+ map = ypnicknames[lcv + 1];
break;
}
}
--- ypcat/ypalias_init.c 2003-08-28 15:55:29.000000000 -0700
+++ /dev/null 2003-08-28 09:41:50.000000000 -0700
@@ -1,146 +0,0 @@
-/* $Revision$ */
-
-/*
- * 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.
- */
-
-/* Code contributed by Greywolf <greywolf@starwolf.com>
- * 28 August 2003. All rights released to The NetBSD Foundation.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-__RCSID("$Revision$");
-#endif
-
-#include <sys/errno.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <paths.h>
-
-#ifndef _PATH_YPNICKNAMES
-#define _PATH_YPNICKNAMES "/var/yp/nicknames"
-#endif
-
-extern int errno;
-
-struct ypalias {
- char *alias, *name;
-} 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" },
- {0},
-};
-
-struct ypalias *ypalias_init __P((void));
-
-struct ypalias *
-ypalias_init()
-{
- FILE *fp;
- char *cp;
- struct ypalias *ypa;
- int strsiz = BUFSIZ;
- int maxstrsiz = 0;
- int i, nlines = 0;
-
- if ((fp = fopen("/var/yp/nicknames","r")) == (FILE *) NULL) {
- return &def_ypaliases[0];
- }
-
- if ((ypa = malloc(sizeof *ypa)) == (struct ypalias *) NULL) {
- errx(2, "malloc %d (ypa) failed in ypalias_init: %s",
- sizeof(*ypa), strerror(errno));
- }
-
- if ((ypa->alias = malloc(strsiz)) == (char *) NULL) {
- errx(2, "malloc %d (.alias) failed in ypalias_init: %s",
- strsiz, strerror(errno));
- }
-
- /* find how many */
- while (fgets(ypa->alias, strsiz, fp)) {
- if ((i = strlen(ypa->alias)) > maxstrsiz) {
- maxstrsiz = i + 1;
- }
- nlines++;
- }
-
- rewind(fp);
-
- (void) free(ypa->alias);
- (void) free(ypa);
-
- if ((ypa = calloc(nlines + 1, sizeof(*ypa))) ==
- (struct ypalias *) NULL) {
- errx(2, "calloc failed in ypalias_init: %s",
- strerror(errno));
-
- }
-
- for (i = 0; i < nlines; i++) {
- if (((ypa + i)->alias = malloc(maxstrsiz)) ==
- (char *) NULL) {
- errx(2, "malloc %d failed in ypalias_init: %s",
- maxstrsiz, strerror(errno));
- }
- if (fgets((ypa +i)->alias, maxstrsiz, fp) ==
- (char *) NULL) {
- errx(2, "fgets failed in ypalias_init: %s",
- strerror(errno));
- }
- if (cp = strchr((ypa + i)->alias, '\n')) {
- *cp = 0; /* chop the newline */
- }
- for (cp = (ypa + i)->alias; *cp && !isspace(*cp); cp++) {
- ; /* skip */
- }
- if (*cp == 0) {
- fprintf(stderr, "malformed alias in %s at line %d\n",
- _PATH_YPNICKNAMES, i + 1);
- return &def_ypaliases[0];
- };
- *cp = 0;
- (ypa + i)->name = cp + 1;
- while (isspace(*(ypa + i)->name)) {
- ++(ypa + i)->name;
- }
- }
- (ypa + i)->alias = (ypa + i)->name = (char *) 0;
- (void) fclose(fp);
- return ypa;
-}
--- ypcat/nicknames 2003-08-28 16:05:18.000000000 -0700
+++ /dev/null 2003-08-28 09:41:50.000000000 -0700
@@ -1,9 +0,0 @@
-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
> Release-Note:
> Audit-Trail:
> Unformatted:
X-send-pr-version: 3.95
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic