Mercurial > dovecot > core-2.2
changeset 4035:335ac59efffd HEAD
If passwd-file is being used as userdb, complain immediately if some entries
don't have userdb information. Also some other cleanups and crashfix for
today's earlier changes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 20 Feb 2006 18:31:46 +0200 |
parents | b533c52196e3 |
children | bb6a724a3396 |
files | src/auth/db-passwd-file.c src/auth/db-passwd-file.h src/auth/passdb-passwd-file.c src/auth/userdb-passwd-file.c |
diffstat | 4 files changed, 99 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/db-passwd-file.c Mon Feb 20 16:16:00 2006 +0200 +++ b/src/auth/db-passwd-file.c Mon Feb 20 18:31:46 2006 +0200 @@ -26,6 +26,7 @@ /* args = uid, gid, user info, home dir, shell, extra_fields */ struct passwd_user *pu; const char *p, *extra_fields = NULL; + char *user; if (hash_lookup(pw->users, username) != NULL) { i_error("passwd-file %s: User %s exists more than once", @@ -34,11 +35,7 @@ } pu = p_new(pw->pool, struct passwd_user, 1); - pu->user_realm = p_strdup(pw->pool, username); - - pu->realm = strchr(pu->user_realm, '@'); - if (pu->realm != NULL) - pu->realm++; + user = p_strdup(pw->pool, username); p = pass == NULL ? NULL : strchr(pass, '['); if (p == NULL) { @@ -84,6 +81,14 @@ return; } args++; + } else { + if (pw->db->userdb) { + i_error("passwd-file %s: User %s is missing " + "userdb info", pw->path, username); + } + if (pw->first_missing_userdb_info == NULL) + pw->first_missing_userdb_info = user; + pw->missing_userdb_info_count++; } /* user info */ @@ -120,7 +125,7 @@ p_strsplit_spaces(pw->pool, extra_fields, " "); } - hash_insert(pw->users, pu->user_realm, pu); + hash_insert(pw->users, user, pu); } static struct passwd_file * @@ -133,7 +138,8 @@ pw->path = i_strdup(expanded_path); pw->fd = -1; - hash_insert(db->files, pw->path, pw); + if (db->files != NULL) + hash_insert(db->files, pw->path, pw); return pw; } @@ -160,6 +166,7 @@ pw->fd = fd; pw->stamp = st.st_mtime; + pw->size = st.st_size; pw->pool = pool_alloconly_create("passwd_file", 10240);; pw->users = hash_create(default_pool, pw->pool, 100, @@ -199,6 +206,9 @@ pw->fd = -1; } + pw->first_missing_userdb_info = NULL; + pw->missing_userdb_info_count = 0; + if (pw->users != NULL) { hash_destroy(pw->users); pw->users = NULL; @@ -211,7 +221,8 @@ static void passwd_file_free(struct passwd_file *pw) { - hash_remove(pw->db->files, pw->path); + if (pw->db->files != NULL) + hash_remove(pw->db->files, pw->path); passwd_file_close(pw); i_free(pw->path); @@ -232,7 +243,7 @@ return FALSE; } - if (st.st_mtime != pw->stamp) { + if (st.st_mtime != pw->stamp || st.st_size != pw->size) { passwd_file_close(pw); return passwd_file_open(pw); } @@ -252,7 +263,7 @@ } struct db_passwd_file * -db_passwd_file_parse(const char *path, bool userdb, bool debug) +db_passwd_file_init(const char *path, bool userdb, bool debug) { struct db_passwd_file *db; const char *p; @@ -261,13 +272,7 @@ db = db_passwd_file_find(path); if (db != NULL) { db->refcount++; - if (userdb && !db->userdb) { - db->userdb = TRUE; - if (db->default_file != NULL) { - /* resync */ - db->default_file->stamp = 0; - } - } + db->userdb = TRUE; return db; } @@ -275,8 +280,6 @@ db->refcount = 1; db->userdb = userdb; db->debug = debug; - db->files = hash_create(default_pool, default_pool, 100, - str_hash, (hash_cmp_callback_t *)strcmp); for (p = path; *p != '\0'; p++) { if (*p == '%' && p[1] != '\0') { @@ -306,12 +309,12 @@ } db->path = i_strdup(path); - - if (!db->vars) { - /* no variables, open the file immediately */ + if (db->vars) { + db->files = hash_create(default_pool, default_pool, 100, + str_hash, + (hash_cmp_callback_t *)strcmp); + } else { db->default_file = passwd_file_new(db, path); - if (!passwd_file_open(db->default_file)) - exit(FATAL_DEFAULT); } db->next = passwd_files; @@ -319,6 +322,15 @@ return db; } +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)) + exit(FATAL_DEFAULT); + } +} + void db_passwd_file_unref(struct db_passwd_file **_db) { struct db_passwd_file *db = *_db; @@ -338,12 +350,18 @@ } } - iter = hash_iterate_init(db->files); - while (hash_iterate(iter, &key, &value)) - passwd_file_free(value); - hash_iterate_deinit(iter); + if (db->default_file != NULL) + passwd_file_free(db->default_file); + else { + iter = hash_iterate_init(db->files); + while (hash_iterate(iter, &key, &value)) { + struct passwd_file *file = value; - hash_destroy(db->files); + passwd_file_free(file); + } + hash_iterate_deinit(iter); + hash_destroy(db->files); + } i_free(db->path); i_free(db); }
--- a/src/auth/db-passwd-file.h Mon Feb 20 16:16:00 2006 +0200 +++ b/src/auth/db-passwd-file.h Mon Feb 20 18:31:46 2006 +0200 @@ -2,9 +2,6 @@ #define __DB_PASSWD_FILE_H struct passwd_user { - char *user_realm; /* user@realm */ - const char *realm; /* NULL or points to user_realm */ - uid_t uid; gid_t gid; @@ -19,9 +16,13 @@ char *path; time_t stamp; + off_t size; int fd; struct hash_table *users; + + const char *first_missing_userdb_info; + unsigned int missing_userdb_info_count; }; struct db_passwd_file { @@ -43,7 +44,8 @@ db_passwd_file_lookup(struct db_passwd_file *db, struct auth_request *request); struct db_passwd_file * -db_passwd_file_parse(const char *path, bool userdb, bool debug); +db_passwd_file_init(const char *path, bool userdb, bool debug); +void db_passwd_file_parse(struct db_passwd_file *db); void db_passwd_file_unref(struct db_passwd_file **db); #endif
--- a/src/auth/passdb-passwd-file.c Mon Feb 20 16:16:00 2006 +0200 +++ b/src/auth/passdb-passwd-file.c Mon Feb 20 18:31:46 2006 +0200 @@ -50,24 +50,26 @@ crypted_pass, scheme); } - t_push(); - str = t_str_new(512); - table = auth_request_get_var_expand_table(request, NULL); + if (pu->extra_fields != NULL) { + t_push(); + str = t_str_new(512); + table = auth_request_get_var_expand_table(request, NULL); - for (p = pu->extra_fields; *p != NULL; p++) { - value = strchr(*p, '='); - if (value != NULL) { - key = t_strdup_until(*p, value); - str_truncate(str, 0); - var_expand(str, value + 1, table); - value = str_c(str); - } else { - key = *p; - value = ""; + for (p = pu->extra_fields; *p != NULL; p++) { + value = strchr(*p, '='); + if (value != NULL) { + key = t_strdup_until(*p, value); + str_truncate(str, 0); + var_expand(str, value + 1, table); + value = str_c(str); + } else { + key = *p; + value = ""; + } + auth_request_set_field(request, key, value, NULL); } - auth_request_set_field(request, key, value, NULL); + t_pop(); } - t_pop(); ret = auth_request_password_verify(request, password, crypted_pass, scheme, "passwd-file"); @@ -100,8 +102,7 @@ } static struct passdb_module * -passwd_file_preinit(struct auth_passdb *auth_passdb, - const char *args __attr_unused__) +passwd_file_preinit(struct auth_passdb *auth_passdb, const char *args) { struct passwd_file_passdb_module *module; @@ -110,16 +111,18 @@ module->auth = auth_passdb->auth; module->module.cache_key = PASSWD_FILE_CACHE_KEY; module->module.default_pass_scheme = PASSWD_FILE_DEFAULT_SCHEME; + module->pwf = + db_passwd_file_init(args, FALSE, module->auth->verbose_debug); return &module->module; } -static void passwd_file_init(struct passdb_module *_module, const char *args) +static void passwd_file_init(struct passdb_module *_module, + const char *args __attr_unused__) { struct passwd_file_passdb_module *module = (struct passwd_file_passdb_module *)_module; - module->pwf = - db_passwd_file_parse(args, FALSE, module->auth->verbose_debug); + db_passwd_file_parse(module->pwf); } static void passwd_file_deinit(struct passdb_module *_module)
--- a/src/auth/userdb-passwd-file.c Mon Feb 20 16:16:00 2006 +0200 +++ b/src/auth/userdb-passwd-file.c Mon Feb 20 18:31:46 2006 +0200 @@ -43,48 +43,51 @@ if (pu->home != NULL) auth_stream_reply_add(reply, "home", pu->home); - t_push(); - str = t_str_new(512); - table = auth_request_get_var_expand_table(auth_request, NULL); + if (pu->extra_fields != NULL) { + t_push(); + str = t_str_new(512); + table = auth_request_get_var_expand_table(auth_request, NULL); - for (p = pu->extra_fields; *p != NULL; p++) { - if (strncmp(*p, "userdb_", 7) != 0) - continue; + for (p = pu->extra_fields; *p != NULL; p++) { + if (strncmp(*p, "userdb_", 7) != 0) + continue; - key = *p + 7; - value = strchr(key, '='); - if (value != NULL) { - key = t_strdup_until(key, value); - str_truncate(str, 0); - var_expand(str, value + 1, table); - value = str_c(str); + key = *p + 7; + value = strchr(key, '='); + if (value != NULL) { + key = t_strdup_until(key, value); + str_truncate(str, 0); + var_expand(str, value + 1, table); + value = str_c(str); + } + auth_stream_reply_add(reply, key, value); } - auth_stream_reply_add(reply, key, value); + t_pop(); } - t_pop(); callback(reply, auth_request); } static struct userdb_module * -passwd_file_preinit(struct auth_userdb *auth_userdb, - const char *args __attr_unused__) +passwd_file_preinit(struct auth_userdb *auth_userdb, const char *args) { struct passwd_file_userdb_module *module; module = p_new(auth_userdb->auth->pool, struct passwd_file_userdb_module, 1); module->auth = auth_userdb->auth; + module->pwf = + db_passwd_file_init(args, TRUE, module->auth->verbose_debug); return &module->module; } -static void passwd_file_init(struct userdb_module *_module, const char *args) +static void passwd_file_init(struct userdb_module *_module, + const char *args __attr_unused__) { struct passwd_file_userdb_module *module = (struct passwd_file_userdb_module *)_module; - module->pwf = - db_passwd_file_parse(args, TRUE, module->auth->verbose_debug); + db_passwd_file_parse(module->pwf); } static void passwd_file_deinit(struct userdb_module *_module)