113
src/chgpasswd.c
113
src/chgpasswd.c
@@ -61,9 +61,9 @@
|
||||
const char *Prog;
|
||||
static bool eflg = false;
|
||||
static bool md5flg = false;
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
static bool sflg = false;
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
|
||||
static /*@null@*//*@observer@*/const char *crypt_method = NULL;
|
||||
#define cflg (NULL != crypt_method)
|
||||
@@ -73,6 +73,9 @@ static long sha_rounds = 5000;
|
||||
#ifdef USE_BCRYPT
|
||||
static long bcrypt_rounds = 13;
|
||||
#endif
|
||||
#ifdef USE_YESCRYPT
|
||||
static long yescrypt_cost = 5;
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
static bool is_shadow_grp;
|
||||
@@ -128,14 +131,15 @@ static /*@noreturn@*/void usage (int status)
|
||||
Prog);
|
||||
(void) fprintf (usageout,
|
||||
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
|
||||
#if !defined(USE_SHA_CRYPT) && !defined(USE_BCRYPT)
|
||||
"NONE DES MD5"
|
||||
#elif defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
"NONE DES MD5 SHA256 SHA512 BCRYPT"
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
"NONE DES MD5 SHA256 SHA512"
|
||||
#else
|
||||
"NONE DES MD5 BCRYPT"
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
" SHA256 SHA512"
|
||||
#endif
|
||||
#if defined(USE_BCRYPT)
|
||||
" BCRYPT"
|
||||
#endif
|
||||
#if defined(USE_YESCRYPT)
|
||||
" YESCRYPT"
|
||||
#endif
|
||||
);
|
||||
(void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout);
|
||||
@@ -144,11 +148,11 @@ static /*@noreturn@*/void usage (int status)
|
||||
" the MD5 algorithm\n"),
|
||||
usageout);
|
||||
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA or BCRYPT\n"
|
||||
" crypt algorithms\n"),
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n"
|
||||
" or YESCRYPT crypt algorithms\n"),
|
||||
usageout);
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
(void) fputs ("\n", usageout);
|
||||
|
||||
exit (status);
|
||||
@@ -162,19 +166,22 @@ static /*@noreturn@*/void usage (int status)
|
||||
static void process_flags (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
int bad_s;
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
static struct option long_options[] = {
|
||||
{"crypt-method", required_argument, NULL, 'c'},
|
||||
{"encrypted", no_argument, NULL, 'e'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"md5", no_argument, NULL, 'm'},
|
||||
{"root", required_argument, NULL, 'R'},
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
{"sha-rounds", required_argument, NULL, 's'},
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
while ((c = getopt_long (argc, argv,
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
"c:ehmR:s:",
|
||||
#else
|
||||
"c:ehmR:",
|
||||
@@ -195,40 +202,36 @@ static void process_flags (int argc, char **argv)
|
||||
break;
|
||||
case 'R': /* no-op, handled in process_root_flag () */
|
||||
break;
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
bad_s = 0;
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
|
||||
&& (0 == getlong(optarg, &sha_rounds)))
|
||||
|| ( (0 == strcmp (crypt_method, "BCRYPT"))
|
||||
&& (0 == getlong(optarg, &sha_rounds)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (( (0 == strcmp (crypt_method, "BCRYPT"))
|
||||
&& (0 == getlong(optarg, &bcrypt_rounds)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
|
||||
&& (0 == getlong(optarg, &yescrypt_cost)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_YESCRYPT */
|
||||
if (bad_s != 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (E_USAGE);
|
||||
}
|
||||
break;
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
if (0 == getlong(optarg, &sha_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (E_USAGE);
|
||||
}
|
||||
break;
|
||||
#elif defined(USE_BCRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
if (0 == getlong(optarg, &bcrypt_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (E_USAGE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
|
||||
default:
|
||||
usage (E_USAGE);
|
||||
@@ -247,7 +250,7 @@ static void process_flags (int argc, char **argv)
|
||||
*/
|
||||
static void check_flags (void)
|
||||
{
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
if (sflg && !cflg) {
|
||||
fprintf (stderr,
|
||||
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||
@@ -271,10 +274,13 @@ static void check_flags (void)
|
||||
#ifdef USE_SHA_CRYPT
|
||||
&& (0 != strcmp (crypt_method, "SHA256"))
|
||||
&& (0 != strcmp (crypt_method, "SHA512"))
|
||||
#endif
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#ifdef USE_BCRYPT
|
||||
&& (0 != strcmp (crypt_method, "BCRYPT"))
|
||||
#endif
|
||||
#endif /* USE_BCRYPT */
|
||||
#ifdef USE_YESCRYPT
|
||||
&& (0 != strcmp (crypt_method, "YESCRYPT"))
|
||||
#endif /* USE_YESCRYPT */
|
||||
) {
|
||||
fprintf (stderr,
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
@@ -497,23 +503,24 @@ int main (int argc, char **argv)
|
||||
if (md5flg) {
|
||||
crypt_method = "MD5";
|
||||
}
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
if (sflg) {
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if ( (0 == strcmp (crypt_method, "SHA256"))
|
||||
|| (0 == strcmp (crypt_method, "SHA512"))) {
|
||||
arg = &sha_rounds;
|
||||
}
|
||||
else if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
arg = &bcrypt_rounds;
|
||||
}
|
||||
}
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
if (sflg) {
|
||||
arg = &sha_rounds;
|
||||
}
|
||||
#elif defined(USE_BCRYPT)
|
||||
if (sflg) {
|
||||
arg = &bcrypt_rounds;
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (0 == strcmp (crypt_method, "YESCRYPT")) {
|
||||
arg = &yescrypt_cost;
|
||||
}
|
||||
#endif /* USE_YESCRYPT */
|
||||
}
|
||||
#endif
|
||||
salt = crypt_make_salt (crypt_method, arg);
|
||||
|
||||
107
src/chpasswd.c
107
src/chpasswd.c
@@ -58,7 +58,7 @@
|
||||
const char *Prog;
|
||||
static bool eflg = false;
|
||||
static bool md5flg = false;
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
static bool sflg = false;
|
||||
#endif
|
||||
|
||||
@@ -70,6 +70,9 @@ static long sha_rounds = 5000;
|
||||
#ifdef USE_BCRYPT
|
||||
static long bcrypt_rounds = 13;
|
||||
#endif
|
||||
#ifdef USE_YESCRYPT
|
||||
static long yescrypt_cost = 5;
|
||||
#endif
|
||||
|
||||
static bool is_shadow_pwd;
|
||||
static bool pw_locked = false;
|
||||
@@ -121,14 +124,15 @@ static /*@noreturn@*/void usage (int status)
|
||||
Prog);
|
||||
(void) fprintf (usageout,
|
||||
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
|
||||
#if !defined(USE_SHA_CRYPT) && !defined(USE_BCRYPT)
|
||||
"NONE DES MD5"
|
||||
#elif defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
"NONE DES MD5 SHA256 SHA512 BCRYPT"
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
"NONE DES MD5 SHA256 SHA512"
|
||||
#else
|
||||
"NONE DES MD5 BCRYPT"
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
" SHA256 SHA512"
|
||||
#endif
|
||||
#if defined(USE_BCRYPT)
|
||||
" BCRYPT"
|
||||
#endif
|
||||
#if defined(USE_YESCRYPT)
|
||||
" YESCRYPT"
|
||||
#endif
|
||||
);
|
||||
(void) fputs (_(" -e, --encrypted supplied passwords are encrypted\n"), usageout);
|
||||
@@ -137,11 +141,11 @@ static /*@noreturn@*/void usage (int status)
|
||||
" the MD5 algorithm\n"),
|
||||
usageout);
|
||||
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA or BCRYPT\n"
|
||||
" crypt algorithms\n"),
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n"
|
||||
" or YESCRYPT crypt algorithms\n"),
|
||||
usageout);
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
(void) fputs ("\n", usageout);
|
||||
|
||||
exit (status);
|
||||
@@ -155,20 +159,23 @@ static /*@noreturn@*/void usage (int status)
|
||||
static void process_flags (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
int bad_s;
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
static struct option long_options[] = {
|
||||
{"crypt-method", required_argument, NULL, 'c'},
|
||||
{"encrypted", no_argument, NULL, 'e'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"md5", no_argument, NULL, 'm'},
|
||||
{"root", required_argument, NULL, 'R'},
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
{"sha-rounds", required_argument, NULL, 's'},
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c = getopt_long (argc, argv,
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
"c:ehmR:s:",
|
||||
#else
|
||||
"c:ehmR:",
|
||||
@@ -189,40 +196,36 @@ static void process_flags (int argc, char **argv)
|
||||
break;
|
||||
case 'R': /* no-op, handled in process_root_flag () */
|
||||
break;
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
bad_s = 0;
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
|
||||
&& (0 == getlong(optarg, &sha_rounds)))
|
||||
|| ( (0 == strcmp (crypt_method, "BCRYPT"))
|
||||
&& (0 == getlong(optarg, &sha_rounds)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (( (0 == strcmp (crypt_method, "BCRYPT"))
|
||||
&& (0 == getlong(optarg, &bcrypt_rounds)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
|
||||
&& (0 == getlong(optarg, &yescrypt_cost)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_YESCRYPT */
|
||||
if (bad_s != 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (E_USAGE);
|
||||
}
|
||||
break;
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
if (0 == getlong(optarg, &sha_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (E_USAGE);
|
||||
}
|
||||
break;
|
||||
#elif defined(USE_BCRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
if (0 == getlong(optarg, &bcrypt_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (E_USAGE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
|
||||
default:
|
||||
usage (E_USAGE);
|
||||
@@ -241,7 +244,7 @@ static void process_flags (int argc, char **argv)
|
||||
*/
|
||||
static void check_flags (void)
|
||||
{
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
if (sflg && !cflg) {
|
||||
fprintf (stderr,
|
||||
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||
@@ -269,6 +272,9 @@ static void check_flags (void)
|
||||
#ifdef USE_BCRYPT
|
||||
&& (0 != strcmp (crypt_method, "BCRYPT"))
|
||||
#endif /* USE_BCRYPT */
|
||||
#ifdef USE_YESCRYPT
|
||||
&& (0 != strcmp (crypt_method, "YESCRYPT"))
|
||||
#endif /* USE_YESCRYPT */
|
||||
) {
|
||||
fprintf (stderr,
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
@@ -530,23 +536,24 @@ int main (int argc, char **argv)
|
||||
if (md5flg) {
|
||||
crypt_method = "MD5";
|
||||
}
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
if (sflg) {
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if ( (0 == strcmp (crypt_method, "SHA256"))
|
||||
|| (0 == strcmp (crypt_method, "SHA512"))) {
|
||||
arg = &sha_rounds;
|
||||
}
|
||||
else if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
arg = &bcrypt_rounds;
|
||||
}
|
||||
}
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
if (sflg) {
|
||||
arg = &sha_rounds;
|
||||
}
|
||||
#elif defined(USE_BCRYPT)
|
||||
if (sflg) {
|
||||
arg = &bcrypt_rounds;
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (0 == strcmp (crypt_method, "YESCRYPT")) {
|
||||
arg = &yescrypt_cost;
|
||||
}
|
||||
#endif /* USE_YESCRYPT */
|
||||
}
|
||||
#endif
|
||||
salt = crypt_make_salt (crypt_method, arg);
|
||||
|
||||
134
src/newusers.c
134
src/newusers.c
@@ -89,6 +89,9 @@ static long sha_rounds = 5000;
|
||||
#ifdef USE_BCRYPT
|
||||
static long bcrypt_rounds = 13;
|
||||
#endif /* USE_BCRYPT */
|
||||
#ifdef USE_YESCRYPT
|
||||
static long yescrypt_cost = 5;
|
||||
#endif /* USE_YESCRYPT */
|
||||
#endif /* !USE_PAM */
|
||||
|
||||
static bool is_shadow;
|
||||
@@ -139,14 +142,15 @@ static void usage (int status)
|
||||
#ifndef USE_PAM
|
||||
(void) fprintf (usageout,
|
||||
_(" -c, --crypt-method METHOD the crypt method (one of %s)\n"),
|
||||
#if !defined(USE_SHA_CRYPT) && !defined(USE_BCRYPT)
|
||||
"NONE DES MD5"
|
||||
#elif defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
"NONE DES MD5 SHA256 SHA512 BCRYPT"
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
"NONE DES MD5 SHA256 SHA512"
|
||||
#else
|
||||
"NONE DES MD5 BCRYPT"
|
||||
"NONE DES MD5"
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
" SHA256 SHA512"
|
||||
#endif
|
||||
#if defined(USE_BCRYPT)
|
||||
" BCRYPT"
|
||||
#endif
|
||||
#if defined(USE_YESCRYPT)
|
||||
" YESCRYPT"
|
||||
#endif
|
||||
);
|
||||
#endif /* !USE_PAM */
|
||||
@@ -154,11 +158,11 @@ static void usage (int status)
|
||||
(void) fputs (_(" -r, --system create system accounts\n"), usageout);
|
||||
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
||||
#ifndef USE_PAM
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA or BCRYPT\n"
|
||||
" crypt algorithms\n"),
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
(void) fputs (_(" -s, --sha-rounds number of rounds for the SHA, BCRYPT\n"
|
||||
" or YESCRYPT crypt algorithms\n"),
|
||||
usageout);
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
#endif /* !USE_PAM */
|
||||
(void) fputs ("\n", usageout);
|
||||
|
||||
@@ -433,25 +437,28 @@ static int update_passwd (struct passwd *pwd, const char *password)
|
||||
void *crypt_arg = NULL;
|
||||
char *cp;
|
||||
if (NULL != crypt_method) {
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if (sflg) {
|
||||
if ( (0 == strcmp (crypt_method, "SHA256"))
|
||||
|| (0 == strcmp (crypt_method, "SHA512"))) {
|
||||
crypt_arg = &sha_rounds;
|
||||
}
|
||||
else if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
}
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (sflg) {
|
||||
if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
crypt_arg = &bcrypt_rounds;
|
||||
}
|
||||
}
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (sflg) {
|
||||
crypt_arg = &sha_rounds;
|
||||
if (0 == strcmp (crypt_method, "YESCRYPT")) {
|
||||
crypt_arg = &yescrypt_cost;
|
||||
}
|
||||
}
|
||||
#elif defined(USE_BCRYPT)
|
||||
if (sflg) {
|
||||
crypt_arg = &bcrypt_rounds;
|
||||
}
|
||||
#endif
|
||||
#endif /* USE_YESCRYPT */
|
||||
}
|
||||
|
||||
if ((NULL != crypt_method) && (0 == strcmp(crypt_method, "NONE"))) {
|
||||
@@ -484,25 +491,28 @@ static int add_passwd (struct passwd *pwd, const char *password)
|
||||
#ifndef USE_PAM
|
||||
void *crypt_arg = NULL;
|
||||
if (NULL != crypt_method) {
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if (sflg) {
|
||||
if ( (0 == strcmp (crypt_method, "SHA256"))
|
||||
|| (0 == strcmp (crypt_method, "SHA512"))) {
|
||||
crypt_arg = &sha_rounds;
|
||||
}
|
||||
else if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
}
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (sflg) {
|
||||
if (0 == strcmp (crypt_method, "BCRYPT")) {
|
||||
crypt_arg = &bcrypt_rounds;
|
||||
}
|
||||
}
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (sflg) {
|
||||
crypt_arg = &sha_rounds;
|
||||
if (0 == strcmp (crypt_method, "YESCRYPT")) {
|
||||
crypt_arg = &yescrypt_cost;
|
||||
}
|
||||
}
|
||||
#elif defined(USE_BCRYPT)
|
||||
if (sflg) {
|
||||
crypt_arg = &bcrypt_rounds;
|
||||
}
|
||||
#endif
|
||||
#endif /* USE_PAM */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -619,6 +629,9 @@ static int add_passwd (struct passwd *pwd, const char *password)
|
||||
static void process_flags (int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
int bad_s;
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
static struct option long_options[] = {
|
||||
{"badnames", no_argument, NULL, 'b'},
|
||||
#ifndef USE_PAM
|
||||
@@ -628,20 +641,20 @@ static void process_flags (int argc, char **argv)
|
||||
{"system", no_argument, NULL, 'r'},
|
||||
{"root", required_argument, NULL, 'R'},
|
||||
#ifndef USE_PAM
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
{"sha-rounds", required_argument, NULL, 's'},
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
#endif /* !USE_PAM */
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c = getopt_long (argc, argv,
|
||||
#ifndef USE_PAM
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
"c:bhrs:",
|
||||
#else /* !USE_SHA_CRYPT && !USE_BCRYPT */
|
||||
#else /* !USE_SHA_CRYPT && !USE_BCRYPT && !USE_YESCRYPT */
|
||||
"c:bhr",
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT */
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
#else /* USE_PAM */
|
||||
"bhr",
|
||||
#endif
|
||||
@@ -664,40 +677,36 @@ static void process_flags (int argc, char **argv)
|
||||
case 'R': /* no-op, handled in process_root_flag () */
|
||||
break;
|
||||
#ifndef USE_PAM
|
||||
#if defined(USE_SHA_CRYPT) && defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
bad_s = 0;
|
||||
#if defined(USE_SHA_CRYPT)
|
||||
if ( ( ((0 == strcmp (crypt_method, "SHA256")) || (0 == strcmp (crypt_method, "SHA512")))
|
||||
&& (0 == getlong(optarg, &sha_rounds)))
|
||||
|| ( (0 == strcmp (crypt_method, "BCRYPT"))
|
||||
&& (0 == getlong(optarg, &sha_rounds)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_SHA_CRYPT */
|
||||
#if defined(USE_BCRYPT)
|
||||
if (( (0 == strcmp (crypt_method, "BCRYPT"))
|
||||
&& (0 == getlong(optarg, &bcrypt_rounds)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_BCRYPT */
|
||||
#if defined(USE_YESCRYPT)
|
||||
if (( (0 == strcmp (crypt_method, "YESCRYPT"))
|
||||
&& (0 == getlong(optarg, &yescrypt_cost)))) {
|
||||
bad_s = 1;
|
||||
}
|
||||
#endif /* USE_YESCRYPT */
|
||||
if (bad_s != 0) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
#elif defined(USE_SHA_CRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
if (0 == getlong(optarg, &sha_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
#elif defined(USE_BCRYPT)
|
||||
case 's':
|
||||
sflg = true;
|
||||
if (0 == getlong(optarg, &bcrypt_rounds)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid numeric argument '%s'\n"),
|
||||
Prog, optarg);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
#endif /* !USE_PAM */
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
@@ -731,14 +740,14 @@ static void process_flags (int argc, char **argv)
|
||||
static void check_flags (void)
|
||||
{
|
||||
#ifndef USE_PAM
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
|
||||
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
|
||||
if (sflg && !cflg) {
|
||||
fprintf (stderr,
|
||||
_("%s: %s flag is only allowed with the %s flag\n"),
|
||||
Prog, "-s", "-c");
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
#endif /* USE_SHA_CRYPT || USE_BCRYPT || USE_YESCRYPT */
|
||||
|
||||
if (cflg) {
|
||||
if ( (0 != strcmp (crypt_method, "DES"))
|
||||
@@ -751,6 +760,9 @@ static void check_flags (void)
|
||||
#ifdef USE_BCRYPT
|
||||
&& (0 != strcmp (crypt_method, "BCRYPT"))
|
||||
#endif /* USE_BCRYPT */
|
||||
#ifdef USE_YESCRYPT
|
||||
&& (0 != strcmp (crypt_method, "YESCRYPT"))
|
||||
#endif /* USE_YESCRYPT */
|
||||
) {
|
||||
fprintf (stderr,
|
||||
_("%s: unsupported crypt method: %s\n"),
|
||||
|
||||
@@ -283,6 +283,9 @@ static int new_password (const struct passwd *pw)
|
||||
#ifdef USE_BCRYPT
|
||||
|| (strcmp (method, "BCRYPT") == 0)
|
||||
#endif /* USE_BCRYPT*/
|
||||
#ifdef USE_YESCRYPT
|
||||
|| (strcmp (method, "YESCRYPT") == 0)
|
||||
#endif /* USE_YESCRYPT*/
|
||||
|
||||
) {
|
||||
pass_max_len = -1;
|
||||
|
||||
Reference in New Issue
Block a user