* src/chgpasswd.c: Add annotations to indicate that usage() does

not return.
	* src/chgpasswd.c: Split usage in smaller parts. Those parts are
	already translated for chpasswd. Usage is now closer to
	chpasswd's.
	* src/chgpasswd.c: Remove dead code. No need to set crypt_method
	to NULL when it is already NULL. sflg is only set if crypt_method
	is not NULL.
This commit is contained in:
nekral-guest 2011-07-22 23:52:08 +00:00
parent bb67476209
commit 1def4ef49d
2 changed files with 49 additions and 35 deletions

View File

@ -1,3 +1,14 @@
2011-07-23 Nicolas François <nicolas.francois@centraliens.net>
* src/chgpasswd.c: Add annotations to indicate that usage() does
not return.
* src/chgpasswd.c: Split usage in smaller parts. Those parts are
already translated for chpasswd. Usage is now closer to
chpasswd's.
* src/chgpasswd.c: Remove dead code. No need to set crypt_method
to NULL when it is already NULL. sflg is only set if crypt_method
is not NULL.
2011-07-23 Nicolas François <nicolas.francois@centraliens.net> 2011-07-23 Nicolas François <nicolas.francois@centraliens.net>
* src/expiry.c: Remove dead code. * src/expiry.c: Remove dead code.

View File

@ -2,7 +2,7 @@
* Copyright (c) 1990 - 1994, Julianne Frances Haugh * Copyright (c) 1990 - 1994, Julianne Frances Haugh
* Copyright (c) 2006 , Tomasz Kłoczko * Copyright (c) 2006 , Tomasz Kłoczko
* Copyright (c) 2006 , Jonas Meurer * Copyright (c) 2006 , Jonas Meurer
* Copyright (c) 2007 - 2009, Nicolas François * Copyright (c) 2007 - 2011, Nicolas François
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -78,7 +78,7 @@ static bool gr_locked = false;
/* local function prototypes */ /* local function prototypes */
static void fail_exit (int code); static void fail_exit (int code);
static void usage (int status); static /*@noreturn@*/void usage (int status);
static void process_flags (int argc, char **argv); static void process_flags (int argc, char **argv);
static void check_flags (void); static void check_flags (void);
static void check_perms (void); static void check_perms (void);
@ -114,28 +114,34 @@ static void fail_exit (int code)
/* /*
* usage - display usage message and exit * usage - display usage message and exit
*/ */
static void usage (int status) static /*@noreturn@*/void usage (int status)
{ {
(void) fprintf ((E_SUCCESS != status) ? stderr : stdout, FILE *usageout = (E_SUCCESS != status) ? stderr : stdout;
_("Usage: %s [options]\n" (void) fprintf (usageout,
"\n" _("Usage: %s [options]\n"
"Options:\n" "\n"
" -c, --crypt-method the crypt method (one of %s)\n" "Options:\n"),
" -e, --encrypted supplied passwords are encrypted\n" Prog);
" -h, --help display this help message and exit\n" void) fprintf (usageout,
" -m, --md5 encrypt the clear text password using\n" _(" -c, --crypt-method <METHOD> the crypt method (one of %s)\n"),
" the MD5 algorithm\n"
"%s"
"\n"),
Prog,
#ifndef USE_SHA_CRYPT #ifndef USE_SHA_CRYPT
"NONE DES MD5", "" "NONE DES MD5"
#else #else /* USE_SHA_CRYPT */
"NONE DES MD5 SHA256 SHA512", "NONE DES MD5 SHA256 SHA512"
_(" -s, --sha-rounds number of SHA rounds for the SHA*\n" #endif /* USE_SHA_CRYPT */
" crypt algorithms\n") );
#endif (void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout);
); (void) fputs (_(" -h, --help display this help message and exit\n"), usageout);
(void) fputs (_(" -m, --md5 encrypt the clear text password using\n"
" the MD5 algorithm\n"),
usageout);
#ifdef USE_SHA_CRYPT
(void) fputs (_(" -s, --sha-rounds number of SHA rounds for the SHA*\n"
" crypt algorithms\n"),
usageout);
#endif /* USE_SHA_CRYPT */
(void) fputs ("\n", usageout);
exit (status); exit (status);
} }
@ -176,7 +182,7 @@ static void process_flags (int argc, char **argv)
break; break;
case 'h': case 'h':
usage (E_SUCCESS); usage (E_SUCCESS);
break; /*@notreached@*/break;
case 'm': case 'm':
md5flg = true; md5flg = true;
break; break;
@ -193,7 +199,7 @@ static void process_flags (int argc, char **argv)
#endif #endif
default: default:
usage (E_USAGE); usage (E_USAGE);
break; /*@notreached@*/break;
} }
} }
@ -442,21 +448,18 @@ int main (int argc, char **argv)
continue; continue;
} }
newpwd = cp; newpwd = cp;
if (!eflg && if ( (!eflg)
(NULL == crypt_method || && ( (NULL == crypt_method)
0 != strcmp(crypt_method, "NONE"))) { || (0 != strcmp(crypt_method, "NONE")))) {
void *arg = NULL; void *arg = NULL;
if (md5flg) { if (md5flg) {
crypt_method = "MD5"; crypt_method = "MD5";
} else if (crypt_method != NULL) {
#ifdef USE_SHA_CRYPT
if (sflg) {
arg = &sha_rounds;
}
#endif
} else {
crypt_method = NULL;
} }
#ifdef USE_SHA_CRYPT
if (sflg) {
arg = &sha_rounds;
}
#endif
cp = pw_encrypt (newpwd, cp = pw_encrypt (newpwd,
crypt_make_salt(crypt_method, arg)); crypt_make_salt(crypt_method, arg));
} }