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
...@@ -47,6 +47,13 @@ mu_set_user_email (const char *candidate) ...@@ -47,6 +47,13 @@ mu_set_user_email (const char *candidate)
47 char *email = NULL; 47 char *email = NULL;
48 const char *domain = NULL; 48 const char *domain = NULL;
49 49
50 if (!candidate)
51 {
52 free (mu_user_email);
53 mu_user_email = NULL;
54 return 0;
55 }
56
50 if ((err = mu_address_create (&addr, candidate)) != 0) 57 if ((err = mu_address_create (&addr, candidate)) != 0)
51 return err; 58 return err;
52 59
...@@ -62,7 +69,6 @@ mu_set_user_email (const char *candidate) ...@@ -62,7 +69,6 @@ mu_set_user_email (const char *candidate)
62 if ((err = mu_address_aget_email (addr, 1, &email)) != 0) 69 if ((err = mu_address_aget_email (addr, 1, &email)) != 0)
63 goto cleanup; 70 goto cleanup;
64 71
65 if (mu_user_email)
66 free (mu_user_email); 72 free (mu_user_email);
67 73
68 mu_user_email = email; 74 mu_user_email = email;
...@@ -81,15 +87,17 @@ static char *mu_user_email_domain = 0; ...@@ -81,15 +87,17 @@ static char *mu_user_email_domain = 0;
81 int 87 int
82 mu_set_user_email_domain (const char *domain) 88 mu_set_user_email_domain (const char *domain)
83 { 89 {
84 char *d = NULL; 90 char *d;
85
86 if (!domain)
87 return EINVAL;
88 91
92 if (domain)
93 {
89 d = strdup (domain); 94 d = strdup (domain);
90 95
91 if (!d) 96 if (!d)
92 return ENOMEM; 97 return ENOMEM;
98 }
99 else
100 d = NULL;
93 101
94 if (mu_user_email_domain) 102 if (mu_user_email_domain)
95 free (mu_user_email_domain); 103 free (mu_user_email_domain);
...@@ -154,7 +162,7 @@ mu_get_user_email (const char *name) ...@@ -154,7 +162,7 @@ mu_get_user_email (const char *name)
154 162
155 if (!name) 163 if (!name)
156 { 164 {
157 struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ()); 165 struct mu_auth_data *auth = mu_get_auth_by_uid (geteuid ());
158 if (!auth) 166 if (!auth)
159 { 167 {
160 errno = EINVAL; 168 errno = EINVAL;
......
...@@ -271,6 +271,8 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp) ...@@ -271,6 +271,8 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
271 mu_mailbox_t mbox; 271 mu_mailbox_t mbox;
272 int status; 272 int status;
273 273
274 mu_set_user_email_domain (default_domain);
275
274 if (name && !is_remote_url (url)) 276 if (name && !is_remote_url (url))
275 { 277 {
276 auth = mu_get_auth_by_name (name); 278 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) ...@@ -283,6 +285,10 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
283 return EX_NOUSER; 285 return EX_NOUSER;
284 } 286 }
285 287
288 status = mu_set_user_email (name);
289 if (status)
290 mu_error (_("%s: invalid email: %s"), name, mu_strerror (status));
291
286 if (current_uid) 292 if (current_uid)
287 auth->change_uid = 0; 293 auth->change_uid = 0;
288 294
...@@ -314,6 +320,8 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp) ...@@ -314,6 +320,8 @@ do_delivery (mu_url_t url, mu_message_t msg, const char *name, char **errp)
314 return exit_code = EX_TEMPFAIL; 320 return exit_code = EX_TEMPFAIL;
315 } 321 }
316 } 322 }
323 else
324 mu_set_user_email (NULL);
317 325
318 if (!url) 326 if (!url)
319 { 327 {
......
...@@ -29,7 +29,7 @@ char *quotadbname = NULL; /* Name of mailbox quota database */ ...@@ -29,7 +29,7 @@ char *quotadbname = NULL; /* Name of mailbox quota database */
29 char *quota_query = NULL; /* SQL query to retrieve mailbox quota */ 29 char *quota_query = NULL; /* SQL query to retrieve mailbox quota */
30 30
31 char *sender_address = NULL; 31 char *sender_address = NULL;
32 32 char *default_domain;
33 mu_script_t script_handler; 33 mu_script_t script_handler;
34 34
35 mu_list_t script_list; 35 mu_list_t script_list;
...@@ -450,6 +450,8 @@ struct mu_cfg_param maidag_cfg_param[] = { ...@@ -450,6 +450,8 @@ struct mu_cfg_param maidag_cfg_param[] = {
450 { "forward-file-checks", mu_cfg_callback, NULL, 0, cb_forward_file_checks, 450 { "forward-file-checks", mu_cfg_callback, NULL, 0, cb_forward_file_checks,
451 N_("Configure safety checks for the forward file."), 451 N_("Configure safety checks for the forward file."),
452 N_("arg: list") }, 452 N_("arg: list") },
453 { "domain", mu_cfg_string, &default_domain, 0, NULL,
454 N_("Default email domain") },
453 /* LMTP support */ 455 /* LMTP support */
454 { "group", mu_cfg_callback, &lmtp_groups, 0, cb_group, 456 { "group", mu_cfg_callback, &lmtp_groups, 0, cb_group,
455 N_("In LMTP mode, retain these supplementary groups."), 457 N_("In LMTP mode, retain these supplementary groups."),
......
...@@ -128,6 +128,7 @@ extern char *forward_file; ...@@ -128,6 +128,7 @@ extern char *forward_file;
128 extern int forward_file_checks; 128 extern int forward_file_checks;
129 129
130 extern char *sender_address; 130 extern char *sender_address;
131 extern char *default_domain;
131 extern mu_list_t script_list; 132 extern mu_list_t script_list;
132 extern char *message_id_header; 133 extern char *message_id_header;
133 extern int sieve_debug_flags; 134 extern int sieve_debug_flags;
......