From aa4d1febf100b8a74cc5b03dfd8b24c11cd61c70 Mon Sep 17 00:00:00 2001 From: kleink Date: Sun, 21 Dec 1997 17:49:18 +0000 Subject: [PATCH] Due to the feedback received, change chown(), fchown() and lchown() not to clear the setgid and setuid bits if called by the superuser. Addresses PR kern/4662. --- sys/kern/vfs_syscalls.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 98947a1f0651..4006c981d69c 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_syscalls.c,v 1.106 1997/10/30 22:47:08 enami Exp $ */ +/* $NetBSD: vfs_syscalls.c,v 1.107 1997/12/21 17:49:18 kleink Exp $ */ /* * Copyright (c) 1989, 1993 @@ -1661,8 +1661,12 @@ change_owner(vp, uid, gid, p) if ((error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) != 0) goto out; - /* Clear (S_ISUID | S_ISGID) bits: alter va_mode only if necessary. */ - if (vattr.va_mode & (S_ISUID | S_ISGID)) + /* + * Unless the caller is the superuser, clear the (S_ISUID | S_ISGID) + * bits, but alter va_mode only if those are actually set on the vnode. + */ + if ((suser(p->p_ucred, &p->p_acflag) != 0) && + (vattr.va_mode & (S_ISUID | S_ISGID))) newmode = vattr.va_mode & ~(S_ISUID | S_ISGID); VATTR_NULL(&vattr);