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 | |
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.
-rw-r--r-- | sys/compat/freebsd/syscalls.master | 8 | ||||
-rw-r--r-- | sys/compat/hpux/hpux_compat.c | 27 | ||||
-rw-r--r-- | sys/compat/hpux/syscalls.master | 8 | ||||
-rw-r--r-- | sys/compat/linux/linux_dummy.c | 5 | ||||
-rw-r--r-- | sys/compat/linux/linux_misc.c | 229 | ||||
-rw-r--r-- | sys/compat/linux/syscalls.master | 29 |
6 files changed, 86 insertions, 220 deletions
diff --git a/sys/compat/freebsd/syscalls.master b/sys/compat/freebsd/syscalls.master index 496bb58f76b..32fbf8e867c 100644 --- a/sys/compat/freebsd/syscalls.master +++ b/sys/compat/freebsd/syscalls.master @@ -1,4 +1,4 @@ - $OpenBSD: syscalls.master,v 1.18 2002/07/06 19:14:20 nordin Exp $ + $OpenBSD: syscalls.master,v 1.19 2002/10/30 20:10:48 millert Exp $ ; $NetBSD: syscalls.master,v 1.3 1995/10/10 18:28:40 mycroft Exp $ ; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94 @@ -531,8 +531,10 @@ 308 UNIMPL kldstat 309 UNIMPL kldfirstmod 310 UNIMPL getsid -311 UNIMPL setresuid -312 UNIMPL setresgid +311 NOARGS { int sys_setresuid(uid_t ruid, uid_t euid, \ + uid_t suid); } +312 NOARGS { int sys_setresgid(gid_t rgid, gid_t egid, \ + gid_t sgid); } 313 UNIMPL signanosleep 314 UNIMPL aio_return 315 UNIMPL aio_suspend diff --git a/sys/compat/hpux/hpux_compat.c b/sys/compat/hpux/hpux_compat.c index ac19d041061..cb30435c0d2 100644 --- a/sys/compat/hpux/hpux_compat.c +++ b/sys/compat/hpux/hpux_compat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hpux_compat.c,v 1.20 2002/08/02 18:06:25 millert Exp $ */ +/* $OpenBSD: hpux_compat.c,v 1.21 2002/10/30 20:10:48 millert Exp $ */ /* $NetBSD: hpux_compat.c,v 1.35 1997/05/08 16:19:48 mycroft Exp $ */ /* @@ -996,31 +996,6 @@ hpux_sys_setpgrp2(p, v, retval) return (sys_setpgid(p, uap, retval)); } -/* - * XXX Same as BSD setre[ug]id right now. Need to consider saved ids. - */ -int -hpux_sys_setresuid(p, v, retval) - struct proc *p; - void *v; - register_t *retval; -{ - struct hpux_sys_setresuid_args *uap = v; - - return (compat_43_sys_setreuid(p, uap, retval)); -} - -int -hpux_sys_setresgid(p, v, retval) - struct proc *p; - void *v; - register_t *retval; -{ - struct hpux_sys_setresgid_args *uap = v; - - return (compat_43_sys_setregid(p, uap, retval)); -} - int hpux_sys_getrlimit(p, v, retval) struct proc *p; diff --git a/sys/compat/hpux/syscalls.master b/sys/compat/hpux/syscalls.master index 89c44c345b9..7ee748ea294 100644 --- a/sys/compat/hpux/syscalls.master +++ b/sys/compat/hpux/syscalls.master @@ -1,4 +1,4 @@ - $OpenBSD: syscalls.master,v 1.8 2002/03/14 00:42:25 miod Exp $ + $OpenBSD: syscalls.master,v 1.9 2002/10/30 20:10:48 millert Exp $ ; $NetBSD: syscalls.master,v 1.13 1997/03/16 03:48:04 thorpej Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -195,8 +195,10 @@ 123 NOARGS { int sys_fchown(int fd, int uid, int gid); } 124 NOARGS { int sys_fchmod(int fd, int mode); } 125 UNIMPL -126 STD { int hpux_sys_setresuid(uid_t r, uid_t e, uid_t s); } -127 STD { int hpux_sys_setresgid(gid_t r, gid_t e, gid_t s); } +126 NOARGS { int sys_setresuid(uid_t ruid, uid_t uide, \ + uid_t suid); } +127 NOARGS { int sys_setresgid(gid_t rgid, gid_t egid, \ + gid_t sgid); } 128 STD { int hpux_sys_rename(char *from, char *to); } 129 STD { int hpux_sys_truncate(char *path, long length); } 130 NOARGS { int compat_43_sys_ftruncate(int fd, long length); } diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c index ac06b9a0451..5883b487338 100644 --- a/sys/compat/linux/linux_dummy.c +++ b/sys/compat/linux/linux_dummy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_dummy.c,v 1.9 2002/10/28 03:39:30 fgsch Exp $ */ +/* $OpenBSD: linux_dummy.c,v 1.10 2002/10/30 20:10:48 millert Exp $ */ /*- * Copyright (c) 1994-1995 Søren Schmidt @@ -113,9 +113,6 @@ DUMMY(lchown); /* #198 */ DUMMY(setreuid); /* #203 */ DUMMY(setregid); /* #204 */ DUMMY(fchown); /* #207 */ -DUMMY(setresuid); /* #208 */ -DUMMY(setresgid); /* #210 */ -DUMMY(getresgid); /* #211 */ DUMMY(chown); /* #212 */ DUMMY(setfsgid); /* #216 */ DUMMY(pivot_root); /* #217 */ 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. diff --git a/sys/compat/linux/syscalls.master b/sys/compat/linux/syscalls.master index b1dfbe05728..7e08a7175f2 100644 --- a/sys/compat/linux/syscalls.master +++ b/sys/compat/linux/syscalls.master @@ -1,4 +1,4 @@ - $OpenBSD: syscalls.master,v 1.35 2002/10/28 03:35:53 fgsch Exp $ + $OpenBSD: syscalls.master,v 1.36 2002/10/30 20:10:48 millert Exp $ ; $NetBSD: syscalls.master,v 1.15 1995/12/18 14:35:10 fvdl Exp $ ; @(#)syscalls.master 8.1 (Berkeley) 7/19/93 @@ -269,19 +269,19 @@ struct timespec *rmtp); } 163 STD { int linux_sys_mremap(void *old_address, size_t old_size, \ size_t new_size, long flags); } -164 STD { int linux_sys_setresuid16(uid_t ruid, uid_t euid, \ - uid_t suid); } -165 NOARGS linux_getresuid16 { int linux_sys_getresuid( \ - uid_t *ruid, uid_t *euid, uid_t *suid); } +164 STD { int linux_sys_setresuid16(u_int16_t ruid, \ + u_int16_t euid, u_int16_t suid); } +165 STD { int linux_sys_getresuid16(u_int16_t *ruid, \ + u_int16_t *euid, u_int16_t *suid); } 166 STD { int linux_sys_vm86(void); } 167 STD { int linux_sys_query_module(void); } 168 NOARGS { int sys_poll(struct pollfd *fds, u_int nfds, \ int timeout); } 169 STD { int linux_sys_nfsservctl(void); } -170 STD { int linux_sys_setresgid16(gid_t rgid, gid_t egid, \ - gid_t sgid); } -171 STD { int linux_sys_getresgid16(gid_t *rgid, gid_t *egid, \ - gid_t *sgid); } +170 STD { int linux_sys_setresgid16(u_int16_t rgid, \ + u_int16_t egid, u_int16_t sgid); } +171 STD { int linux_sys_getresgid16(u_int16_t *rgid, \ + u_int16_t *egid, u_int16_t *sgid); } 172 STD { int linux_sys_prctl(void); } 173 STD { int linux_sys_rt_sigreturn( \ struct linux_rt_sigframe *sfp); } @@ -336,11 +336,14 @@ 205 NOARGS { int sys_getgroups(u_int gidsetsize, gid_t *gidset); } 206 NOARGS { int sys_setgroups(u_int gidsetsize, gid_t *gidset); } 207 NOARGS { int linux_sys_fchown(void); } -208 NOARGS { int linux_sys_setresuid(void); } -209 STD { int linux_sys_getresuid(uid_t *ruid, uid_t *euid, \ +208 NOARGS { int sys_setresuid(uid_t ruid, uid_t euid, \ + uid_t suid); } +209 NOARGS { int sys_getresuid(uid_t *ruid, uid_t *euid, \ uid_t *suid); } -210 NOARGS { int linux_sys_setresgid(void); } -211 NOARGS { int linux_sys_getresgid(void); } +210 NOARGS { int sys_setresgid(gid_t rgid, gid_t egid, \ + gid_t sgid); } +211 NOARGS { int sys_getresgid(gid_t *rgid, gid_t *egid, \ + gid_t *sgid); } 212 NOARGS { int linux_sys_chown(void); } 213 NOARGS { int sys_setuid(uid_t uid); } 214 NOARGS { int sys_setgid(gid_t gid); } |