diff options
author | 1996-08-01 05:26:01 +0000 | |
---|---|---|
committer | 1996-08-01 05:26:01 +0000 | |
commit | e063f9cddab2e0214ccbe135d8ab0218cb8b68b8 (patch) | |
tree | f611e291eecdfea6f00f04185370a47cc69c6021 | |
parent | Resolve import conflicts (diff) | |
download | wireguard-openbsd-e063f9cddab2e0214ccbe135d8ab0218cb8b68b8.tar.xz wireguard-openbsd-e063f9cddab2e0214ccbe135d8ab0218cb8b68b8.zip |
Implemented _POSIX_SAVED_IDS behaviour according to 1003.1-1990, with
allowed extension from Appendix B, section 4.2.2.
-rw-r--r-- | lib/libc/sys/setuid.2 | 18 | ||||
-rw-r--r-- | sys/kern/kern_prot.c | 33 | ||||
-rw-r--r-- | sys/sys/unistd.h | 10 |
3 files changed, 37 insertions, 24 deletions
diff --git a/lib/libc/sys/setuid.2 b/lib/libc/sys/setuid.2 index deca532b388..b271097c84b 100644 --- a/lib/libc/sys/setuid.2 +++ b/lib/libc/sys/setuid.2 @@ -62,8 +62,11 @@ user IDs and the saved set-user-ID of the current process to the specified value. The .Fn setuid -function is permitted if the specified ID is equal to the real user ID -of the process, or if the effective user ID is that of the super user. +function is permitted if the effective user ID is that of the super user, +or if the specified user ID is the same as the effective user ID. If +not, but the specified user ID is the same as the real user ID, +.Fn setuid +will set the effective user ID to the real user ID. .Pp The .Fn setgid @@ -73,8 +76,11 @@ group IDs and the saved set-group-ID of the current process to the specified value. The .Fn setgid -function is permitted if the specified ID is equal to the real group ID -of the process, or if the effective user ID is that of the super user. +function is permitted if the effective user ID is that of the super user, +or if the specified group ID is the same as the effective group ID. If +not, but the specified group ID is the same as the real group ID, +.Fn setgid +will set the effective group ID to the real group ID. .Pp The .Fn seteuid @@ -109,10 +115,10 @@ The and .Fn setgid functions are compliant with the -.St -p1003.1-88 +.St -p1003.1-90 specification with .Li _POSIX_SAVED_IDS -not defined. +defined, with the extensions allowed in section B.4.2.2. The .Fn seteuid and diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index f957ecbccb3..fe386801da0 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_prot.c,v 1.2 1996/03/03 17:19:52 niklas Exp $ */ +/* $OpenBSD: kern_prot.c,v 1.3 1996/08/01 05:26:02 tholo Exp $ */ /* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */ /* @@ -275,19 +275,29 @@ sys_setuid(p, v, retval) uid = SCARG(uap, uid); #endif if (uid != pc->p_ruid && + uid != pc->pc_ucred->cr_uid && (error = suser(pc->pc_ucred, &p->p_acflag))) return (error); /* * Everything's okay, do it. - * Transfer proc count to new user. + */ + if (uid == pc->pc_ucred->cr_uid || + suser(pc->pc_ucred, &p->p_acflag) == 0) { + /* + * Transfer proc count to new user. + */ + if (uid != pc->p_ruid) { + (void)chgproccnt(pc->p_ruid, -1); + (void)chgproccnt(uid, 1); + } + pc->p_ruid = uid; + pc->p_svuid = uid; + } + /* * Copy credentials so other references do not see our changes. */ - (void)chgproccnt(pc->p_ruid, -1); - (void)chgproccnt(uid, 1); pc->pc_ucred = crcopy(pc->pc_ucred); pc->pc_ucred->cr_uid = uid; - pc->p_ruid = uid; - pc->p_svuid = uid; p->p_flag |= P_SUGID; return (0); } @@ -343,12 +353,17 @@ sys_setgid(p, v, retval) #else gid = SCARG(uap, gid); #endif - if (gid != pc->p_rgid && (error = suser(pc->pc_ucred, &p->p_acflag))) + if (gid != pc->p_rgid && + gid != pc->pc_ucred->cr_gid && + (error = suser(pc->pc_ucred, &p->p_acflag))) return (error); + if (gid == pc->pc_ucred->cr_gid || + suser(pc->pc_ucred, &p->p_acflag) == 0) { + pc->p_rgid = gid; + pc->p_svgid = gid; + } pc->pc_ucred = crcopy(pc->pc_ucred); pc->pc_ucred->cr_gid = gid; - pc->p_rgid = gid; - pc->p_svgid = gid; /* ??? */ p->p_flag |= P_SUGID; return (0); } diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index ec861cea36d..2a58fdf7f49 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: unistd.h,v 1.2 1996/03/03 12:12:40 niklas Exp $ */ +/* $OpenBSD: unistd.h,v 1.3 1996/08/01 05:26:03 tholo Exp $ */ /* $NetBSD: unistd.h,v 1.10 1994/06/29 06:46:06 cgd Exp $ */ /* @@ -42,15 +42,7 @@ /* compile-time symbolic constants */ #define _POSIX_JOB_CONTROL /* implementation supports job control */ -/* - * Although we have saved user/group IDs, we do not use them in setuid - * as described in POSIX 1003.1, because the feature does not work for - * root. We use the saved IDs in seteuid/setegid, which are not currently - * part of the POSIX 1003.1 specification. - */ -#ifdef _NOT_AVAILABLE #define _POSIX_SAVED_IDS /* saved set-user-ID and set-group-ID */ -#endif #define _POSIX_VERSION 198808L #define _POSIX2_VERSION 199212L |