Commit 291db85e 291db85eaf2426cd8fbb240171b4d9921be78cd9 by Sergey Poznyakoff

Maidag: avoid using auth_by_uid when delivering message.

When delivering message, the library may need to know the email
address of the user on behalf of whom maidag is called. In particular,
that happens when using the vacation extension.  In that case the
library would construct the email by concatenating user name, obtained
as a result of mu_get_auth_by_uid, and current domain name.  Avoid
this by remembering email address the message is being delivered to.

* libmailutils/base/usremail.c (mu_set_user_email): NULL
argument clears email.
(mu_get_user_email): Use EUID instead of UID.
* maidag/deliver.c (do_delivery): Set user email prior to
delivery.
* maidag/maidag.c (default_domain): New variable.
(maidag_cfg_param): New setting "domain".
* maidag/maidag.h (default_domain): New extern.
1 parent 9ae85910
......@@ -46,6 +46,13 @@ mu_set_user_email (const char *candidate)
size_t emailno = 0;
char *email = NULL;
const char *domain = NULL;
if (!candidate)
{
free (mu_user_email);
mu_user_email = NULL;
return 0;
}
if ((err = mu_address_create (&addr, candidate)) != 0)
return err;
......@@ -62,8 +69,7 @@ mu_set_user_email (const char *candidate)
if ((err = mu_address_aget_email (addr, 1, &email)) != 0)
goto cleanup;
if (mu_user_email)
free (mu_user_email);
free (mu_user_email);
mu_user_email = email;
......@@ -81,16 +87,18 @@ static char *mu_user_email_domain = 0;
int
mu_set_user_email_domain (const char *domain)
{
char *d = NULL;
char *d;
if (!domain)
return EINVAL;
d = strdup (domain);
if (!d)
return ENOMEM;
if (domain)
{
d = strdup (domain);
if (!d)
return ENOMEM;
}
else
d = NULL;
if (mu_user_email_domain)
free (mu_user_email_domain);
......@@ -154,7 +162,7 @@ mu_get_user_email (const char *name)
if (!name)
{
struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
struct mu_auth_data *auth = mu_get_auth_by_uid (geteuid ());
if (!auth)
{
errno = EINVAL;
......
......@@ -271,6 +271,8 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
mu_mailbox_t mbox;
int status;
mu_set_user_email_domain (default_domain);
if (name && !is_remote_url (url))
{
auth = mu_get_auth_by_name (name);
......@@ -283,6 +285,10 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
return EX_NOUSER;
}
status = mu_set_user_email (name);
if (status)
mu_error (_("%s: invalid email: %s"), name, mu_strerror (status));
if (current_uid)
auth->change_uid = 0;
......@@ -314,6 +320,8 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
return exit_code = EX_TEMPFAIL;
}
}
else
mu_set_user_email (NULL);
if (!url)
{
......
......@@ -29,7 +29,7 @@ char *quotadbname = NULL; /* Name of mailbox quota database */
char *quota_query = NULL; /* SQL query to retrieve mailbox quota */
char *sender_address = NULL;
char *default_domain;
mu_script_t script_handler;
mu_list_t script_list;
......@@ -450,6 +450,8 @@ struct mu_cfg_param maidag_cfg_param[] = {
{ "forward-file-checks", mu_cfg_callback, NULL, 0, cb_forward_file_checks,
N_("Configure safety checks for the forward file."),
N_("arg: list") },
{ "domain", mu_cfg_string, &default_domain, 0, NULL,
N_("Default email domain") },
/* LMTP support */
{ "group", mu_cfg_callback, &lmtp_groups, 0, cb_group,
N_("In LMTP mode, retain these supplementary groups."),
......
......@@ -127,7 +127,8 @@ extern char *quota_query;
extern char *forward_file;
extern int forward_file_checks;
extern char *sender_address;
extern char *sender_address;
extern char *default_domain;
extern mu_list_t script_list;
extern char *message_id_header;
extern int sieve_debug_flags;
......