Fix logic error in try_chown - we shouldn't arbitrarily chown
authorJeremy Allison <jra@samba.org>
Fri, 23 Jan 2009 00:04:36 +0000 (16:04 -0800)
committerJeremy Allison <jra@samba.org>
Fri, 23 Jan 2009 00:04:36 +0000 (16:04 -0800)
to ourselves unless that was passed in.
Jeremy.

source/smbd/posix_acls.c

index 945dc991c4a2cefb916c52bd2d789f83c22d156f..2fd047b2d07aabeaf4ac5fa2f883c375d86e0fc1 100644 (file)
@@ -3095,6 +3095,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;
        }
@@ -3103,12 +3112,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);