(changeuser): check that setuid' and
setgid' succeeded.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4812 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -8,17 +8,27 @@
|
|||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dropcopy: Make a temporary copy of the user's mail drop and
|
* Run as the user in `pwd'
|
||||||
* save a stream pointer for it.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
int
|
||||||
changeuser(POP *p, struct passwd *pwd)
|
changeuser(POP *p, struct passwd *pwd)
|
||||||
{
|
{
|
||||||
/* Now we run as the user. */
|
if(setuid(pwd->pw_uid) < 0) {
|
||||||
if (pwd) {
|
pop_log (p, POP_PRIORITY,
|
||||||
setuid(pwd->pw_uid);
|
"Unable to change to uid %u: %s",
|
||||||
setgid(pwd->pw_gid);
|
(unsigned)pwd->pw_uid,
|
||||||
|
strerror(errno));
|
||||||
|
return pop_msg (p, POP_FAILURE,
|
||||||
|
"Unable to change uid");
|
||||||
|
}
|
||||||
|
if(setgid(pwd->pw_gid) < 0) {
|
||||||
|
pop_log (p, POP_PRIORITY,
|
||||||
|
"Unable to change to gid %u: %s",
|
||||||
|
(unsigned)pwd->pw_gid,
|
||||||
|
strerror(errno));
|
||||||
|
return pop_msg (p, POP_FAILURE,
|
||||||
|
"Unable to change gid");
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if(p->debug)
|
if(p->debug)
|
||||||
@@ -26,8 +36,14 @@ changeuser(POP *p, struct passwd *pwd)
|
|||||||
(unsigned)getuid(),
|
(unsigned)getuid(),
|
||||||
(unsigned)getgid());
|
(unsigned)getgid());
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
return POP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* dropcopy: Make a temporary copy of the user's mail drop and
|
||||||
|
* save a stream pointer for it.
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
pop_dropcopy(POP *p, struct passwd *pwp)
|
pop_dropcopy(POP *p, struct passwd *pwp)
|
||||||
{
|
{
|
||||||
@@ -41,6 +57,7 @@ pop_dropcopy(POP *p, struct passwd *pwp)
|
|||||||
long offset; /* Old/New boundary */
|
long offset; /* Old/New boundary */
|
||||||
int nchar; /* Bytes written/read */
|
int nchar; /* Bytes written/read */
|
||||||
int tf_fd; /* fd for temp file */
|
int tf_fd; /* fd for temp file */
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Create a temporary maildrop into which to copy the updated maildrop */
|
/* Create a temporary maildrop into which to copy the updated maildrop */
|
||||||
snprintf(p->temp_drop, sizeof(p->temp_drop), POP_DROP,p->user);
|
snprintf(p->temp_drop, sizeof(p->temp_drop), POP_DROP,p->user);
|
||||||
@@ -67,10 +84,8 @@ pop_dropcopy(POP *p, struct passwd *pwp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now give this file to the user */
|
/* Now give this file to the user */
|
||||||
if (pwp) {
|
chown(template, pwp->pw_uid, pwp->pw_gid);
|
||||||
chown(template,pwp->pw_uid, pwp->pw_gid);
|
chmod(template, 0600);
|
||||||
}
|
|
||||||
chmod(template,0600);
|
|
||||||
|
|
||||||
/* Now link this file to the temporary maildrop. If this fails it
|
/* Now link this file to the temporary maildrop. If this fails it
|
||||||
* is probably because the temporary maildrop already exists. If so,
|
* is probably because the temporary maildrop already exists. If so,
|
||||||
@@ -81,7 +96,9 @@ pop_dropcopy(POP *p, struct passwd *pwp)
|
|||||||
fclose(tf);
|
fclose(tf);
|
||||||
unlink(template);
|
unlink(template);
|
||||||
|
|
||||||
changeuser(p, pwp);
|
ret = changeuser(p, pwp);
|
||||||
|
if (ret != POP_SUCCESS)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* Open for append, this solves the crash recovery problem */
|
/* Open for append, this solves the crash recovery problem */
|
||||||
if ((dfd = open(p->temp_drop,O_RDWR|O_APPEND|O_CREAT,0600)) == -1){
|
if ((dfd = open(p->temp_drop,O_RDWR|O_APPEND|O_CREAT,0600)) == -1){
|
||||||
|
Reference in New Issue
Block a user