[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-sysutils] argp changes for chage.c
From: |
Barry deFreese |
Subject: |
[Bug-sysutils] argp changes for chage.c |
Date: |
Thu, 20 May 2004 20:02:12 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5 |
Hey folks,
OK, I mutilated the hell out of chage.c to add argp functionality. I
still have a few minor problems but I wanted to run it by you guys to
see what you think. I'm still struggling a little with the uses of min,
max, etc when they should exist in the expiry struct??
Also, when trying to build, I get the following error:
make[3]: Entering directory `/src2/bdefreese/sysutils-cvs/sysutils/build/po'
cd ../../po && rm -f sv.gmo && /usr/bin/msgfmt -c --statistics -o sv.gmo
sv.po
sv.po:1459: `msgid' and `msgstr' entries do not both end with '\n'
/usr/bin/msgfmt: found 1 fatal error
make[3]: *** [../../po/sv.gmo] Error 1
make[3]: Leaving directory `/src2/bdefreese/sysutils-cvs/sysutils/build/po'
make[2]: *** [stamp-po] Error 2
make[2]: Leaving directory `/src2/bdefreese/sysutils-cvs/sysutils/build/po'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/src2/bdefreese/sysutils-cvs/sysutils/build'
make: *** [all] Error 2
Thanks guys,
--
Barry deFreese
Debian 3.0r1 "Woody"
GNU/Hurd
Registered Linux "Newbie" #302256 - Hurd H4XX0r wannabe
"Programming today is a race between software engineers striving
to build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots. So far, the Universe is
winning." Rich Cook.
? build
? chage_argp_20040520.diff
? config.rpath
? etc/Makefile.in
? etc/pam.d/Makefile.in
? m4/intmax.m4
? m4/longdouble.m4
? m4/longlong.m4
? m4/nls.m4
? m4/po.m4
? m4/printf-posix.m4
? m4/signed.m4
? m4/size_max.m4
? m4/wchar_t.m4
? m4/wint_t.m4
? m4/xsize.m4
? man/Makefile.in
? man/sv/Makefile.in
? po/Makevars.template
? po/sysutils.pot
Index: po/sv.po
===================================================================
RCS file: /cvsroot/sysutils/sysutils/po/sv.po,v
retrieving revision 1.2
diff -u -p -r1.2 sv.po
--- po/sv.po 20 May 2004 10:13:05 -0000 1.2
+++ po/sv.po 21 May 2004 03:44:29 -0000
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: GNU sysutils 0.1.3\n"
"Report-Msgid-Bugs-To: address@hidden"
-"POT-Creation-Date: 2004-05-20 00:16+0300\n"
+"POT-Creation-Date: 2004-05-20 19:30-0400\n"
"PO-Revision-Date: 2004-05-20 00:02+0300\n"
"Last-Translator: David Weinehall <address@hidden>\n"
"Language-Team: Swedish <address@hidden>\n"
@@ -31,8 +31,8 @@ msgstr ""
"Lägg till ett skal i listan med giltiga inloggningsskal.\n"
"\n"
" -f, --force tillåt icke-existerande skal att läggas till\n"
-" --verbose varna om det angivna skalet redan "
-"finns med i listan\n"
+" --verbose varna om det angivna skalet redan finns med i "
+"listan\n"
#: src/add-shell.c:118 src/remove-shell.c:120
#, c-format
@@ -47,13 +47,11 @@ msgstr ""
msgid "add a shell to the list of valid shells\n"
msgstr "lägga till ett skal till listan med giltiga inloggningsskal\n"
-#: src/add-shell.c:124 src/add-shell.c:177 src/chage.c:156 src/chage.c:176
-#: src/chage.c:196 src/chage.c:224 src/chage.c:244 src/chage.c:272
-#: src/chage.c:310 src/chage.c:346 src/chage.c:367 src/chage.c:377
-#: src/chage.c:390 src/chage.c:422 src/chage.c:457 src/chage.c:476
-#: src/chage.c:496 src/chage.c:515 src/chage.c:535 src/chage.c:554
-#: src/chage.c:574 src/chage.c:593 src/chage.c:613 src/chage.c:632
-#: src/chage.c:652 src/chage.c:671 src/chage.c:753 src/chage.c:763
+#: src/add-shell.c:124 src/add-shell.c:177 src/chage.c:171 src/chage.c:221
+#: src/chage.c:237 src/chage.c:269 src/chage.c:304 src/chage.c:323
+#: src/chage.c:343 src/chage.c:362 src/chage.c:382 src/chage.c:401
+#: src/chage.c:421 src/chage.c:440 src/chage.c:460 src/chage.c:479
+#: src/chage.c:499 src/chage.c:518 src/chage.c:600 src/chage.c:610
#: src/chfn.c:131 src/chfn.c:156 src/chfn.c:173 src/chfn.c:190 src/chfn.c:207
#: src/chfn.c:224 src/chfn.c:259 src/chfn.c:274 src/chfn.c:320 src/chfn.c:366
#: src/chfn.c:394 src/chfn.c:422 src/chfn.c:450 src/chfn.c:478 src/chfn.c:512
@@ -126,10 +124,9 @@ msgstr ""
"%s: för få argument\n"
"Skriv '%s --help' för mer information.\n"
-#: src/add-shell.c:143 src/chage.c:319 src/chfn.c:246 src/chgrpmem.c:414
-#: src/chsh.c:166 src/cppw.c:205 src/lsgroup.c:249 src/lsuser.c:331
-#: src/passwd.c:150 src/remove-shell.c:146 src/rmgroup.c:142 src/rmuser.c:155
-#: src/vipw.c:241
+#: src/add-shell.c:143 src/chfn.c:246 src/chgrpmem.c:414 src/chsh.c:166
+#: src/cppw.c:205 src/lsgroup.c:249 src/lsuser.c:331 src/passwd.c:150
+#: src/remove-shell.c:146 src/rmgroup.c:142 src/rmuser.c:155 src/vipw.c:241
#, c-format
msgid ""
"%s: too many arguments\n"
@@ -148,59 +145,7 @@ msgstr "%s: ogiltigt skal angivet\n"
msgid "%s: warning: `%s' already exists in the list of valid shells\n"
msgstr "%s: varning: `%s' finns redan i listan med giltiga inloggningsskal\n"
-#: src/chage.c:45
-#, c-format
-msgid ""
-"Usage: %s [OPTION]... USERS\n"
-"Change password aging information for the specified users.\n"
-"\n"
-"USERS should be a comma-separated list of users,\n"
-"or the word ALL to change expiry-information for all users.\n"
-"\n"
-" -d, --lstchg the date of when the password was last changed\n"
-" (YYYY-MM-DD); empty == now\n"
-" -m, --min the minimum number of days before the password\n"
-" can be changed\n"
-" -M, --max the maximum number of days before the password\n"
-" must be changed\n"
-" -W, --warn the number of days of before password expiry to "
-"warn\n"
-" -I, --inact the max number of days of inactivity after "
-"password\n"
-" expiry before the account is locked\n"
-" -E, --expire the date of expiration for the account\n"
-" (YYYY-MM-DD); empty == never\n"
-" --verbose warn if the specified users does not exist\n"
-msgstr ""
-"Användning: %s [FLAGGA]... ANVÄNDARE\n"
-"Ändra bäst-före-information om lösenorden för användare.\n"
-"\n"
-"ANVÄNDARE skall vara en kommaseparerad lista av användare\n"
-"eller ordet ALL för att ändra bäst-före information för alla användare.\n"
-"\n"
-" -d, --lstchg det datum då lösenordet senast ändrades\n"
-" (ÅÅÅÅ-MM-DD); tomt == nu\n"
-" -m, --min minimalt antal dagar innan lösenordet får bytas\n"
-" -M, --max maximalt antal dagar innan lösenordet måste bytas\n"
-" -W, --warn antal dagar innan lösenordets bäst-före datum som "
-"en\n"
-" varning skall utfärdas\n"
-" -I, --inact hur många dagar utan aktivitet som tillåts efter\n"
-" bäst-före datumet innan kontot låses\n"
-" -E, --expire kontots bäst-före datum (ÅÅÅÅ-MM-DD); tomt == "
-"aldrig\n"
-" --verbose varna om användarna inte existerar\n"
-
-#: src/chage.c:147 src/chage.c:167 src/chage.c:187 src/chage.c:215
-#: src/chage.c:235 src/chage.c:263 src/chfn.c:148 src/chfn.c:165
-#: src/chfn.c:182 src/chfn.c:199 src/chfn.c:216 src/chsh.c:140
-#: src/mkgroup.c:194 src/mkgroup.c:211 src/mkuser.c:314 src/mkuser.c:334
-#: src/sysutils.c:1177
-#, c-format
-msgid "%s: invalid value supplied to `%s'\n"
-msgstr "%s: felaktigt värde för '%s'\n"
-
-#: src/chage.c:303 src/chgroup.c:210 src/chuser.c:306
+#: src/chage.c:164 src/chgroup.c:210 src/chuser.c:306
#, c-format
msgid ""
"%s: insufficient privileges\n"
@@ -209,48 +154,48 @@ msgstr ""
"%s: otillräcklig behörighet\n"
"Du måste vara användaradministratör för att %s.\n"
-#: src/chage.c:306
+#: src/chage.c:167
msgid "change password aging information"
msgstr "ändra bäst-före information om lösenord"
-#: src/chage.c:340 src/chgroup.c:282 src/chgrpmem.c:436 src/chuser.c:413
+#: src/chage.c:192 src/chgroup.c:282 src/chgrpmem.c:436 src/chuser.c:413
#: src/lsage.c:275 src/lsgroup.c:270 src/lsuser.c:352
#, c-format
msgid "%s: could not find any %s; the %s might be corrupt\n"
msgstr "%s: kan inte hitta några %s; %s kan vara korrupt\n"
-#: src/chage.c:342 src/chage.c:364 src/chgrpmem.c:132 src/chgrpmem.c:240
+#: src/chage.c:194 src/chage.c:218 src/chgrpmem.c:132 src/chgrpmem.c:240
#: src/chuser.c:415 src/chuser.c:474 src/lsage.c:277 src/lsgroup.c:365
#: src/lsgroup.c:379 src/lsgroup.c:408 src/lsuser.c:354
msgid "users"
msgstr "användare"
-#: src/chage.c:342 src/chuser.c:415 src/lsage.c:277 src/lsuser.c:354
+#: src/chage.c:194 src/chuser.c:415 src/lsage.c:277 src/lsuser.c:354
msgid "user database"
msgstr "användardatabasen"
-#: src/chage.c:362
+#: src/chage.c:216
#, c-format
msgid "%s: the specified list of %s contains invalid characters\n"
msgstr "%s: den angivna listan med %s innehåller ogiltiga tecken\n"
-#: src/chage.c:397 src/chgroup.c:323 src/chgrpmem.c:478 src/chuser.c:454
+#: src/chage.c:244 src/chgroup.c:323 src/chgrpmem.c:478 src/chuser.c:454
#: src/lsgroup.c:317 src/lsuser.c:401
#, c-format
msgid "%s: warning: %s `%s' does not exist\n"
msgstr "%s: varning: %s '%s' existerar inte\n"
-#: src/chage.c:399 src/chfn.c:330 src/chsh.c:230 src/chuser.c:456
+#: src/chage.c:246 src/chfn.c:330 src/chsh.c:230 src/chuser.c:456
#: src/lsuser.c:403 src/passwd.c:246
msgid "user"
msgstr "användare"
-#: src/chage.c:412
+#: src/chage.c:259
#, c-format
msgid "%s: multiple users can only be processed in batch-mode\n"
msgstr "%s: multipla användare kan endast behandlas i batch-läge\n"
-#: src/chage.c:440
+#: src/chage.c:287
#, c-format
msgid ""
"Changing aging information for `%s'\n"
@@ -259,13 +204,13 @@ msgstr ""
"Ändrar bäst-före-information för '%s'\n"
"Ange det nya värdet, eller tryck enter för att behålla det gamla värdet\n"
-#: src/chage.c:450
+#: src/chage.c:297
#, c-format
msgid "\tMinimum Password Age [%ld]: "
msgstr "Minsta lösenordsålder [%ld]: "
-#: src/chage.c:468 src/chage.c:507 src/chage.c:546 src/chage.c:585
-#: src/chage.c:624 src/chage.c:663 src/chfn.c:379 src/chfn.c:407
+#: src/chage.c:315 src/chage.c:354 src/chage.c:393 src/chage.c:432
+#: src/chage.c:471 src/chage.c:510 src/chfn.c:379 src/chfn.c:407
#: src/chfn.c:435 src/chfn.c:463 src/chfn.c:491
#, c-format
msgid ""
@@ -277,27 +222,27 @@ msgstr ""
"Inkorrekt indata\n"
"\n"
-#: src/chage.c:489
+#: src/chage.c:336
#, c-format
msgid "\tMaximum Password Age [%ld]: "
msgstr "Högsta lösenordsålder [%ld]: "
-#: src/chage.c:528
+#: src/chage.c:375
#, c-format
msgid "\tLast Password Change (YYYY-MM-DD) [%s]: "
msgstr "Senaste lösenordsändring (ÅÅÅÅ-MM-DD) [%s]: "
-#: src/chage.c:567
+#: src/chage.c:414
#, c-format
msgid "\tPassword Expiration Warning [%ld]: "
msgstr "Lösenordsupphörningsvarning [%ld]: "
-#: src/chage.c:606
+#: src/chage.c:453
#, c-format
msgid "\tPassword Inactive [%ld]: "
msgstr "Lösenord inaktivt [%ld]: "
-#: src/chage.c:645
+#: src/chage.c:492
#, c-format
msgid "\tAccount Expiration Date (YYYY-MM-DD) [%s]: "
msgstr "Kontot upphör (ÅÅÅÅ-MM-DD) [%s]: "
@@ -340,6 +285,13 @@ msgstr " -h, --hphone använda
msgid " -o, --other other information for the user\n"
msgstr " -o, --other övrig information\n"
+#: src/chfn.c:148 src/chfn.c:165 src/chfn.c:182 src/chfn.c:199 src/chfn.c:216
+#: src/chsh.c:140 src/mkgroup.c:194 src/mkgroup.c:211 src/mkuser.c:314
+#: src/mkuser.c:334 src/sysutils.c:1177
+#, c-format
+msgid "%s: invalid value supplied to `%s'\n"
+msgstr "%s: felaktigt värde för '%s'\n"
+
#: src/chfn.c:280 src/chsh.c:197 src/lsage.c:234 src/passwd.c:198
#, c-format
msgid ""
@@ -1682,6 +1634,49 @@ msgstr ""
#, c-format
msgid "%s: failed to edit `%s'; %s\n"
msgstr "%s: misslyckades att ändra '%s'; %s\n"
+
+#~ msgid ""
+#~ "Usage: %s [OPTION]... USERS\n"
+#~ "Change password aging information for the specified users.\n"
+#~ "\n"
+#~ "USERS should be a comma-separated list of users,\n"
+#~ "or the word ALL to change expiry-information for all users.\n"
+#~ "\n"
+#~ " -d, --lstchg the date of when the password was last changed\n"
+#~ " (YYYY-MM-DD); empty == now\n"
+#~ " -m, --min the minimum number of days before the password\n"
+#~ " can be changed\n"
+#~ " -M, --max the maximum number of days before the password\n"
+#~ " must be changed\n"
+#~ " -W, --warn the number of days of before password expiry to "
+#~ "warn\n"
+#~ " -I, --inact the max number of days of inactivity after "
+#~ "password\n"
+#~ " expiry before the account is locked\n"
+#~ " -E, --expire the date of expiration for the account\n"
+#~ " (YYYY-MM-DD); empty == never\n"
+#~ " --verbose warn if the specified users does not exist\n"
+#~ msgstr ""
+#~ "Användning: %s [FLAGGA]... ANVÄNDARE\n"
+#~ "Ändra bäst-före-information om lösenorden för användare.\n"
+#~ "\n"
+#~ "ANVÄNDARE skall vara en kommaseparerad lista av användare\n"
+#~ "eller ordet ALL för att ändra bäst-före information för alla användare.\n"
+#~ "\n"
+#~ " -d, --lstchg det datum då lösenordet senast ändrades\n"
+#~ " (ÅÅÅÅ-MM-DD); tomt == nu\n"
+#~ " -m, --min minimalt antal dagar innan lösenordet får bytas\n"
+#~ " -M, --max maximalt antal dagar innan lösenordet måste "
+#~ "bytas\n"
+#~ " -W, --warn antal dagar innan lösenordets bäst-före datum "
+#~ "som en\n"
+#~ " varning skall utfärdas\n"
+#~ " -I, --inact hur många dagar utan aktivitet som tillåts "
+#~ "efter\n"
+#~ " bäst-före datumet innan kontot låses\n"
+#~ " -E, --expire kontots bäst-före datum (ÅÅÅÅ-MM-DD); tomt == "
+#~ "aldrig\n"
+#~ " --verbose varna om användarna inte existerar\n"
#~ msgid "change passwords in batch"
#~ msgstr "ändra flera lösenord samtidigt"
Index: src/chage.c
===================================================================
RCS file: /cvsroot/sysutils/sysutils/src/chage.c,v
retrieving revision 1.2
diff -u -p -r1.2 chage.c
--- src/chage.c 20 May 2004 10:16:30 -0000 1.2
+++ src/chage.c 21 May 2004 03:44:30 -0000
@@ -26,60 +26,114 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <argp.h>
#include "misc.h"
#include "sysutils.h"
#define PRG_NAME "chage"
+/* Static program flags for argp */
+const char *argp_program_version = "chage (sysutils) 0.1.2";
+const char *argp_program_bug_address = "<address@hidden>";
+static char doc[] = "Change password aging information for the specified
users\n\n"
+ "USERS should be a list of users, seperated by a space "
+ "or the word ALL to change expiry-information for all "
+ "users.\n";
+static char args_doc[] = " USERS";
+
extern int optind;
extern char *optarg;
extern const char *progname;
-/**
- * Show usage information
- */
-static void usage(void)
+/* Program options struct for argp parser */
+static struct argp_option options[] =
{
- fprintf(stdout,
- _("Usage: %s [OPTION]... USERS\n"
- "Change password aging information for the specified "
- "users.\n"
- "\n"
- "USERS should be a comma-separated list of users,\n"
- "or the word ALL to change expiry-information for all "
- "users.\n"
- "\n"
- " -d, --lstchg the date of when the password "
- "was last changed\n"
- " (YYYY-MM-DD); empty == now\n"
- " -m, --min the minimum number of days "
- "before the password\n"
- " can be changed\n"
- " -M, --max the maximum number of days before "
- "the password\n"
- " must be changed\n"
- " -W, --warn the number of days of before "
- "password expiry to warn\n"
- " -I, --inact the max number of days of "
- "inactivity after password\n"
- " expiry before the account is "
- "locked\n"
- " -E, --expire the date of expiration for the "
- "account\n"
- " (YYYY-MM-DD); empty == never\n"
- " --verbose warn if the specified users "
- "does not exist\n"),
- progname);
- usage_help();
+ {"lstchg", 'd', "DATE", 0, "the date of when the password was last
changed "
+ "(YYYY-MM-DD); empty == now"},
+ {"min", 'm', "VALUE", 0, "the minimum number of days before the
password "
+ "can be changed"},
+ {"max", 'M', "VALUE", 0, "the maximum number of days before the
password "
+ "must be changed"},
+ {"warn", 'W', "VALUE", 0, "the number of days to warn before the
password expires"},
+ {"inact", 'I', "VALUE", 0, "the max number of days of inactivity after
password "
+ "expiry before the account is locked"},
+ {"expire", 'E', "DATE", 0, "the date of expiration for the account "
+ "(YYYY-MM-DD); empty == never"},
+ {"verbose", 'v', 0, 0, "Verbose"},
+ {0}
+};
+
+/* Available arguments */
+struct arguments
+{
+ char *args;
+ char *lstchg_date;
+ int min_val;
+ int max_val;
+ int warn_val;
+ int inact_val;
+ char *expire_date;
+ int verbose;
+ int usercount;
+ char **users;
+};
+
+/* parse a single option */
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ struct arguments *arguments = state->input;
+
+ switch (key)
+ {
+ case 'd':
+ arguments->lstchg_date = arg;
+ break;
+ case 'm':
+ arguments->min_val = atoi(arg);
+ break;
+ case 'M':
+ arguments->max_val = atoi(arg);
+ break;
+ case 'W':
+ arguments->warn_val = atoi(arg);
+ break;
+ case 'I':
+ arguments->inact_val = atoi(arg);
+ break;
+ case 'E':
+ arguments->expire_date = arg;
+ break;
+ case 'v':
+ arguments->verbose = 1;
+ break;
+ case ARGP_KEY_INIT:
+ memset(&arguments, -2, sizeof(arguments));
+ arguments->users = (char**) malloc(sizeof(char **));
+ break;
+ case ARGP_KEY_ARGS:
+ argp_usage (state);
+ case ARGP_KEY_ARG:
+ arguments->usercount++;
+ arguments->users = (char **)realloc(arguments->users,
arguments->usercount * sizeof(char *));
+ arguments->users[state->arg_num] = arg;
+ break;
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
}
+/* argp parser */
+static struct argp argp = { options, parse_opt, args_doc, doc };
+
/**
* The program's main-function
*
* @param argc The number of arguments
* @param argv The arguments
- * @return 0 on success, errno on failure
+ * @return 0 on success, errno on failure
*/
int main(int argc, char *argv[])
{
@@ -87,215 +141,22 @@ int main(int argc, char *argv[])
FILE *spwfp = NULL;
struct spwd *sp;
- int empty = 1;
- int changed = 0;
- int verbose = 0;
-
- int optc;
- int opt_index;
-
- int status = 0;
-
char *spwname = NULL;
char *spbname = NULL;
char *username = NULL;
+ int status = 0;
+
char **usrarray = NULL;
- struct expirydata expiry = {
- .lstchg = -2,
- .min = -2,
- .max = -2,
- .warn = -2,
- .inact = -2,
- .expire = -2,
- };
-
- char *lstchg = NULL;
- char *min = NULL;
- char *max = NULL;
- char *warn = NULL;
- char *inact = NULL;
- char *expire = NULL;
-
- struct option const options[] = {
- { AS_LSTCHG, optional_argument, 0, 'd' },
- { AS_MIN, required_argument, 0, 'm' },
- { AS_MAX, required_argument, 0, 'M' },
- { AS_WARN, required_argument, 0, 'W' },
- { AS_INACT, required_argument, 0, 'I' },
- { AS_EXPIRE, optional_argument, 0, 'E' },
- { "verbose", no_argument, 0, 'v' },
- { "help", no_argument, 0, 'h' },
- { "version", no_argument, 0, 'V' },
- { 0, 0, 0, 0 }
- };
+ struct arguments arguments;
- errno = 0;
+ argp_parse (&argp, argc, argv, 0, 0, &arguments);
- /* Initialise support for locales, and set the program-name */
+ /* Initialize support for locales, and set the program-name */
if ((status = init_locales(PRG_NAME)))
goto EXIT;
- /* Parse the command-line options */
- while ((optc = getopt_long(argc, argv, "d::m:M:W:I:E::",
- options, &opt_index)) != -1) {
- switch (optc) {
- case 'm':
- if ((status = is_long(optarg))) {
- fprintf(stderr,
- _("%s: invalid value supplied to "
- "`%s'\n"),
- progname, "-m | --min");
- goto EXIT;
- }
-
- if ((status = string_to_long(optarg,
- (void **)&expiry.min))) {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "string_to_long",
- strerror(errno));
- goto EXIT;
- }
-
- break;
-
- case 'M':
- if ((status = is_long(optarg))) {
- fprintf(stderr,
- _("%s: invalid value supplied to "
- "`%s'\n"),
- progname, "-M | --max");
- goto EXIT;
- }
-
- if ((status = string_to_long(optarg,
- (void **)&expiry.max))) {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "string_to_long",
- strerror(errno));
- goto EXIT;
- }
-
- break;
-
- case 'd':
- if ((status = is_valid_date(optarg))) {
- fprintf(stderr,
- _("%s: invalid value supplied to "
- "`%s'\n"),
- progname, "-d | --lstchg");
- goto EXIT;
- }
-
- if ((status = string_to_date(optarg,
- (void **)&expiry.lstchg)))
{
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "string_to_date",
- strerror(errno));
- goto EXIT;
- } else if (expiry.lstchg == -2) {
- if ((expiry.lstchg = get_current_date()) == -1)
{
- status = errno;
- goto EXIT;
- }
- }
-
- if (!expiry.lstchg)
- expiry.lstchg = -1;
-
- break;
-
- case 'I':
- if ((status = is_long(optarg))) {
- fprintf(stderr,
- _("%s: invalid value supplied to "
- "`%s'\n"),
- progname, "-I | --inact");
- goto EXIT;
- }
-
- if ((status = string_to_long(optarg,
- (void **)&expiry.inact))) {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "string_to_long",
- strerror(errno));
- goto EXIT;
- }
-
- break;
-
- case 'E':
- if ((status = is_valid_date(optarg))) {
- fprintf(stderr,
- _("%s: invalid value supplied to "
- "`%s'\n"),
- progname, "-E | --expire");
- goto EXIT;
- }
-
- if ((status = string_to_date(optarg,
- (void **)&expiry.expire)))
{
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "string_to_date",
- strerror(errno));
- goto EXIT;
- } else if (expiry.expire == -2) {
- if ((expiry.expire = get_current_date()) == -1)
{
- status = errno;
- goto EXIT;
- }
- }
-
- if (!expiry.expire)
- expiry.expire = -1;
-
- break;
-
- case 'W':
- if ((status = is_long(optarg))) {
- fprintf(stderr,
- _("%s: invalid value supplied to "
- "`%s'\n"),
- progname, "-W | --warn");
- goto EXIT;
- }
-
- if ((status = string_to_long(optarg,
- (void **)&expiry.warn))) {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "string_to_long",
- strerror(errno));
- goto EXIT;
- }
-
- break;
-
- case 'v':
- verbose = 1;
- break;
-
- case 'h':
- usage();
- goto EXIT;
-
- case 'V':
- version();
- goto EXIT;
-
- default:
- usage();
- status = EINVAL;
- goto EXIT;
- }
- }
-
/* Make sure the caller has root privileges */
if ((status = is_useradmin())) {
if (status == EPERM) {
@@ -313,15 +174,6 @@ int main(int argc, char *argv[])
goto EXIT;
}
- /* Make sure we get the correct number of arguments */
- if ((argc - optind) > 1) {
- fprintf(stderr,
- _("%s: too many arguments\n"
- "Try `%s --help' for more information.\n"),
- progname, progname);
- status = EINVAL;
- goto EXIT;
- }
/* There are two alternatives here, neither of which are really
* pretty; either to read the entire passwd file once to get
@@ -330,7 +182,7 @@ int main(int argc, char *argv[])
* user-entries. Since the latter is probably the most common,
* the latter has been chosen.
*/
- if (!strcmp(argv[argc - 1], "ALL")) {
+ if (!strcmp(arguments.users[0], "ALL")) {
char *tmp = NULL;
if (!(tmp = get_all_users())) {
@@ -341,49 +193,44 @@ int main(int argc, char *argv[])
"might be corrupt\n"),
progname, _("users"), _("user database"));
status = ENOENT;
- } else if (!(usrarray = strsplit(tmp, ",", 0))) {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "strsplit", strerror(errno));
- status = errno;
}
free(tmp);
if (status)
goto EXIT;
- } else {
+ } else {
char *tmp = NULL;
uid_t i = 0; /* We're scanning <= LASTUID, hence uid_t */
- if ((status = is_valid_namelist(argv[argc - 1]))) {
- if (status == EINVAL) {
- fprintf(stderr,
- _("%s: the specified list of %s "
- "contains invalid characters\n"),
- progname, _("users"));
- } else {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "is_valid_namelist",
- strerror(errno));
- }
-
- goto EXIT;
- }
+ /* FIXME?? There is probably a better way to handle since the userlist
+ * is now in an argp struct but I didn't want to hack the code
+ * up too bad. bdd
+ */
+ int u;
+ for (u = 0; u < arguments.usercount; u++)
+ {
+ if ((status = is_valid_namelist(arguments.users[u]))) {
+ if (status == EINVAL) {
+ fprintf(stderr,
+ _("%s: the specified list of %s
"
+ "contains invalid
characters\n"),
+ progname, _("users"));
+ } else {
+ fprintf(stderr,
+ _("%s: `%s' failed; %s\n"),
+ progname, "is_valid_namelist",
+ strerror(errno));
+ }
- if (!(usrarray = strsplit(argv[argc - 1], ",", 0))) {
- fprintf(stderr,
- _("%s: `%s' failed; %s\n"),
- progname, "strsplit", strerror(errno));
- status = errno;
- goto EXIT;
+ goto EXIT;
+ }
}
/* If verbose mode has been requested,
* warn about all non-existing users
*/
- while (verbose && (tmp = usrarray[i++])) {
+ while (arguments.verbose && (tmp = arguments.users[i++])) {
if (!getpwnam(tmp)) {
if (errno) {
fprintf(stderr,
@@ -403,11 +250,11 @@ int main(int argc, char *argv[])
}
}
- if (optind == 1) {
+ if (argc == 1 && arguments.usercount >1) {
/* If we get multiple usernames, but no options have been
* specified (interactive mode requested) we abort
*/
- if (usrarray[1]) {
+ if (arguments.usercount > 1) {
fprintf(stderr,
_("%s: multiple users can only be processed "
"in batch-mode\n"),
@@ -417,7 +264,7 @@ int main(int argc, char *argv[])
}
/* Get the current expiry-information */
- if (!(sp = getspnam(usrarray[0])) && errno) {
+ if (!(sp = getspnam(arguments.users[0])) && errno) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "getspnam()", strerror(errno));
@@ -425,12 +272,12 @@ int main(int argc, char *argv[])
goto EXIT;
}
- expiry.lstchg = sp->sp_lstchg;
- expiry.min = sp->sp_min;
- expiry.max = sp->sp_max;
- expiry.warn = sp->sp_warn;
- expiry.inact = sp->sp_inact;
- expiry.expire = sp->sp_expire;
+ arguments.lstchg_date = sp->sp_lstchg;
+ arguments.min_val = sp->sp_min;
+ arguments.max_val = sp->sp_max;
+ arguments.warn_val = sp->sp_warn;
+ arguments.inact_val = sp->sp_inact;
+ arguments.expire_date = sp->sp_expire;
/* Note: from this point on we know that username is valid,
* since it existed in the user database, hence we can
@@ -448,10 +295,10 @@ int main(int argc, char *argv[])
while (1) {
fprintf(stdout,
_("\tMinimum Password Age [%ld]: "),
- expiry.min);
+ arguments.min_val);
(void)fflush(stdout);
- if (!(min = input_string(1))) {
+ if (!(arguments.min_val = input_string(1))) {
if (errno) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
@@ -464,14 +311,14 @@ int main(int argc, char *argv[])
}
}
- if (is_long(min)) {
+ if (is_long(arguments.min_val)) {
fprintf(stderr, _("\nInvalid input\n\n"));
free(min);
continue;
}
if ((status = string_to_long(min,
- (void **)&expiry.min))) {
+ (void
**)&arguments.min_val))) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "string_to_long",
@@ -487,7 +334,7 @@ int main(int argc, char *argv[])
while (1) {
fprintf(stdout,
_("\tMaximum Password Age [%ld]: "),
- expiry.max);
+ argument.max_val);
(void)fflush(stdout);
if (!(max = input_string(1))) {
@@ -510,7 +357,7 @@ int main(int argc, char *argv[])
}
if ((status = string_to_long(max,
- (void **)&expiry.max))) {
+ (void
**)&arguments.max_val))) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "string_to_long",
@@ -526,7 +373,7 @@ int main(int argc, char *argv[])
while (1) {
fprintf(stdout,
_("\tLast Password Change (YYYY-MM-DD) [%s]: "),
- date_to_string(expiry.lstchg));
+ date_to_string(arguments.lstchg_date));
(void)fflush(stdout);
if (!(lstchg = input_string(1))) {
@@ -549,7 +396,7 @@ int main(int argc, char *argv[])
}
if ((status = string_to_date(lstchg,
- (void **)&expiry.lstchg)))
{
+ (void
**)&arguments.lstchg_date))) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "string_to_date",
@@ -565,7 +412,7 @@ int main(int argc, char *argv[])
while (1) {
fprintf(stdout,
_("\tPassword Expiration Warning [%ld]: "),
- expiry.warn);
+ arguments.warn_val);
(void)fflush(stdout);
if (!(warn = input_string(1))) {
@@ -588,7 +435,7 @@ int main(int argc, char *argv[])
}
if ((status = string_to_long(warn,
- (void **)&expiry.warn))) {
+ (void
**)&arguments.warn_val))) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "string_to_long",
@@ -604,7 +451,7 @@ int main(int argc, char *argv[])
while (1) {
fprintf(stdout,
_("\tPassword Inactive [%ld]: "),
- expiry.inact);
+ arguments.inact_val);
(void)fflush(stdout);
if (!(inact = input_string(1))) {
@@ -627,7 +474,7 @@ int main(int argc, char *argv[])
}
if ((status = string_to_long(inact,
- (void **)&expiry.inact))) {
+ (void
**)&arguments.inact_val))) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "string_to_long",
@@ -643,7 +490,7 @@ int main(int argc, char *argv[])
while (1) {
fprintf(stdout,
_("\tAccount Expiration Date (YYYY-MM-DD) [%s]:
"),
- date_to_string(expiry.expire));
+ date_to_string(arguments.expire_date));
(void)fflush(stdout);
if (!(expire = input_string(1))) {
@@ -666,7 +513,7 @@ int main(int argc, char *argv[])
}
if ((status = string_to_date(expire,
- (void **)&expiry.expire))) {
+ (void
**)&arguments.expire_date))) {
fprintf(stderr,
_("%s: `%s' failed; %s\n"),
progname, "string_to_date",
@@ -731,18 +578,18 @@ int main(int argc, char *argv[])
/* If the entry is part of the array of users to edit,
* perform changes; if not, copy the old values
*/
- if (is_in_array(usrarray, sp->sp_namp)) {
- sp2.sp_lstchg = (expiry.lstchg != -2) ? expiry.lstchg :
+ if (is_in_array(arguments.users, sp->sp_namp)) {
+ sp2.sp_lstchg = (arguments.lstchg_date != -2) ?
arguments.lstchg_date :
sp->sp_lstchg;
- sp2.sp_min = (expiry.min != -2) ? expiry.min :
+ sp2.sp_min = (arguments.min_val != -2) ?
arguments.min_val :
sp->sp_min;
- sp2.sp_max = (expiry.max != -2) ? expiry.max :
+ sp2.sp_max = (arguments.max_val != -2) ?
arguments.max_val :
sp->sp_max;
- sp2.sp_warn = (expiry.warn != -2) ? expiry.warn :
+ sp2.sp_warn = (arguments.warn_val != -2) ?
arguments.warn_val :
sp->sp_warn;
- sp2.sp_inact = (expiry.inact != -2) ? expiry.inact :
+ sp2.sp_inact = (arguments.inact_val != -2) ?
arguments.inact_val :
sp->sp_inact;
- sp2.sp_expire = (expiry.expire != -2) ? expiry.expire :
+ sp2.sp_expire = (arguments.expire_date != -2) ?
arguments.expire_date :
sp->sp_expire;
changed = 1;
}
- [Bug-sysutils] argp changes for chage.c,
Barry deFreese <=