summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-11-04 17:36:52 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-11-04 17:36:52 +0000
commitbb752c910c1af619c42aacce827fa485c50bcf47 (patch)
tree1823273d89ab2d2ad1ab571f05511aee343d8971
parentd11e29902e92221b239efffa670a4c346da52f9a (diff)
downloadmailutils-bb752c910c1af619c42aacce827fa485c50bcf47.tar.gz
mailutils-bb752c910c1af619c42aacce827fa485c50bcf47.tar.bz2
(switch_user_id): Changed prototype to honour mu_auth_data->change_uid member.
-rw-r--r--mail.local/mail.local.h2
-rw-r--r--mail.local/main.c27
-rw-r--r--mail.local/script.c4
3 files changed, 21 insertions, 12 deletions
diff --git a/mail.local/mail.local.h b/mail.local/mail.local.h
index dea6c2977..276a6ccf0 100644
--- a/mail.local/mail.local.h
+++ b/mail.local/mail.local.h
@@ -102,7 +102,7 @@ extern void setgroupquota __P((char *str));
extern int check_quota __P((char *name, size_t size, size_t *rest));
int mda __P((FILE *fp, char *username));
-int switch_user_id __P((uid_t uid));
+int switch_user_id __P((struct mu_auth_data *auth, int user));
void mailer_err __P((char *fmt, ...));
#ifdef WITH_GUILE
diff --git a/mail.local/main.c b/mail.local/main.c
index d661cd206..464f14d1b 100644
--- a/mail.local/main.c
+++ b/mail.local/main.c
@@ -29,7 +29,6 @@ int lock_timeout = 300;
#define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE)
void close_fds ();
-int switch_user_id (uid_t uid);
FILE *make_tmp (const char *from, char **tempfile);
void deliver (FILE *fp, char *name);
void guess_retval (int ec);
@@ -257,9 +256,19 @@ close_fds ()
}
int
-switch_user_id (uid_t uid)
+switch_user_id (struct mu_auth_data *auth, int user)
{
int rc;
+ uid_t uid;
+
+ if (auth->change_uid == 0)
+ return 0;
+
+ if (user)
+ uid = auth->uid;
+ else
+ uid = 0;
+
#if defined(HAVE_SETREUID)
rc = setreuid (0, uid);
#elif defined(HAVE_SETRESUID)
@@ -279,13 +288,14 @@ FILE *
make_tmp (const char *from, char **tempfile)
{
time_t t;
- int fd = mu_tempfile (NULL, tempfile);
FILE *fp;
char *buf = NULL;
size_t n = 0;
int line;
- if (fd == -1 || (fp = fdopen (fd, "w+")) == NULL)
+ *tempfile = mu_tempname (NULL);
+ fp = fopen (*tempfile, "w+");
+ if (fp == NULL)
{
mailer_err ("unable to open temporary file");
exit (exit_code);
@@ -370,7 +380,6 @@ deliver (FILE *fp, char *name)
mailer_err ("Out of memory");
return;
}
- sprintf (path, "%s%s", mu_path_maildir, name);
if ((status = mailbox_create (&mbox, path)) != 0)
{
@@ -387,10 +396,10 @@ deliver (FILE *fp, char *name)
/* Actually open the mailbox. Switch to the user's euid to make
sure the maildrop file will have right privileges, in case it
will be created */
- if (switch_user_id (auth->uid))
+ if (switch_user_id (auth, 1))
return;
status = mailbox_open (mbox, MU_STREAM_RDWR|MU_STREAM_CREAT);
- if (switch_user_id (0))
+ if (switch_user_id (auth, 0))
return;
if (status != 0)
{
@@ -457,7 +466,7 @@ deliver (FILE *fp, char *name)
}
#endif
- if (!failed && switch_user_id (auth->uid) == 0)
+ if (!failed && switch_user_id (auth, 1) == 0)
{
off_t off = size;
size_t nwr;
@@ -478,7 +487,7 @@ deliver (FILE *fp, char *name)
off += nwr;
}
free (buf);
- switch_user_id (0);
+ switch_user_id (auth, 0);
}
if (!failed)
diff --git a/mail.local/script.c b/mail.local/script.c
index c69966bea..621861bef 100644
--- a/mail.local/script.c
+++ b/mail.local/script.c
@@ -80,13 +80,13 @@ mda_switch_to_user (struct mda_data *md)
if (auth)
{
- switch_user_id (auth->uid);
+ switch_user_id (auth, 1);
chdir (auth->dir);
mu_auth_data_free (auth);
}
else
{
- switch_user_id (0);
+ switch_user_id (auth, 0);
chdir ("/");
}
}

Return to:

Send suggestions and report system problems to the System administrator.