]> granicus.if.org Git - shadow/commitdiff
Simplify gpasswd's main():
authornekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 27 Dec 2007 21:19:57 +0000 (21:19 +0000)
committernekral-guest <nekral-guest@5a98b0ae-9ef6-0310-add3-de5d479b70d7>
Thu, 27 Dec 2007 21:19:57 +0000 (21:19 +0000)
Also split check_flags() out of main().

ChangeLog
src/gpasswd.c

index 7c3f03c2e867341caf12bcb4b41da36da29e3841..ac146c9b286cb535ae2b733800f8575ff6c3f7b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,7 +10,7 @@
        update_group(). Split out from main() to simplify this (too) big
        function.
        * src/gpasswd.c: New functions: check_perms(), get_group(),
-       change_passwd(). Split out of main() to simplify main().
+       change_passwd(), check_flags(). Split out of main() to simplify main().
 
 2007-12-27  Nicolas François  <nicolas.francois@centraliens.net>
 
index d8fbb0c7005884b8b1abbedf3ebd4d1ac519bc82..04f6bd5e2b11dc7fa942a3f50ef13a4e0bf867f2 100644 (file)
@@ -88,6 +88,7 @@ static void usage (void);
 static RETSIGTYPE catch_signals (int killed);
 static int check_list (const char *users);
 static void process_flags (int argc, char **argv);
+static void check_flags (int argc, int opt_index);
 static void open_files (void);
 static void close_files (void);
 #ifdef SHADOWGRP
@@ -265,6 +266,30 @@ static void process_flags (int argc, char **argv)
                        usage ();
                }
        }
+
+       /* Get the name of the group that is being affected. */
+       group = argv[optind];
+
+       check_flags (argc, optind);
+}
+
+/*
+ * check_flags - check the validity of options
+ */
+static void check_flags (int argc, int opt_index)
+{
+       /*
+        * Make sure exclusive flags are exclusive
+        */
+       if (aflg + dflg + rflg + Rflg + (Aflg || Mflg) > 1)
+               usage ();
+
+       /*
+        * Make sure one (and only one) group was provided
+        */
+       if ((argc != (opt_index+1)) || (NULL == group)) {
+               usage ();
+       }
 }
 
 /*
@@ -676,13 +701,6 @@ int main (int argc, char **argv)
        /* Parse the options */
        process_flags (argc, argv);
 
-       /*
-        * Make sure exclusive flags are exclusive
-        */
-
-       if (aflg + dflg + rflg + Rflg + (Aflg || Mflg) > 1)
-               usage ();
-
        /*
         * Determine the name of the user that invoked this command. This
         * is really hit or miss because there are so many ways that command
@@ -701,14 +719,6 @@ int main (int argc, char **argv)
        }
        myname = xstrdup (pw->pw_name);
 
-       /*
-        * Get the name of the group that is being affected. The group entry
-        * will be completely replicated so it may be modified later on.
-        */
-
-       if (!(group = argv[optind]))
-               usage ();
-
        /*
         * Replicate the group so it can be modified later on.
         */