chpasswd: add IS_CRYPT_METHOD
Use macro IS_CRYPT_METHOD instead of ’strcmp(crypt_method, xx)==0’ to make the code more cleanup
This commit is contained in:
parent
3c1e5fcf16
commit
9cdb5251b6
@ -30,6 +30,8 @@
|
|||||||
#include "exitcodes.h"
|
#include "exitcodes.h"
|
||||||
#include "shadowlog.h"
|
#include "shadowlog.h"
|
||||||
|
|
||||||
|
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global variables
|
* Global variables
|
||||||
*/
|
*/
|
||||||
@ -179,20 +181,20 @@ static void process_flags (int argc, char **argv)
|
|||||||
sflg = true;
|
sflg = true;
|
||||||
bad_s = 0;
|
bad_s = 0;
|
||||||
#if defined(USE_SHA_CRYPT)
|
#if defined(USE_SHA_CRYPT)
|
||||||
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
|
if ((IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512"))
|
||||||
&& (0 == getlong(optarg, &sha_rounds)))) {
|
&& (0 == getlong(optarg, &sha_rounds))) {
|
||||||
bad_s = 1;
|
bad_s = 1;
|
||||||
}
|
}
|
||||||
#endif /* USE_SHA_CRYPT */
|
#endif /* USE_SHA_CRYPT */
|
||||||
#if defined(USE_BCRYPT)
|
#if defined(USE_BCRYPT)
|
||||||
if (( (0 == strcmp (crypt_method, "BCRYPT"))
|
if (IS_CRYPT_METHOD("BCRYPT")
|
||||||
&& (0 == getlong(optarg, &bcrypt_rounds)))) {
|
&& (0 == getlong(optarg, &bcrypt_rounds))) {
|
||||||
bad_s = 1;
|
bad_s = 1;
|
||||||
}
|
}
|
||||||
#endif /* USE_BCRYPT */
|
#endif /* USE_BCRYPT */
|
||||||
#if defined(USE_YESCRYPT)
|
#if defined(USE_YESCRYPT)
|
||||||
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
|
if (IS_CRYPT_METHOD("YESCRYPT")
|
||||||
&& (0 == getlong(optarg, &yescrypt_cost)))) {
|
&& (0 == getlong(optarg, &yescrypt_cost))) {
|
||||||
bad_s = 1;
|
bad_s = 1;
|
||||||
}
|
}
|
||||||
#endif /* USE_YESCRYPT */
|
#endif /* USE_YESCRYPT */
|
||||||
@ -240,18 +242,18 @@ static void check_flags (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cflg) {
|
if (cflg) {
|
||||||
if ( (0 != strcmp (crypt_method, "DES"))
|
if ((!IS_CRYPT_METHOD("DES"))
|
||||||
&& (0 != strcmp (crypt_method, "MD5"))
|
&&(!IS_CRYPT_METHOD("MD5"))
|
||||||
&& (0 != strcmp (crypt_method, "NONE"))
|
&&(!IS_CRYPT_METHOD("NONE"))
|
||||||
#ifdef USE_SHA_CRYPT
|
#ifdef USE_SHA_CRYPT
|
||||||
&& (0 != strcmp (crypt_method, "SHA256"))
|
&&(!IS_CRYPT_METHOD("SHA256"))
|
||||||
&& (0 != strcmp (crypt_method, "SHA512"))
|
&&(!IS_CRYPT_METHOD("SHA512"))
|
||||||
#endif /* USE_SHA_CRYPT */
|
#endif /* USE_SHA_CRYPT */
|
||||||
#ifdef USE_BCRYPT
|
#ifdef USE_BCRYPT
|
||||||
&& (0 != strcmp (crypt_method, "BCRYPT"))
|
&&(!IS_CRYPT_METHOD("BCRYPT"))
|
||||||
#endif /* USE_BCRYPT */
|
#endif /* USE_BCRYPT */
|
||||||
#ifdef USE_YESCRYPT
|
#ifdef USE_YESCRYPT
|
||||||
&& (0 != strcmp (crypt_method, "YESCRYPT"))
|
&&(!IS_CRYPT_METHOD("YESCRYPT"))
|
||||||
#endif /* USE_YESCRYPT */
|
#endif /* USE_YESCRYPT */
|
||||||
) {
|
) {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
@ -396,7 +398,7 @@ static const char *get_salt(void)
|
|||||||
{
|
{
|
||||||
void *arg = NULL;
|
void *arg = NULL;
|
||||||
|
|
||||||
if (eflg || ((NULL != crypt_method) && (0 == strcmp (crypt_method, "NONE")))) {
|
if (eflg || IS_CRYPT_METHOD("NONE")) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,18 +408,17 @@ static const char *get_salt(void)
|
|||||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||||
if (sflg) {
|
if (sflg) {
|
||||||
#if defined(USE_SHA_CRYPT)
|
#if defined(USE_SHA_CRYPT)
|
||||||
if ((0 == strcmp (crypt_method, "SHA256"))
|
if (IS_CRYPT_METHOD("SHA256") || IS_CRYPT_METHOD("SHA512")) {
|
||||||
|| (0 == strcmp (crypt_method, "SHA512"))) {
|
|
||||||
arg = &sha_rounds;
|
arg = &sha_rounds;
|
||||||
}
|
}
|
||||||
#endif /* USE_SHA_CRYPT */
|
#endif /* USE_SHA_CRYPT */
|
||||||
#if defined(USE_BCRYPT)
|
#if defined(USE_BCRYPT)
|
||||||
if (0 == strcmp (crypt_method, "BCRYPT")) {
|
if (IS_CRYPT_METHOD("BCRYPT")) {
|
||||||
arg = &bcrypt_rounds;
|
arg = &bcrypt_rounds;
|
||||||
}
|
}
|
||||||
#endif /* USE_BCRYPT */
|
#endif /* USE_BCRYPT */
|
||||||
#if defined(USE_YESCRYPT)
|
#if defined(USE_YESCRYPT)
|
||||||
if (0 == strcmp (crypt_method, "YESCRYPT")) {
|
if (IS_CRYPT_METHOD("YESCRYPT")) {
|
||||||
arg = &yescrypt_cost;
|
arg = &yescrypt_cost;
|
||||||
}
|
}
|
||||||
#endif /* USE_YESCRYPT */
|
#endif /* USE_YESCRYPT */
|
||||||
|
Loading…
Reference in New Issue
Block a user