]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: Added ADD-USER command to add stats to a user without having a session.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 Feb 2016 12:55:56 +0000 (14:55 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 Feb 2016 13:25:43 +0000 (15:25 +0200)
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.

src/stats/fifo-input-connection.c
src/stats/mail-user.c
src/stats/mail-user.h

index 1bda765140452c00ad01821206fd8342943f771f..10e0207b8a24fd754af56f0e2b41021d0c0f1faf 100644 (file)
@@ -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);
 
index 77a26bd94060a490f3752aa99a8924798b22bb4d..3358483fa76d049a1dbebd910cbdaf924bc9de3a 100644 (file)
@@ -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;
+
+       /* <user> <service> <diff stats> */
+       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;
index 2c7e934c383e686c7f64a518b0d5957d6fa9e665..ff1949e497aecff3bbab728338d5cfbb9678c937 100644 (file)
@@ -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);