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 Pull up revision 1.10 (requested...



details:   https://anonhg.NetBSD.org/src/rev/9d540da812c5
branches:  netbsd-1-6
changeset: 529488:9d540da812c5
user:      tron <tron%NetBSD.org@localhost>
date:      Sun Nov 24 16:07:29 2002 +0000

description:
Pull up revision 1.10 (requested by martti in ticket #741):
As discussed on tech-userlevel on Jun, 10 2002, make changes to not use
getpwnam() to get the user's passwd entry but read it from the passwd file
yppasswdd will later update. This allows a NetBSD machine to be master NIS
server without requiring the NIS accounts to exist (via /etc/master.passwd,
nis or other ways) on the local machine.

diffstat:

 usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c |  50 ++++++++++++++++++++++----------
 1 files changed, 34 insertions(+), 16 deletions(-)

diffs (100 lines):

diff -r ad92949d2f1b -r 9d540da812c5 usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c
--- a/usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c   Sun Nov 24 16:03:15 2002 +0000
+++ b/usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c   Sun Nov 24 16:07:29 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: yppasswdd_mkpw.c,v 1.9 2001/08/18 19:35:32 ad Exp $    */
+/*     $NetBSD: yppasswdd_mkpw.c,v 1.9.2.1 2002/11/24 16:07:29 tron 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 2001/08/18 19:35:32 ad Exp $");
+__RCSID("$NetBSD: yppasswdd_mkpw.c,v 1.9.2.1 2002/11/24 16:07:29 tron Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -68,9 +68,11 @@
 void
 make_passwd(yppasswd *argp, struct svc_req *rqstp, SVCXPRT *transp)
 {
-       struct passwd *pw;
+       struct passwd pw;
        int pfd, tfd;
        char mpwd[MAXPATHLEN];
+       char buf[8192]; /* from libutil */
+       FILE *fpw;
 
 #define REPLY(val)     do { \
                int res = (val); \
@@ -91,12 +93,30 @@
        }
        handling_request = 1;
 
-       pw = getpwnam(argp->newpw.pw_name);
-       if (!pw)
+       (void)strlcpy(mpwd, pw_getprefix(), sizeof(mpwd));
+       (void)strlcat(mpwd, _PATH_MASTERPASSWD, sizeof(mpwd));
+       fpw = fopen(mpwd, "r");
+       if (fpw == NULL) {
+               warnx("%s", mpwd);
                RETURN(1);
-
-       if (*pw->pw_passwd &&
-           strcmp(crypt(argp->oldpass, pw->pw_passwd), pw->pw_passwd) != 0)
+       }
+       for(;;) {
+               if (fgets(buf, sizeof(buf), fpw) == NULL) {
+                       if (feof(fpw))
+                               warnx("%s: %s not found", mpwd,
+                                   argp->newpw.pw_name);
+                       else
+                               warnx("%s: %s", mpwd, strerror(errno));
+                       RETURN(1);
+               }
+               if (pw_scan(buf, &pw, NULL) == 0)
+                       continue;
+               if (strncmp(argp->newpw.pw_name, pw.pw_name, MAXLOGNAME) == 0)
+                       break;
+       }
+       fclose(fpw);
+       if (*pw.pw_passwd &&
+           strcmp(crypt(argp->oldpass, pw.pw_passwd), pw.pw_passwd) != 0)
                RETURN(1);
 
        pw_init();
@@ -105,8 +125,6 @@
                warnx("the passwd file is busy.");
                RETURN(1);
        }
-       (void)strlcpy(mpwd, pw_getprefix(), sizeof(mpwd));
-       (void)strlcat(mpwd, _PATH_MASTERPASSWD, sizeof(mpwd));
        pfd = open(mpwd, O_RDONLY, 0);
        if (pfd < 0) {
                pw_abort();
@@ -120,17 +138,17 @@
         * class and reset the timer.
         */
        if (!nopw) {
-               pw->pw_passwd = argp->newpw.pw_passwd;
-               pw->pw_change = 0;
+               pw.pw_passwd = argp->newpw.pw_passwd;
+               pw.pw_change = 0;
        }
        if (!nogecos)
-               pw->pw_gecos = argp->newpw.pw_gecos;
+               pw.pw_gecos = argp->newpw.pw_gecos;
        if (!noshell)
-               pw->pw_shell = argp->newpw.pw_shell;
+               pw.pw_shell = argp->newpw.pw_shell;
 
-       pw_copy(pfd, tfd, pw, NULL);
+       pw_copy(pfd, tfd, &pw, NULL);
 
-       if (pw_mkdb(pw->pw_name, 0) < 0) {
+       if (pw_mkdb(pw.pw_name, 0) < 0) {
                warnx("pw_mkdb failed");
                pw_abort();
                RETURN(1);



Home | Main Index | Thread Index | Old Index