]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
chpasswd: add --prefix/-P options
authorJaroslav Jindrak <dzejrou@gmail.com>
Fri, 28 Apr 2023 18:30:18 +0000 (20:30 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 9 Jun 2023 14:22:24 +0000 (16:22 +0200)
src/chpasswd.c

index 3cfd611ebd40a0b8de5ebc75d690da555e2ed1b3..3dec07966cfebf534e3f574d9183823c80ecbb4b 100644 (file)
@@ -54,6 +54,8 @@ static long bcrypt_rounds = 13;
 static long yescrypt_cost = 5;
 #endif
 
+static const char *prefix = "";
+
 static bool is_shadow_pwd;
 static bool pw_locked = false;
 static bool spw_locked = false;
@@ -123,6 +125,7 @@ usage (int status)
                        "                                the MD5 algorithm\n"),
                      usageout);
        (void) fputs (_("  -R, --root CHROOT_DIR         directory to chroot into\n"), usageout);
+       (void) fputs (_("  -P, --prefix PREFIX_DIR       directory prefix\n"), usageout);
 #if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
        (void) fputs (_("  -s, --sha-rounds              number of rounds for the SHA, BCRYPT\n"
                        "                                or YESCRYPT crypt algorithms\n"),
@@ -150,6 +153,7 @@ static void process_flags (int argc, char **argv)
                {"help",         no_argument,       NULL, 'h'},
                {"md5",          no_argument,       NULL, 'm'},
                {"root",         required_argument, NULL, 'R'},
+               {"prefix",       required_argument, NULL, 'P'},
 #if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
                {"sha-rounds",   required_argument, NULL, 's'},
 #endif                         /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
@@ -158,9 +162,9 @@ static void process_flags (int argc, char **argv)
 
        while ((c = getopt_long (argc, argv,
 #if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
-                                "c:ehmR:s:",
+                                "c:ehmR:P:s:",
 #else
-                                "c:ehmR:",
+                                "c:ehmR:P:",
 #endif
                                 long_options, NULL)) != -1) {
                switch (c) {
@@ -178,6 +182,8 @@ static void process_flags (int argc, char **argv)
                        break;
                case 'R': /* no-op, handled in process_root_flag () */
                        break;
+               case 'P': /* no-op, handled in process_prefix_flag () */
+                       break;
 #if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
                case 's':
                        sflg = true;
@@ -462,6 +468,7 @@ int main (int argc, char **argv)
 
        salt = get_salt();
        process_root_flag ("-R", argc, argv);
+       prefix = process_prefix_flag ("-P", argc, argv);
 
 #ifdef USE_PAM
        if (md5flg || eflg || cflg) {