[BACK]Return to local_passwd.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / passwd

Diff for /src/usr.bin/passwd/local_passwd.c between version 1.13 and 1.14

version 1.13, 2000/12/12 02:19:58 version 1.14, 2001/06/18 21:09:23
Line 49 
Line 49 
 #include <ctype.h>  #include <ctype.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <util.h>  #include <util.h>
   #include <login_cap.h>
   
 static uid_t uid;  static uid_t uid;
 extern int pwd_gensalt __P(( char *, int, struct passwd *, char));  extern int pwd_gensalt __P((char *, int, struct passwd *, login_cap_t *, char));
 extern int pwd_check __P((struct passwd *, char *));  extern int pwd_check __P((struct passwd *, login_cap_t *, char *));
 extern int pwd_gettries __P((struct passwd *));  extern int pwd_gettries __P((struct passwd *, login_cap_t *));
   
   char *getnewpasswd __P((struct passwd *, login_cap_t *, int));
   
 int  int
 local_passwd(uname, authenticated)  local_passwd(uname, authenticated)
         char *uname;          char *uname;
         int authenticated;          int authenticated;
 {  {
         struct passwd *pw;          struct passwd *pw;
           login_cap_t *lc;
         int pfd, tfd;          int pfd, tfd;
         char *getnewpasswd();          time_t period;
   
         if (!(pw = getpwnam(uname))) {          if (!(pw = getpwnam(uname))) {
 #ifdef YP  #ifdef YP
Line 72 
Line 76 
                 warnx("unknown user %s.", uname);                  warnx("unknown user %s.", uname);
                 return(1);                  return(1);
         }          }
           if ((lc = login_getclass(pw->pw_class)) == NULL) {
                   warnx("unable to get login class for user %s.", uname);
                   return(1);
           }
   
         uid = authenticated ? pw->pw_uid : getuid();          uid = authenticated ? pw->pw_uid : getuid();
         if (uid && uid != pw->pw_uid) {          if (uid && uid != pw->pw_uid) {
Line 91 
Line 99 
         if (pfd < 0 || fcntl(pfd, F_SETFD, 1) == -1)          if (pfd < 0 || fcntl(pfd, F_SETFD, 1) == -1)
                 pw_error(_PATH_MASTERPASSWD, 1, 1);                  pw_error(_PATH_MASTERPASSWD, 1, 1);
   
         /*          /* Get the new password. */
          * Get the new password.  Reset passwd change time to zero; when          pw->pw_passwd = getnewpasswd(pw, lc, authenticated);
          * classes are implemented, go and get the "offset" value for this  
          * class and reset the timer.  
          */  
         pw->pw_passwd = getnewpasswd(pw, authenticated);  
         pw->pw_change = 0;  
         pw_copy(pfd, tfd, pw);  
   
           /* Reset password change time based on login.conf. */
           period = login_getcaptime(lc, "passwordtime", 0, 0);
           if (period > 0)
                   pw->pw_change = time(NULL) + period;
           else
                   pw->pw_change = 0;
   
           /* Update master.passwd file and build .db version. */
           pw_copy(pfd, tfd, pw);
         if (pw_mkdb(uname) < 0)          if (pw_mkdb(uname) < 0)
                 pw_error((char *)NULL, 0, 1);                  pw_error((char *)NULL, 0, 1);
   
         return(0);          return(0);
 }  }
   
 char *  char *
 getnewpasswd(pw, authenticated)  getnewpasswd(pw, lc, authenticated)
         register struct passwd *pw;          struct passwd *pw;
           login_cap_t *lc;
         int authenticated;          int authenticated;
 {  {
         register char *p;          register char *p;
Line 124 
Line 137 
                 }                  }
         }          }
   
         pwd_tries = pwd_gettries(pw);          pwd_tries = pwd_gettries(pw, lc);
   
         for (buf[0] = '\0', tries = 0;;) {          for (buf[0] = '\0', tries = 0;;) {
                 p = getpass("New password:");                  p = getpass("New password:");
Line 138 
Line 151 
                 }                  }
   
                 if ((tries++ < pwd_tries || pwd_tries == 0)                  if ((tries++ < pwd_tries || pwd_tries == 0)
                     && pwd_check(pw, p) == 0)                      && pwd_check(pw, lc, p) == 0)
                         continue;                          continue;
                 strlcpy(buf, p, sizeof(buf));                  strlcpy(buf, p, sizeof(buf));
                 if (!strcmp(buf, getpass("Retype new password:")))                  if (!strcmp(buf, getpass("Retype new password:")))
                         break;                          break;
                 (void)printf("Mismatch; try again, EOF to quit.\n");                  (void)printf("Mismatch; try again, EOF to quit.\n");
         }          }
         if(!pwd_gensalt(salt, _PASSWORD_LEN, pw, 'l')) {          if (!pwd_gensalt(salt, _PASSWORD_LEN, pw, lc, 'l')) {
                 (void)printf("Couldn't generate salt.\n");                  (void)printf("Couldn't generate salt.\n");
                 pw_error(NULL, 0, 0);                  pw_error(NULL, 0, 0);
         }          }

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14