]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_storage_service_next() now returns error string.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 27 May 2016 10:01:41 +0000 (13:01 +0300)
committerGitLab <gitlab@git.dovecot.net>
Mon, 30 May 2016 12:26:24 +0000 (15:26 +0300)
src/doveadm/doveadm-dsync.c
src/doveadm/doveadm-mail.c
src/lib-storage/mail-storage-service.c
src/lib-storage/mail-storage-service.h
src/lmtp/commands.c

index a82b715f3f3d25535ad6b08817dffd8672dc37a8..92dba0d839e126383cca85c26c529e31e98e76ef 100644 (file)
@@ -334,7 +334,7 @@ cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user,
        struct dsync_brain *brain2;
        struct mail_user *user2;
        struct setting_parser_context *set_parser;
-       const char *set_line, *location;
+       const char *set_line, *location, *error;
        bool brain1_running, brain2_running, changed1, changed2;
        int ret;
 
@@ -356,8 +356,10 @@ cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user,
        if (settings_parse_line(set_parser, set_line) < 0)
                i_unreached();
        ret = mail_storage_service_next(ctx->ctx.storage_service,
-                                       ctx->ctx.cur_service_user, &user2);
+                                       ctx->ctx.cur_service_user,
+                                       &user2, &error);
        if (ret < 0) {
+               i_error("Failed to initialize user: %s", error);
                ctx->ctx.exit_code = ret == -1 ? EX_TEMPFAIL : EX_CONFIG;
                return -1;
        }
index ca89a94c8cf2a12b9137f1fd5b381766250852a6..8cfe09537a474cf8004cdc720b7fd0e70eb36555 100644 (file)
@@ -388,9 +388,8 @@ doveadm_mail_next_user(struct doveadm_mail_cmd_context *ctx,
 
        ret = mail_storage_service_next(ctx->storage_service,
                                        ctx->cur_service_user,
-                                       &ctx->cur_mail_user);
+                                       &ctx->cur_mail_user, error_r);
        if (ret < 0) {
-               *error_r = "User init failed";
                mail_storage_service_user_free(&ctx->cur_service_user);
                return ret;
        }
