Mercurial > dovecot > core-2.2
changeset 22384:9a117c44073e
lib-storage: If userdb returns chdir extra field, chdir() there instead of home
This can avoid unnecessary home directory accesses if indexes are stored
outside the home and there's no other reason to chdir() to home.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Mon, 24 Jul 2017 16:37:42 +0300 |
parents | 0a22d391254f |
children | ae8fe0ac1f34 |
files | src/lib-storage/mail-storage-service.c |
diffstat | 1 files changed, 11 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-storage-service.c Mon Jul 24 16:36:45 2017 +0300 +++ b/src/lib-storage/mail-storage-service.c Mon Jul 24 16:37:42 2017 +0300 @@ -80,6 +80,7 @@ const char *log_prefix, *auth_token, *auth_user; const char *system_groups_user, *uid_source, *gid_source; + const char *chdir_path; const struct mail_user_settings *user_set; const struct setting_parser_info *user_info; struct setting_parser_context *set_parser; @@ -276,6 +277,8 @@ if (strncmp(line, "system_groups_user=", 19) == 0) { user->system_groups_user = p_strdup(user->pool, line + 19); + } else if (strncmp(line, "chdir=", 6) == 0) { + user->chdir_path = p_strdup(user->pool, line+6); } else if (strncmp(line, "nice=", 5) == 0) { #ifdef HAVE_SETPRIORITY int n; @@ -704,17 +707,20 @@ because the current directory may not be accessible after dropping privileges, and for example unlink_directory() requires ability to open the current directory. */ - if (home[0] == '\0') { + const char *chdir_path = user->chdir_path != NULL ? + user->chdir_path : home; + + if (chdir_path[0] == '\0') { if (chdir("/") < 0) i_error("chdir(/) failed: %m"); - } else if (chdir(home) < 0) { + } else if (chdir(chdir_path) < 0) { if (errno == EACCES) { i_error("%s", eacces_error_get("chdir", - t_strconcat(home, "/", NULL))); + t_strconcat(chdir_path, "/", NULL))); } else if (errno != ENOENT) - i_error("chdir(%s) failed: %m", home); + i_error("chdir(%s) failed: %m", chdir_path); else if (mail_set->mail_debug) - i_debug("Home dir not found: %s", home); + i_debug("Home dir not found: %s", chdir_path); if (chdir("/") < 0) i_error("chdir(/) failed: %m");