/[mailutils]/mailutils/mail.local/main.c
ViewVC logotype

Diff of /mailutils/mail.local/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by gray, Sun Nov 3 12:50:32 2002 UTC revision 1.20 by gray, Mon Nov 4 17:36:52 2002 UTC
# Line 29  int lock_timeout = 300; Line 29  int lock_timeout = 300;
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);
# Line 257  close_fds () Line 256  close_fds ()
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)
# Line 279  FILE * Line 288  FILE *
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);
# Line 370  deliver (FILE *fp, char *name) Line 380  deliver (FILE *fp, char *name)
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      {      {
# Line 387  deliver (FILE *fp, char *name) Line 396  deliver (FILE *fp, char *name)
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      {      {
# Line 457  deliver (FILE *fp, char *name) Line 466  deliver (FILE *fp, char *name)
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;
# Line 478  deliver (FILE *fp, char *name) Line 487  deliver (FILE *fp, char *name)
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)

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26