[Pkg-shadow-commits] r1509 - in upstream/trunk: . src
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Thu Dec 27 21:19:57 UTC 2007
Author: nekral-guest
Date: 2007-12-27 21:19:57 +0000 (Thu, 27 Dec 2007)
New Revision: 1509
Modified:
upstream/trunk/ChangeLog
upstream/trunk/src/gpasswd.c
Log:
Simplify gpasswd's main():
Also split check_flags() out of main().
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2007-12-27 21:04:22 UTC (rev 1508)
+++ upstream/trunk/ChangeLog 2007-12-27 21:19:57 UTC (rev 1509)
@@ -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 at centraliens.net>
Modified: upstream/trunk/src/gpasswd.c
===================================================================
--- upstream/trunk/src/gpasswd.c 2007-12-27 21:04:22 UTC (rev 1508)
+++ upstream/trunk/src/gpasswd.c 2007-12-27 21:19:57 UTC (rev 1509)
@@ -88,6 +88,7 @@
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,9 +266,33 @@
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 ();
+ }
+}
+
+/*
* open_files - lock and open the group databases
*
* It will call exit in case of error.
@@ -677,13 +702,6 @@
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
* can be executed and so many ways to trip up the routines that
@@ -702,14 +720,6 @@
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.
*/
#ifdef SHADOWGRP
More information about the Pkg-shadow-commits
mailing list