]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
authtest binary is now accessed via "doveadm auth" and "doveadm user".
authorTimo Sirainen <tss@iki.fi>
Thu, 8 Oct 2009 22:43:17 +0000 (18:43 -0400)
committerTimo Sirainen <tss@iki.fi>
Thu, 8 Oct 2009 22:43:17 +0000 (18:43 -0400)
--HG--
branch : HEAD

.hgignore
src/doveadm/Makefile.am
src/doveadm/doveadm-auth.c [moved from src/util/authtest.c with 77% similarity]
src/doveadm/doveadm.c
src/doveadm/doveadm.h
src/util/Makefile.am

index c1e9c122fc4be5098bf83a05d96993933f0775f2..68f75cf9f05e222b56000d543be6362f1b29355b 100644 (file)
--- 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
index e0842165cb50c22c8e4d60468a616bfff1ca4d05..f371e7b7c7bfd7accd8d2e4a0ae56e2c5f7c17f8 100644 (file)
@@ -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
similarity index 77%
rename from src/util/authtest.c
rename to src/doveadm/doveadm-auth.c
index 1dcfdbe49d5235f1d8528065a54a1535595f7017..f52ec41831a99b4c1879ca11d60680a91e0e1177 100644 (file)
@@ -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 <stdio.h>
 #include <stdlib.h>
@@ -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 <auth socket path>] [-x <auth info>] <user> [<password]");
-}
-
-int main(int argc, char *argv[])
+static void
+auth_cmd_common(const struct doveadm_cmd *cmd, int argc, char *argv[])
 {
-       const char *getopt_str;
+       const char *auth_socket_path = NULL;
        struct authtest_input input;
-       int c, ret;
+       int c;
 
        memset(&input, 0, sizeof(input));
-       input.info.service = "authtest";
+       input.info.service = "doveadm";
 
-       master_service = master_service_init("authtest",
-                                            MASTER_SERVICE_FLAG_STANDALONE,
-                                            argc, argv);
-       getopt_str = t_strconcat("a:x:", master_service_getopt_string(), NULL);
-       while ((c = getopt(argc, argv, getopt_str)) > 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 <auth socket path>] [-x <auth info>] <user> [<password>]", NULL
+};
+
+struct doveadm_cmd doveadm_cmd_user = {
+       cmd_user, "user",
+       "[-a <auth socket path>] [-x <auth info>] <user> [<user> ...]", NULL
+};
index d73f5bca7fc8b46967387617b96ec60c8ab849d5..15d790463e8644b53531d81f13d68057d820ebcc 100644 (file)
@@ -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);
index e2c79570be4aa1c12e46934d915f8a86f73f5727..d75ecef95484122feb0029615fb3d7fba0db25a5 100644 (file)
@@ -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);
index e513c582857794ce14057dc6bc99999350d88a41..d1a02509c7c4572d417f615d6f3c083d14449262 100644 (file)
@@ -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 = \