From: Timo Sirainen Date: Fri, 27 May 2016 10:01:41 +0000 (+0300) Subject: lib-storage: mail_storage_service_next() now returns error string. X-Git-Tag: 2.3.0.rc1~3625 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=61d3fd14828b68d789f3df73d1dbed56e37b7931;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: mail_storage_service_next() now returns error string. --- diff --git a/src/doveadm/doveadm-dsync.c b/src/doveadm/doveadm-dsync.c index a82b715f3f..92dba0d839 100644 --- a/src/doveadm/doveadm-dsync.c +++ b/src/doveadm/doveadm-dsync.c @@ -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; } diff --git a/src/doveadm/doveadm-mail.c b/src/doveadm/doveadm-mail.c index ca89a94c8c..8cfe09537a 100644 --- a/src/doveadm/doveadm-mail.c +++ b/src/doveadm/doveadm-mail.c @@ -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; } diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index 062e8254d4..1928a3d579 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -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 : diff --git a/src/lib-storage/mail-storage-service.h b/src/lib-storage/mail-storage-service.h index 318d528615..2f8f1ef8ac 100644 --- a/src/lib-storage/mail-storage-service.h +++ b/src/lib-storage/mail-storage-service.h @@ -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. */ diff --git a/src/lmtp/commands.c b/src/lmtp/commands.c index 49abcafd61..9211cc93b5 100644 --- a/src/lmtp/commands.c +++ b/src/lmtp/commands.c @@ -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;