]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-passwd-file - Use event based logging
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 31 Oct 2019 12:41:56 +0000 (14:41 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 12 Mar 2021 12:18:13 +0000 (12:18 +0000)
src/auth/db-passwd-file.c
src/auth/db-passwd-file.h

index 2b42eb32dab55a1b9f77aa0a3551299c1863c1c0..6a5113cd44ff2c10a69d93120d9bbbb7ba5b63cd 100644 (file)
@@ -36,8 +36,7 @@ passwd_file_add(struct passwd_file *pw, const char *username,
        size_t len;
 
        if (hash_table_lookup(pw->users, username) != NULL) {
-               i_error("passwd-file %s: User %s exists more than once",
-                       pw->path, username);
+               e_error(pw->event, "User %s exists more than once", username);
                return;
        }
 
@@ -60,9 +59,8 @@ passwd_file_add(struct passwd_file *pw, const char *username,
                        pu->password = p_strconcat(pw->pool, "{DIGEST-MD5}",
                                                   pass, NULL);
                        if (strlen(pu->password) != 32 + 12) {
-                               i_error("passwd-file %s: User %s "
-                                       "has invalid password",
-                                       pw->path, username);
+                               e_error(pw->event, "User %s "
+                                       "has invalid password", username);
                                return;
                        }
                } else {
@@ -83,8 +81,8 @@ passwd_file_add(struct passwd_file *pw, const char *username,
        } else {
                pu->uid = userdb_parse_uid(NULL, *args);
                if (pu->uid == 0 || pu->uid == (uid_t)-1) {
-                       i_error("passwd-file %s: User %s has invalid UID '%s'",
-                               pw->path, username, *args);
+                       e_error(pw->event, "User %s has invalid UID '%s'",
+                               username, *args);
                        return;
                }
                args++;
@@ -92,8 +90,8 @@ passwd_file_add(struct passwd_file *pw, const char *username,
 
        if (*args == NULL) {
                if (pw->db->userdb_warn_missing) {
-                       i_error("passwd-file %s: User %s is missing "
-                               "userdb info", pw->path, username);
+                       e_error(pw->event, "User %s is missing userdb info",
+                               username);
                }
                /* don't allow userdb lookups */
                pu->uid = 0;
@@ -103,8 +101,8 @@ passwd_file_add(struct passwd_file *pw, const char *username,
        else {
                pu->gid = userdb_parse_gid(NULL, *args);
                if (pu->gid == 0 || pu->gid == (gid_t)-1) {
-                       i_error("passwd-file %s: User %s has invalid GID '%s'",
-                               pw->path, username, *args);
+                       e_error(pw->event, "User %s has invalid GID '%s'",
+                               username, *args);
                        return;
                }
                args++;
@@ -157,6 +155,9 @@ passwd_file_new(struct db_passwd_file *db, const char *expanded_path)
        pw->db = db;
        pw->path = i_strdup(expanded_path);
        pw->fd = -1;
+       pw->event = event_create(db->event);
+       event_set_append_log_prefix(pw->event,
+               t_strdup_printf("passwd-file %s:", pw->path));
 
        if (hash_table_is_created(db->files))
                hash_table_insert(db->files, pw->path, pw);
@@ -223,11 +224,11 @@ static int passwd_file_open(struct passwd_file *pw, bool startup,
 
        if ((time_secs > PARSE_TIME_STARTUP_WARN_SECS && startup) ||
            (time_secs > PARSE_TIME_RELOAD_WARN_SECS && !startup)) {
-               i_warning("passwd-file %s: Reading %u users took %u secs",
-                         pw->path, hash_table_count(pw->users), time_secs);
-       } else if (pw->db->debug) {
-               i_debug("passwd-file %s: Read %u users in %u secs",
-                       pw->path, hash_table_count(pw->users), time_secs);
+               e_warning(pw->event, "Reading %u users took %u secs",
+                         hash_table_count(pw->users), time_secs);
+       } else {
+               e_debug(pw->event, "Read %u users in %u secs",
+                       hash_table_count(pw->users), time_secs);
        }
        return 0;
 }
@@ -246,6 +247,7 @@ static void passwd_file_free(struct passwd_file *pw)
                hash_table_remove(pw->db->files, pw->path);
 
        passwd_file_close(pw);
+       event_unref(&pw->event);
        i_free(pw->path);
        i_free(pw);
 }
@@ -334,7 +336,8 @@ db_passwd_file_init(const char *path, bool userdb, bool debug)
        db->refcount = 1;
        if (userdb)
                db_passwd_file_set_userdb(db);
-       db->debug = debug;
+       db->event = event_create(auth_event);
+       event_set_forced_debug(db->event, debug);
 
        for (p = path; *p != '\0'; p++) {
                if (*p == '%' && p[1] != '\0') {
@@ -378,7 +381,7 @@ void db_passwd_file_parse(struct db_passwd_file *db)
        if (db->default_file != NULL && db->default_file->stamp == 0) {
                /* no variables, open the file immediately */
                if (passwd_file_open(db->default_file, TRUE, &error) < 0)
-                       i_error("passwd-file: %s", error);
+                       e_error(db->default_file->event, "%s", error);
        }
 }
 
@@ -411,6 +414,7 @@ void db_passwd_file_unref(struct db_passwd_file **_db)
                hash_table_iterate_deinit(&iter);
                hash_table_destroy(&db->files);
        }
+       event_unref(&db->event);
        i_free(db->path);
        i_free(db);
 }
index 646e07349f1cad03d79fd8e21cdbd3da8207643f..498f9c374e183c0cd7d0d06e68f62f06626b9567 100644 (file)
@@ -19,6 +19,7 @@ struct passwd_file {
         struct db_passwd_file *db;
        pool_t pool;
        int refcount;
+       struct event *event;
 
        time_t last_sync_time;
        char *path;
@@ -33,6 +34,7 @@ struct db_passwd_file {
        struct db_passwd_file *next;
 
        int refcount;
+       struct event *event;
 
        char *path;
        HASH_TABLE(char *, struct passwd_file *) files;
@@ -41,7 +43,6 @@ struct db_passwd_file {
        bool vars:1;
        bool userdb:1;
        bool userdb_warn_missing:1;
-       bool debug:1;
 };
 
 int db_passwd_file_lookup(struct db_passwd_file *db,