]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: If userdb returns chdir extra field, chdir() there instead of home
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Jul 2017 13:37:42 +0000 (16:37 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 25 Jul 2017 15:14:52 +0000 (18:14 +0300)
This can avoid unnecessary home directory accesses if indexes are stored
outside the home and there's no other reason to chdir() to home.

src/lib-storage/mail-storage-service.c

index 590deeeb7455125cab3c9faadd44146b6d116d6d..edfc6dd7c274cde8d5017554e1ad27052c148759 100644 (file)
@@ -80,6 +80,7 @@ struct mail_storage_service_user {
        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 @@ user_reply_handle(struct mail_storage_service_ctx *ctx,
                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 @@ mail_storage_service_init_post(struct mail_storage_service_ctx *ctx,
                   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");