From: Timo Sirainen Date: Fri, 5 Feb 2016 12:55:56 +0000 (+0200) Subject: stats: Added ADD-USER command to add stats to a user without having a session. X-Git-Tag: 2.2.22.rc1~208 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7a0a5c1e8310503c44be9ecd37be095604f7fa6;p=thirdparty%2Fdovecot%2Fcore.git stats: Added ADD-USER command to add stats to a user without having a session. This will be used by at least the auth process. Although the auth process does have a session, it's a bit too early to start using it yet. At least the PID should be possible to change when the session moves to imap process. Also the unsuccessful authentication sessions shouldn't really be added at all. --- diff --git a/src/stats/fifo-input-connection.c b/src/stats/fifo-input-connection.c index 1bda765140..10e0207b8a 100644 --- a/src/stats/fifo-input-connection.c +++ b/src/stats/fifo-input-connection.c @@ -6,6 +6,7 @@ #include "ostream.h" #include "master-service.h" #include "mail-session.h" +#include "mail-user.h" #include "mail-command.h" #include "fifo-input-connection.h" @@ -36,6 +37,8 @@ fifo_input_connection_request(const char *const *args, const char **error_r) return mail_session_disconnect_parse(args, error_r); if (strcmp(cmd, "UPDATE-SESSION") == 0) return mail_session_update_parse(args, error_r); + if (strcmp(cmd, "ADD-USER") == 0) + return mail_user_add_parse(args, error_r); if (strcmp(cmd, "UPDATE-CMD") == 0) return mail_command_update_parse(args, error_r); diff --git a/src/stats/mail-user.c b/src/stats/mail-user.c index 77a26bd940..3358483fa7 100644 --- a/src/stats/mail-user.c +++ b/src/stats/mail-user.c @@ -1,9 +1,11 @@ /* Copyright (c) 2011-2016 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "buffer.h" #include "ioloop.h" #include "hash.h" #include "llist.h" +#include "base64.h" #include "global-memory.h" #include "stats-settings.h" #include "mail-stats.h" @@ -117,6 +119,38 @@ void mail_user_refresh(struct mail_user *user, mail_domain_refresh(user->domain, diff_stats); } +int mail_user_add_parse(const char *const *args, const char **error_r) +{ + struct mail_user *user; + struct stats *diff_stats; + buffer_t *buf; + const char *service, *error; + + /* */ + if (str_array_length(args) < 3) { + *error_r = "ADD-USER: Too few parameters"; + return -1; + } + + user = mail_user_login(args[0]); + service = args[1]; + + buf = buffer_create_dynamic(pool_datastack_create(), 256); + if (base64_decode(args[2], strlen(args[2]), NULL, buf) < 0) { + *error_r = t_strdup_printf("ADD-USER %s %s: Invalid base64 input", + user->name, service); + return -1; + } + diff_stats = stats_alloc(pool_datastack_create()); + if (!stats_import(buf->data, buf->used, user->stats, diff_stats, &error)) { + *error_r = t_strdup_printf("ADD-USER %s %s: %s", + user->name, service, error); + return -1; + } + mail_user_refresh(user, diff_stats); + return 0; +} + void mail_users_free_memory(void) { unsigned int diff; diff --git a/src/stats/mail-user.h b/src/stats/mail-user.h index 2c7e934c38..ff1949e497 100644 --- a/src/stats/mail-user.h +++ b/src/stats/mail-user.h @@ -11,6 +11,7 @@ struct mail_user *mail_user_lookup(const char *username); void mail_user_refresh(struct mail_user *user, const struct stats *diff_stats) ATTR_NULL(2); +int mail_user_add_parse(const char *const *args, const char **error_r); void mail_user_ref(struct mail_user *user); void mail_user_unref(struct mail_user **user);