Blame SOURCES/0016-setcifsacl-fix-adding-ACE-when-owner-sid-in-unexpect.patch

75f41f
From 5053ec60ea609bbb5499e8359681fe998c3d4d68 Mon Sep 17 00:00:00 2001
75f41f
From: Steve French <stfrench@microsoft.com>
75f41f
Date: Fri, 1 Mar 2019 23:11:25 -0600
75f41f
Subject: [PATCH 16/36] setcifsacl: fix adding ACE when owner sid in unexpected
75f41f
 location
75f41f
75f41f
If owner information is after the ACEs instead of before (e.g. Azure servers) in the ACL query
75f41f
then we would get "invalid argument" returned on setcifsacl -a (adding an ACE).
75f41f
75f41f
This fixes that.
75f41f
75f41f
Signed-off-by: Steve French <stfrench@microsoft.com>
75f41f
(cherry picked from commit 0feb1a80f3777f4c244b46958aa9f730de9e18b6)
75f41f
Signed-off-by: Sachin Prabhu <sprabhu@redhat.com>
75f41f
---
75f41f
 setcifsacl.c | 29 ++++++++++++++++++++++++-----
75f41f
 1 file changed, 24 insertions(+), 5 deletions(-)
75f41f
75f41f
diff --git a/setcifsacl.c b/setcifsacl.c
75f41f
index ba34403..1b98c37 100644
75f41f
--- a/setcifsacl.c
75f41f
+++ b/setcifsacl.c
75f41f
@@ -106,13 +106,32 @@ copy_sec_desc(const struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
75f41f
 
75f41f
 	/* copy owner sid */
75f41f
 	owner_sid_ptr = (struct cifs_sid *)((char *)pntsd + osidsoffset);
75f41f
-	nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + osidsoffset);
75f41f
-	size = copy_cifs_sid(nowner_sid_ptr, owner_sid_ptr);
75f41f
-	bufsize += size;
75f41f
+	group_sid_ptr = (struct cifs_sid *)((char *)pntsd + gsidsoffset);
75f41f
+	/*
75f41f
+	 * some servers like Azure return the owner and group SIDs at end rather
75f41f
+	 * than at the beginning of the ACL so don't want to overwrite the last ACEs
75f41f
+         */
75f41f
+	if (dacloffset <= osidsoffset) {
75f41f
+		/* owners placed at end of ACL */
75f41f
+		nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + dacloffset + size);
75f41f
+		pnntsd->osidoffset = dacloffset + size;
75f41f
+		size = copy_cifs_sid(nowner_sid_ptr, owner_sid_ptr);
75f41f
+		bufsize += size;
75f41f
+		/* put group SID after owner SID */
75f41f
+		ngroup_sid_ptr = (struct cifs_sid *)((char *)nowner_sid_ptr + size);
75f41f
+		pnntsd->gsidoffset = pnntsd->osidoffset + size;
75f41f
+	} else {
75f41f
+		/*
75f41f
+		 * Most servers put the owner information at the beginning,
75f41f
+		 * before the ACL
75f41f
+		 */
75f41f
+		nowner_sid_ptr = (struct cifs_sid *)((char *)pnntsd + osidsoffset);
75f41f
+		size = copy_cifs_sid(nowner_sid_ptr, owner_sid_ptr);
75f41f
+		bufsize += size;
75f41f
+		ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + gsidsoffset);
75f41f
+	}
75f41f
 
75f41f
 	/* copy group sid */
75f41f
-	group_sid_ptr = (struct cifs_sid *)((char *)pntsd + gsidsoffset);
75f41f
-	ngroup_sid_ptr = (struct cifs_sid *)((char *)pnntsd + gsidsoffset);
75f41f
 	size = copy_cifs_sid(ngroup_sid_ptr, group_sid_ptr);
75f41f
 	bufsize += size;
75f41f
 
75f41f
-- 
75f41f
1.8.3.1
75f41f