29 |
#define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE) |
#define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE) |
30 |
|
|
31 |
void close_fds (); |
void close_fds (); |
|
int switch_user_id (uid_t uid); |
|
32 |
FILE *make_tmp (const char *from, char **tempfile); |
FILE *make_tmp (const char *from, char **tempfile); |
33 |
void deliver (FILE *fp, char *name); |
void deliver (FILE *fp, char *name); |
34 |
void guess_retval (int ec); |
void guess_retval (int ec); |
256 |
} |
} |
257 |
|
|
258 |
int |
int |
259 |
switch_user_id (uid_t uid) |
switch_user_id (struct mu_auth_data *auth, int user) |
260 |
{ |
{ |
261 |
int rc; |
int rc; |
262 |
|
uid_t uid; |
263 |
|
|
264 |
|
if (auth->change_uid == 0) |
265 |
|
return 0; |
266 |
|
|
267 |
|
if (user) |
268 |
|
uid = auth->uid; |
269 |
|
else |
270 |
|
uid = 0; |
271 |
|
|
272 |
#if defined(HAVE_SETREUID) |
#if defined(HAVE_SETREUID) |
273 |
rc = setreuid (0, uid); |
rc = setreuid (0, uid); |
274 |
#elif defined(HAVE_SETRESUID) |
#elif defined(HAVE_SETRESUID) |
288 |
make_tmp (const char *from, char **tempfile) |
make_tmp (const char *from, char **tempfile) |
289 |
{ |
{ |
290 |
time_t t; |
time_t t; |
|
int fd = mu_tempfile (NULL, tempfile); |
|
291 |
FILE *fp; |
FILE *fp; |
292 |
char *buf = NULL; |
char *buf = NULL; |
293 |
size_t n = 0; |
size_t n = 0; |
294 |
int line; |
int line; |
295 |
|
|
296 |
if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL) |
*tempfile = mu_tempname (NULL); |
297 |
|
fp = fopen (*tempfile, "w+"); |
298 |
|
if (fp == NULL) |
299 |
{ |
{ |
300 |
mailer_err ("unable to open temporary file"); |
mailer_err ("unable to open temporary file"); |
301 |
exit (exit_code); |
exit (exit_code); |
380 |
mailer_err ("Out of memory"); |
mailer_err ("Out of memory"); |
381 |
return; |
return; |
382 |
} |
} |
|
sprintf (path, "%s%s", mu_path_maildir, name); |
|
383 |
|
|
384 |
if ((status = mailbox_create (&mbox, path)) != 0) |
if ((status = mailbox_create (&mbox, path)) != 0) |
385 |
{ |
{ |
396 |
/* Actually open the mailbox. Switch to the user's euid to make |
/* Actually open the mailbox. Switch to the user's euid to make |
397 |
sure the maildrop file will have right privileges, in case it |
sure the maildrop file will have right privileges, in case it |
398 |
will be created */ |
will be created */ |
399 |
if (switch_user_id (auth->uid)) |
if (switch_user_id (auth, 1)) |
400 |
return; |
return; |
401 |
status = mailbox_open (mbox, MU_STREAM_RDWR|MU_STREAM_CREAT); |
status = mailbox_open (mbox, MU_STREAM_RDWR|MU_STREAM_CREAT); |
402 |
if (switch_user_id (0)) |
if (switch_user_id (auth, 0)) |
403 |
return; |
return; |
404 |
if (status != 0) |
if (status != 0) |
405 |
{ |
{ |
466 |
} |
} |
467 |
#endif |
#endif |
468 |
|
|
469 |
if (!failed && switch_user_id (auth->uid) == 0) |
if (!failed && switch_user_id (auth, 1) == 0) |
470 |
{ |
{ |
471 |
off_t off = size; |
off_t off = size; |
472 |
size_t nwr; |
size_t nwr; |
487 |
off += nwr; |
off += nwr; |
488 |
} |
} |
489 |
free (buf); |
free (buf); |
490 |
switch_user_id (0); |
switch_user_id (auth, 0); |
491 |
} |
} |
492 |
|
|
493 |
if (!failed) |
if (!failed) |