version 1.20, 2004/07/15 17:23:44 |
version 1.21, 2004/11/02 08:03:55 |
|
|
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; |
|
|
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); |
|
|
strlcpy(salt, ":", saltlen); |
strlcpy(salt, ":", saltlen); |
warnx("Unknown option %s.", now); |
warnx("Unknown option %s.", now); |
} |
} |
|
free(oldnext); |
return 1; |
return 1; |
} |
} |
|
|