Skip to content

Commit

Permalink
lib-storage: mail_storage_service_next() now returns error string.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed May 30, 2016
1 parent 6dc2060 commit 61d3fd1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
6 changes: 4 additions & 2 deletions src/doveadm/doveadm-dsync.c
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/doveadm/doveadm-mail.c
Expand Up @@ -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;
}
Expand Down
24 changes: 12 additions & 12 deletions src/lib-storage/mail-storage-service.c
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 ||
Expand All @@ -1402,24 +1403,23 @@ 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;

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);
Expand Down Expand Up @@ -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 :
Expand Down
3 changes: 2 additions & 1 deletion src/lib-storage/mail-storage-service.h
Expand Up @@ -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. */
Expand Down
9 changes: 6 additions & 3 deletions src/lmtp/commands.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 61d3fd1

Please sign in to comment.