doveadm-pw.c (dovecot-2.3.16) | : | doveadm-pw.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
#include <ctype.h> | #include <ctype.h> | |||
#include <fcntl.h> | #include <fcntl.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#define DEFAULT_SCHEME "CRYPT" | #define DEFAULT_SCHEME "CRYPT" | |||
static struct module *modules = NULL; | static struct module *modules = NULL; | |||
static void cmd_pw(int argc, char *argv[]) | static void cmd_pw(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
const char *hash = NULL; | const char *hash = NULL; | |||
const char *scheme = NULL; | const char *scheme = NULL; | |||
const char *plaintext = NULL; | const char *plaintext = NULL; | |||
const char *test_hash = NULL; | const char *test_hash = NULL; | |||
bool list_schemes = FALSE, reverse_verify = FALSE; | bool list_schemes = FALSE, reverse_verify = FALSE; | |||
int c; | int64_t rounds_int64; | |||
struct module_dir_load_settings mod_set; | struct module_dir_load_settings mod_set; | |||
struct password_generate_params gen_params; | struct password_generate_params gen_params; | |||
i_zero(&gen_params); | i_zero(&gen_params); | |||
password_schemes_init(); | password_schemes_init(); | |||
i_zero(&mod_set); | i_zero(&mod_set); | |||
mod_set.abi_version = DOVECOT_ABI_VERSION; | mod_set.abi_version = DOVECOT_ABI_VERSION; | |||
mod_set.require_init_funcs = TRUE; | mod_set.require_init_funcs = TRUE; | |||
mod_set.ignore_dlopen_errors = TRUE; | mod_set.ignore_dlopen_errors = TRUE; | |||
mod_set.debug = doveadm_debug; | mod_set.debug = doveadm_debug; | |||
modules = module_dir_load_missing(modules, AUTH_MODULE_DIR, NULL, &mod_se t); | modules = module_dir_load_missing(modules, AUTH_MODULE_DIR, NULL, &mod_se t); | |||
module_dir_init(modules); | module_dir_init(modules); | |||
while ((c = getopt(argc, argv, "lp:r:s:t:u:V")) > 0) { | (void)doveadm_cmd_param_bool(cctx, "list", &list_schemes); | |||
switch (c) { | (void)doveadm_cmd_param_str(cctx, "plaintext", &plaintext); | |||
case 'l': | if (doveadm_cmd_param_int64(cctx, "rounds", &rounds_int64)) { | |||
list_schemes = 1; | if (rounds_int64 > UINT_MAX) | |||
break; | i_fatal("Invalid number of rounds: %"PRId64, rounds_int64 | |||
case 'p': | ); | |||
plaintext = optarg; | gen_params.rounds = rounds_int64; | |||
break; | ||||
case 'r': | ||||
if (str_to_uint(optarg, &gen_params.rounds) < 0) | ||||
i_fatal("Invalid number of rounds: %s", optarg); | ||||
break; | ||||
case 's': | ||||
scheme = optarg; | ||||
break; | ||||
case 't': | ||||
test_hash = optarg; | ||||
reverse_verify = TRUE; | ||||
break; | ||||
case 'u': | ||||
gen_params.user = optarg; | ||||
break; | ||||
case 'V': | ||||
reverse_verify = TRUE; | ||||
break; | ||||
case '?': | ||||
default: | ||||
help(&doveadm_cmd_pw); | ||||
} | ||||
} | } | |||
(void)doveadm_cmd_param_str(cctx, "scheme", &scheme); | ||||
if (doveadm_cmd_param_str(cctx, "test-hash", &test_hash)) | ||||
reverse_verify = TRUE; | ||||
(void)doveadm_cmd_param_str(cctx, "user", &gen_params.user); | ||||
(void)doveadm_cmd_param_bool(cctx, "reverse-verify", &reverse_verify); | ||||
if (list_schemes) { | if (list_schemes) { | |||
ARRAY_TYPE(password_scheme_p) arr; | ARRAY_TYPE(password_scheme_p) arr; | |||
const struct password_scheme *const *schemes; | const struct password_scheme *const *schemes; | |||
unsigned int i, count; | unsigned int i, count; | |||
t_array_init(&arr, 30); | t_array_init(&arr, 30); | |||
password_schemes_get(&arr); | password_schemes_get(&arr); | |||
schemes = array_get(&arr, &count); | schemes = array_get(&arr, &count); | |||
for (i = 0; i < count; i++) | for (i = 0; i < count; i++) | |||
printf("%s ", schemes[i]->name); | printf("%s ", schemes[i]->name); | |||
printf("\n"); | printf("\n"); | |||
lib_exit(0); | module_dir_unload(&modules); | |||
password_schemes_deinit(); | ||||
return; | ||||
} | } | |||
if (argc != optind) | ||||
help(&doveadm_cmd_pw); | ||||
scheme = scheme == NULL ? DEFAULT_SCHEME : t_str_ucase(scheme); | scheme = scheme == NULL ? DEFAULT_SCHEME : t_str_ucase(scheme); | |||
if (test_hash != NULL && plaintext == NULL) | if (test_hash != NULL && plaintext == NULL) | |||
plaintext = t_askpass("Enter password to verify: "); | plaintext = t_askpass("Enter password to verify: "); | |||
while (plaintext == NULL) { | while (plaintext == NULL) { | |||
const char *check; | const char *check; | |||
static int lives = 3; | static int lives = 3; | |||
plaintext = t_askpass("Enter new password: "); | plaintext = t_askpass("Enter new password: "); | |||
check = t_askpass("Retype new password: "); | check = t_askpass("Retype new password: "); | |||
skipping to change at line 141 | skipping to change at line 122 | |||
printf("{%s}%s (verified)\n", scheme, hash); | printf("{%s}%s (verified)\n", scheme, hash); | |||
} else { | } else { | |||
printf("{%s}%s\n", scheme, hash); | printf("{%s}%s\n", scheme, hash); | |||
} | } | |||
module_dir_unload(&modules); | module_dir_unload(&modules); | |||
password_schemes_deinit(); | password_schemes_deinit(); | |||
} | } | |||
struct doveadm_cmd doveadm_cmd_pw = { | struct doveadm_cmd_ver2 doveadm_cmd_pw = { | |||
cmd_pw, "pw", | .name = "pw", | |||
"[-l] [-p plaintext] [-r rounds] [-s scheme] [-t hash] [-u user] [-V]" | .cmd = cmd_pw, | |||
.usage = "[-l] [-p plaintext] [-r rounds] [-s scheme] [-t hash] [-u user] | ||||
[-V]", | ||||
DOVEADM_CMD_PARAMS_START | ||||
DOVEADM_CMD_PARAM('l', "list", CMD_PARAM_BOOL, 0) | ||||
DOVEADM_CMD_PARAM('p', "plaintext", CMD_PARAM_STR, 0) | ||||
DOVEADM_CMD_PARAM('r', "rounds", CMD_PARAM_INT64, 0) | ||||
DOVEADM_CMD_PARAM('s', "scheme", CMD_PARAM_STR, 0) | ||||
DOVEADM_CMD_PARAM('t', "test-hash", CMD_PARAM_STR, 0) | ||||
DOVEADM_CMD_PARAM('u', "user", CMD_PARAM_STR, 0) | ||||
DOVEADM_CMD_PARAM('V', "reverse-verify", CMD_PARAM_BOOL, 0) | ||||
DOVEADM_CMD_PARAMS_END | ||||
}; | }; | |||
End of changes. 7 change blocks. | ||||
38 lines changed or deleted | 31 lines changed or added |