diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-10-30 20:10:49 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-10-30 20:10:49 +0000 |
commit | 8f5206fef6e1f20fbd462a7a9b64ee338afbec7c (patch) | |
tree | 91706af7f0d189f67e01f31d99f5111000a11206 /sys/compat/linux/linux_misc.c | |
parent | cc75464191402fc7408d43c0c4dcb28f42101089 (diff) |
Now that we have [gs]etres[ug]id() as a native system call, use it
for HP-UX, FreeBSD, and Linux emulations. Note that Linux has two
versions of these system calls. One for 16bit uids and another for
32bit uids.
Diffstat (limited to 'sys/compat/linux/linux_misc.c')
-rw-r--r-- | sys/compat/linux/linux_misc.c | 229 |
1 files changed, 58 insertions, 171 deletions
diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 58b4910cbd5..3fa69f6bf15 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_misc.c,v 1.46 2002/10/28 03:39:30 fgsch Exp $ */ +/* $OpenBSD: linux_misc.c,v 1.47 2002/10/30 20:10:48 millert Exp $ */ /* $NetBSD: linux_misc.c,v 1.27 1996/05/20 01:59:21 fvdl Exp $ */ /* @@ -217,96 +217,85 @@ linux_sys_setresgid16(p, v, retval) register_t *retval; { struct linux_sys_setresgid16_args /* { - syscallarg(gid_t) rgid; - syscallarg(gid_t) egid; - syscallarg(gid_t) sgid; + syscallarg(u_int16_t) rgid; + syscallarg(u_int16_t) egid; + syscallarg(u_int16_t) sgid; } */ *uap = v; - struct pcred *pc = p->p_cred; - gid_t rgid, egid, sgid; - int error; + struct sys_setresgid_args nuap; + u_int16_t rgid, egid, sgid; rgid = SCARG(uap, rgid); + SCARG(&nuap, rgid) = (rgid == (u_int16_t)-1) ? (gid_t)-1 : rgid; egid = SCARG(uap, egid); + SCARG(&nuap, egid) = (egid == (u_int16_t)-1) ? (gid_t)-1 : egid; sgid = SCARG(uap, sgid); + SCARG(&nuap, sgid) = (sgid == (u_int16_t)-1) ? (gid_t)-1 : sgid; - /* - * Note: These checks are a little different than the OpenBSD - * setregid(2) call performs. This precisely follows the - * behavior of the Linux kernel. - */ - if (rgid != (gid_t)-1 && - rgid != pc->p_rgid && - rgid != pc->pc_ucred->cr_gid && - rgid != pc->p_svgid && - (error = suser(pc->pc_ucred, &p->p_acflag))) - return (error); + return sys_setresgid(p, &nuap, retval); +} - if (egid != (gid_t)-1 && - egid != pc->p_rgid && - egid != pc->pc_ucred->cr_gid && - egid != pc->p_svgid && - (error = suser(pc->pc_ucred, &p->p_acflag))) - return (error); +int +linux_sys_getresgid16(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct linux_sys_getresgid16_args /* { + syscallarg(u_int16_t *) rgid; + syscallarg(u_int16_t *) egid; + syscallarg(u_int16_t *) sgid; + } */ *uap = v; + struct sys_getresgid_args nuap; - if (sgid != (gid_t)-1 && - sgid != pc->p_rgid && - sgid != pc->pc_ucred->cr_gid && - sgid != pc->p_svgid && - (error = suser(pc->pc_ucred, &p->p_acflag))) - return (error); + SCARG(&nuap, rgid) = (gid_t *)SCARG(uap, rgid); + SCARG(&nuap, egid) = (gid_t *)SCARG(uap, egid); + SCARG(&nuap, sgid) = (gid_t *)SCARG(uap, sgid); - /* - * Now assign the real, effective, and saved GIDs. - * Note that Linux, unlike OpenBSD in setregid(2), does not - * set the saved UID in this call unless the user specifies - * it. - */ - if (rgid != (gid_t)-1) - pc->p_rgid = rgid; + return sys_getresgid(p, &nuap, retval); +} - if (egid != (gid_t)-1) { - pc->pc_ucred = crcopy(pc->pc_ucred); - pc->pc_ucred->cr_gid = egid; - } +int +linux_sys_setresuid16(p, v, retval) + struct proc *p; + void *v; + register_t *retval; +{ + struct linux_sys_setresuid16_args /* { + syscallarg(u_int16_t) ruid; + syscallarg(u_int16_t) euid; + syscallarg(u_int16_t) suid; + } */ *uap = v; + struct sys_setresuid_args nuap; + u_int16_t ruid, euid, suid; - if (sgid != (gid_t)-1) - pc->p_svgid = sgid; + ruid = SCARG(uap, ruid); + SCARG(&nuap, ruid) = (ruid == (u_int16_t)-1) ? (uid_t)-1 : ruid; + euid = SCARG(uap, euid); + SCARG(&nuap, euid) = (euid == (u_int16_t)-1) ? (uid_t)-1 : euid; + suid = SCARG(uap, suid); + SCARG(&nuap, suid) = (suid == (u_int16_t)-1) ? (uid_t)-1 : suid; - if (rgid != (gid_t)-1 && egid != (gid_t)-1 && sgid != (gid_t)-1) - p->p_flag |= P_SUGID; - return (0); + return sys_setresuid(p, &nuap, retval); } int -linux_sys_getresgid16(p, v, retval) +linux_sys_getresuid16(p, v, retval) struct proc *p; void *v; register_t *retval; { - struct linux_sys_getresgid16_args /* { - syscallarg(gid_t *) rgid; - syscallarg(gid_t *) egid; - syscallarg(gid_t *) sgid; + struct linux_sys_getresuid16_args /* { + syscallarg(u_int16_t *) ruid; + syscallarg(u_int16_t *) euid; + syscallarg(u_int16_t *) suid; } */ *uap = v; - struct pcred *pc = p->p_cred; - int error; - - /* - * Linux copies these values out to userspace like so: - * - * 1. Copy out rgid. - * 2. If that succeeds, copy out egid. - * 3. If both of those succeed, copy out sgid. - */ - if ((error = copyout(&pc->p_rgid, SCARG(uap, rgid), - sizeof(gid_t))) != 0) - return (error); + struct sys_getresuid_args nuap; - if ((error = copyout(&pc->pc_ucred->cr_uid, SCARG(uap, egid), - sizeof(gid_t))) != 0) - return (error); + SCARG(&nuap, ruid) = (uid_t *)SCARG(uap, ruid); + SCARG(&nuap, euid) = (uid_t *)SCARG(uap, euid); + SCARG(&nuap, suid) = (uid_t *)SCARG(uap, suid); - return (copyout(&pc->p_svgid, SCARG(uap, sgid), sizeof(gid_t))); + return sys_getresuid(p, &nuap, retval); } /* @@ -1344,108 +1333,6 @@ linux_sys___sysctl(p, v, retval) return sys___sysctl(p, &bsa, retval); } -int -linux_sys_setresuid16(p, v, retval) - struct proc *p; - void *v; - register_t *retval; -{ - struct linux_sys_setresuid16_args /* { - syscallarg(uid_t) ruid; - syscallarg(uid_t) euid; - syscallarg(uid_t) suid; - } */ *uap = v; - struct pcred *pc = p->p_cred; - uid_t ruid, euid, suid; - int error; - - ruid = SCARG(uap, ruid); - euid = SCARG(uap, euid); - suid = SCARG(uap, suid); - - /* - * Note: These checks are a little different than the OpenBSD - * setreuid(2) call performs. This precisely follows the - * behavior of the Linux kernel. - */ - if (ruid != (uid_t)-1 && - ruid != pc->p_ruid && - ruid != pc->pc_ucred->cr_uid && - ruid != pc->p_svuid && - (error = suser(pc->pc_ucred, &p->p_acflag))) - return (error); - - if (euid != (uid_t)-1 && - euid != pc->p_ruid && - euid != pc->pc_ucred->cr_uid && - euid != pc->p_svuid && - (error = suser(pc->pc_ucred, &p->p_acflag))) - return (error); - - if (suid != (uid_t)-1 && - suid != pc->p_ruid && - suid != pc->pc_ucred->cr_uid && - suid != pc->p_svuid && - (error = suser(pc->pc_ucred, &p->p_acflag))) - return (error); - - /* - * Now assign the new real, effective, and saved UIDs. - * Note that Linux, unlike OpenBSD in setreuid(2), does not - * set the saved UID in this call unless the user specifies - * it. - */ - if (ruid != (uid_t)-1) { - (void)chgproccnt(pc->p_ruid, -1); - (void)chgproccnt(ruid, 1); - pc->p_ruid = ruid; - } - - if (euid != (uid_t)-1) { - pc->pc_ucred = crcopy(pc->pc_ucred); - pc->pc_ucred->cr_uid = euid; - } - - if (suid != (uid_t)-1) - pc->p_svuid = suid; - - if (ruid != (uid_t)-1 && euid != (uid_t)-1 && suid != (uid_t)-1) - p->p_flag |= P_SUGID; - return (0); -} - -int -linux_sys_getresuid(p, v, retval) - struct proc *p; - void *v; - register_t *retval; -{ - struct linux_sys_getresuid_args /* { - syscallarg(uid_t *) ruid; - syscallarg(uid_t *) euid; - syscallarg(uid_t *) suid; - } */ *uap = v; - struct pcred *pc = p->p_cred; - int error; - - /* - * Linux copies these values out to userspace like so: - * - * 1. Copy out ruid. - * 2. If that succeeds, copy out euid. - * 3. If both of those succeed, copy out suid. - */ - if ((error = copyout(&pc->p_ruid, SCARG(uap, ruid), - sizeof(uid_t))) != 0) - return (error); - - if ((error = copyout(&pc->pc_ucred->cr_uid, SCARG(uap, euid), - sizeof(uid_t))) != 0) - return (error); - - return (copyout(&pc->p_svuid, SCARG(uap, suid), sizeof(uid_t))); -} - /* * We have nonexistent fsuid equal to uid. * If modification is requested, refuse. |