From: Jeremy Allison Date: Fri, 23 Jan 2009 00:04:36 +0000 (-0800) Subject: Fix logic error in try_chown - we shouldn't arbitrarily chown X-Git-Tag: samba-3.0.36~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48d9974adf6cff6cc75821f4f62f1b20365b9780;p=thirdparty%2Fsamba.git Fix logic error in try_chown - we shouldn't arbitrarily chown to ourselves unless that was passed in. Jeremy. (cherry picked from commit 60289187a91e23787be581b824076651230245b2) --- diff --git a/source/smbd/posix_acls.c b/source/smbd/posix_acls.c index 5132e9725df..ed38ffcae15 100644 --- a/source/smbd/posix_acls.c +++ b/source/smbd/posix_acls.c @@ -3097,6 +3097,15 @@ int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid) return -1; } + /* only allow chown to the current user. This is more secure, + and also copes with the case where the SID in a take ownership ACL is + a local SID on the users workstation + */ + if (uid != current_user.ut.uid) { + errno = EPERM; + return -1; + } + if (SMB_VFS_STAT(conn,fname,&st)) { return -1; } @@ -3105,12 +3114,6 @@ int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid) return -1; } - /* only allow chown to the current user. This is more secure, - and also copes with the case where the SID in a take ownership ACL is - a local SID on the users workstation - */ - uid = current_user.ut.uid; - become_root(); /* Keep the current file gid the same. */ ret = SMB_VFS_FCHOWN(fsp, fsp->fh->fd, uid, (gid_t)-1);