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

Diff for /src/usr.bin/passwd/pwd_check.c between version 1.3 and 1.4

version 1.3, 2000/11/24 21:07:04 version 1.4, 2001/06/18 21:09:23
Line 44 
Line 44 
 #include <paths.h>  #include <paths.h>
 #include <pwd.h>  #include <pwd.h>
 #include <util.h>  #include <util.h>
   #include <login_cap.h>
   
 struct pattern {  struct pattern {
         char *match;          char *match;
Line 80 
Line 81 
 };  };
   
 int  int
 pwd_check(struct passwd *pwd, char *password)  pwd_check(struct passwd *pwd, login_cap_t *lc, char *password)
 {  {
         regex_t rgx;          regex_t rgx;
         int i, res;          int i, res, min_len;
         char    option[LINE_MAX];          char *cp, option[LINE_MAX];
         int pipefds[2];          int pipefds[2];
   
         if (strlen(password) <= 5) {          min_len = (int) login_getcapnum(lc, "minpasswordlen", 6, 6);
           if (min_len > 0 && strlen(password) < min_len) {
                 printf("Please enter a longer password.\n");                  printf("Please enter a longer password.\n");
                 return (0);                  return (0);
         }          }
Line 104 
Line 106 
         }          }
   
         /* Okay, now pass control to an external program */          /* Okay, now pass control to an external program */
         pw_getconf(option, LINE_MAX, pwd->pw_name, "pwdcheck");  
   
         /* Try to find an entry for the group */          /*
         if (*option == 0) {           * Check login.conf, falling back onto the deprecated passwd.conf
                 struct group *grp;           */
                 char grpkey[LINE_MAX];          if ((cp = login_getcapstr(lc, "passwordcheck", NULL, NULL)) != NULL) {
                   strlcpy(option, cp, sizeof(option));
                   free(cp);
           } else {
                   pw_getconf(option, LINE_MAX, pwd->pw_name, "pwdcheck");
   
                 grp = getgrgid(pwd->pw_gid);                  /* Try to find an entry for the group */
                 if (grp != NULL) {                  if (*option == 0) {
                         snprintf(grpkey, LINE_MAX-1, ".%s", grp->gr_name);                          struct group *grp;
                         grpkey[LINE_MAX-1] = 0;                          char grpkey[LINE_MAX];
                         pw_getconf(option, LINE_MAX, grpkey, "pwdcheck");  
                           grp = getgrgid(pwd->pw_gid);
                           if (grp != NULL) {
                                   snprintf(grpkey, LINE_MAX-1, ".%s",
                                       grp->gr_name);
                                   grpkey[LINE_MAX-1] = 0;
                                   pw_getconf(option, LINE_MAX, grpkey,
                                       "pwdcheck");
                           }
                           if (*option == 0)
                                   pw_getconf(option, LINE_MAX, "default",
                                       "pwdcheck");
                 }                  }
                 if (*option == 0)  
                         pw_getconf(option, LINE_MAX, "default", "pwdcheck");  
         }          }
   
         /* If no checker is specified, we accept the password */          /* If no checker is specified, we accept the password */
Line 168 
Line 182 
         return (0);          return (0);
 }  }
   
 int pwd_gettries( struct passwd *pwd ) {  int pwd_gettries( struct passwd *pwd, login_cap_t *lc )
   {
         char option[LINE_MAX];          char option[LINE_MAX];
         char *ep = option;          char *ep = option;
           quad_t ntries;
   
           /*
            * Check login.conf, falling back onto the deprecated passwd.conf
            */
           if ((ntries = login_getcapnum(lc, "passwordtries", -1, -1)) != -1) {
                   if (ntries > INT_MAX || ntries < 0) {
                           fprintf(stderr,
                               "Warning: pwdtries out of range in /etc/login.conf");
                           goto out;
                   }
                   return((int)ntries);
           }
   
         pw_getconf(option, LINE_MAX, pwd->pw_name, "pwdtries");          pw_getconf(option, LINE_MAX, pwd->pw_name, "pwdtries");
   
         /* Try to find an entry for the group */          /* Try to find an entry for the group */
         if (*option == 0) {          if (*option == 0) {
                 struct group *grp;                  struct group *grp;
                 char grpkey[LINE_MAX];                  char grpkey[LINE_MAX];
   
                 grp = getgrgid(pwd->pw_gid);                  grp = getgrgid(pwd->pw_gid);
                 if (grp != NULL) {                  if (grp != NULL) {
                         snprintf(grpkey, LINE_MAX-1, ".%s", grp->gr_name);                          snprintf(grpkey, LINE_MAX-1, ".%s", grp->gr_name);
                         grpkey[LINE_MAX-1] = 0;                          grpkey[LINE_MAX-1] = 0;
                         pw_getconf(option, LINE_MAX, grpkey, "pwdtries");                          pw_getconf(option, LINE_MAX, grpkey, "pwdtries");
                 }                  }
                 if (*option == 0)                  if (*option == 0)
                         pw_getconf(option, LINE_MAX, "default", "pwdtries");                          pw_getconf(option, LINE_MAX, "default", "pwdtries");
         }          }
   
         if (*option == 0)          if (*option == 0)
Line 202 
Line 230 
                 }                  }
                 if ((errno == ERANGE && (lval == LONG_MAX                  if ((errno == ERANGE && (lval == LONG_MAX
                                          || lval == LONG_MIN)) ||                                           || lval == LONG_MIN)) ||
                     (lval > INT_MAX || lval < INT_MIN)) {                      (lval > INT_MAX || lval < 0)) {
                         fprintf(stderr,                          fprintf(stderr,
                                 "Warning: pwdtries out of range in /etc/passwd.conf");                                  "Warning: pwdtries out of range in /etc/passwd.conf");
                         goto out;                          goto out;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4