]> granicus.if.org Git - shadow/blobdiff - src/chgpasswd.c
Re-indent.
[shadow] / src / chgpasswd.c
index 40ec53d47b09060d183465786b5c56e51e2100c5..5c4ded6bef13192a70b295a2787d3042622e4dcf 100644 (file)
  * Global variables
  */
 const char *Prog;
-static bool cflg   = false;
 static bool eflg   = false;
 static bool md5flg = false;
 #ifdef USE_SHA_CRYPT
 static bool sflg   = false;
 #endif
 
-static const char *crypt_method = NULL;
+static /*@null@*//*@observer@*/const char *crypt_method = NULL;
+#define cflg (NULL != crypt_method)
 #ifdef USE_SHA_CRYPT
 static long sha_rounds = 5000;
 #endif
@@ -135,6 +135,7 @@ static /*@noreturn@*/void usage (int status)
        (void) fputs (_("  -m, --md5                     encrypt the clear text password using\n"
                        "                                the MD5 algorithm\n"),
                      usageout);
+       (void) fputs (_("  -R, --root CHROOT_DIR         directory to chroot into\n"), usageout);
 #ifdef USE_SHA_CRYPT
        (void) fputs (_("  -s, --sha-rounds              number of SHA rounds for the SHA*\n"
                        "                                crypt algorithms\n"),
@@ -152,13 +153,13 @@ static /*@noreturn@*/void usage (int status)
  */
 static void process_flags (int argc, char **argv)
 {
-       int option_index = 0;
        int c;
        static struct option long_options[] = {
                {"crypt-method", required_argument, NULL, 'c'},
                {"encrypted", no_argument, NULL, 'e'},
                {"help", no_argument, NULL, 'h'},
                {"md5", no_argument, NULL, 'm'},
+               {"root", required_argument, NULL, 'R'},
 #ifdef USE_SHA_CRYPT
                {"sha-rounds", required_argument, NULL, 's'},
 #endif
@@ -167,14 +168,13 @@ static void process_flags (int argc, char **argv)
 
        while ((c = getopt_long (argc, argv,
 #ifdef USE_SHA_CRYPT
-                                "c:ehms:",
+                                "c:ehmR:s:",
 #else
-                                "c:ehm",
+                                "c:ehmR:",
 #endif
-                                long_options, &option_index)) != -1) {
+                                long_options, NULL)) != -1) {
                switch (c) {
                case 'c':
-                       cflg = true;
                        crypt_method = optarg;
                        break;
                case 'e':
@@ -186,6 +186,8 @@ static void process_flags (int argc, char **argv)
                case 'm':
                        md5flg = true;
                        break;
+               case 'R': /* no-op, handled in process_root_flag () */
+                       break;
 #ifdef USE_SHA_CRYPT
                case 's':
                        sflg = true;
@@ -397,6 +399,8 @@ int main (int argc, char **argv)
        (void) bindtextdomain (PACKAGE, LOCALEDIR);
        (void) textdomain (PACKAGE);
 
+       process_root_flag ("-R", argc, argv);
+
        process_flags (argc, argv);
 
        OPENLOG ("chgpasswd");
@@ -450,7 +454,7 @@ int main (int argc, char **argv)
                newpwd = cp;
                if (   (!eflg)
                    && (   (NULL == crypt_method)
-                       || (0 != strcmp(crypt_method, "NONE")))) {
+                       || (0 != strcmp (crypt_method, "NONE")))) {
                        void *arg = NULL;
                        if (md5flg) {
                                crypt_method = "MD5";
@@ -461,7 +465,7 @@ int main (int argc, char **argv)
                        }
 #endif
                        cp = pw_encrypt (newpwd,
-                                        crypt_make_salt(crypt_method, arg));
+                                        crypt_make_salt (crypt_method, arg));
                }
 
                /*
@@ -486,15 +490,15 @@ int main (int argc, char **argv)
                         */
                        sg = sgr_locate (name);
 
-                       if (   (NULL == sp)
-                           && (strcmp (pw->pw_passwd,
+                       if (   (NULL == sg)
+                           && (strcmp (gr->gr_passwd,
                                        SHADOW_PASSWD_STRING) == 0)) {
                                static char *empty = NULL;
                                /* If the password is set to 'x' in
                                 * group, but there are no entries in
                                 * gshadow, create one.
                                 */
-                               newsg.sg_namp   = name;
+                               newsg.sg_name   = name;
                                /* newsg.sg_passwd = NULL; will be set later */
                                newsg.sg_adm    = ∅
                                newsg.sg_mem    = dup_list (gr->gr_mem);
@@ -514,9 +518,10 @@ int main (int argc, char **argv)
                        newsg = *sg;
                        newsg.sg_passwd = cp;
                }
-#endif
                if (   (NULL == sg)
-                   || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) {
+                   || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0))
+#endif
+               {
                        newgr = *gr;
                        newgr.gr_passwd = cp;
                }
@@ -536,9 +541,10 @@ int main (int argc, char **argv)
                                continue;
                        }
                }
-#endif
                if (   (NULL == sg)
-                   || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) {
+                   || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0))
+#endif
+               {
                        if (gr_update (&newgr) == 0) {
                                fprintf (stderr,
                                         _("%s: line %d: failed to prepare the new %s entry '%s'\n"),