Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/passwd Changes to passwd(1) for login.conf. Supporte...



details:   https://anonhg.NetBSD.org/src/rev/4985ae44d806
branches:  trunk
changeset: 480418:4985ae44d806
user:      mjl <mjl%NetBSD.org@localhost>
date:      Wed Jan 12 05:04:41 2000 +0000

description:
Changes to passwd(1) for login.conf. Supported capabilities are
minpasswordlen and passwordtime (expiry time).

diffstat:

 usr.bin/passwd/local_passwd.c |  35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)

diffs (93 lines):

diff -r b8e8433e0349 -r 4985ae44d806 usr.bin/passwd/local_passwd.c
--- a/usr.bin/passwd/local_passwd.c     Wed Jan 12 05:02:10 2000 +0000
+++ b/usr.bin/passwd/local_passwd.c     Wed Jan 12 05:04:41 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: local_passwd.c,v 1.16 1998/07/11 15:55:48 mrg Exp $    */
+/*     $NetBSD: local_passwd.c,v 1.17 2000/01/12 05:04:41 mjl Exp $    */
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "from: @(#)local_passwd.c    8.3 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: local_passwd.c,v 1.16 1998/07/11 15:55:48 mrg Exp $");
+__RCSID("$NetBSD: local_passwd.c,v 1.17 2000/01/12 05:04:41 mjl Exp $");
 #endif
 #endif /* not lint */
 
@@ -55,10 +55,11 @@
 #include <time.h>
 #include <unistd.h>
 #include <util.h>
+#include <login_cap.h>
 
 #include "extern.h"
 
-static char   *getnewpasswd __P((struct passwd *));
+static char   *getnewpasswd __P((struct passwd *, int));
 
 static uid_t uid;
 
@@ -80,13 +81,14 @@
 }
 
 static char *
-getnewpasswd(pw)
+getnewpasswd(pw, min_pw_len)
        struct passwd *pw;
+       int min_pw_len;
 {
        int tries;
        char *p, *t;
        char buf[_PASSWORD_LEN+1], salt[9];
-
+       
        (void)printf("Changing local password for %s.\n", pw->pw_name);
 
        if (uid && pw->pw_passwd[0] &&
@@ -102,6 +104,10 @@
                        (void)printf("Password unchanged.\n");
                        pw_error(NULL, 0, 0);
                }
+               if (min_pw_len > 0 && strlen(p) < min_pw_len) {
+                       (void) printf("Password is too short.\n");
+                       continue;
+               }
                if (strlen(p) <= 5 && ++tries < 2) {
                        (void)printf("Please enter a longer password.\n");
                        continue;
@@ -139,7 +145,10 @@
        struct passwd *pw;
        struct passwd old_pw;
        int pfd, tfd;
-
+       int min_pw_len = 0;
+       int pw_expiry  = 0;
+       login_cap_t *lc;
+       
        if (!(pw = getpwnam(uname))) {
                warnx("unknown user %s", uname);
                return (1);
@@ -155,12 +164,16 @@
        old_pw = *pw;
 
        /*
-        * Get the new password.  Reset passwd change time to zero; when
-        * classes are implemented, go and get the "offset" value for this
-        * class and reset the timer.
+        * Get class restrictions for this user, then get the new password. 
         */
-       pw->pw_passwd = getnewpasswd(pw);
-       pw->pw_change = 0;
+       if((lc = login_getclass(pw->pw_class))) {
+               min_pw_len = (int) login_getcapnum(lc, "minpasswordlen", 0, 0);
+               pw_expiry  = (int) login_getcaptime(lc, "passwordtime", 0, 0);
+               login_close(lc);
+       }
+
+       pw->pw_passwd = getnewpasswd(pw, min_pw_len);
+       pw->pw_change = pw_expiry ? pw_expiry + time(NULL) : 0;
 
        /*
         * Now that the user has given us a new password, let us



Home | Main Index | Thread Index | Old Index