Mercurial > dovecot > core-2.2
changeset 12991:d0f54521bb3b
doveadm cleanup: Don't try to keep auth/user comand handlers in same function.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 04 May 2011 14:58:03 +0200 |
parents | c9b7e829c6a9 |
children | 23b6234ce0ae |
files | src/doveadm/doveadm-auth.c |
diffstat | 1 files changed, 41 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/doveadm-auth.c Wed May 04 11:43:59 2011 +0200 +++ b/src/doveadm/doveadm-auth.c Wed May 04 14:58:03 2011 +0200 @@ -199,8 +199,43 @@ auth_master_deinit(&conn); } -static void -auth_cmd_common(const struct doveadm_cmd *cmd, int argc, char *argv[]) +static void cmd_auth(int argc, char *argv[]) +{ + const char *auth_socket_path = NULL; + struct authtest_input input; + int c; + + memset(&input, 0, sizeof(input)); + input.info.service = "doveadm"; + + while ((c = getopt(argc, argv, "a:x:")) > 0) { + switch (c) { + case 'a': + auth_socket_path = optarg; + break; + case 'x': + auth_user_info_parse(&input.info, optarg); + break; + default: + help(&doveadm_cmd_auth); + } + } + + if (optind == argc) + help(&doveadm_cmd_auth); + + input.username = argv[optind++]; + input.password = argv[optind] != NULL ? argv[optind++] : + t_askpass("Password: "); + if (argv[optind] != NULL) + i_fatal("Unexpected parameter: %s", argv[optind]); + if (cmd_auth_input(auth_socket_path, &input) < 0) + exit(FATAL_DEFAULT); + if (!input.success) + exit(1); +} + +static void cmd_user(int argc, char *argv[]) { const char *auth_socket_path = NULL; struct authtest_input input; @@ -220,12 +255,12 @@ auth_user_info_parse(&input.info, optarg); break; default: - help(cmd); + help(&doveadm_cmd_user); } } if (optind == argc) - help(cmd); + help(&doveadm_cmd_user); have_wildcards = FALSE; for (i = optind; argv[i] != NULL; i++) { @@ -236,19 +271,9 @@ } } - if (cmd == &doveadm_cmd_auth) { - input.username = argv[optind++]; - input.password = argv[optind] != NULL ? argv[optind++] : - t_askpass("Password: "); - if (argv[optind] != NULL) - i_fatal("Unexpected parameter: %s", argv[optind]); - if (cmd_auth_input(auth_socket_path, &input) < 0) - exit(FATAL_DEFAULT); - if (!input.success) - exit(1); - } else if (have_wildcards) { + if (have_wildcards) cmd_user_list(auth_socket_path, argv + optind); - } else { + else { bool first = TRUE; bool notfound = FALSE; @@ -270,16 +295,6 @@ } } -static void cmd_auth(int argc, char *argv[]) -{ - auth_cmd_common(&doveadm_cmd_auth, argc, argv); -} - -static void cmd_user(int argc, char *argv[]) -{ - auth_cmd_common(&doveadm_cmd_user, argc, argv); -} - struct doveadm_cmd doveadm_cmd_auth = { cmd_auth, "auth", "[-a <auth socket path>] [-x <auth info>] <user> [<password>]"