]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
* Provide the crypt method to all the
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 24 Nov 2007 00:26:31 +0000 (00:26 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Sat, 24 Nov 2007 00:26:31 +0000 (00:26 +0000)
  crypt_make_salt invocations.
* Tag the ENCRYPTMETHOD_SELECT dependent code
  accordingly.

ChangeLog
src/newusers.c

index 7bdbc80db0017bc600dd49ad82455c37e86a5428..fcc896f03c9ec1ae70a057c686ee755a22d2e8bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * libmisc/salt.c: Make sure method is not NULL, defaulting to DES.
index 5bdf567f73cf51ad38e8197e423658695a8cbe63..df82bd0f3fa744af9be7aff61f0e580cf39c4e8c 100644 (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)
 {
-       void *arg = NULL;
+       void *crypt_arg = NULL;
        if (crypt_method != NULL) {
                if (sflg)
-                       arg = &sha_rounds;
+                       crypt_arg = &sha_rounds;
        }
 
        if (crypt_method != NULL && 0 == strcmp(crypt_method, "NONE")) {
@@ -245,7 +245,7 @@ static void update_passwd (struct passwd *pwd, const char *passwd)
        } else {
                pwd->pw_passwd = pw_encrypt (passwd,
                                             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;
        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
@@ -274,7 +279,8 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
        if ((sp = spw_locate (pwd->pw_name))) {
                spent = *sp;
                spent.sp_pwdp = pw_encrypt (passwd,
-                                           crypt_make_salt (NULL, NULL));
+                                           crypt_make_salt (crypt_method,
+                                                            crypt_arg));
                return !spw_update (&spent);
        }
 
@@ -294,7 +300,8 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
         * shadow password file entry.
         */
        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_min = getdef_num ("PASS_MIN_DAYS", 0);
        /* 10000 is infinity this week */
@@ -337,12 +344,20 @@ int main (int argc, char **argv)
                static struct option long_options[] = {
                        {"crypt-method", required_argument, NULL, 'c'},
                        {"help", no_argument, NULL, 'h'},
+#ifdef ENCRYPTMETHOD_SELECT
                        {"sha-rounds", required_argument, NULL, 's'},
+#endif
                        {NULL, 0, NULL, '\0'}
                };
 
                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) {
                        switch (c) {
                        case 'c':
@@ -352,6 +367,7 @@ int main (int argc, char **argv)
                        case 'h':
                                usage ();
                                break;
+#ifdef ENCRYPTMETHOD_SELECT
                        case 's':
                                sflg = 1;
                                if (!getlong(optarg, &sha_rounds)) {
@@ -361,6 +377,7 @@ int main (int argc, char **argv)
                                        usage ();
                                }
                                break;
+#endif
                        case 0:
                                /* long option */
                                break;