Allow to be run from console by a non-privileged user (useful with fetchmail)
Showing
1 changed file
with
32 additions
and
8 deletions
... | @@ -24,7 +24,7 @@ int ex_quota_tempfail; /* Return temporary failure if mailbox quota is | ... | @@ -24,7 +24,7 @@ int ex_quota_tempfail; /* Return temporary failure if mailbox quota is |
24 | exceeded. If this variable is not set, mail.local | 24 | exceeded. If this variable is not set, mail.local |
25 | will return "service unavailable" */ | 25 | will return "service unavailable" */ |
26 | int exit_code = EX_OK; /* Exit code to be used */ | 26 | int exit_code = EX_OK; /* Exit code to be used */ |
27 | uid_t uid; /* Current user name */ | 27 | uid_t uid; /* Current user id */ |
28 | char *quotadbname = NULL; /* Name of mailbox quota database */ | 28 | 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 | ||
... | @@ -333,9 +333,15 @@ main (int argc, char *argv[]) | ... | @@ -333,9 +333,15 @@ main (int argc, char *argv[]) |
333 | mu_sieve_argp_init (); | 333 | mu_sieve_argp_init (); |
334 | /* Parse command line */ | 334 | /* Parse command line */ |
335 | mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, NULL); | 335 | mu_argp_parse (&argp, &argc, &argv, 0, argp_capa, &arg_index, NULL); |
336 | |||
337 | uid = getuid (); | ||
338 | |||
339 | if (uid == 0) | ||
340 | { | ||
341 | openlog ("mail.local", LOG_PID, log_facility); | ||
342 | mu_error_set_print (mu_syslog_error_printer); | ||
343 | } | ||
336 | 344 | ||
337 | openlog ("mail.local", LOG_PID, log_facility); | ||
338 | mu_error_set_print (mu_syslog_error_printer); | ||
339 | if (debug_flags) | 345 | if (debug_flags) |
340 | { | 346 | { |
341 | int rc; | 347 | int rc; |
... | @@ -359,15 +365,31 @@ main (int argc, char *argv[]) | ... | @@ -359,15 +365,31 @@ main (int argc, char *argv[]) |
359 | } | 365 | } |
360 | } | 366 | } |
361 | 367 | ||
362 | uid = getuid (); | ||
363 | |||
364 | argc -= arg_index; | 368 | argc -= arg_index; |
365 | argv += arg_index; | 369 | argv += arg_index; |
366 | 370 | ||
367 | if (!argc) | 371 | if (!argc) |
368 | { | 372 | { |
369 | mu_error (_("Missing arguments. Try --help for more info.")); | 373 | if (uid) |
370 | return EX_USAGE; | 374 | { |
375 | static char *s_argv[2]; | ||
376 | struct mu_auth_data *auth = mu_get_auth_by_uid (uid); | ||
377 | |||
378 | if (!uid) | ||
379 | { | ||
380 | mu_error (_("Cannot get username")); | ||
381 | return EX_UNAVAILABLE; | ||
382 | } | ||
383 | |||
384 | s_argv[0] = auth->name; | ||
385 | argv = s_argv; | ||
386 | argc = 1; | ||
387 | } | ||
388 | else | ||
389 | { | ||
390 | mu_error (_("Missing arguments. Try --help for more info.")); | ||
391 | return EX_USAGE; | ||
392 | } | ||
371 | } | 393 | } |
372 | 394 | ||
373 | /* Register local mbox formats. */ | 395 | /* Register local mbox formats. */ |
... | @@ -663,7 +685,9 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -663,7 +685,9 @@ deliver (mu_mailbox_t imbx, char *name) |
663 | exit_code = EX_UNAVAILABLE; | 685 | exit_code = EX_UNAVAILABLE; |
664 | return; | 686 | return; |
665 | } | 687 | } |
666 | 688 | if (uid) | |
689 | auth->change_uid = 0; | ||
690 | |||
667 | if (!sieve_test (auth, imbx)) | 691 | if (!sieve_test (auth, imbx)) |
668 | { | 692 | { |
669 | exit_code = EX_OK; | 693 | exit_code = EX_OK; | ... | ... |
-
Please register or sign in to post a comment