[Pkg-shadow-commits] r1587 - in upstream/trunk: . src
nekral-guest at alioth.debian.org
nekral-guest at alioth.debian.org
Tue Jan 1 13:13:47 UTC 2008
Author: nekral-guest
Date: 2008-01-01 13:13:47 +0000 (Tue, 01 Jan 2008)
New Revision: 1587
Modified:
upstream/trunk/ChangeLog
upstream/trunk/src/grpck.c
Log:
Split process_flags(), open_files(), and close_files() out of main(). New
global variables is_shadow, sort_mode, use_system_grp_file, and
use_system_sgr_file.
Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog 2007-12-31 20:16:46 UTC (rev 1586)
+++ upstream/trunk/ChangeLog 2008-01-01 13:13:47 UTC (rev 1587)
@@ -1,3 +1,9 @@
+2008-01-01 Nicolas François <nicolas.francois at centraliens.net>
+
+ * src/grpck.c: Split process_flags(), open_files(), and
+ close_files() out of main(). New global variables is_shadow,
+ sort_mode, use_system_grp_file, and use_system_sgr_file.
+
2007-12-31 Nicolas François <nicolas.francois at centraliens.net>
* man/po/Makefile.in.in: If remove-potcdate.sin does not exist,
Modified: upstream/trunk/src/grpck.c
===================================================================
--- upstream/trunk/src/grpck.c 2007-12-31 20:16:46 UTC (rev 1586)
+++ upstream/trunk/src/grpck.c 2008-01-01 13:13:47 UTC (rev 1587)
@@ -66,11 +66,16 @@
*/
static char *Prog;
static const char *grp_file = GROUP_FILE;
+static int use_system_grp_file = 1;
#ifdef SHADOWGRP
static const char *sgr_file = SGROUP_FILE;
+static int use_system_sgr_file = 1;
+static int is_shadow = 0;
#endif
+/* Options */
static int read_only = 0;
+static int sort_mode = 0;
/* local function prototypes */
static void usage (void);
@@ -106,36 +111,13 @@
}
/*
- * grpck - verify group file integrity
+ * process_flags -
*/
-int main (int argc, char **argv)
+static void process_flags (int argc, char **argv)
{
int arg;
- int errors = 0;
- int changed = 0;
- int i;
- struct commonio_entry *gre, *tgre;
- struct group *grp;
- int sort_mode = 0;
-#ifdef SHADOWGRP
- struct commonio_entry *sge, *tsge;
- struct sgrp *sgr;
- int is_shadow = 0;
-#endif
-
/*
- * Get my name so that I can use it to report errors.
- */
- Prog = Basename (argv[0]);
-
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-
- OPENLOG ("grpck");
-
- /*
* Parse the command line arguments
*/
while ((arg = getopt (argc, argv, "qrs")) != EOF) {
@@ -163,11 +145,13 @@
* Make certain we have the right number of arguments
*/
#ifdef SHADOWGRP
- if (optind != argc && optind + 1 != argc && optind + 2 != argc)
+ if ((argc < optind) || (argc > (optind + 2)))
#else
- if (optind != argc && optind + 1 != argc)
+ if ((argc < optind) || (argc > (optind + 1)))
#endif
+ {
usage ();
+ }
/*
* If there are two left over filenames, use those as the group and
@@ -176,34 +160,42 @@
if (optind != argc) {
grp_file = argv[optind];
gr_name (grp_file);
+ use_system_grp_file = 0;
}
#ifdef SHADOWGRP
- if (optind + 2 == argc) {
+ if ((optind + 2) == argc) {
sgr_file = argv[optind + 1];
sgr_name (sgr_file);
is_shadow = 1;
- } else if (optind == argc)
+ use_system_sgr_file = 0;
+ } else if (optind == argc) {
is_shadow = sgr_file_present ();
+ }
#endif
+}
+static void open_files ()
+{
/*
* Lock the files if we aren't in "read-only" mode
*/
if (!read_only) {
- if (!gr_lock ()) {
+ if (gr_lock () == 0) {
fprintf (stderr, _("%s: cannot lock file %s\n"),
- Prog, grp_file);
- if (optind == argc)
+ Prog, grp_file);
+ if (use_system_grp_file) {
SYSLOG ((LOG_WARN, "cannot lock %s", grp_file));
+ }
closelog ();
exit (E_CANT_LOCK);
}
#ifdef SHADOWGRP
- if (is_shadow && !sgr_lock ()) {
+ if (is_shadow && (sgr_lock () == 0)) {
fprintf (stderr, _("%s: cannot lock file %s\n"),
- Prog, sgr_file);
- if (optind == argc)
+ Prog, sgr_file);
+ if (use_system_sgr_file) {
SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file));
+ }
closelog ();
exit (E_CANT_LOCK);
}
@@ -214,25 +206,92 @@
* Open the files. Use O_RDONLY if we are in read_only mode,
* O_RDWR otherwise.
*/
- if (!gr_open (read_only ? O_RDONLY : O_RDWR)) {
+ if (gr_open (read_only ? O_RDONLY : O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open file %s\n"), Prog,
- grp_file);
- if (optind == argc)
+ grp_file);
+ if (use_system_grp_file) {
SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
+ }
closelog ();
exit (E_CANT_OPEN);
}
#ifdef SHADOWGRP
- if (is_shadow && !sgr_open (read_only ? O_RDONLY : O_RDWR)) {
+ if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_RDWR) == 0)) {
fprintf (stderr, _("%s: cannot open file %s\n"), Prog,
- sgr_file);
- if (optind == argc)
+ sgr_file);
+ if (use_system_sgr_file) {
SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
+ }
closelog ();
exit (E_CANT_OPEN);
}
#endif
+}
+static void close_files (int changed)
+{
+ /*
+ * All done. If there were no change we can just abandon any
+ * changes to the files.
+ */
+ if (changed) {
+ if (gr_close () == 0) {
+ fprintf (stderr, _("%s: cannot update file %s\n"),
+ Prog, grp_file);
+ exit (E_CANT_UPDATE);
+ }
+#ifdef SHADOWGRP
+ if (is_shadow && (sgr_close () == 0)) {
+ fprintf (stderr, _("%s: cannot update file %s\n"),
+ Prog, sgr_file);
+ exit (E_CANT_UPDATE);
+ }
+#endif
+ }
+
+ /*
+ * Don't be anti-social - unlock the files when you're done.
+ */
+#ifdef SHADOWGRP
+ if (is_shadow) {
+ sgr_unlock ();
+ }
+#endif
+ (void) gr_unlock ();
+}
+
+/*
+ * grpck - verify group file integrity
+ */
+int main (int argc, char **argv)
+{
+ int errors = 0;
+ int changed = 0;
+ int i;
+ struct commonio_entry *gre, *tgre;
+ struct group *grp;
+
+#ifdef SHADOWGRP
+ struct commonio_entry *sge, *tsge;
+ struct sgrp *sgr;
+#endif
+
+ /*
+ * Get my name so that I can use it to report errors.
+ */
+ Prog = Basename (argv[0]);
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
+ OPENLOG ("grpck");
+
+ /* Parse the command line arguments */
+ process_flags (argc, argv);
+
+ open_files ();
+
if (sort_mode) {
gr_sort ();
#ifdef SHADOWGRP
@@ -631,35 +690,10 @@
shadow_done:
#endif /* SHADOWGRP */
- /*
- * All done. If there were no change we can just abandon any
- * changes to the files.
- */
- if (changed) {
- write_and_bye:
- if (!gr_close ()) {
- fprintf (stderr, _("%s: cannot update file %s\n"),
- Prog, grp_file);
- exit (E_CANT_UPDATE);
- }
-#ifdef SHADOWGRP
- if (is_shadow && !sgr_close ()) {
- fprintf (stderr, _("%s: cannot update file %s\n"),
- Prog, sgr_file);
- exit (E_CANT_UPDATE);
- }
-#endif
- }
+ write_and_bye:
+ /* Commit the change in the database if needed */
+ close_files (changed);
- /*
- * Don't be anti-social - unlock the files when you're done.
- */
-#ifdef SHADOWGRP
- if (is_shadow)
- sgr_unlock ();
-#endif
- (void) gr_unlock ();
-
nscd_flush_cache ("group");
/*
More information about the Pkg-shadow-commits
mailing list