dovecot-2.1: doveadm: Added "auth cache flush" command.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jul 4 10:58:52 EEST 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/1093c74f54af
changeset: 14600:1093c74f54af
user: Timo Sirainen <tss at iki.fi>
date: Wed Jul 04 10:57:40 2012 +0300
description:
doveadm: Added "auth cache flush" command.
diffstat:
src/doveadm/doveadm-auth.c | 82 +++++++++++++++++++++++++++++++++++++++------
src/doveadm/doveadm.c | 3 +-
src/doveadm/doveadm.h | 3 +-
src/lib-auth/auth-master.c | 43 ++++++++++++++++++++++++
src/lib-auth/auth-master.h | 4 ++
5 files changed, 120 insertions(+), 15 deletions(-)
diffs (247 lines):
diff -r 007bf0047ab0 -r 1093c74f54af src/doveadm/doveadm-auth.c
--- a/src/doveadm/doveadm-auth.c Wed Jul 04 10:56:53 2012 +0300
+++ b/src/doveadm/doveadm-auth.c Wed Jul 04 10:57:40 2012 +0300
@@ -27,6 +27,8 @@
bool success;
};
+static void auth_cmd_help(doveadm_command_t *cmd);
+
static int
cmd_user_input(const char *auth_socket_path, const struct authtest_input *input,
const char *show_field)
@@ -214,12 +216,52 @@
auth_master_deinit(&conn);
}
+static void cmd_auth_cache_flush(int argc, char *argv[])
+{
+ const char *auth_socket_path = NULL;
+ struct auth_master_connection *conn;
+ unsigned int count;
+ int c;
+
+ while ((c = getopt(argc, argv, "a:")) > 0) {
+ switch (c) {
+ case 'a':
+ auth_socket_path = optarg;
+ break;
+ default:
+ auth_cmd_help(cmd_auth_cache_flush);
+ }
+ }
+ argv += optind;
+
+ if (auth_socket_path == NULL) {
+ auth_socket_path = t_strconcat(doveadm_settings->base_dir,
+ "/auth-master", NULL);
+ }
+
+ conn = auth_master_init(auth_socket_path, 0);
+ if (auth_master_cache_flush(conn, (void *)argv, &count) < 0) {
+ i_error("Cache flush failed");
+ doveadm_exit_code = EX_TEMPFAIL;
+ } else {
+ printf("%u cache entries flushed\n", count);
+ }
+ auth_master_deinit(&conn);
+}
+
static void cmd_auth(int argc, char *argv[])
{
const char *auth_socket_path = NULL;
struct authtest_input input;
int c;
+ if (null_strcmp(argv[1], "cache") == 0 &&
+ null_strcmp(argv[2], "flush") == 0) {
+ /* kludgy: handle "doveadm auth cache" command instead */
+ cmd_auth_cache_flush(argc-2, argv+2);
+ return;
+ }
+
memset(&input, 0, sizeof(input));
input.info.service = "doveadm";
@@ -232,12 +274,12 @@
auth_user_info_parse(&input.info, optarg);
break;
default:
- help(&doveadm_cmd_auth);
+ auth_cmd_help(cmd_auth);
}
}
if (optind == argc)
- help(&doveadm_cmd_auth);
+ auth_cmd_help(cmd_auth);
input.username = argv[optind++];
input.password = argv[optind] != NULL ? argv[optind++] :
@@ -331,12 +373,12 @@
auth_user_info_parse(&input.info, optarg);
break;
default:
- help(&doveadm_cmd_user);
+ auth_cmd_help(cmd_user);
}
}
if (optind == argc)
- help(&doveadm_cmd_user);
+ auth_cmd_help(cmd_user);
have_wildcards = FALSE;
for (i = optind; argv[i] != NULL; i++) {
@@ -380,12 +422,30 @@
mail_storage_service_deinit(&storage_service);
}
-struct doveadm_cmd doveadm_cmd_auth = {
- cmd_auth, "auth",
- "[-a <auth socket path>] [-x <auth info>] <user> [<password>]"
+struct doveadm_cmd doveadm_cmd_auth[] = {
+ { cmd_auth, "auth",
+ "[-a <auth socket path>] [-x <auth info>] <user> [<password>]" },
+ { cmd_auth_cache_flush, "auth cache flush",
+ "[-a <master socket path>] [<user>]" },
+ { cmd_user, "user",
+ "[-a <userdb socket path>] [-x <auth info>] [-f field] [-m] <user mask> [...]" }
};
-struct doveadm_cmd doveadm_cmd_user = {
- cmd_user, "user",
- "[-a <userdb socket path>] [-x <auth info>] [-f field] [-m] <user mask> [...]"
-};
+static void auth_cmd_help(doveadm_command_t *cmd)
+{
+ unsigned int i;
+
+ for (i = 0; i < N_ELEMENTS(doveadm_cmd_auth); i++) {
+ if (doveadm_cmd_auth[i].cmd == cmd)
+ help(&doveadm_cmd_auth[i]);
+ }
+ i_unreached();
+}
+
+void doveadm_register_auth_commands(void)
+{
+ unsigned int i;
+
+ for (i = 0; i < N_ELEMENTS(doveadm_cmd_auth); i++)
+ doveadm_register_cmd(&doveadm_cmd_auth[i]);
+}
diff -r 007bf0047ab0 -r 1093c74f54af src/doveadm/doveadm.c
--- a/src/doveadm/doveadm.c Wed Jul 04 10:56:53 2012 +0300
+++ b/src/doveadm/doveadm.c Wed Jul 04 10:57:40 2012 +0300
@@ -271,8 +271,6 @@
&doveadm_cmd_config,
&doveadm_cmd_stop,
&doveadm_cmd_reload,
- &doveadm_cmd_auth,
- &doveadm_cmd_user,
&doveadm_cmd_dump,
&doveadm_cmd_pw,
&doveadm_cmd_who,
@@ -342,6 +340,7 @@
quick_init = TRUE;
} else {
quick_init = FALSE;
+ doveadm_register_auth_commands();
doveadm_register_director_commands();
doveadm_register_instance_commands();
doveadm_register_mount_commands();
diff -r 007bf0047ab0 -r 1093c74f54af src/doveadm/doveadm.h
--- a/src/doveadm/doveadm.h Wed Jul 04 10:56:53 2012 +0300
+++ b/src/doveadm/doveadm.h Wed Jul 04 10:57:40 2012 +0300
@@ -22,8 +22,6 @@
extern struct doveadm_cmd doveadm_cmd_stop;
extern struct doveadm_cmd doveadm_cmd_reload;
-extern struct doveadm_cmd doveadm_cmd_auth;
-extern struct doveadm_cmd doveadm_cmd_user;
extern struct doveadm_cmd doveadm_cmd_dump;
extern struct doveadm_cmd doveadm_cmd_pw;
extern struct doveadm_cmd doveadm_cmd_who;
@@ -41,6 +39,7 @@
void help(const struct doveadm_cmd *cmd) ATTR_NORETURN;
void doveadm_master_send_signal(int signo);
+void doveadm_register_auth_commands(void);
void doveadm_register_director_commands(void);
void doveadm_register_proxy_commands(void);
void doveadm_register_log_commands(void);
diff -r 007bf0047ab0 -r 1093c74f54af src/lib-auth/auth-master.c
--- a/src/lib-auth/auth-master.c Wed Jul 04 10:56:53 2012 +0300
+++ b/src/lib-auth/auth-master.c Wed Jul 04 10:57:40 2012 +0300
@@ -9,6 +9,7 @@
#include "istream.h"
#include "ostream.h"
#include "str.h"
+#include "strescape.h"
#include "master-interface.h"
#include "auth-master.h"
@@ -564,6 +565,48 @@
}
static bool
+auth_cache_flush_reply_callback(const char *cmd, const char *const *args,
+ void *context)
+{
+ unsigned int *countp = context;
+
+ if (strcmp(cmd, "OK") != 0)
+ *countp = -1U;
+ else if (args[0] == NULL || str_to_uint(args[0], countp) < 0)
+ *countp = -1U;
+
+ io_loop_stop(current_ioloop);
+ return TRUE;
+}
+
+int auth_master_cache_flush(struct auth_master_connection *conn,
+ const char *const *users, unsigned int *count_r)
+{
+ string_t *str;
+
+ *count_r = -1U;
+
+ conn->reply_callback = auth_cache_flush_reply_callback;
+ conn->reply_context = count_r;
+
+ str = t_str_new(128);
+ str_printfa(str, "CACHE-FLUSH\t%u", auth_master_next_request_id(conn));
+ if (users != NULL) {
+ for (; *users != NULL; users++) {
+ str_append_c(str, '\t');
+ str_tabescape_write(str, *users);
+ }
+ }
+ str_append_c(str, '\n');
+
+ conn->prefix = "auth cache flush";
+ (void)auth_master_run_cmd(conn, str_c(str));
+ conn->prefix = DEFAULT_USERDB_LOOKUP_PREFIX;
+
+ return *count_r == -1U ? -1 : 0;
+}
+
+static bool
auth_user_list_reply_callback(const char *cmd, const char *const *args,
void *context)
{
diff -r 007bf0047ab0 -r 1093c74f54af src/lib-auth/auth-master.h
--- a/src/lib-auth/auth-master.h Wed Jul 04 10:56:53 2012 +0300
+++ b/src/lib-auth/auth-master.h Wed Jul 04 10:57:40 2012 +0300
@@ -38,6 +38,10 @@
int auth_master_pass_lookup(struct auth_master_connection *conn,
const char *user, const struct auth_user_info *info,
pool_t pool, const char *const **fields_r);
+/* Flush authentication cache for everyone (users=NULL) or only for specified
+ users. Returns number of users flushed from cache. */
+int auth_master_cache_flush(struct auth_master_connection *conn,
+ const char *const *users, unsigned int *count_r);
/* Parse userdb extra fields into auth_user_reply structure. */
void auth_user_fields_parse(const char *const *fields, pool_t pool,
More information about the dovecot-cvs
mailing list