pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 3dcc1b6 by Anonymous on Fri 6th Oct 2023 11:40
original post 20c803b87 by Anonymous on Thu 5th Oct 2023 13:32
Download diff
Show old version | new version | both versions

    
11
diff --git a/daemon/acl.c b/daemon/acl.c
2-
index 3a86735..1145011 100644
2+
index 3a86735..80287e1 100644
33
--- a/daemon/acl.c
44
+++ b/daemon/acl.c
5-
@@ -60,11 +60,16 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
5+
@@ -60,19 +60,28 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
66
     dprintf(ACLLVL, "create_unknownsid: CreateWellKnownSid type %d returned %d "
77
             "GetLastError %d sid len %d needed\n", type, status,
88
             GetLastError(), *sid_len);
99
-    if (status)
1010
-        return ERROR_INTERNAL_ERROR;
1111
+    if (status) {
1212
+        status = ERROR_INTERNAL_ERROR;
1313
+	goto err;
1414
+    }
1515
     status = GetLastError();
16-
     if (status != ERROR_INSUFFICIENT_BUFFER)
16+
-    if (status != ERROR_INSUFFICIENT_BUFFER)
1717
-        return status;
18-
+       	goto err;
18+
+    if (status != ERROR_INSUFFICIENT_BUFFER)
19+
+        goto err;
1920
+#if 1
2021
+(*sid_len) += 128;
2122
+#endif
2223
     *sid = malloc(*sid_len);
23-
     if (*sid == NULL)
24+
-    if (*sid == NULL)
24-
         return ERROR_INSUFFICIENT_BUFFER;
25+
-        return ERROR_INSUFFICIENT_BUFFER;
25-
@@ -73,6 +78,7 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
26+
+    if (*sid == NULL) {
27+
+        status = ERROR_INSUFFICIENT_BUFFER;
2633
         return ERROR_SUCCESS;
2734
     free(*sid);
35+
+    *sid = NULL;
2836
     status = GetLastError();
2937
+err:
3038
     eprintf("create_unknownsid: CreateWellKnownSid failed with %d\n", status);
3139
     return status;
3240
 }
33-
@@ -90,20 +96,131 @@ static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
41+
@@ -90,20 +99,223 @@ static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
3442
     }
3543
 }
3644
45+
-static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name)
3746
+/*
3847
+ * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an
3948
+ * UNIX/POSIX uid directly into a SID.
4049
+ *
41-
+ * Example:
50+
+ * Examples:
4251
+ * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the
43-
+ * SID as "S-1-22-1-1616"
52+
+ * SID as "S-1-22-1-1616":
4453
+ * $ getent passwd Unix_User+1616
4554
+ * Unix_User+1616:*:4278191696:4278191696:U-Unix_User\1616,S-1-22-1-1616:/:/sbin/nologin
4655
+ *
56+
+ * GID 1984 gets mapped to "Unix_Group+1984", encoding the GID into the
4761
+ */
4862
+
5063
+#define SECURITY_SAMBA_UNIX_AUTHORITY { { 0,0,0,0,0,22 } }
5164
+SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
5265
+
53-
+BOOL AllocateUnixUserSID(unsigned long uid, PSID *pSid)
66+
+static
67+
+BOOL allocate_unixuser_sid(unsigned long uid, PSID *pSid)
5468
+{
5569
+    PSID sid = NULL;
5670
+    PSID malloced_sid = NULL;
5771
+    DWORD sid_len;
5872
+
5973
+    if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid,
6074
+        0, 0, 0, 0, 0, 0, &sid)) {
6175
+        sid_len = GetLengthSid(sid);
6276
+#if 1
6377
+sid_len += 128;
6478
+#endif
6579
+	malloced_sid = malloc(sid_len);
6680
+
6781
+	if (malloced_sid) {
6882
+	    /*
6983
+	     * |AllocateAndInitializeSid()| has an own memory
7084
+	     * allocator, but we need the sid in memory from
7185
+	     * |malloc()|
7286
+	     */
7387
+	    if (CopySid(sid_len, malloced_sid, sid)) {
7488
+	        FreeSid(sid);
7589
+	        *pSid = malloced_sid;
76-
+                dprintf(ACLLVL, "AllocateUnixUserSID(): Allocated "
90+
+                dprintf(ACLLVL, "allocate_unixuser_sid(): Allocated "
7791
+		    "Unix_User+%lu: success, len=%ld\n",
7892
+	            uid, (long)sid_len);
7993
+                return TRUE;
8094
+	    }
8195
+	}
8296
+    }
8397
+
8498
+    FreeSid(sid);
8599
+    free(malloced_sid);
86-
+    dprintf(ACLLVL, "AllocateUnixUserSID(): Failed to allocate "
100+
+    dprintf(ACLLVL, "allocate_unixuser_sid(): Failed to allocate "
87-
+        "Unix_User+%lu: error code %d\n",
101+
+        "SID for Unix_User+%lu: error code %d\n",
88102
+        uid, GetLastError());
89103
+    return FALSE;
90104
+}
91105
+
92-
 static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name)
106+
+static
93-
 {
107+
+BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
94-
     int status = ERROR_INTERNAL_ERROR;
108+
+{
95-
     SID_NAME_USE sid_type;
109+
+    PSID sid = NULL;
96-
     LPSTR tmp_buf = NULL;
110+
+    PSID malloced_sid = NULL;
97-
     DWORD tmp = 0;
111+
+    DWORD sid_len;
99112
+
100-
+    if (isdigit(name[0])) {
113+
+    if (AllocateAndInitializeSid(&sid_id_auth, 2, 2, (DWORD)gid,
101-
+        /* fixme: |name| can be a group name, too */
114+
+        0, 0, 0, 0, 0, 0, &sid)) {
102-
+        name_uid = atol(name);
115+
+        sid_len = GetLengthSid(sid);
103-
+    }
116+
+#if 1
104-
+    else if(!strcmp(name, "nobody")) {
117+
+sid_len += 128;
105-
+        name_uid = 65534;
118+
+#endif
106-
+    }
119+
+	malloced_sid = malloc(sid_len);
107-
+    else if(!strcmp(name, "nogroup")) {
120+
+
108-
+        name_uid = 65534;
121+
+	if (malloced_sid) {
109-
+    }
122+
+	    /*
110-
+    else if(!strcmp(name, "root")) {
123+
+	     * |AllocateAndInitializeSid()| has an own memory
111-
+        name_uid = 0;
124+
+	     * allocator, but we need the sid in memory from
112-
+    }
125+
+	     * |malloc()|
113-
+    else if(!strcmp(name, "rmainz")) {
126+
+	     */
114-
+        name_uid = 1616;
127+
+	    if (CopySid(sid_len, malloced_sid, sid)) {
128+
+	        FreeSid(sid);
115136
+    }
124-
+    }
137+
+

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at