Subject: Re: yppasswd fix (please review)
To: None <tech-userlevel@netbsd.org>
From: Martin J. Laubach <mjl@emsi.priv.at>
List: tech-userlevel
Date: 12/17/1999 01:27:59
| I've talked to Martin Laubach in the mean time, and he offered me a
| different patch which I prefer to mine. It removes duplicating work that
| 's in libc already, and only does the RPC dance to see if the data was
| fetched via NIS or not.
...which you will find below. It basically lets do libc (getpwent())
do the hard work, and just tries to induce where the data came from.
The Right Thing, of course, would be to create a version of getpwent()
that tells us where it found a user entry. It's quite high on luke's
todo-list (on page 392). In the meantime, this change will probably
do.
mjl
Index: Makefile
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/passwd/Makefile,v
retrieving revision 1.22
diff -a -b -u -r1.22 Makefile
--- Makefile 1999/07/20 09:35:21 1.22
+++ Makefile 1999/09/14 18:47:37
@@ -5,11 +5,10 @@
.include <bsd.crypto.mk>
PROG= passwd
-SRCS= local_passwd.c yp_passwd.c passwd.c getpwent.c
-.PATH: ${.CURDIR}/../../lib/libc/gen
+SRCS= local_passwd.c yp_passwd.c passwd.c
DPADD+= ${LIBRPCSVC} ${LIBCRYPT} ${LIBUTIL}
LDADD+= -lrpcsvc -lcrypt -lutil
-CPPFLAGS+=-I${.CURDIR} -I${.CURDIR}/../../lib/libc/include -DYP
+CPPFLAGS+=-I${.CURDIR} -DYP
LINKS= ${BINDIR}/passwd ${BINDIR}/yppasswd
MLINKS= passwd.1 yppasswd.1
@@ -26,5 +25,5 @@
.include <bsd.prog.mk>
-getpwent.o: getpwent.c
- ${COMPILE.c} -UYP ${.IMPSRC}
+# getpwent.o: getpwent.c
+# ${COMPILE.c} -UYP ${.IMPSRC}
Index: yp_passwd.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/passwd/yp_passwd.c,v
retrieving revision 1.20
diff -a -b -u -r1.20 yp_passwd.c
--- yp_passwd.c 1999/08/16 03:02:46 1.20
+++ yp_passwd.c 1999/09/14 18:47:38
@@ -74,8 +74,7 @@
extern int yflag, yppwd;
static char *getnewpasswd __P((struct passwd *, char **));
-static struct passwd *interpret __P((struct passwd *, char *));
-static struct passwd *ypgetpwnam __P((char *));
+static int ypgetpwnam __P((char *));
static void pw_error __P((char *, int, int));
static void test_local __P((char *));
@@ -155,8 +154,10 @@
if (rpcport >= IPPORT_RESERVED)
errx(1, "yppasswd daemon is on an invalid port.");
- /* Get user's login identity */
- if (!(pw = ypgetpwnam(username))) {
+ /* Bail out if this is a local (non-yp) user, */
+ /* then get user's login identity */
+ if (!ypgetpwnam(username) ||
+ !(pw = getpwnam(username))) {
test_local(username);
errx(1, "unknown user %s", username);
}
@@ -260,66 +261,10 @@
return(strdup(crypt(buf, salt)));
}
-static char *pwskip __P((char *));
-
-static char *
-pwskip(p)
- char *p;
-{
-
- while (*p && *p != ':' && *p != '\n')
- ++p;
- if (*p)
- *p++ = 0;
- return (p);
-}
-
-static struct passwd *
-interpret(pwent, line)
- struct passwd *pwent;
- char *line;
-{
- char *p = line;
-
- pwent->pw_passwd = "*";
- pwent->pw_uid = 0;
- pwent->pw_gid = 0;
- pwent->pw_gecos = "";
- pwent->pw_dir = "";
- pwent->pw_shell = "";
- pwent->pw_change = 0;
- pwent->pw_expire = 0;
- pwent->pw_class = "";
-
- /* line without colon separators is no good, so ignore it */
- if (!strchr(p,':'))
- return (NULL);
-
- pwent->pw_name = p;
- p = pwskip(p);
- pwent->pw_passwd = p;
- p = pwskip(p);
- pwent->pw_uid = (uid_t)strtoul(p, NULL, 10);
- p = pwskip(p);
- pwent->pw_gid = (gid_t)strtoul(p, NULL, 10);
- p = pwskip(p);
- pwent->pw_gecos = p;
- p = pwskip(p);
- pwent->pw_dir = p;
- p = pwskip(p);
- pwent->pw_shell = p;
- while (*p && *p != '\n')
- p++;
- *p = '\0';
- return (pwent);
-}
-
-static struct passwd *
+static int
ypgetpwnam(nam)
char *nam;
{
- static struct passwd pwent;
- static char line[1024];
char *val;
int reason, vallen;
@@ -329,14 +274,10 @@
if (reason != 0) {
if (val != NULL)
free(val);
- return (NULL);
+ return 0;
}
- val[vallen] = '\0';
- (void)strncpy(line, val, sizeof(line) - 1);
- line[sizeof(line) - 1] = '\0';
free(val);
-
- return (interpret(&pwent, line));
+ return 1;
}
#endif /* YP */