(switch_user_id): Changed prototype to honour mu_auth_data->change_uid member.
Showing
3 changed files
with
21 additions
and
12 deletions
... | @@ -102,7 +102,7 @@ extern void setgroupquota __P((char *str)); | ... | @@ -102,7 +102,7 @@ extern void setgroupquota __P((char *str)); |
102 | extern int check_quota __P((char *name, size_t size, size_t *rest)); | 102 | extern int check_quota __P((char *name, size_t size, size_t *rest)); |
103 | 103 | ||
104 | int mda __P((FILE *fp, char *username)); | 104 | int mda __P((FILE *fp, char *username)); |
105 | int switch_user_id __P((uid_t uid)); | 105 | int switch_user_id __P((struct mu_auth_data *auth, int user)); |
106 | void mailer_err __P((char *fmt, ...)); | 106 | void mailer_err __P((char *fmt, ...)); |
107 | 107 | ||
108 | #ifdef WITH_GUILE | 108 | #ifdef WITH_GUILE | ... | ... |
... | @@ -29,7 +29,6 @@ int lock_timeout = 300; | ... | @@ -29,7 +29,6 @@ int lock_timeout = 300; |
29 | #define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE) | 29 | #define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE) |
30 | 30 | ||
31 | void close_fds (); | 31 | void close_fds (); |
32 | int switch_user_id (uid_t uid); | ||
33 | FILE *make_tmp (const char *from, char **tempfile); | 32 | FILE *make_tmp (const char *from, char **tempfile); |
34 | void deliver (FILE *fp, char *name); | 33 | void deliver (FILE *fp, char *name); |
35 | void guess_retval (int ec); | 34 | void guess_retval (int ec); |
... | @@ -257,9 +256,19 @@ close_fds () | ... | @@ -257,9 +256,19 @@ close_fds () |
257 | } | 256 | } |
258 | 257 | ||
259 | int | 258 | int |
260 | switch_user_id (uid_t uid) | 259 | switch_user_id (struct mu_auth_data *auth, int user) |
261 | { | 260 | { |
262 | int rc; | 261 | 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 | |||
263 | #if defined(HAVE_SETREUID) | 272 | #if defined(HAVE_SETREUID) |
264 | rc = setreuid (0, uid); | 273 | rc = setreuid (0, uid); |
265 | #elif defined(HAVE_SETRESUID) | 274 | #elif defined(HAVE_SETRESUID) |
... | @@ -279,13 +288,14 @@ FILE * | ... | @@ -279,13 +288,14 @@ FILE * |
279 | make_tmp (const char *from, char **tempfile) | 288 | make_tmp (const char *from, char **tempfile) |
280 | { | 289 | { |
281 | time_t t; | 290 | time_t t; |
282 | int fd = mu_tempfile (NULL, tempfile); | ||
283 | FILE *fp; | 291 | FILE *fp; |
284 | char *buf = NULL; | 292 | char *buf = NULL; |
285 | size_t n = 0; | 293 | size_t n = 0; |
286 | int line; | 294 | int line; |
287 | 295 | ||
288 | if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL) | 296 | *tempfile = mu_tempname (NULL); |
297 | fp = fopen (*tempfile, "w+"); | ||
298 | if (fp == NULL) | ||
289 | { | 299 | { |
290 | mailer_err ("unable to open temporary file"); | 300 | mailer_err ("unable to open temporary file"); |
291 | exit (exit_code); | 301 | exit (exit_code); |
... | @@ -370,7 +380,6 @@ deliver (FILE *fp, char *name) | ... | @@ -370,7 +380,6 @@ deliver (FILE *fp, char *name) |
370 | mailer_err ("Out of memory"); | 380 | mailer_err ("Out of memory"); |
371 | return; | 381 | return; |
372 | } | 382 | } |
373 | sprintf (path, "%s%s", mu_path_maildir, name); | ||
374 | 383 | ||
375 | if ((status = mailbox_create (&mbox, path)) != 0) | 384 | if ((status = mailbox_create (&mbox, path)) != 0) |
376 | { | 385 | { |
... | @@ -387,10 +396,10 @@ deliver (FILE *fp, char *name) | ... | @@ -387,10 +396,10 @@ deliver (FILE *fp, char *name) |
387 | /* Actually open the mailbox. Switch to the user's euid to make | 396 | /* Actually open the mailbox. Switch to the user's euid to make |
388 | sure the maildrop file will have right privileges, in case it | 397 | sure the maildrop file will have right privileges, in case it |
389 | will be created */ | 398 | will be created */ |
390 | if (switch_user_id (auth->uid)) | 399 | if (switch_user_id (auth, 1)) |
391 | return; | 400 | return; |
392 | status = mailbox_open (mbox, MU_STREAM_RDWR|MU_STREAM_CREAT); | 401 | status = mailbox_open (mbox, MU_STREAM_RDWR|MU_STREAM_CREAT); |
393 | if (switch_user_id (0)) | 402 | if (switch_user_id (auth, 0)) |
394 | return; | 403 | return; |
395 | if (status != 0) | 404 | if (status != 0) |
396 | { | 405 | { |
... | @@ -457,7 +466,7 @@ deliver (FILE *fp, char *name) | ... | @@ -457,7 +466,7 @@ deliver (FILE *fp, char *name) |
457 | } | 466 | } |
458 | #endif | 467 | #endif |
459 | 468 | ||
460 | if (!failed && switch_user_id (auth->uid) == 0) | 469 | if (!failed && switch_user_id (auth, 1) == 0) |
461 | { | 470 | { |
462 | off_t off = size; | 471 | off_t off = size; |
463 | size_t nwr; | 472 | size_t nwr; |
... | @@ -478,7 +487,7 @@ deliver (FILE *fp, char *name) | ... | @@ -478,7 +487,7 @@ deliver (FILE *fp, char *name) |
478 | off += nwr; | 487 | off += nwr; |
479 | } | 488 | } |
480 | free (buf); | 489 | free (buf); |
481 | switch_user_id (0); | 490 | switch_user_id (auth, 0); |
482 | } | 491 | } |
483 | 492 | ||
484 | if (!failed) | 493 | if (!failed) | ... | ... |
... | @@ -80,13 +80,13 @@ mda_switch_to_user (struct mda_data *md) | ... | @@ -80,13 +80,13 @@ mda_switch_to_user (struct mda_data *md) |
80 | 80 | ||
81 | if (auth) | 81 | if (auth) |
82 | { | 82 | { |
83 | switch_user_id (auth->uid); | 83 | switch_user_id (auth, 1); |
84 | chdir (auth->dir); | 84 | chdir (auth->dir); |
85 | mu_auth_data_free (auth); | 85 | mu_auth_data_free (auth); |
86 | } | 86 | } |
87 | else | 87 | else |
88 | { | 88 | { |
89 | switch_user_id (0); | 89 | switch_user_id (auth, 0); |
90 | chdir ("/"); | 90 | chdir ("/"); |
91 | } | 91 | } |
92 | } | 92 | } | ... | ... |
-
Please register or sign in to post a comment