From 540beaa79ef809753498086aa75a0c84af11cf1c Mon Sep 17 00:00:00 2001 From: Johan Danielsson Date: Thu, 23 Apr 1998 18:38:46 +0000 Subject: [PATCH] Move changing of uid to separate function. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4797 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/popper/pop_dropcopy.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/appl/popper/pop_dropcopy.c b/appl/popper/pop_dropcopy.c index 499ca7be8..84e7760b2 100644 --- a/appl/popper/pop_dropcopy.c +++ b/appl/popper/pop_dropcopy.c @@ -12,6 +12,22 @@ RCSID("$Id$"); * save a stream pointer for it. */ +void +changeuser(POP *p, struct passwd *pwd) +{ + /* Now we run as the user. */ + if (pwd) { + setuid(pwd->pw_uid); + setgid(pwd->pw_gid); + } +#ifdef DEBUG + if(p->debug) + pop_log(p, POP_DEBUG,"uid = %u, gid = %u", + (unsigned)getuid(), + (unsigned)getgid()); +#endif /* DEBUG */ +} + int pop_dropcopy(POP *p, struct passwd *pwp) { @@ -65,17 +81,7 @@ pop_dropcopy(POP *p, struct passwd *pwp) fclose(tf); unlink(template); - /* Now we run as the user. */ - if (pwp) { - setuid(pwp->pw_uid); - setgid(pwp->pw_gid); - } -#ifdef DEBUG - if(p->debug) - pop_log(p, POP_DEBUG,"uid = %u, gid = %u", - (unsigned)getuid(), - (unsigned)getgid()); -#endif /* DEBUG */ + changeuser(p, pwp); /* Open for append, this solves the crash recovery problem */ if ((dfd = open(p->temp_drop,O_RDWR|O_APPEND|O_CREAT,0600)) == -1){