]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
chpasswd: fix function problem with -R parameter
authorjuyin <zhuyan34@huawei.com>
Thu, 31 Mar 2022 08:48:52 +0000 (16:48 +0800)
committerSerge Hallyn <serge@hallyn.com>
Mon, 4 Apr 2022 02:07:09 +0000 (21:07 -0500)
Generating salt value depends on /dev/urandom. But after the
function process_root_flag changed the root directory, It does
not exist.

So, generate salt value before changeing the directory.

Fixes: #514
src/chpasswd.c

index 94e923abee43e7f59a87785e87bc8e345db6596f..d0da14c69087accec08bcd1ebc1d3af06578bc22 100644 (file)
@@ -451,10 +451,11 @@ int main (int argc, char **argv)
        (void) bindtextdomain (PACKAGE, LOCALEDIR);
        (void) textdomain (PACKAGE);
 
-       process_root_flag ("-R", argc, argv);
-
        process_flags (argc, argv);
 
+       salt = get_salt();
+       process_root_flag ("-R", argc, argv);
+
 #ifdef USE_PAM
        if (md5flg || eflg || cflg) {
                use_pam = false;
@@ -545,7 +546,6 @@ int main (int argc, char **argv)
                const struct passwd *pw;
                struct passwd newpw;
 
-               salt = get_salt();
                if (salt) {
                        cp = pw_encrypt (newpwd, salt);
                        if (NULL == cp) {