aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>1995-04-29 11:46:15 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>1995-04-29 11:46:15 +0000
commit2c3be6c34e36df27dd9237c804784b278c4d8d31 (patch)
treea4b81eff628e63948d43e96e7bfcd610c0d9c5e6 /sys
parentbcac5617610e6e964658ee966421c5a1dc5f46f9 (diff)
downloadsrc-2c3be6c34e36df27dd9237c804784b278c4d8d31.tar.gz
src-2c3be6c34e36df27dd9237c804784b278c4d8d31.zip
set[ug]id(): call suser() only when neccesarry
Submitted by: bde
Notes
Notes: svn path=/head/; revision=8162
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_prot.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 814d06c8adeb..200d73195fbf 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_prot.c 8.6 (Berkeley) 1/21/94
- * $Id: kern_prot.c,v 1.9 1995/04/28 17:00:27 ache Exp $
+ * $Id: kern_prot.c,v 1.10 1995/04/28 18:17:29 ache Exp $
*/
/*
@@ -261,24 +261,24 @@ setuid(p, uap, retval)
int error;
uid = uap->uid;
- error = suser(pc->pc_ucred, &p->p_acflag);
- if (uid != pc->p_ruid && uid != pc->p_svuid && error)
+ if (uid != pc->p_ruid && uid != pc->p_svuid &&
+ (error = suser(pc->pc_ucred, &p->p_acflag)))
return (error);
/*
* Everything's okay, do it.
* Transfer proc count to new user.
* Copy credentials so other references do not see our changes.
*/
- if (!error && uid != pc->p_ruid) {
+ if (pc->pc_ucred->cr_uid == 0 && uid != pc->p_ruid) {
(void)chgproccnt(pc->p_ruid, -1);
(void)chgproccnt(uid, 1);
}
pc->pc_ucred = crcopy(pc->pc_ucred);
- pc->pc_ucred->cr_uid = uid;
- if (!error) {
+ if (pc->pc_ucred->cr_uid == 0) {
pc->p_ruid = uid;
pc->p_svuid = uid;
}
+ pc->pc_ucred->cr_uid = uid;
p->p_flag |= P_SUGID;
return (0);
}
@@ -326,12 +326,12 @@ setgid(p, uap, retval)
int error;
gid = uap->gid;
- error = suser(pc->pc_ucred, &p->p_acflag);
- if (gid != pc->p_rgid && gid != pc->p_svgid && error)
+ if (gid != pc->p_rgid && gid != pc->p_svgid &&
+ (error = suser(pc->pc_ucred, &p->p_acflag)))
return (error);
pc->pc_ucred = crcopy(pc->pc_ucred);
pc->pc_ucred->cr_groups[0] = gid;
- if (!error) {
+ if (pc->pc_ucred->cr_uid == 0) {
pc->p_rgid = gid;
pc->p_svgid = gid;
}