From: Timo Sirainen Date: Fri, 20 Jan 2023 00:11:28 +0000 (+0200) Subject: lib-storage: Don't set home directory immediately when userdb lookup is disabled X-Git-Tag: 2.4.0~3115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f645a89d2b9a7894984e27c6a9196d0d84157205;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Don't set home directory immediately when userdb lookup is disabled This is going to be needed by the following change that creates shared users via service_user. Otherwise the shared users' home directory will be wrong. Do set home immediately if it's provided by mail_storage_service_input.userdb_fields. This will be used by the raw-storage user to set the home directory. Also update some comments explaining about how NULL works for home. --- diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index 855026e89c..cf4baba956 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -93,6 +93,7 @@ struct mail_storage_service_user { bool anonymous:1; bool admin:1; bool master_service_user_set:1; + bool home_from_userdb:1; }; struct module *mail_storage_service_modules = NULL; @@ -254,8 +255,10 @@ user_reply_handle(struct mail_storage_service_ctx *ctx, home = p + 2; } - if (home != NULL) + if (home != NULL) { set_keyval(ctx, user, "mail_home", home); + user->home_from_userdb = TRUE; + } if (chroot != NULL) { if (!validate_chroot(user->user_set, chroot)) { @@ -690,7 +693,11 @@ mail_storage_service_init_post(struct mail_storage_service_ctx *ctx, if (user->input.autocreated) mail_user->autocreated = TRUE; mail_storage_service_user_ref(user); - mail_user_set_home(mail_user, *home == '\0' ? NULL : home); + if (!user->input.no_userdb_lookup || user->home_from_userdb) { + /* userdb lookup is done. The (lack of) home directory is now + known. */ + mail_user_set_home(mail_user, *home == '\0' ? NULL : home); + } mail_user_set_vars(mail_user, service_name, &conn_data); mail_user->uid = priv->uid == (uid_t)-1 ? geteuid() : priv->uid; mail_user->gid = priv->gid == (gid_t)-1 ? getegid() : priv->gid; diff --git a/src/lib-storage/mail-user.h b/src/lib-storage/mail-user.h index 1bddfdb268..c65d52c8e7 100644 --- a/src/lib-storage/mail-user.h +++ b/src/lib-storage/mail-user.h @@ -161,9 +161,9 @@ int mail_user_var_expand(struct mail_user *user, const struct setting_parser_info *info, void *set, const char **error_r); -/* Specify the user's home directory. This should be called also when it's - known that the user doesn't have a home directory to avoid the internal - lookup. */ +/* Specify the user's home directory. This should be called also with home=NULL + when it's known that the user doesn't have a home directory to avoid the + internal lookup. */ void mail_user_set_home(struct mail_user *user, const char *home); /* Get the home directory for the user. Returns 1 if home directory looked up successfully, 0 if there is no home directory (either user doesn't exist or