]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Replace i_<log>() with e_<log>()
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 27 Sep 2022 13:43:45 +0000 (13:43 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 26 Oct 2022 16:35:08 +0000 (16:35 +0000)
src/auth/auth-cache.c
src/auth/auth-policy.c
src/auth/auth-token.c
src/auth/db-sql.c
src/auth/main.c
src/auth/test-auth-cache.c

index 46f697cee7142019965709882339d03ec42fa8d5..fb635f7118e2edc19eb4123a687ccecf91e6deb5 100644 (file)
@@ -8,12 +8,14 @@
 #include "var-expand.h"
 #include "auth-request.h"
 #include "auth-cache.h"
+#include "auth-common.h"
 
 #include <time.h>
 
 struct auth_cache {
        HASH_TABLE(char *, struct auth_cache_node *) hash;
        struct auth_cache_node *head, *tail;
+       struct event *event;
 
        size_t max_size, size_left;
        unsigned int ttl_secs, neg_ttl_secs;
@@ -191,7 +193,7 @@ static void sig_auth_cache_clear(const siginfo_t *si ATTR_UNUSED, void *context)
 {
        struct auth_cache *cache = context;
 
-       i_info("SIGHUP received, %u cache entries flushed",
+       e_info(cache->event, "SIGHUP received, %u cache entries flushed",
               auth_cache_clear(cache));
 }
 
@@ -202,18 +204,18 @@ static void sig_auth_cache_stats(const siginfo_t *si ATTR_UNUSED, void *context)
        size_t cache_used;
 
        total_count = cache->hit_count + cache->miss_count;
-       i_info("Authentication cache hits %u/%u (%u%%)",
+       e_info(cache->event, "Authentication cache hits %u/%u (%u%%)",
               cache->hit_count, total_count,
               total_count == 0 ? 100 : (cache->hit_count * 100 / total_count));
 
-       i_info("Authentication cache inserts: "
+       e_info(cache->event, "Authentication cache inserts: "
               "positive: %u entries %llu bytes, "
               "negative: %u entries %llu bytes",
               cache->pos_entries, cache->pos_size,
               cache->neg_entries, cache->neg_size);
 
        cache_used = cache->max_size - cache->size_left;
-       i_info("Authentication cache current size: "
+       e_info(cache->event, "Authentication cache current size: "
               "%zu bytes used of %zu bytes (%u%%)",
               cache_used, cache->max_size,
               (unsigned int)(cache_used * 100ULL / cache->max_size));
@@ -236,6 +238,7 @@ struct auth_cache *auth_cache_new(size_t max_size, unsigned int ttl_secs,
        cache->size_left = max_size;
        cache->ttl_secs = ttl_secs;
        cache->neg_ttl_secs = neg_ttl_secs;
+       cache->event = event_create(auth_event);
 
        lib_signals_set_handler(SIGHUP, LIBSIG_FLAGS_SAFE,
                                sig_auth_cache_clear, cache);
@@ -254,6 +257,7 @@ void auth_cache_free(struct auth_cache **_cache)
 
        auth_cache_clear(cache);
        hash_table_destroy(&cache->hash);
+       event_unref(&cache->event);
        i_free(cache);
 }
 
index 0a7d85a7935e2dfe540d05bb3b517ae961eade50..65e630a5c73ae374e13c0c62bc3bc20c2291279c 100644 (file)
@@ -227,7 +227,8 @@ void auth_policy_init(void)
        auth_policy_json_template = i_strdup(str_c(template));
 
        if (global_auth_settings->policy_log_only)
-               i_warning("auth-policy: Currently in log-only mode. Ignoring "
+               e_warning(auth_event,
+                         "auth-policy: Currently in log-only mode. Ignoring "
                          "tarpit and disconnect instructions from policy server");
 }
 
index b61b7b91521991ea4514581187649434b671e111..48afcc68085bba891974ff7772e4f494781283ff 100644 (file)
@@ -42,19 +42,19 @@ auth_token_read_secret(const char *path,
        fd = open(path, O_RDONLY);
        if (fd == -1) {
                if (errno != ENOENT)
-                       i_error("open(%s) failed: %m", path);
+                       e_error(auth_event, "open(%s) failed: %m", path);
                return -1;
        }
 
        if (fstat(fd, &st) < 0) {
-               i_error("fstat(%s) failed: %m", path);
+               e_error(auth_event, "fstat(%s) failed: %m", path);
                i_close_fd(&fd);
                return -1;
        }
 
        /* check secret len and file type */
        if (st.st_size != AUTH_TOKEN_SECRET_LEN || !S_ISREG(st.st_mode)) {
-               i_error("Corrupted token secret file: %s", path);
+               e_error(auth_event, "Corrupted token secret file: %s", path);
                i_close_fd(&fd);
                i_unlink(path);
                return -1;
@@ -62,7 +62,7 @@ auth_token_read_secret(const char *path,
 
        /* verify that we're not dealing with a symbolic link */
        if (lstat(path, &lst) < 0) {
-               i_error("lstat(%s) failed: %m", path);
+               e_error(auth_event, "lstat(%s) failed: %m", path);
                i_close_fd(&fd);
                return -1;
        }
@@ -72,7 +72,7 @@ auth_token_read_secret(const char *path,
            st.st_uid != geteuid() || st.st_nlink > 1 ||
            !S_ISREG(lst.st_mode) || st.st_ino != lst.st_ino ||
            !CMP_DEV_T(st.st_dev, lst.st_dev)) {
-               i_error("Compromised token secret file: %s", path);
+               e_error(auth_event, "Compromised token secret file: %s", path);
                i_close_fd(&fd);
                i_unlink(path);
                return -1;
@@ -82,13 +82,13 @@ auth_token_read_secret(const char *path,
 
        ret = read_full(fd, secret_r, AUTH_TOKEN_SECRET_LEN);
        if (ret < 0)
-               i_error("read(%s) failed: %m", path);
+               e_error(auth_event, "read(%s) failed: %m", path);
        else if (ret == 0) {
-               i_error("Token secret file unexpectedly shrank: %s", path);
+               e_error(auth_event, "Token secret file unexpectedly shrank: %s", path);
                ret = -1;
        }
        if (close(fd) < 0)
-               i_error("close(%s) failed: %m", path);
+               e_error(auth_event, "close(%s) failed: %m", path);
 
        e_debug(auth_event, "Read auth token secret from %s", path);
        return ret;
@@ -109,15 +109,15 @@ auth_token_write_secret(const char *path,
        umask(old_mask);
 
        if (fd == -1) {
-               i_error("open(%s) failed: %m", temp_path);
+               e_error(auth_event, "open(%s) failed: %m", temp_path);
                return -1;
        }
 
        ret = write_full(fd, secret, AUTH_TOKEN_SECRET_LEN);
        if (ret < 0)
-               i_error("write(%s) failed: %m", temp_path);
+               e_error(auth_event, "write(%s) failed: %m", temp_path);
        if (close(fd) < 0) {
-               i_error("close(%s) failed: %m", temp_path);
+               e_error(auth_event, "close(%s) failed: %m", temp_path);
                ret = -1;
        }
 
@@ -127,7 +127,7 @@ auth_token_write_secret(const char *path,
        }
 
        if (rename(temp_path, path) < 0) {
-               i_error("rename(%s, %s) failed: %m", temp_path, path);
+               e_error(auth_event, "rename(%s, %s) failed: %m", temp_path, path);
                i_unlink(temp_path);
                return -1;
        }
@@ -146,7 +146,8 @@ void auth_token_init(void)
                random_fill(auth_token_secret, sizeof(auth_token_secret));
 
                if (auth_token_write_secret(secret_path, auth_token_secret) < 0) {
-                       i_error("Failed to write auth token secret file; "
+                       e_error(auth_event,
+                               "Failed to write auth token secret file; "
                                "returned tokens will be invalid once auth restarts");
                }
        }
index f5ad3ba386158b2b0eea9c2b1baf304dc5ec566f..c6a51c7bfde1b323d78567f893ba7c9f9f30ba11 100644 (file)
@@ -7,6 +7,7 @@
 #include "settings.h"
 #include "auth-request.h"
 #include "auth-worker-server.h"
+#include "auth-common.h"
 #include "db-sql.h"
 
 #include <stddef.h>
@@ -162,13 +163,15 @@ void db_sql_check_userdb_warning(struct db_sql_connection *conn)
 
        if (strcmp(conn->set.user_query,
                   default_db_sql_settings.user_query) != 0) {
-               i_warning("sql: Ignoring changed user_query in %s, "
+               e_warning(auth_event,
+                         "sql: Ignoring changed user_query in %s, "
                          "because userdb sql not used. "
                          "(If this is intentional, set userdb_warning_disable=yes)",
                          conn->config_path);
        } else if (strcmp(conn->set.iterate_query,
                          default_db_sql_settings.iterate_query) != 0) {
-               i_warning("sql: Ignoring changed iterate_query in %s, "
+               e_warning(auth_event,
+                         "sql: Ignoring changed iterate_query in %s, "
                          "because userdb sql not used. "
                          "(If this is intentional, set userdb_warning_disable=yes)",
                          conn->config_path);
index 828bb7ffa9f87a51158e16f693d2dbba815ef09d..d572ecd3d7dfcb87ea6a015b565d63f013e5de97 100644 (file)
@@ -311,7 +311,8 @@ static void main_deinit(void)
 static void worker_connected(struct master_service_connection *conn)
 {
        if (auth_worker_has_connections()) {
-               i_error("Auth workers can handle only a single client");
+               e_error(auth_event,
+                       "Auth workers can handle only a single client");
                return;
        }
 
index ea71b1baff338657a2ee0abb1104ad674c3837c6..05efcf2353d71cff6fe7d48f0e240e2f758084b0 100644 (file)
@@ -19,6 +19,8 @@ auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT + 1] = {
        { '\0', NULL, NULL }
 };
 
+struct event *auth_event;
+
 struct var_expand_table *
 auth_request_get_var_expand_table_full(const struct auth_request *auth_request ATTR_UNUSED,
                                       const char *username ATTR_UNUSED,
@@ -74,9 +76,13 @@ static void test_auth_cache_parse_key(void)
 
 int main(void)
 {
+       lib_init();
+       auth_event = event_create(NULL);
        static void (*const test_functions[])(void) = {
                test_auth_cache_parse_key,
                NULL
        };
-       return test_run(test_functions);
+       int ret = test_run(test_functions);
+       event_unref(&auth_event);
+       return ret;
 }