Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-6]: src/usr.sbin/rpc.yppasswdd Pullup rev 1.12 (requested by 16...



details:   https://anonhg.NetBSD.org/src/rev/a0d7a3ccb6b5
branches:  netbsd-1-6
changeset: 531349:a0d7a3ccb6b5
user:      jmc <jmc%NetBSD.org@localhost>
date:      Thu May 20 03:43:18 2004 +0000

description:
Pullup rev 1.12 (requested by 1694 in ticket #wennmach)

Problem: rpc.yppasswdd didn't work if invoked with the -noshell option.

Reason: In routine make_passwd() in yppasswdd_mkpw.c, fgets() is used
to read master.passwd line-by-line. The lines are then parsed using
pw_scan(), without removing the trailing \n from the line. pw_scan()
fills in the shell name into pw.pw_shell, including the trailing \n.

Subsequently, rpc.yppasswdd calls pw_copy(), which copies master.passwd
to ptmp, updating the entry for pw.pw_name. pw_copy() terminates the
updated entry with an additonal \n, so that there is now an empty line
in ptmp.

Finally, rpc.yppasswdd calls pw_mkdb(3), which exec's /usr/sbin/pwd_mkdb
to install ptmp to master.passwd (and to create the pwd.db and spwd.db
data bases). pwd_mkdb chokes on the empty ptmp line.

Fix: remove the trailing \n from the buffer fgets() returns. As a side
effect, this gets us some additional error checking.

diffstat:

 usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (49 lines):

diff -r 46c88742b09d -r a0d7a3ccb6b5 usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c
--- a/usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c   Fri May 14 06:10:14 2004 +0000
+++ b/usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c   Thu May 20 03:43:18 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: yppasswdd_mkpw.c,v 1.9.2.1 2002/11/24 16:07:29 tron Exp $      */
+/*     $NetBSD: yppasswdd_mkpw.c,v 1.9.2.2 2004/05/20 03:43:18 jmc Exp $       */
 
 /*
  * Copyright (c) 1996 Jason R. Thorpe <thorpej%NetBSD.ORG@localhost>
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: yppasswdd_mkpw.c,v 1.9.2.1 2002/11/24 16:07:29 tron Exp $");
+__RCSID("$NetBSD: yppasswdd_mkpw.c,v 1.9.2.2 2004/05/20 03:43:18 jmc Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -72,6 +72,8 @@
        int pfd, tfd;
        char mpwd[MAXPATHLEN];
        char buf[8192]; /* from libutil */
+       char *p;
+       int lineno;
        FILE *fpw;
 
 #define REPLY(val)     do { \
@@ -100,7 +102,7 @@
                warnx("%s", mpwd);
                RETURN(1);
        }
-       for(;;) {
+       for(lineno = 1; ; lineno++) {
                if (fgets(buf, sizeof(buf), fpw) == NULL) {
                        if (feof(fpw))
                                warnx("%s: %s not found", mpwd,
@@ -109,6 +111,12 @@
                                warnx("%s: %s", mpwd, strerror(errno));
                        RETURN(1);
                }
+               if ((p = strchr(buf, '\n')) == NULL) {
+                       warnx("line %d too long", lineno);
+                       RETURN(1);
+               }
+               /* get rid of trailing \n */
+               *p = '\0';
                if (pw_scan(buf, &pw, NULL) == 0)
                        continue;
                if (strncmp(argp->newpw.pw_name, pw.pw_name, MAXLOGNAME) == 0)



Home | Main Index | Thread Index | Old Index