index 062e8254d4554077add32d82a9e0b3b52c6d19df..1928a3d579f7833e8c48d6e772b01c715f8e6564 100644 (file)
@@ -1324,7 +1324,8 @@ void mail_storage_service_save_userdb_fields(struct mail_storage_service_ctx *ct
 static int
 mail_storage_service_next_real(struct mail_storage_service_ctx *ctx,
                               struct mail_storage_service_user *user,
-                              struct mail_user **mail_user_r)
+                              struct mail_user **mail_user_r,
+                              const char **error_r)
 {
        struct mail_storage_service_privileges priv;
        const char *error;
@@ -1335,13 +1336,12 @@ mail_storage_service_next_real(struct mail_storage_service_ctx *ctx,
                (user->flags & MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP) != 0;
        bool use_chroot;
 
-       if (service_parse_privileges(ctx, user, &priv, &error) < 0) {
-               i_error("%s", error);
+       if (service_parse_privileges(ctx, user, &priv, error_r) < 0)
                return -2;
-       }
 
        if (*priv.home != '/' && *priv.home != '\0') {
-               i_error("Relative home directory paths not supported: %s",
+               *error_r = t_strdup_printf(
+                       "Relative home directory paths not supported: %s",
                        priv.home);
                return -2;
        }
@@ -1389,7 +1389,8 @@ mail_storage_service_next_real(struct mail_storage_service_ctx *ctx,
                if (service_drop_privileges(user, &priv,
                                            disallow_root, temp_priv_drop,
                                            FALSE, &error) < 0) {
-                       i_error("Couldn't drop privileges: %s", error);
+                       *error_r = t_strdup_printf(
+                               "Couldn't drop privileges: %s", error);
                        return -1;
                }
                if (!temp_priv_drop ||
@@ -1402,16 +1403,15 @@ mail_storage_service_next_real(struct mail_storage_service_ctx *ctx,
        module_dir_init(mail_storage_service_modules);
 
        if (mail_storage_service_init_post(ctx, user, &priv,
-                                          mail_user_r, &error) < 0) {
-               i_error("User initialization failed: %s", error);
+                                          mail_user_r, error_r) < 0)
                return -2;
-       }
        return 0;
 }
 
 int mail_storage_service_next(struct mail_storage_service_ctx *ctx,
                              struct mail_storage_service_user *user,
-                             struct mail_user **mail_user_r)
+                             struct mail_user **mail_user_r,
+                             const char **error_r)
 {
        char *old_log_prefix = i_strdup(i_get_failure_prefix());
        int ret;
@@ -1419,7 +1419,7 @@ int mail_storage_service_next(struct mail_storage_service_ctx *ctx,
        mail_storage_service_set_log_prefix(ctx, user->user_set, user,
                                            &user->input, NULL);
        i_set_failure_prefix("%s", old_log_prefix);
-       ret = mail_storage_service_next_real(ctx, user, mail_user_r);
+       ret = mail_storage_service_next_real(ctx, user, mail_user_r, error_r);
        if ((user->flags & MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT) != 0)
                i_set_failure_prefix("%s", old_log_prefix);
        i_free(old_log_prefix);
@@ -1452,7 +1452,7 @@ int mail_storage_service_lookup_next(struct mail_storage_service_ctx *ctx,
        if (ret <= 0)
                return ret;
 
-       ret = mail_storage_service_next(ctx, user, mail_user_r);
+       ret = mail_storage_service_next(ctx, user, mail_user_r, error_r);
        if (ret < 0) {
                mail_storage_service_user_free(&user);
                *error_r = ret == -2 ? ERRSTR_INVALID_USER_SETTINGS :
index 318d528615be99a070261ce60d29a913f6870877..2f8f1ef8accd86390ddcd31f1dc1a65cb0f8e5d4 100644 (file)
@@ -98,7 +98,8 @@ void mail_storage_service_save_userdb_fields(struct mail_storage_service_ctx *ct
 /* Returns 0 if ok, -1 if fatal error, -2 if error is user-specific. */
 int mail_storage_service_next(struct mail_storage_service_ctx *ctx,
                              struct mail_storage_service_user *user,
-                             struct mail_user **mail_user_r);
+                             struct mail_user **mail_user_r,
+                             const char **error_r);
 void mail_storage_service_restrict_setenv(struct mail_storage_service_ctx *ctx,
                                          struct mail_storage_service_user *user);
 /* Combine lookup() and next() into one call. */
index 49abcafd616345e1a14a899c0cbdc21e01983d47..9211cc93b5421e01b0d22556d299d7d13952242d 100644 (file)
@@ -584,9 +584,11 @@ lmtp_rcpt_to_is_over_quota(struct client *client,
                return 0;
 
        ret = mail_storage_service_next(storage_service,
-                                       rcpt->service_user, &user);
-       if (ret < 0)
+                                       rcpt->service_user, &user, &errstr);
+       if (ret < 0) {
+               i_error("Failed to initialize user %s: %s", rcpt->address, errstr);
                return -1;
+       }
 
        ns = mail_namespace_find_inbox(user->namespaces);
        box = mailbox_alloc(ns->list, "INBOX", 0);
@@ -830,7 +832,8 @@ client_deliver(struct client *client, const struct mail_recipient *rcpt,
        client_state_set(client, "DATA", username);
        i_set_failure_prefix("lmtp(%s, %s): ", my_pid, username);
        if (mail_storage_service_next(storage_service, rcpt->service_user,
-                                     &client->state.dest_user) < 0) {
+                                     &client->state.dest_user, &error) < 0) {
+               i_error("Failed to initialize user: %s", error);
                client_send_line(client, ERRSTR_TEMP_MAILBOX_FAIL,
                                 rcpt->address);
                return -1;