From 723c066e9900f083dd033a531033e96ad115882e Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 4 May 2011 14:58:03 +0200 Subject: [PATCH] doveadm cleanup: Don't try to keep auth/user comand handlers in same function. --- src/doveadm/doveadm-auth.c | 67 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/src/doveadm/doveadm-auth.c b/src/doveadm/doveadm-auth.c index 2d969d810b..50932a888e 100644 --- a/src/doveadm/doveadm-auth.c +++ b/src/doveadm/doveadm-auth.c @@ -199,8 +199,43 @@ cmd_user_list(const char *auth_socket_path, char *const *users) 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_cmd_common(const struct doveadm_cmd *cmd, int argc, char *argv[]) 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 @@ auth_cmd_common(const struct doveadm_cmd *cmd, int argc, char *argv[]) } } - 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 @@ auth_cmd_common(const struct doveadm_cmd *cmd, int argc, char *argv[]) } } -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 ] [-x ] []" -- 2.47.3