Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/rpc.yppasswdd As discussed on tech-userlevel on Jun...



details:   https://anonhg.NetBSD.org/src/rev/9c8332ed7f92
branches:  trunk
changeset: 534649:9c8332ed7f92
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Jul 31 14:41:56 2002 +0000

description:
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 05197e527aac -r 9c8332ed7f92 usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c
--- a/usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c   Wed Jul 31 12:57:36 2002 +0000
+++ b/usr.sbin/rpc.yppasswdd/yppasswdd_mkpw.c   Wed Jul 31 14:41:56 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.10 2002/07/31 14:41:56 bouyer 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.10 2002/07/31 14:41:56 bouyer 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