summaryrefslogtreecommitdiff
path: root/sys/kern/vfs_syscalls.c
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1996-08-08 06:36:49 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1996-08-08 06:36:49 +0000
commit8bbdba13ee2292814ea3886e24276e7fba0d6501 (patch)
tree05af789b1bf99150a6c012b007a2bcef86425864 /sys/kern/vfs_syscalls.c
parent4d772254ed458ba0aa2aaf4046cb7c94035303bb (diff)
Make {,f}chown(2) behaviour POSIX.1 compliant with SUID / SGID files
Enable CTL_FS processing by sysctl(3) Add CTL_FS request to disable clearing SUID / SGID bit when a files owner or group is changed by root Make sysctl(8) understand CTL_FS requests
Diffstat (limited to 'sys/kern/vfs_syscalls.c')
-rw-r--r--sys/kern/vfs_syscalls.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 783d9779c59..36e7dddcd48 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_syscalls.c,v 1.11 1996/08/08 04:23:03 tholo Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.12 1996/08/08 06:36:47 tholo Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
@@ -60,6 +60,8 @@
#include <vm/vm.h>
#include <sys/sysctl.h>
+extern int suid_clear;
+
static int change_dir __P((struct nameidata *, struct proc *));
void checkdirs __P((struct vnode *));
@@ -1498,15 +1500,16 @@ sys_chown(p, v, retval)
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
- error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
- if (error)
- goto out;
- mode = vattr.va_mode;
- if (vattr.va_uid != SCARG(uap, uid))
- mode &= ~VSUID;
- if (vattr.va_gid != SCARG(uap, gid))
- mode &= ~VSGID;
- if (mode == vattr.va_mode)
+ if (suser(p->p_ucred, &p->p_acflag) ||
+ suid_clear) {
+ error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
+ if (error)
+ goto out;
+ mode = vattr.va_mode & ~(VSUID | VSGID);
+ if (mode == vattr.va_mode)
+ mode = VNOVAL;
+ }
+ else
mode = VNOVAL;
VATTR_NULL(&vattr);
vattr.va_uid = SCARG(uap, uid);
@@ -1548,15 +1551,16 @@ sys_fchown(p, v, retval)
if (vp->v_mount->mnt_flag & MNT_RDONLY)
error = EROFS;
else {
- error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
- if (error)
- goto out;
- mode = vattr.va_mode;
- if (vattr.va_uid != SCARG(uap, uid))
- mode &= ~VSUID;
- if (vattr.va_gid != SCARG(uap, gid))
- mode &= ~VSGID;
- if (mode == vattr.va_mode)
+ if (suser(p->p_ucred, &p->p_acflag) ||
+ suid_clear) {
+ error = VOP_GETATTR(vp, &vattr, p->p_ucred, p);
+ if (error)
+ goto out;
+ mode = vattr.va_mode & ~(VSUID | VSGID);
+ if (mode == vattr.va_mode)
+ mode = VNOVAL;
+ }
+ else
mode = VNOVAL;
VATTR_NULL(&vattr);
vattr.va_uid = SCARG(uap, uid);