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

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