* Provide the crypt method to all the

crypt_make_salt invocations.
* Tag the ENCRYPTMETHOD_SELECT dependent code
  accordingly.
This commit is contained in:
nekral-guest 2007-11-24 00:26:31 +00:00
parent 2e782e3d7d
commit afbf2094a8
2 changed files with 30 additions and 6 deletions

View File

@ -1,3 +1,10 @@
2007-11-24 Nicolas François <nicolas.francois@centraliens.net>
* src/newusers.c: Provide the crypt method to all the
crypt_make_salt invocations.
* src/newusers.c: Tag the ENCRYPTMETHOD_SELECT dependent code
accordingly.
2007-11-24 Nicolas François <nicolas.francois@centraliens.net> 2007-11-24 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/salt.c: Make sure method is not NULL, defaulting to DES. * libmisc/salt.c: Make sure method is not NULL, defaulting to DES.

View File

@ -234,10 +234,10 @@ static int add_user (const char *name, const char *uid, uid_t * nuid, gid_t gid)
static void update_passwd (struct passwd *pwd, const char *passwd) static void update_passwd (struct passwd *pwd, const char *passwd)
{ {
void *arg = NULL; void *crypt_arg = NULL;
if (crypt_method != NULL) { if (crypt_method != NULL) {
if (sflg) if (sflg)
arg = &sha_rounds; crypt_arg = &sha_rounds;
} }
if (crypt_method != NULL && 0 == strcmp(crypt_method, "NONE")) { if (crypt_method != NULL && 0 == strcmp(crypt_method, "NONE")) {
@ -245,7 +245,7 @@ static void update_passwd (struct passwd *pwd, const char *passwd)
} else { } else {
pwd->pw_passwd = pw_encrypt (passwd, pwd->pw_passwd = pw_encrypt (passwd,
crypt_make_salt (crypt_method, crypt_make_salt (crypt_method,
arg)); crypt_arg));
} }
} }
@ -256,6 +256,11 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
{ {
const struct spwd *sp; const struct spwd *sp;
struct spwd spent; struct spwd spent;
void *crypt_arg = NULL;
if (crypt_method != NULL) {
if (sflg)
crypt_arg = &sha_rounds;
}
/* /*
* In the case of regular password files, this is real easy - pwd * In the case of regular password files, this is real easy - pwd
@ -274,7 +279,8 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
if ((sp = spw_locate (pwd->pw_name))) { if ((sp = spw_locate (pwd->pw_name))) {
spent = *sp; spent = *sp;
spent.sp_pwdp = pw_encrypt (passwd, spent.sp_pwdp = pw_encrypt (passwd,
crypt_make_salt (NULL, NULL)); crypt_make_salt (crypt_method,
crypt_arg));
return !spw_update (&spent); return !spw_update (&spent);
} }
@ -294,7 +300,8 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
* shadow password file entry. * shadow password file entry.
*/ */
spent.sp_namp = pwd->pw_name; spent.sp_namp = pwd->pw_name;
spent.sp_pwdp = pw_encrypt (passwd, crypt_make_salt (NULL, NULL)); spent.sp_pwdp = pw_encrypt (passwd,
crypt_make_salt (crypt_method, crypt_arg));
spent.sp_lstchg = time ((time_t *) 0) / SCALE; spent.sp_lstchg = time ((time_t *) 0) / SCALE;
spent.sp_min = getdef_num ("PASS_MIN_DAYS", 0); spent.sp_min = getdef_num ("PASS_MIN_DAYS", 0);
/* 10000 is infinity this week */ /* 10000 is infinity this week */
@ -337,12 +344,20 @@ int main (int argc, char **argv)
static struct option long_options[] = { static struct option long_options[] = {
{"crypt-method", required_argument, NULL, 'c'}, {"crypt-method", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
#ifdef ENCRYPTMETHOD_SELECT
{"sha-rounds", required_argument, NULL, 's'}, {"sha-rounds", required_argument, NULL, 's'},
#endif
{NULL, 0, NULL, '\0'} {NULL, 0, NULL, '\0'}
}; };
while ((c = while ((c =
getopt_long (argc, argv, "c:hs:", long_options, getopt_long (argc, argv,
#ifdef ENCRYPTMETHOD_SELECT
"c:hs:",
#else
"c:h",
#endif
long_options,
&option_index)) != -1) { &option_index)) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
@ -352,6 +367,7 @@ int main (int argc, char **argv)
case 'h': case 'h':
usage (); usage ();
break; break;
#ifdef ENCRYPTMETHOD_SELECT
case 's': case 's':
sflg = 1; sflg = 1;
if (!getlong(optarg, &sha_rounds)) { if (!getlong(optarg, &sha_rounds)) {
@ -361,6 +377,7 @@ int main (int argc, char **argv)
usage (); usage ();
} }
break; break;
#endif
case 0: case 0:
/* long option */ /* long option */
break; break;