From ea73bcd87b6113f77ccda683d15b5a39003b8eaa Mon Sep 17 00:00:00 2001 From: Uri Simchoni Date: Thu, 11 Aug 2016 23:37:42 +0300 Subject: [PATCH] smbd: use owner uid for free disk calculation if owner is inherited 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 Reviewed-by: Jeremy Allison --- source3/smbd/quotas.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/source3/smbd/quotas.c b/source3/smbd/quotas.c index f3a727c0ed14..2db18cdb21cd 100644 --- a/source3/smbd/quotas.c +++ b/source3/smbd/quotas.c @@ -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; -- 2.34.1