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

Diff for /src/usr.bin/passwd/Attic/pwd_gensalt.c between version 1.20 and 1.21

version 1.20, 2004/07/15 17:23:44 version 1.21, 2004/11/02 08:03:55
Line 51 
Line 51 
 int  int
 pwd_gensalt(char *salt, int saltlen, login_cap_t *lc, char type)  pwd_gensalt(char *salt, int saltlen, login_cap_t *lc, char type)
 {  {
         char *next, *now;          char *next, *now, *oldnext;
   
         *salt = '\0';          *salt = '\0';
   
         switch (type) {          switch (type) {
         case 'y':          case 'y':
                 next = login_getcapstr(lc, "ypcipher", YPCIPHER_DEF,                  next = login_getcapstr(lc, "ypcipher", NULL, NULL);
                     YPCIPHER_DEF);                  if (next == NULL && (next = strdup(YPCIPHER_DEF)) == NULL) {
                           warn(NULL);
                           return 0;
                   }
                 break;                  break;
         case 'l':          case 'l':
         default:          default:
                 next = login_getcapstr(lc, "localcipher", LOCALCIPHER_DEF,                  next = login_getcapstr(lc, "localcipher", NULL, NULL);
                     LOCALCIPHER_DEF);                  if (next == NULL && (next = strdup(LOCALCIPHER_DEF)) == NULL) {
                           warn(NULL);
                           return 0;
                   }
                 break;                  break;
         }          }
   
           oldnext = next;
         now = strsep(&next, ",");          now = strsep(&next, ",");
         if (!strcmp(now, "old")) {          if (!strcmp(now, "old")) {
                 if (saltlen < 3)                  if (saltlen < 3) {
                           free(oldnext);
                         return 0;                          return 0;
                   }
                 to64(&salt[0], arc4random(), 2);                  to64(&salt[0], arc4random(), 2);
                 salt[2] = '\0';                  salt[2] = '\0';
         } else if (!strcmp(now, "newsalt")) {          } else if (!strcmp(now, "newsalt")) {
                 u_int32_t rounds = atol(next);                  u_int32_t rounds = atol(next);
   
                 if (saltlen < 10)                  if (saltlen < 10) {
                           free(oldnext);
                         return 0;                          return 0;
                   }
                 /* Check rounds, 24 bit is max */                  /* Check rounds, 24 bit is max */
                 if (rounds < 7250)                  if (rounds < 7250)
                         rounds = 7250;                          rounds = 7250;
Line 88 
Line 99 
                 to64(&salt[5], arc4random(), 4);                  to64(&salt[5], arc4random(), 4);
                 salt[9] = '\0';                  salt[9] = '\0';
         } else if (!strcmp(now, "md5")) {          } else if (!strcmp(now, "md5")) {
                 if (saltlen < 13)       /* $1$8salt$\0 */                  if (saltlen < 13) {     /* $1$8salt$\0 */
                           free(oldnext);
                         return 0;                          return 0;
                   }
   
                 strlcpy(salt, "$1$", saltlen);                  strlcpy(salt, "$1$", saltlen);
                 to64(&salt[3], arc4random(), 4);                  to64(&salt[3], arc4random(), 4);
Line 105 
Line 118 
                 strlcpy(salt, ":", saltlen);                  strlcpy(salt, ":", saltlen);
                 warnx("Unknown option %s.", now);                  warnx("Unknown option %s.", now);
         }          }
           free(oldnext);
         return 1;          return 1;
 }  }
   

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21