[Pkg-shadow-commits] r1530 - in upstream/trunk: . src

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Fri Dec 28 10:41:22 UTC 2007


Author: nekral-guest
Date: 2007-12-28 10:41:22 +0000 (Fri, 28 Dec 2007)
New Revision: 1530

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/groupadd.c
Log:
Split the processing of options out of main().


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2007-12-28 10:30:39 UTC (rev 1529)
+++ upstream/trunk/ChangeLog	2007-12-28 10:41:22 UTC (rev 1530)
@@ -14,6 +14,7 @@
 	the return code was E_SUCCESS, fail_exit() wouldn't have exited. Fix
 	the scope of #idef WITH_AUDIT.
 	* src/groupadd.c: Avoid implicit brackets.
+	* src/groupadd.c: Split the processing of options out of main().
 
 2007-12-27  Nicolas François  <nicolas.francois at centraliens.net>
 

Modified: upstream/trunk/src/groupadd.c
===================================================================
--- upstream/trunk/src/groupadd.c	2007-12-28 10:30:39 UTC (rev 1529)
+++ upstream/trunk/src/groupadd.c	2007-12-28 10:41:22 UTC (rev 1530)
@@ -353,9 +353,89 @@
 }
 
 /*
+ * process_args - parse the command line options
+ *
+ *	It will not return if an error is encountered.
+ */
+static void process_args (int argc, char **argv)
+{
+	char *cp;
+	int option_index = 0;
+	int c;
+	static struct option long_options[] = {
+		{"force", no_argument, NULL, 'f'},
+		{"gid", required_argument, NULL, 'g'},
+		{"help", no_argument, NULL, 'h'},
+		{"key", required_argument, NULL, 'K'},
+		{"non-unique", required_argument, NULL, 'o'},
+		{NULL, 0, NULL, '\0'}
+	};
+
+	while ((c =
+		getopt_long (argc, argv, "fg:hK:o", long_options,
+			     &option_index)) != -1) {
+		switch (c) {
+		case 'f':
+			/*
+			 * "force" - do nothing, just exit(0), if the
+			 * specified group already exists. With -g, if
+			 * specified gid already exists, choose another
+			 * (unique) gid (turn off -g). Based on the RedHat's
+			 * patch from shadow-utils-970616-9.
+			 */
+			fflg++;
+			break;
+		case 'g':
+			gflg++;
+			group_id = get_gid (optarg);
+			break;
+		case 'h':
+			usage ();
+			break;
+		case 'K':
+			/*
+			 * override login.defs defaults (-K name=value)
+			 * example: -K GID_MIN=100 -K GID_MAX=499
+			 * note: -K GID_MIN=10,GID_MAX=499 doesn't work yet
+			 */
+			cp = strchr (optarg, '=');
+			if (!cp) {
+				fprintf (stderr,
+					 _
+					 ("%s: -K requires KEY=VALUE\n"),
+					 Prog);
+				exit (E_BAD_ARG);
+			}
+			/* terminate name, point to value */
+			*cp++ = '\0';
+			if (putdef_str (optarg, cp) < 0) {
+				exit (E_BAD_ARG);
+			}
+			break;
+		case 'o':
+			oflg++;
+			break;
+		default:
+			usage ();
+		}
+	}
+
+	if (oflg && !gflg) {
+		usage ();
+	}
+
+	if (optind != argc - 1) {
+		usage ();
+	}
+
+	group_name = argv[optind];
+
+	check_new_name ();
+}
+
+/*
  * main - groupadd command
  */
-
 int main (int argc, char **argv)
 {
 #ifdef USE_PAM
@@ -377,83 +457,11 @@
 
 	OPENLOG ("groupadd");
 
-	{
-		/*
-		 * Parse the command line options.
-		 */
-		char *cp;
-		int option_index = 0;
-		int c;
-		static struct option long_options[] = {
-			{"force", no_argument, NULL, 'f'},
-			{"gid", required_argument, NULL, 'g'},
-			{"help", no_argument, NULL, 'h'},
-			{"key", required_argument, NULL, 'K'},
-			{"non-unique", required_argument, NULL, 'o'},
-			{NULL, 0, NULL, '\0'}
-		};
+	/*
+	 * Parse the command line options.
+	 */
+	process_args (argc, argv);
 
-		while ((c =
-			getopt_long (argc, argv, "fg:hK:o", long_options,
-				     &option_index)) != -1) {
-			switch (c) {
-			case 'f':
-				/*
-				 * "force" - do nothing, just exit(0), if the
-				 * specified group already exists. With -g, if
-				 * specified gid already exists, choose another
-				 * (unique) gid (turn off -g). Based on the RedHat's
-				 * patch from shadow-utils-970616-9.
-				 */
-				fflg++;
-				break;
-			case 'g':
-				gflg++;
-				group_id = get_gid (optarg);
-				break;
-			case 'h':
-				usage ();
-				break;
-			case 'K':
-				/*
-				 * override login.defs defaults (-K name=value)
-				 * example: -K GID_MIN=100 -K GID_MAX=499
-				 * note: -K GID_MIN=10,GID_MAX=499 doesn't work yet
-				 */
-				cp = strchr (optarg, '=');
-				if (!cp) {
-					fprintf (stderr,
-						 _
-						 ("%s: -K requires KEY=VALUE\n"),
-						 Prog);
-					exit (E_BAD_ARG);
-				}
-				/* terminate name, point to value */
-				*cp++ = '\0';
-				if (putdef_str (optarg, cp) < 0) {
-					exit (E_BAD_ARG);
-				}
-				break;
-			case 'o':
-				oflg++;
-				break;
-			default:
-				usage ();
-			}
-		}
-	}
-
-	if (oflg && !gflg) {
-		usage ();
-	}
-
-	if (optind != argc - 1) {
-		usage ();
-	}
-
-	group_name = argv[argc - 1];
-	check_new_name ();
-
 #ifdef USE_PAM
 	retval = PAM_SUCCESS;
 




More information about the Pkg-shadow-commits mailing list