[Pkg-shadow-commits] r1531 - in upstream/trunk: . src
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Fri Dec 28 11:22:27 UTC 2007
Author: nekral-guest
Date: 2007-12-28 11:22:27 +0000 (Fri, 28 Dec 2007)
New Revision: 1531
Modified:
upstream/trunk/ChangeLog
upstream/trunk/src/groupadd.c
Log:
* process_args renamed process_flags
* Add the options checks in process_flags (group_name, group ID uniqueness)
* Add the parameters' names in the prototypes.
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2007-12-28 10:41:22 UTC (rev 1530)
+++ upstream/trunk/ChangeLog 2007-12-28 11:22:27 UTC (rev 1531)
@@ -14,7 +14,9 @@
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().
+ * src/groupadd.c: Split the processing and checking of options out of
+ main() (process_flags).
+ * src/groupadd.c: Add the parameters' names in the prototypes.
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:41:22 UTC (rev 1530)
+++ upstream/trunk/src/groupadd.c 2007-12-28 11:22:27 UTC (rev 1531)
@@ -78,18 +78,19 @@
/* local function prototypes */
static void usage (void);
-static void new_grent (struct group *);
+static void new_grent (struct group *grent);
#ifdef SHADOWGRP
-static void new_sgent (struct sgrp *);
+static void new_sgent (struct sgrp *sgent);
#endif
static void grp_update (void);
static void find_new_gid (void);
static void check_new_name (void);
static void close_files (void);
static void open_files (void);
-static void fail_exit (int);
+static void fail_exit (int code);
static gid_t get_gid (const char *gidstr);
+static void process_flags (int argc, char **argv);
/*
* usage - display usage message and exit
@@ -326,6 +327,7 @@
sgr_unlock ();
}
#endif
+
#ifdef WITH_AUDIT
if (code != E_SUCCESS) {
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding group",
@@ -353,12 +355,15 @@
}
/*
- * process_args - parse the command line options
+ * process_flags - parse the command line options
*
* It will not return if an error is encountered.
*/
-static void process_args (int argc, char **argv)
+static void process_flags (int argc, char **argv)
{
+ /*
+ * Parse the command line options.
+ */
char *cp;
int option_index = 0;
int c;
@@ -420,6 +425,9 @@
}
}
+ /*
+ * Check the flags consistency
+ */
if (oflg && !gflg) {
usage ();
}
@@ -431,6 +439,43 @@
group_name = argv[optind];
check_new_name ();
+
+ /*
+ * Check if the group already exist.
+ */
+ /* local, no need for xgetgrnam */
+ if (getgrnam (group_name)) {
+ /* The group already exist */
+ if (fflg) {
+ /* OK, no need to do anything */
+ exit (E_SUCCESS);
+ }
+ fprintf (stderr, _("%s: group %s exists\n"), Prog, group_name);
+#ifdef WITH_AUDIT
+ audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
+ "adding group", group_name, -1, 0);
+#endif
+ exit (E_NAME_IN_USE);
+ }
+
+ if (gflg && (getgrgid (group_id) != NULL)) {
+ /* A GID was specified, and a group already exist with that GID
+ * - either we will use this GID anyway (-o)
+ * - either we ignore the specified GID and
+ * we will use another one(-f)
+ * - either it is a failure
+ */
+ if (oflg) {
+ /* Continue with this GID */
+ } else if (fflg) {
+ /* Turn off -g, we can use any GID */
+ gflg = 0;
+ } else {
+ fprintf (stderr, _("%s: GID %u is not unique\n"),
+ Prog, (unsigned int) group_id);
+ fail_exit (E_GID_IN_USE);
+ }
+ }
}
/*
@@ -460,7 +505,7 @@
/*
* Parse the command line options.
*/
- process_args (argc, argv);
+ process_flags (argc, argv);
#ifdef USE_PAM
retval = PAM_SUCCESS;
@@ -503,21 +548,6 @@
#endif
/*
- * Start with a quick check to see if the group exists.
- */
- if (getgrnam (group_name)) { /* local, no need for xgetgrnam */
- if (fflg) {
- exit (E_SUCCESS);
- }
- fprintf (stderr, _("%s: group %s exists\n"), Prog, group_name);
-#ifdef WITH_AUDIT
- audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding group",
- group_name, -1, 0);
-#endif
- exit (E_NAME_IN_USE);
- }
-
- /*
* Do the hard stuff - open the files, create the group entries,
* then close and update the files.
*/
More information about the Pkg-shadow-commits
mailing list