summaryrefslogtreecommitdiff
path: root/sys/kern/kern_prot.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-01-30 03:29:50 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-01-30 03:29:50 +0000
commite9389a44941c88aa9f36b0eb98cb77abc32542cf (patch)
treee61849abc74c49a8d331c1f43c57da45b0d5f0e5 /sys/kern/kern_prot.c
parent2caf64284c4778676d10a14338c02351b9774fe6 (diff)
Bring back setreuid(2) and setregid(2) as first class syscalls
(but still implemented via setres[ug]id(2)). Basically this just moves them from COMPAT_43 into kern_prot.c. Also fixes a typo in my old implementation. The userland portion will follow in a few days. deraadt@ OK
Diffstat (limited to 'sys/kern/kern_prot.c')
-rw-r--r--sys/kern/kern_prot.c68
1 files changed, 67 insertions, 1 deletions
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 69b0fc2d62e..6795de25359 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_prot.c,v 1.22 2002/10/30 20:02:58 millert Exp $ */
+/* $OpenBSD: kern_prot.c,v 1.23 2003/01/30 03:29:49 millert Exp $ */
/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */
/*
@@ -532,6 +532,72 @@ sys_setresgid(p, v, retval)
/* ARGSUSED */
int
+sys_setregid(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct sys_setregid_args /* {
+ syscallarg(gid_t) rgid;
+ syscallarg(gid_t) egid;
+ } */ *uap = v;
+ struct pcred *pc = p->p_cred;
+ struct sys_setresgid_args sresgidargs;
+ gid_t rgid, egid;
+
+ rgid = SCARG(&sresgidargs, rgid) = SCARG(uap, rgid);
+ egid = SCARG(&sresgidargs, egid) = SCARG(uap, egid);
+
+ /*
+ * The saved gid presents a bit of a dilemma, as it did not
+ * exist when setregid(2) was conceived. We only set the saved
+ * gid when the real gid is specified and either its value would
+ * change, or where the saved and effective gids are different.
+ */
+ if (rgid != (gid_t)-1 && (rgid != pc->p_rgid ||
+ pc->p_svgid != (egid != (gid_t)-1 ? egid : pc->pc_ucred->cr_gid)))
+ SCARG(&sresgidargs, sgid) = rgid;
+ else
+ SCARG(&sresgidargs, sgid) = (gid_t)-1;
+
+ return (sys_setresgid(p, &sresgidargs, retval));
+}
+
+/* ARGSUSED */
+int
+sys_setreuid(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct sys_setreuid_args /* {
+ syscallarg(uid_t) ruid;
+ syscallarg(uid_t) euid;
+ } */ *uap = v;
+ struct pcred *pc = p->p_cred;
+ struct sys_setresuid_args sresuidargs;
+ uid_t ruid, euid;
+
+ ruid = SCARG(&sresuidargs, ruid) = SCARG(uap, ruid);
+ euid = SCARG(&sresuidargs, euid) = SCARG(uap, euid);
+
+ /*
+ * The saved uid presents a bit of a dilemma, as it did not
+ * exist when setreuid(2) was conceived. We only set the saved
+ * uid when the real uid is specified and either its value would
+ * change, or where the saved and effective uids are different.
+ */
+ if (ruid != (uid_t)-1 && (ruid != pc->p_ruid ||
+ pc->p_svuid != (euid != (uid_t)-1 ? euid : pc->pc_ucred->cr_uid)))
+ SCARG(&sresuidargs, suid) = ruid;
+ else
+ SCARG(&sresuidargs, suid) = (uid_t)-1;
+
+ return (sys_setresuid(p, &sresuidargs, retval));
+}
+
+/* ARGSUSED */
+int
sys_setuid(p, v, retval)
struct proc *p;
void *v;