smb2_server: call smbXsrv_connection_disconnect_transport() early on network errors
[gd/samba-autobuild/.git] / source3 / smbd / quotas.c
index c9472682f8fe08541435a476ab0b56d8623e9008..604631f81d6d283680b5506aa88ce3bdc69f036f 100644 (file)
@@ -447,11 +447,26 @@ try_group_quota:
                return false;
        }
 
-       id.gid = getegid();
-
        ZERO_STRUCT(D);
-       r = SMB_VFS_GET_QUOTA(conn, fname, SMB_GROUP_QUOTA_TYPE, id,
-                             &D);
+
+       /*
+        * If new files created under this folder get this folder's
+        * GID, then available space is governed by the quota of the
+        * folder's GID, not the primary group of the creating user.
+        */
+       if (VALID_STAT(fname->st) &&
+           S_ISDIR(fname->st.st_ex_mode) &&
+           fname->st.st_ex_mode & S_ISGID) {
+               id.gid = fname->st.st_ex_gid;
+               become_root();
+               r = SMB_VFS_GET_QUOTA(conn, fname, SMB_GROUP_QUOTA_TYPE, id,
+                                     &D);
+               unbecome_root();
+       } else {
+               id.gid = getegid();
+               r = SMB_VFS_GET_QUOTA(conn, fname, SMB_GROUP_QUOTA_TYPE, id,
+                                     &D);
+       }
 
        if (r == -1) {
                return False;