smbd: use owner uid for free disk calculation if owner is inherited
authorUri Simchoni <uri@samba.org>
Thu, 11 Aug 2016 20:37:42 +0000 (23:37 +0300)
committerJeremy Allison <jra@samba.org>
Fri, 12 Aug 2016 23:53:15 +0000 (01:53 +0200)
If "inherit owner" is enabled, then new files created under a
directory shall consume the quota of the directory's owner, so
the free disk calculation should take that quota into account,
not the quota of the user creating the file.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12145

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/quotas.c

index f3a727c..2db18cd 100644 (file)
@@ -506,8 +506,25 @@ bool disk_quotas(connection_struct *conn, struct smb_filename *fname,
        ZERO_STRUCT(D);
        id.uid = geteuid();
 
-       r = SMB_VFS_GET_QUOTA(conn, fname->base_name, SMB_USER_QUOTA_TYPE, id,
-                             &D);
+       /* if new files created under this folder get this
+        * folder's UID, then available space is governed by
+        * the quota of the folder's UID, not the creating user.
+        */
+       if (lp_inherit_owner(SNUM(conn)) != INHERIT_OWNER_NO &&
+           id.uid != fname->st.st_ex_uid && id.uid != sec_initial_uid()) {
+               int save_errno;
+
+               id.uid = fname->st.st_ex_uid;
+               become_root();
+               r = SMB_VFS_GET_QUOTA(conn, fname->base_name,
+                                     SMB_USER_QUOTA_TYPE, id, &D);
+               save_errno = errno;
+               unbecome_root();
+               errno = save_errno;
+       } else {
+               r = SMB_VFS_GET_QUOTA(conn, fname->base_name,
+                                     SMB_USER_QUOTA_TYPE, id, &D);
+       }
 
        if (r == -1) {
                goto try_group_quota;