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

nekral-guest at alioth.debian.org nekral-guest at alioth.debian.org
Sun Jul 27 00:59:42 UTC 2008


Author: nekral-guest
Date: 2008-07-27 00:59:42 +0000 (Sun, 27 Jul 2008)
New Revision: 2216

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/src/groupmems.c
Log:
	* src/groupmems.c: Add functions process_flags() and check_perms()
	from code of main().
	* src/groupmems.c: Harmonize the failure message in case of PAM
	failure with the other programs.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2008-07-27 00:35:04 UTC (rev 2215)
+++ upstream/trunk/ChangeLog	2008-07-27 00:59:42 UTC (rev 2216)
@@ -1,5 +1,12 @@
 2008-07-27  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* src/groupmems.c: Add functions process_flags() and check_perms()
+	from code of main().
+	* src/groupmems.c: Harmonize the failure message in case of PAM
+	failure with the other programs.
+
+2008-07-27  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* src/groupmems.c: Remove isgroup(), which always returns TRUE.
 
 2008-07-27  Nicolas François  <nicolas.francois at centraliens.net>

Modified: upstream/trunk/src/groupmems.c
===================================================================
--- upstream/trunk/src/groupmems.c	2008-07-27 00:35:04 UTC (rev 2215)
+++ upstream/trunk/src/groupmems.c	2008-07-27 00:59:42 UTC (rev 2216)
@@ -69,6 +69,8 @@
 static int exclusive = 0;
 static char *Prog;
 
+static void process_flags (int argc, char **argv);
+static void check_perms (void);
 #define isroot()		(getuid () == 0)
 
 static char *whoami (void)
@@ -106,17 +108,12 @@
 	exit (EXIT_USAGE);
 }
 
-int main (int argc, char **argv) 
+/*
+ * process_flags - perform command line argument setting
+ */
+static void process_flags (int argc, char **argv)
 {
 	int arg;
-	char *name;
-	struct group *grp;
-
-#ifdef USE_PAM
-	pam_handle_t *pamh = NULL;
-	int retval;
-#endif
-
 	int option_index = 0;
 	static struct option long_options[] = {
 		{"add", required_argument, NULL, 'a'},
@@ -127,18 +124,8 @@
 		{NULL, 0, NULL, '\0'}
 	};
 
-	/*
-	 * Get my name so that I can use it to report errors.
-	 */
-	Prog = Basename (argv[0]);
-
-	(void) setlocale (LC_ALL, "");
-	(void) bindtextdomain (PACKAGE, LOCALEDIR);
-	(void) textdomain (PACKAGE);
-
-	while ((arg =
-		getopt_long (argc, argv, "a:d:g:lp", long_options,
-			     &option_index)) != EOF) {
+	while ((arg = getopt_long (argc, argv, "a:d:g:lp", long_options,
+	                           &option_index)) != EOF) {
 		switch (arg) {
 		case 'a':
 			adduser = strdup (optarg);
@@ -175,17 +162,16 @@
 		exit (EXIT_INVALID_USER);
 	}
 
-	if (!isroot () && NULL != thisgroup) {
-		fputs (_("Only root can add members to different groups\n"),
-		       stderr);
-		exit (EXIT_NOT_ROOT);
-	} else if (isroot () && NULL != thisgroup) {
-		name = thisgroup;
-	} else if (NULL == (name = whoami ())) {
-		fputs (_("Not primary owner of current group\n"), stderr);
-		exit (EXIT_NOT_PRIMARY);
-	}
+}
+
+static void check_perms (void)
+{
 #ifdef USE_PAM
+	pam_handle_t *pamh = NULL;
+	int retval;
+#endif
+
+#ifdef USE_PAM
 	retval = PAM_SUCCESS;
 
 	{
@@ -197,7 +183,7 @@
 
 		if (retval == PAM_SUCCESS) {
 			retval = pam_start ("groupmod", pampw->pw_name,
-					    &conv, &pamh);
+			                    &conv, &pamh);
 		}
 	}
 
@@ -216,11 +202,45 @@
 	}
 
 	if (retval != PAM_SUCCESS) {
-		fputs (_("PAM authentication failed for\n"), stderr);
+		fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
 		exit (1);
 	}
+
+	if (retval == PAM_SUCCESS) {
+		(void) pam_end (pamh, PAM_SUCCESS);
+	}
 #endif
+}
 
+int main (int argc, char **argv) 
+{
+	char *name;
+	struct group *grp;
+
+	/*
+	 * Get my name so that I can use it to report errors.
+	 */
+	Prog = Basename (argv[0]);
+
+	(void) setlocale (LC_ALL, "");
+	(void) bindtextdomain (PACKAGE, LOCALEDIR);
+	(void) textdomain (PACKAGE);
+
+	process_flags (argc, argv);
+
+	if (!isroot () && NULL != thisgroup) {
+		fputs (_("Only root can add members to different groups\n"),
+		       stderr);
+		exit (EXIT_NOT_ROOT);
+	} else if (isroot () && NULL != thisgroup) {
+		name = thisgroup;
+	} else if (NULL == (name = whoami ())) {
+		fputs (_("Not primary owner of current group\n"), stderr);
+		exit (EXIT_NOT_PRIMARY);
+	}
+
+	check_perms ();
+
 	if (!gr_lock ()) {
 		fputs (_("Unable to lock group file\n"), stderr);
 		exit (EXIT_GROUP_FILE);
@@ -271,10 +291,5 @@
 
 	gr_unlock ();
 
-#ifdef USE_PAM
-	if (retval == PAM_SUCCESS) {
-		(void) pam_end (pamh, PAM_SUCCESS);
-	}
-#endif				/* USE_PAM */
 	exit (EXIT_SUCCESS);
 }




More information about the Pkg-shadow-commits mailing list