From f50ea0370137dd93d9953d91ea73486ca0784de9 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 8 Oct 2009 18:43:17 -0400 Subject: [PATCH] authtest binary is now accessed via "doveadm auth" and "doveadm user". --HG-- branch : HEAD --- .hgignore | 1 - src/doveadm/Makefile.am | 5 +- .../authtest.c => doveadm/doveadm-auth.c} | 87 +++++++++++-------- src/doveadm/doveadm.c | 4 +- src/doveadm/doveadm.h | 2 + src/util/Makefile.am | 6 -- 6 files changed, 60 insertions(+), 45 deletions(-) rename src/{util/authtest.c => doveadm/doveadm-auth.c} (77%) diff --git a/.hgignore b/.hgignore index c1e9c122fc..68f75cf9f0 100644 --- a/.hgignore +++ b/.hgignore @@ -78,7 +78,6 @@ src/plugins/expire/expire-tool src/plugins/fts-squat/squat-test src/pop3-login/pop3-login src/pop3/pop3 -src/util/authtest src/util/gdbhelper src/util/idxview src/util/imap-utf7 diff --git a/src/doveadm/Makefile.am b/src/doveadm/Makefile.am index e0842165cb..f371e7b7c7 100644 --- a/src/doveadm/Makefile.am +++ b/src/doveadm/Makefile.am @@ -29,8 +29,9 @@ doveadm_DEPENDENCIES = \ doveadm_SOURCES = \ doveadm.c \ - doveadm-pw.c \ - doveadm-mail.c + doveadm-auth.c \ + doveadm-mail.c \ + doveadm-pw.c noinst_HEADERS = \ doveadm-mail.h diff --git a/src/util/authtest.c b/src/doveadm/doveadm-auth.c similarity index 77% rename from src/util/authtest.c rename to src/doveadm/doveadm-auth.c index 1dcfdbe49d..f52ec41831 100644 --- a/src/util/authtest.c +++ b/src/doveadm/doveadm-auth.c @@ -3,12 +3,13 @@ #include "lib.h" #include "ioloop.h" #include "array.h" +#include "askpass.h" #include "base64.h" #include "str.h" -#include "master-service.h" #include "auth-client.h" -#include "auth-server-connection.h" #include "auth-master.h" +#include "auth-server-connection.h" +#include "doveadm.h" #include #include @@ -20,9 +21,8 @@ struct authtest_input { struct auth_user_info info; }; -static const char *auth_socket_path = NULL; - -static int authtest_userdb(const struct authtest_input *input) +static int +cmd_user_input(const char *auth_socket_path, const struct authtest_input *input) { struct auth_master_connection *conn; pool_t pool; @@ -67,7 +67,6 @@ static int authtest_userdb(const struct authtest_input *input) auth_master_deinit(&conn); return ret == 0 ? 1 : 0; } - static void auth_callback(struct auth_client_request *request ATTR_UNUSED, enum auth_request_status status, @@ -128,7 +127,7 @@ static void auth_connected(struct auth_client *client, } static int -authtest_passdb(struct authtest_input *input) +cmd_auth_input(const char *auth_socket_path, struct authtest_input *input) { struct auth_client *client; @@ -164,26 +163,17 @@ static void auth_user_info_parse(struct auth_user_info *info, const char *arg) } } -static void usage(void) -{ - i_fatal( -"usage: authtest [-a ] [-x ] [ 0) { + while ((c = getopt(argc, argv, "a:x:")) > 0) { switch (c) { case 'a': auth_socket_path = optarg; @@ -192,21 +182,48 @@ int main(int argc, char *argv[]) auth_user_info_parse(&input.info, optarg); break; default: - if (!master_service_parse_option(master_service, - c, optarg)) - usage(); + help(cmd); } } if (optind == argc) - usage(); - - input.username = argv[optind++]; - if (argv[optind] == NULL) - ret = authtest_userdb(&input); - else { - input.password = argv[optind]; - ret = authtest_passdb(&input); + help(cmd); + + if (cmd == &doveadm_cmd_auth) { + input.username = argv[optind++]; + input.password = argv[optind] != NULL ? argv[optind] : + t_askpass("Password: "); + if (cmd_auth_input(auth_socket_path, &input) < 0) + exit(1); + } else { + bool first = TRUE; + + while ((input.username = argv[optind++]) != NULL) { + if (first) + first = FALSE; + else + putchar('\n'); + if (cmd_user_input(auth_socket_path, &input) < 0) + exit(1); + } } - master_service_deinit(&master_service); - return ret; } + +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 ] []", NULL +}; + +struct doveadm_cmd doveadm_cmd_user = { + cmd_user, "user", + "[-a ] [-x ] [ ...]", NULL +}; diff --git a/src/doveadm/doveadm.c b/src/doveadm/doveadm.c index d73f5bca7f..15d790463e 100644 --- a/src/doveadm/doveadm.c +++ b/src/doveadm/doveadm.c @@ -79,6 +79,8 @@ int main(int argc, char *argv[]) i_array_init(&doveadm_cmds, 32); doveadm_mail_init(); doveadm_register_cmd(&doveadm_cmd_help); + doveadm_register_cmd(&doveadm_cmd_auth); + doveadm_register_cmd(&doveadm_cmd_user); doveadm_register_cmd(&doveadm_cmd_pw); /* "+" is GNU extension to stop at the first non-option. @@ -96,7 +98,7 @@ int main(int argc, char *argv[]) argv += optind; if (!doveadm_try_run(cmd_name, argc, argv) && - doveadm_mail_try_run(cmd_name, argc, argv)) + !doveadm_mail_try_run(cmd_name, argc, argv)) usage(); master_service_deinit(&master_service); diff --git a/src/doveadm/doveadm.h b/src/doveadm/doveadm.h index e2c79570be..d75ecef954 100644 --- a/src/doveadm/doveadm.h +++ b/src/doveadm/doveadm.h @@ -12,6 +12,8 @@ struct doveadm_cmd { const char *long_usage; }; +extern struct doveadm_cmd doveadm_cmd_auth; +extern struct doveadm_cmd doveadm_cmd_user; extern struct doveadm_cmd doveadm_cmd_pw; void doveadm_register_cmd(const struct doveadm_cmd *cmd); diff --git a/src/util/Makefile.am b/src/util/Makefile.am index e513c58285..d1a02509c7 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -1,7 +1,6 @@ pkglibexecdir = $(libexecdir)/dovecot pkglibexec_PROGRAMS = \ - authtest \ rawlog \ gdbhelper \ idxview \ @@ -24,11 +23,6 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/auth \ -DPKG_RUNDIR=\""$(rundir)"\" -authtest_LDADD = $(LIBDOVECOT) -authtest_DEPENDENCIES = $(LIBDOVECOT) -authtest_SOURCES = \ - authtest.c - rawlog_LDADD = $(LIBDOVECOT) rawlog_DEPENDENCIES = $(LIBDOVECOT) rawlog_SOURCES = \ -- 2.47.3