pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post c7ef9f79 by Anonymous on Fri 13th Oct 2023 16:15
original post c8dfa790 by Anonymous on Tue 19th Sep 2023 13:52
Download diff
Show old version | new version | both versions

    
11
diff --git a/daemon/acl.c b/daemon/acl.c
2-
index 3a86735..61a737d 100644
2+
index e65548e..a0c01c5 100644
33
--- a/daemon/acl.c
44
+++ b/daemon/acl.c
5-
@@ -65,6 +65,9 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
5+
@@ -20,16 +20,18 @@
6-
     status = GetLastError();
6+
  */
7-
     if (status != ERROR_INSUFFICIENT_BUFFER)
7+
8-
         return status;
8+
 #include <Windows.h>
9-
+#if 1
9+
+#include <stdio.h>
10-
+*sid_len += 256;
10+
 #include <strsafe.h>
11-
+#endif
11+
-#include <sddl.h>
12-
     *sid = malloc(*sid_len);
12+
-
13-
     if (*sid == NULL)
13+
-#include "nfs41_ops.h"
14-
         return ERROR_INSUFFICIENT_BUFFER;
14+
-#include "nfs41_build_features.h"
15-
@@ -97,6 +100,11 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name)
15+
-#include "delegation.h"
16-
     LPSTR tmp_buf = NULL;
16+
-#include "daemon_debug.h"
17-
     DWORD tmp = 0;
17+
-#include "util.h"
18-
18+
+#include <sddl.h>
19-
+#if 1
19+
+
20-
+    /* test mapping: Map UNIX user "rmainz" to Windows user "roland_mainz" */
20+
+#include "nfs41_ops.h"
21-
+    if (!_stricmp(name, "rmainz"))
21+
+#include "nfs41_build_features.h"
22-
+    	name = "roland_mainz";
22+
+#include "delegation.h"
23-
+#endif
23+
+#include "daemon_debug.h"
24-
     status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type);
24+
+#include "util.h"
25-
     dprintf(ACLLVL, "map_name_2_sid: LookupAccountName for %s returned %d "
25+
 #include "upcall.h"
26-
             "GetLastError %d name len %d domain len %d\n", name, status,
26+
 #include "nfs41_xdr.h"
27-
@@ -107,6 +115,9 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name)
27+
+#include "idmap.h"
28-
     status = GetLastError();
28+
29-
     switch(status) {
29+
 //#define DEBUG_ACLS
30-
     case ERROR_INSUFFICIENT_BUFFER:
30+
 #define ACLLVL 2 /* dprintf level for acl logging */
31-
+#if 1
31+
@@ -58,32 +60,32 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid,
32-
+*sid_len += 256;
32+
     *sid = NULL;
33-
+#endif
33+
34-
         *sid = malloc(*sid_len);
34+
     status = CreateWellKnownSid(type, NULL, *sid, sid_len);
35-
         if (*sid == NULL) {
35+
-    dprintf(ACLLVL, "create_unknownsid: CreateWellKnownSid type %d returned %d "
36-
             status = GetLastError();
36+
-            "GetLastError %d sid len %d needed\n", type, status,
37-
@@ -798,4 +809,4 @@ const nfs41_upcall_op nfs41_op_setacl = {
37+
-            GetLastError(), *sid_len);
38-
     parse_setacl,
38+
-    if (status) {
39-
     handle_setacl,
39+
-        status = ERROR_INTERNAL_ERROR;
40-
     marshall_setacl
40+
-        goto err;
41-
-};
41+
-    }
42-
\ No newline at end of file
42+
-    status = GetLastError();
43-
+};
43+
-    if (status != ERROR_INSUFFICIENT_BUFFER)
44-
diff --git a/daemon/idmap.c b/daemon/idmap.c
44+
-        goto err;
45-
index 0dfa8ef..b50f4e2 100644
45+
-
46-
--- a/daemon/idmap.c
46+
-    *sid = malloc(*sid_len);
47-
+++ b/daemon/idmap.c
47+
-    if (*sid == NULL) {
48-
@@ -31,6 +31,7 @@
48+
-        status = ERROR_INSUFFICIENT_BUFFER;
49-
 #include "list.h"
49+
-        goto err;
50-
 #include "daemon_debug.h"
50+
-    }
51-
51+
-    status = CreateWellKnownSid(type, NULL, *sid, sid_len);
52-
+#define CYGWIN_GETENT_USERDATA 1
52+
-    if (status)
53-
53+
-        return ERROR_SUCCESS;
54-
 #define IDLVL 2 /* dprintf level for idmap logging */
54+
-    free(*sid);
55-
55+
-    *sid = NULL;
56-
@@ -375,6 +376,156 @@ out:
56+
-    status = GetLastError();
57-
     return status;
57+
-err:
58-
 }
58+
-    eprintf("create_unknownsid: CreateWellKnownSid failed with %d\n", status);
59-
59+
-    return status;
60-
+#ifdef CYGWIN_GETENT_USERDATA
60+
-}
61-
+int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid, gid_t *res_gid)
61+
+    dprintf(ACLLVL, "create_unknownsid: CreateWellKnownSid type %d returned %d "
62-
+{
62+
+            "GetLastError %d sid len %d needed\n", type, status,
63-
+    char cmdbuff[1024];
63+
+            GetLastError(), *sid_len);
64-
+    char passwd_line[1024];
64+
+    if (status) {
65-
+    FILE* getent_pipe;
65+
+        status = ERROR_INTERNAL_ERROR;
66-
+    int res = 1;
66+
+        goto err;
67+
+    }
6771
+
68-
+    /* fixme: better quoting for |name| needed */
72+
+    *sid = malloc(*sid_len);
69-
+    (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s passwd \"%s\"",
73+
+    if (*sid == NULL) {
70-
+        "C:\\cygwin64\\bin\\getent.exe",
74+
+        status = ERROR_INSUFFICIENT_BUFFER;
71-
+        name);
75+
+        goto err;
7676
+    }
77-
+
77+
+    status = CreateWellKnownSid(type, NULL, *sid, sid_len);
78-
+    if (fgets(passwd_line, sizeof(passwd_line), getent_pipe))
78+
+    if (status)
79-
+    {
79+
+        return ERROR_SUCCESS;
80-
+        struct _cypwent
80+
+    free(*sid);
81-
+        {
81+
+    *sid = NULL;
82-
+            char* loginname;
82+
+    status = GetLastError();
83-
+            char* passwd;
83+
+err:
84-
+            char* uidstr;
84+
+    eprintf("create_unknownsid: CreateWellKnownSid failed with %d\n", status);
85-
+            char* gidstr;
85+
+    return status;
86-
+            char* comment;
86+
+}
87-
+            char* homedir;
87+
88-
+            char* shell;
88+
 static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
89-
+        } pwent = { 0 };
89+
                                            LPSTR *domain)
90-
+#define PWENT_ENTRY(var, prevvar) \
90+
@@ -95,142 +97,142 @@ static void convert_nfs4name_2_user_domain(LPSTR nfs4name,
91-
+            (((var) = strchr((prevvar), ':'))?(*(var)++ = '\0',(var)):(NULL))
91+
             *domain = &p[1];
92-
+
92+
             break;
93-
+        pwent.loginname = passwd_line;
93+
         }
94-
+        if (!PWENT_ENTRY(pwent.passwd, pwent.loginname)) goto fail;
94+
-    }
95-
+        if (!PWENT_ENTRY(pwent.uidstr, pwent.passwd)) goto fail;
95+
-}
96-
+        if (!PWENT_ENTRY(pwent.gidstr, pwent.uidstr)) goto fail;
96+
-
97-
+        if (!PWENT_ENTRY(pwent.comment, pwent.gidstr)) goto fail;
97+
-#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
98-
+        if (!PWENT_ENTRY(pwent.homedir, pwent.comment)) goto fail;
98+
-/*
99-
+        PWENT_ENTRY(pwent.shell, pwent.homedir);
99+
- * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an
100-
+
100+
- * UNIX/POSIX uid directly into a SID.
101-
+        unsigned long uid;
101+
- *
102-
+        unsigned long gid;
102+
- * Examples:
103-
+
103+
- * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the
104-
+        errno = 0;
104+
- * SID as "S-1-22-1-1616":
105-
+        uid = strtol(pwent.uidstr, NULL, 10);
105+
- * $ getent passwd Unix_User+1616
106-
+        if (errno != 0)
106+
- * Unix_User+1616:*:4278191696:4278191696:U-Unix_User\1616,S-1-22-1-1616:/:/sbin/nologin
107-
+            goto fail;
107+
- *
108-
+
108+
- * GID 1984 gets mapped to "Unix_Group+1984", encoding the GID into the
109-
+        errno = 0;
109+
- * SID as "S-1-22-2-1984":
110-
+        gid = strtol(pwent.gidstr, NULL, 10);
110+
- * $ getent group Unix_Group+1984
111-
+        if (errno != 0)
111+
- * Unix_Group+1984:S-1-22-2-1984:4278192064:
112-
+            goto fail;
112+
- *
113-
+
113+
- */
114-
+#if 1
114+
-
115-
+	/* hack for testing, map "roland_mainz" to rmainz account */
115+
-#define SECURITY_SAMBA_UNIX_AUTHORITY { { 0,0,0,0,0,22 } }
116-
+	if (!_stricmp(pwent.loginname, "roland_mainz")) {
116+
-SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
117-
+		uid = 1616;
117+
-
118-
+		gid = 1616;
118+
-static
119-
+	}
119+
-BOOL allocate_unixuser_sid(unsigned long uid, PSID *pSid)
120-
+#endif
120+
-{
121-
+#if 0
121+
-    PSID sid = NULL;
122-
+        (void)printf("loginname\t=%s\n", pwent.loginname);
122+
-    PSID malloced_sid = NULL;
123-
+        (void)printf("passwd\t=%s\n", pwent.passwd);
123+
-    DWORD sid_len;
124-
+        (void)printf("uidstr\t=%s (%lu)\n", pwent.uidstr, (unsigned long)uid);
124+
-
125-
+        (void)printf("gidstr\t=%s (%lu)\n", pwent.gidstr, (unsigned long)gid);
125+
-    if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid,
126-
+        (void)printf("comment\t=%s\n", pwent.comment);
126+
-        0, 0, 0, 0, 0, 0, &sid)) {
127-
+        (void)printf("homedir\t=%s\n", pwent.homedir);
127+
-        sid_len = GetLengthSid(sid);
128-
+        (void)printf("shell\t=%s\n", pwent.shell);
128+
-
129-
+#endif
129+
-        malloced_sid = malloc(sid_len);
130-
+        if (res_loginname)
130+
-
131-
+            (void)strcpy_s(res_loginname, VAL_LEN, pwent.loginname);
131+
-        if (malloced_sid) {
132-
+        *res_uid = uid;
132+
-            /*
133-
+        *res_gid = gid;
133+
-             * |AllocateAndInitializeSid()| has an own memory
134-
+        res = 0;
134+
-             * allocator, but we need the sid in memory from
135-
+    }
135+
-             * |malloc()|
136-
+
136+
-             */
137-
+fail:
137+
-            if (CopySid(sid_len, malloced_sid, sid)) {
138-
+    (void)_pclose(getent_pipe);
138+
-                FreeSid(sid);
139-
+
139+
-                *pSid = malloced_sid;
140-
+    return res;
140+
-                dprintf(ACLLVL, "allocate_unixuser_sid(): Allocated "
141-
+}
141+
-                    "Unix_User+%lu: success, len=%ld\n",
142-
+
142+
-                    uid, (long)sid_len);
143-
+int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid)
143+
-                return TRUE;
144-
+{
144+
-            }
145-
+    char cmdbuff[1024];
145+
-        }
146-
+    char group_line[1024];
146+
-    }
147-
+    FILE* getent_pipe;
147+
-
148-
+    int res = 1;
148+
-    FreeSid(sid);
149-
+
149+
-    free(malloced_sid);
150-
+    /* fixme: better quoting for |name| needed */
150+
-    dprintf(ACLLVL, "allocate_unixuser_sid(): Failed to allocate "
151-
+    (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s group \"%s\"",
151+
-        "SID for Unix_User+%lu: error code %d\n",
152-
+        "C:\\cygwin64\\bin\\getent.exe",
152+
-        uid, GetLastError());
153-
+        name);
153+
-    return FALSE;
154-
+    if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL)
154+
-}
155-
+    {
155+
-
156-
+        (void)perror("getent failed");
156+
-static
157-
+        return 1;
157+
-BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
158-
+    }
158+
-{
159-
+
159+
-    PSID sid = NULL;
160-
+    if (fgets(group_line, sizeof(group_line), getent_pipe))
160+
-    PSID malloced_sid = NULL;
161-
+    {
161+
-    DWORD sid_len;
162-
+        struct _cygrent
162+
-
163-
+        {
163+
-    if (AllocateAndInitializeSid(&sid_id_auth, 2, 2, (DWORD)gid,
164-
+            char* group_name;
164+
-        0, 0, 0, 0, 0, 0, &sid)) {
165-
+            char* passwd;
165+
-        sid_len = GetLengthSid(sid);
166-
+            char* gidstr;
166+
-
167-
+            char* userlist;
167+
-        malloced_sid = malloc(sid_len);
168-
+        } grent = { 0 };
168+
-
169-
+
169+
-        if (malloced_sid) {
170-
+        grent.group_name = group_line;
170+
-            /*
171-
+        if (!PWENT_ENTRY(grent.passwd, grent.group_name)) goto fail;
171+
-             * |AllocateAndInitializeSid()| has an own memory
172-
+        if (!PWENT_ENTRY(grent.gidstr, grent.passwd)) goto fail;
172+
-             * allocator, but we need the sid in memory from
173-
+        PWENT_ENTRY(grent.userlist, grent.gidstr);
173+
-             * |malloc()|
174-
+
174+
-             */
175-
+        unsigned long gid;
175+
-            if (CopySid(sid_len, malloced_sid, sid)) {
176-
+
176+
-                FreeSid(sid);
177-
+        errno = 0;
177+
-                *pSid = malloced_sid;
178-
+        gid = strtol(grent.gidstr, NULL, 10);
178+
-                dprintf(ACLLVL, "allocate_unixgroup_sid(): Allocated "
179-
+        if (errno != 0)
179+
-                    "Unix_Group+%lu: success, len=%ld\n",
180-
+            goto fail;
180+
-                    gid, (long)sid_len);
181-
+
181+
-                return TRUE;
182-
+#if 1
182+
-            }
183-
+	/* hack for testing, map "roland_mainz" to rmainz account */
183+
-        }
184-
+	if (!_stricmp(grent.group_name, "roland_mainz")) {
184+
-    }
185-
+		gid = 1616;
185+
-
186-
+	}
186+
-    FreeSid(sid);
187-
+#endif
187+
-    free(malloced_sid);
188-
+
188+
-    dprintf(ACLLVL, "allocate_unixgroup_sid(): Failed to allocate "
189-
+        (void)printf("group_name\t=%s\n", grent.group_name);
189+
-        "SID for Unix_Group+%lu: error code %d\n",
190-
+        (void)printf("passwd\t=%s\n", grent.passwd);
190+
-        gid, GetLastError());
191-
+        (void)printf("gidstr\t=%s (%lu)\n", grent.gidstr, (unsigned long)gid);
191+
-    return FALSE;
192-
+        (void)printf("userlist\t=%s\n", grent.userlist);
192+
-}
193-
+
193+
-#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
194-
+        if (res_group_name)
194+
-
195-
+            (void)strcpy_s(res_group_name, VAL_LEN, grent.group_name);
195+
-static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
196-
+        *res_gid = gid;
196+
-{
197-
+        res = 0;
197+
-    int status = ERROR_INTERNAL_ERROR;
198-
+    }
198+
-    SID_NAME_USE sid_type;
199-
+    else
199+
-    LPSTR tmp_buf = NULL;
200-
+    {
200+
-    DWORD tmp = 0;
201-
+        (void)puts("no match for group");
201+
-#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
202-
+    }
202+
-    signed long user_uid = -1;
203-
+
203+
-    signed long group_gid = -1;
204-
+fail:
204+
-#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
205-
+    (void)_pclose(getent_pipe);
205+
-
206-
+
206+
-#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
207-
+    return res;
207+
-    if (query & OWNER_SECURITY_INFORMATION) {
208-
+}
208+
-        if (!strcmp(name, "rmainz")) {
209-
+#endif /* CYGWIN_GETENT_USERDATA */
209+
-            name = "roland_mainz";
210-
210+
-            dprintf(ACLLVL, "map_name_2_sid: remap rmainz --> roland_mainz\n");
211-
 /* generic cache */
211+
-        }
212-
 typedef struct list_entry* (*entry_alloc_fn)();
212+
-        else if (!strcmp(name, "197608")) {
213-
@@ -665,10 +816,10 @@ static int idmap_lookup_user(
213+
-            name = "roland_mainz";
214-
     if (status == NO_ERROR) {
214+
-            dprintf(ACLLVL, "map_name_2_sid: remap 197608 --> roland_mainz\n");
215-
         /* don't return expired entries; query new attributes
215+
-        }
216-
          * and overwrite the entry with cache_insert() */
216+
-        else if (!strcmp(name, "1616")) {
217-
-        if (time(NULL) - user->last_updated < context->config.cache_ttl)
217+
-            name = "roland_mainz";
218-
+        if ((time(NULL) - user->last_updated) < context->config.cache_ttl)
218+
-            dprintf(ACLLVL, "map_name_2_sid: remap 1616 --> roland_mainz\n");
219-
             goto out;
219+
-        }
220-
     }
220+
-    }
221+
-#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
221222
-
222-
+#if 0
223+
-    status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type);
223-
     /* send the query to the ldap server */
224+
-    dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): LookupAccountName returned %d "
224-
     status = idmap_query_attrs(context, lookup,
225+
-            "GetLastError %d name len %d domain len %d\n",
225-
         attributes, optional, values, NUM_ATTRIBUTES);
226+
-            query, name, status, GetLastError(), *sid_len, tmp);
226-
@@ -705,7 +856,91 @@ static int idmap_lookup_user(
227+
-    if (status)
227-
         goto out_free_values;
228+
-        return ERROR_INTERNAL_ERROR;
230229
-
231-
+#else
230+
+    }
232-
+    if (lookup->attr == ATTR_USER_NAME) {
231+
+}
236232
+
237-
+	status = ERROR_NOT_FOUND;
233+
+#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
238-
+
234+
+/*
239-
+        if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) {
235+
+ * Allocate a SID from SECURITY_SAMBA_UNIX_AUTHORITY, which encodes an
240-
+            eprintf("# ATTR_USER_NAME: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid);
236+
+ * UNIX/POSIX uid directly into a SID.
241-
+	    (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC");
237+
+ *
242-
+            StringCchCopyA(user->username, VAL_LEN, lookup->value);
238+
+ * Examples:
243-
+            StringCchCopyA(user->principal, VAL_LEN, principal_name);
239+
+ * UID 1616 gets mapped to "Unix_User+1616", encoding the UID into the
244-
+            user->uid = cy_uid;
240+
+ * SID as "S-1-22-1-1616":
245-
+            user->gid = cy_gid;
241+
+ * $ getent passwd Unix_User+1616
246-
+	    status = 0;
242+
+ * Unix_User+1616:*:4278191696:4278191696:U-Unix_User\1616,S-1-22-1-1616:/:/sbin/nologin
247-
+	}
243+
+ *
248-
+    }
244+
+ * GID 1984 gets mapped to "Unix_Group+1984", encoding the GID into the
249-
+    else if (lookup->attr == ATTR_PRINCIPAL) {
245+
+ * SID as "S-1-22-2-1984":
250-
+	char search_name[VAL_LEN];
246+
+ * $ getent group Unix_Group+1984
251-
+	char principal_name[VAL_LEN];
247+
+ * Unix_Group+1984:S-1-22-2-1984:4278192064:
252-
+	char *s;
248+
+ *
253-
+	uid_t cy_uid = 0;
249+
+ */
255250
+
256-
+	status = ERROR_NOT_FOUND;
251+
+#define SECURITY_SAMBA_UNIX_AUTHORITY { { 0,0,0,0,0,22 } }
252+
+SID_IDENTIFIER_AUTHORITY sid_id_auth = SECURITY_SAMBA_UNIX_AUTHORITY;
257253
+
258-
+	/*
254+
+static
259-
+	 * strip '@' from principal name and use that for getent
255+
+BOOL allocate_unixuser_sid(unsigned long uid, PSID *pSid)
260-
+	 * fixme: This does not work with multiple domains
256+
+{
261-
+	 */
257+
+    PSID sid = NULL;
262-
+	(void)strcpy_s(search_name, sizeof(search_name), lookup->value);
258+
+    PSID malloced_sid = NULL;
263-
+	if (s = strchr(search_name, '@'))
259+
+    DWORD sid_len;
265260
+
266-
+        if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) {
261+
+    if (AllocateAndInitializeSid(&sid_id_auth, 2, 1, (DWORD)uid,
267-
+            eprintf("# ATTR_PRINCIPAL: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid);
262+
+        0, 0, 0, 0, 0, 0, &sid)) {
268-
+	    (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC");
263+
+        sid_len = GetLengthSid(sid);
269264
+
270-
+	    if (!_stricmp(principal_name, lookup->value)) {
265+
+        malloced_sid = malloc(sid_len);
271-
+                StringCchCopyA(user->username, VAL_LEN, search_name);
266+
+
272-
+                StringCchCopyA(user->principal, VAL_LEN, principal_name);
267+
+        if (malloced_sid) {
273-
+                user->uid = cy_uid;
268+
+            /*
274-
+                user->gid = cy_gid;
269+
+             * |AllocateAndInitializeSid()| has an own memory
275-
+	        status = 0;
270+
+             * allocator, but we need the sid in memory from
276-
+	    }
271+
+             * |malloc()|
277-
+	}
272+
+             */
273+
+            if (CopySid(sid_len, malloced_sid, sid)) {
278282
+    }
286283
+
287-
+	status = ERROR_NOT_FOUND;
284+
+    FreeSid(sid);
285+
+    free(malloced_sid);
288291
+
289-
+	(void)snprintf(search_name, sizeof(search_name), "%lu", (unsigned long)search_uid);
292+
+static
293+
+BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
290298
+
291-
+        if (!cygwin_getent_passwd(search_name, res_username, &cy_uid, &cy_gid)) {
299+
+    if (AllocateAndInitializeSid(&sid_id_auth, 2, 2, (DWORD)gid,
292-
+            eprintf("# ATTR_UID: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", res_username, (int)cy_uid, (int)cy_gid);
300+
+        0, 0, 0, 0, 0, 0, &sid)) {
293-
+	    (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", res_username, "GLOBAL.LOC");
301+
+        sid_len = GetLengthSid(sid);
294302
+
295-
+            StringCchCopyA(user->username, VAL_LEN, res_username);
303+
+        malloced_sid = malloc(sid_len);
296-
+            StringCchCopyA(user->principal, VAL_LEN, principal_name);
304+
+
297-
+            user->uid = cy_uid;
305+
+        if (malloced_sid) {
298-
+            user->gid = cy_gid;
306+
+            /*
299-
+            status = 0;
307+
+             * |AllocateAndInitializeSid()| has an own memory
300-
+	}
308+
+             * allocator, but we need the sid in memory from
301-
+    }
309+
+             * |malloc()|
302-
+    else
310+
+             */
303-
+    {
311+
+            if (CopySid(sid_len, malloced_sid, sid)) {
304-
+        status = ERROR_NOT_FOUND;
312+
+                FreeSid(sid);
313+
+                *pSid = malloced_sid;
305320
+    }
306321
+
307-
+    if (status == 0) {
322+
+    FreeSid(sid);
308-
+        user->last_updated = time(NULL);
323+
+    free(malloced_sid);
309-
+	eprintf("## idmap_lookup_user: found username='%s', principal='%s', uid=%lu, gid=%lu\n",
324+
+    dprintf(ACLLVL, "allocate_unixgroup_sid(): Failed to allocate "
310-
+		user->username,
325+
+        "SID for Unix_Group+%lu: error code %d\n",
311-
+		user->principal,
326+
+        gid, GetLastError());
312-
+		(unsigned long)user->uid,
327+
+    return FALSE;
313-
+		(unsigned long)user->gid);
328+
+}
314-
+    }
329+
+#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
315-
+#endif
330+
+
316-
     if (context->config.cache_ttl) {
331+
+static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
317-
         /* insert the entry into the cache */
332+
+{
318-
         cache_insert(&context->users, lookup, &user->entry);
333+
+    int status = ERROR_INTERNAL_ERROR;
319-
@@ -732,10 +967,10 @@ static int idmap_lookup_group(
334+
+    SID_NAME_USE sid_type;
320-
     if (status == NO_ERROR) {
335+
+    LPSTR tmp_buf = NULL;
321-
         /* don't return expired entries; query new attributes
336+
+    DWORD tmp = 0;
322-
          * and overwrite the entry with cache_insert() */
337+
+#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
323-
-        if (time(NULL) - group->last_updated < context->config.cache_ttl)
338+
+    signed long user_uid = -1;
324-
+        if ((time(NULL) - group->last_updated) < context->config.cache_ttl)
339+
+    signed long group_gid = -1;
325-
             goto out;
340+
+#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
326-
     }
341+
+
327-
-
342+
+#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
328-
+#if 0
343+
+    if (query & OWNER_SECURITY_INFORMATION) {
329-
     /* send the query to the ldap server */
344+
+        if (!strcmp(name, "rmainz")) {
330-
     status = idmap_query_attrs(context, lookup,
345+
+            name = "roland_mainz";
331-
         attributes, 0, values, NUM_ATTRIBUTES);
346+
+            dprintf(ACLLVL, "map_name_2_sid: remap rmainz --> roland_mainz\n");
332-
@@ -758,7 +993,48 @@ static int idmap_lookup_group(
347+
+        }
333-
         goto out_free_values;
348+
+        else if (!strcmp(name, "197608")) {
334-
     }
349+
+            name = "roland_mainz";
335-
     group->last_updated = time(NULL);
350+
+            dprintf(ACLLVL, "map_name_2_sid: remap 197608 --> roland_mainz\n");
336-
+#else
351+
+        }
337-
+    if (lookup->attr == ATTR_GROUP_NAME) {
352+
+        else if (!strcmp(name, "1616")) {
338-
+	gid_t cy_gid = 0;
353+
+            name = "roland_mainz";
354+
+            dprintf(ACLLVL, "map_name_2_sid: remap 1616 --> roland_mainz\n");
339358
+
340-
+	status = ERROR_NOT_FOUND;
359+
+    status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type);
360+
+    dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): LookupAccountName returned %d "
341365
+
342-
+        if (!cygwin_getent_group(lookup->value, NULL, &cy_gid)) {
366+
     status = GetLastError();
343-
+            eprintf("# ATTR_GROUP_NAME: cygwin_getent_group: returned %s, gid=%d\n", lookup->value, (int)cy_gid);
367+
     switch(status) {
344-
+            StringCchCopyA(group->name, VAL_LEN, lookup->value);
368+
     case ERROR_INSUFFICIENT_BUFFER:
345-
+            group->gid = cy_gid;
369+
@@ -243,14 +245,14 @@ static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
346-
+	    status = 0;
370+
         if (tmp_buf == NULL)
347-
+	}
371+
             goto out_free_sid;
348-
+    }
372+
         status = LookupAccountName(NULL, name, *sid, sid_len, tmp_buf,
349-
+    else if (lookup->attr == ATTR_GID) {
373+
-                                    &tmp, &sid_type);
350-
+        gid_t search_gid = (gid_t)(lookup->value);
374+
-        free(tmp_buf);
351-
+        char search_name[VAL_LEN];
375+
-        if (!status) {
352-
+	char res_groupname[VAL_LEN];
376+
-            eprintf("map_name_2_sid(query=%x,name='%s'): LookupAccountName failed "
353-
+	gid_t cy_gid = 0;
377+
-                    "with %d\n", query, name, GetLastError());
354-
+
378+
-            goto out_free_sid;
355-
+	status = ERROR_NOT_FOUND;
379+
-        } else {
356-
+
380+
-#ifdef DEBUG_ACLS
357-
+	(void)snprintf(search_name, sizeof(search_name), "%lu", (unsigned long)search_gid);
381+
+                                    &tmp, &sid_type);
358-
+
382+
+        free(tmp_buf);
359-
+        if (!cygwin_getent_group(search_name, res_groupname, &cy_gid)) {
383+
+        if (!status) {
360-
+            eprintf("# ATTR_GID: cygwin_getent_group: returned %s, gid=%d\n", res_groupname, (int)cy_gid);
384+
+            eprintf("map_name_2_sid(query=%x,name='%s'): LookupAccountName failed "
361-
+            StringCchCopyA(group->name, VAL_LEN, res_groupname);
385+
+                    "with %d\n", query, name, GetLastError());
362-
+            group->gid = cy_gid;
386+
+            goto out_free_sid;
363-
+            status = 0;
387+
+        } else {
364-
+	}
388+
+#ifdef DEBUG_ACLS
365-
+    }
389+
             LPSTR ssid = NULL;
366-
+    else
390+
             if (IsValidSid(*sid))
367-
+    {
391+
                 if (ConvertSidToStringSidA(*sid, &ssid))
368-
+        status = ERROR_NOT_FOUND;
392+
@@ -264,115 +266,101 @@ static int map_name_2_sid(int query, DWORD *sid_len, PSID *sid, LPCSTR name)
369-
+    }
393+
             if (ssid) LocalFree(ssid);
370-
394+
 #endif
371-
+    if (status == 0) {
395+
         }
372-
+        group->last_updated = time(NULL);
396+
-        status = ERROR_SUCCESS;
373-
+	eprintf("## idmap_lookup_group: found name='%s', gid=%lu\n",
397+
-        break;
374-
+		group->name,
398+
-    case ERROR_NONE_MAPPED:
375-
+		(unsigned long)group->gid);
399+
-#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
376-
+    }
400+
-        dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
377-
+#endif
401+
-            "trying Unix_User+/Unix_Group+ mapping\n",
378-
     if (context->config.cache_ttl) {
402+
-            query, name);
379-
         /* insert the entry into the cache */
403+
-
380-
         cache_insert(&context->groups, lookup, &group->entry);
404+
-        if ((user_uid == -1) && (query & OWNER_SECURITY_INFORMATION)) {
381-
@@ -795,6 +1071,7 @@ int nfs41_idmap_create(
405+
-            if (isdigit(name[0])) {
382-
         goto out_err_free;
406+
-                user_uid = atol(name);
383-
     }
407+
-            }
384-
408+
-            else if(!strcmp(name, "nobody")) {
385-
+#if 0
409+
-                user_uid = 65534;
386-
     /* initialize ldap and configure options */
410+
-            }
387-
     context->ldap = ldap_init(context->config.hostname, context->config.port);
411+
-            else if(!strcmp(name, "root")) {
388-
     if (context->ldap == NULL) {
412+
-                user_uid = 0;
389-
@@ -824,6 +1101,10 @@ int nfs41_idmap_create(
413+
-            }
390-
             goto out_err_free;
414+
-            else if(!strcmp(name, "rmainz")) {
391-
         }
415+
-                user_uid = 1616;
392-
     }
416+
-            }
393-
+#else
417+
-            else if(!strcmp(name, "swulsch")) {
394-
+    eprintf("nfs41_idmap_create: Force context->config.timeout = 6000;\n");
418+
-                user_uid = 1818;
395-
+    context->config.timeout = 6000;
419+
-            }
396-
+#endif
420+
-            else if(!strcmp(name, "mwenzel")) {
397-
421+
-                user_uid = 8239;
398-
     *context_out = context;
422+
-            }
399-
 out:
423+
-            else if(!strcmp(name, "test001")) {
400-
diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
424+
-                user_uid = 1000;
401-
index bb485cb..25ca6eb 100644
425+
-            }
402-
--- a/daemon/nfs41_daemon.c
426+
-        }
403-
+++ b/daemon/nfs41_daemon.c
427+
-
404-
@@ -389,6 +389,11 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
428+
-        if ((group_gid == -1) && (query & GROUP_SECURITY_INFORMATION)) {
405-
         exit(1);
429+
-            if (isdigit(name[0])) {
406-
     }
430+
-                group_gid = atol(name);
407-
431+
-            }
408-
+#if 1
432+
-            else if(!strcmp(name, "nobody")) {
409-
+    /* force enable for cygwin getent passwd/group testing */
433+
-                group_gid = 65534;
410-
+    cmd_args.ldap_enable = TRUE;
434+
-            }
411-
+#endif
435+
-            else if(!strcmp(name, "root")) {
412-
+
436+
-                group_gid = 0;
413-
     nfs41_server_list_init();
437+
-            }
414-
438+
-            else if(!strcmp(name, "rmainz")) {
415-
     if (cmd_args.ldap_enable) {
439+
-                group_gid = 1616;
416-
440+
-            }
417-
441+
-            else if(!strcmp(name, "swulsch")) {
418-
442+
-                group_gid = 1818;
419-
443+
-            }
420-
444+
-            else if(!strcmp(name, "mwenzel")) {
421-
445+
-                group_gid = 8239;
422-
446+
-            }
423-
447+
-            else if(!strcmp(name, "test001")) {
424-
448+
-                group_gid = 1000;
425-
449+
-            }
426-
450+
-        }
427-
451+
-
428-
452+
-        if (user_uid != -1) {
429-
453+
-            if (allocate_unixuser_sid(user_uid, sid)) {
430-
454+
-                dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
431-
455+
-                    "allocate_unixuser_sid(uid=%ld) success\n",
432-
456+
-                    query, name, user_uid);
433-
457+
-                return ERROR_SUCCESS;
434-
458+
-            }
435-
459+
-
436-
460+
-            status = GetLastError();
437-
461+
-            dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
438-
462+
-                "allocate_unixuser_sid(uid=%ld) failed, error=%d\n",
439-
463+
-                query, name, user_uid, status);
440-
464+
-            return status;
441-
465+
-        }
442-
466+
-
443-
467+
-        if (group_gid != -1) {
444-
468+
-            if (allocate_unixgroup_sid(group_gid, sid)) {
445-
469+
-                dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
446-
470+
-                    "allocate_unixgroup_sid(gid=%ld) success\n",
447-
471+
-                    query, name, group_gid);
448-
472+
-                return ERROR_SUCCESS;
449-
473+
-            }
450-
474+
-
451-
475+
-            status = GetLastError();
452-
476+
-            dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
453-
477+
-                "allocate_unixgroup_sid(gid=%ld) failed, error=%d\n",
454-
478+
-                query, name, group_gid, status);
455-
479+
-            return status;
456-
480+
-        }
457-
481+
-#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
458-
482+
-
459-
483+
-        dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
460-
484+
-            "using WinNullSid mapping\n",
461-
485+
-            query, name);
462-
486+
-
463-
487+
-        status = create_unknownsid(WinNullSid, sid, sid_len);
464-
488+
-        if (status)
465-
489+
-            goto out_free_sid;
466-
490+
-        break;
467-
491+
-    default:
468-
492+
-        dprintf(1, "map_name_2_sid(query=%x,name='%s'): error %d not handled\n",
469-
493+
-            query, name, GetLastError());
470-
494+
-        break;
471-
495+
-    }
472-
496+
-out:
473-
497+
-    return status;
474-
498+
-out_free_sid:
475-
499+
-    status = GetLastError();
476-
500+
-    free(*sid);
477-
501+
-    *sid = NULL;
478-
502+
-    goto out;
479-
503+
-}
480-
504+
-
481-
505+
+        status = ERROR_SUCCESS;
482-
506+
+        break;
483-
507+
+    case ERROR_NONE_MAPPED:
484-
508+
+#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
485-
509+
+        dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
486-
510+
+            "trying Unix_User+/Unix_Group+ mapping\n",
487-
511+
+            query, name);
488-
512+
+
489-
513+
+        if ((user_uid == -1) && (query & OWNER_SECURITY_INFORMATION)) {
490-
514+
+            uid_t map_uid = -1;
491-
515+
+            gid_t gid_dummy = -1;
492-
516+
+
493-
517+
+            if (nfs41_idmap_name_to_ids(
494-
518+
+                global_idmap_context,
495-
519+
+                name,
496-
520+
+                &map_uid,
497-
521+
+                &gid_dummy) == 0) {
498-
522+
+                user_uid = map_uid;
499-
523+
+            }
500-
524+
+            else {
501-
525+
+                dprintf(1, "map_name_2_sid(query=%x,name='%s'): nfs41_idmap_name_to_ids() failed\n",
502-
526+
+                    query, name);
503-
527+
+                /* fixme: try harder here, "1234" should to to |atol()| */
504-
528+
+            }
505-
529+
+        }
506-
530+
+
507-
531+
+        if ((group_gid == -1) && (query & GROUP_SECURITY_INFORMATION)) {
508-
532+
+            gid_t map_gid = -1;
509-
533+
+
510-
534+
+            if (nfs41_idmap_group_to_gid(
511-
535+
+                global_idmap_context,
512-
536+
+                name,
513-
537+
+                &map_gid) == 0) {
514-
538+
+                group_gid = map_gid;
515-
539+
+            }
516-
540+
+            else {
517-
541+
+                dprintf(1, "map_name_2_sid(query=%x,name='%s'): nfs41_idmap_group_to_gid() failed\n",
518-
542+
+                    query, name);
519-
543+
+                /* fixme: try harder here, "1234" should to to |atol()| */
520-
544+
+            }
521-
545+
+        }
522-
546+
+
523-
547+
+        if (user_uid != -1) {
524-
548+
+            if (allocate_unixuser_sid(user_uid, sid)) {
525-
549+
+                dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
526-
550+
+                    "allocate_unixuser_sid(uid=%ld) success\n",
527-
551+
+                    query, name, user_uid);
528-
552+
+                return ERROR_SUCCESS;
529-
553+
+            }
530-
554+
+
531-
555+
+            status = GetLastError();
532-
556+
+            dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
533-
557+
+                "allocate_unixuser_sid(uid=%ld) failed, error=%d\n",
534-
558+
+                query, name, user_uid, status);
535-
559+
+            return status;
536-
560+
+        }
537-
561+
+
538-
562+
+        if (group_gid != -1) {
539-
563+
+            if (allocate_unixgroup_sid(group_gid, sid)) {
540-
564+
+                dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
541-
565+
+                    "allocate_unixgroup_sid(gid=%ld) success\n",
542-
566+
+                    query, name, group_gid);
543-
567+
+                return ERROR_SUCCESS;
544-
568+
+            }
545-
569+
+
546-
570+
+            status = GetLastError();
547-
571+
+            dprintf(ACLLVL, "map_name_2_sid(query=%x,name='%s'): "
548-
572+
+                "allocate_unixgroup_sid(gid=%ld) failed, error=%d\n",
549-
573+
+                query, name, group_gid, status);
550-
574+
+            return status;
551-
575+
+        }
552-
576+
+#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
553-
577+
+
554-
578+
+        dprintf(1, "map_name_2_sid(query=%x,name='%s'): none mapped, "
555-
579+
+            "using WinNullSid mapping\n",
556-
580+
+            query, name);
557-
581+
+
558-
582+
+        status = create_unknownsid(WinNullSid, sid, sid_len);
559-
583+
+        if (status)
560-
584+
+            goto out_free_sid;
561-
585+
+        break;
562-
586+
+    default:
563-
587+
+        dprintf(1, "map_name_2_sid(query=%x,name='%s'): error %d not handled\n",
564-
588+
+            query, name, GetLastError());
565-
589+
+        break;
566-
590+
+    }
567-
591+
+out:
568-
592+
+    return status;
569-
593+
+out_free_sid:
570-
594+
+    status = GetLastError();
571-
595+
+    free(*sid);
572-
596+
+    *sid = NULL;
573-
597+
+    goto out;
574-
598+
+}
575-
599+
+
576-
600+
 static void free_sids(PSID *sids, int count)
577-
601+
 {
578-
602+
     int i;
579-
603+
@@ -426,14 +414,14 @@ static int convert_nfs4acl_2_dacl(nfsacl41 *acl, int file_type,
580-
604+
                                              &sid_len, &flag);
581-
605+
         if (status) {
582-
606+
             free_sids(sids, i);
583-
607+
-            goto out;
584-
608+
-        }
585-
609+
-        if (!flag) {
586-
610+
-            status = map_name_2_sid(0xFFFF /* fixme: Unknown whether user or group */,
587-
611+
-                &sid_len, &sids[i], acl->aces[i].who);
588-
612+
-            if (status) {
589-
613+
-                free_sids(sids, i);
590-
614+
-                goto out;
591-
615+
+            goto out;
592-
616+
+        }
593-
617+
+        if (!flag) {
594-
618+
+            status = map_name_2_sid(0xFFFF /* fixme: Unknown whether user or group */,
595-
619+
+                &sid_len, &sids[i], acl->aces[i].who);
596-
620+
+            if (status) {
597-
621+
+                free_sids(sids, i);
598-
622+
+                goto out;
599-
623+
             }
600-
624+
         }
601-
625+
         size += sid_len - sizeof(DWORD);
602-
626+
@@ -541,30 +529,30 @@ static int handle_getacl(nfs41_upcall *upcall)
603-
627+
     if (args->query & OWNER_SECURITY_INFORMATION) {
604-
628+
         // parse user@domain. currently ignoring domain part XX
605-
629+
         convert_nfs4name_2_user_domain(info.owner, &domain);
606-
630+
-        dprintf(ACLLVL, "handle_getacl: OWNER_SECURITY_INFORMATION: for user=%s "
607-
631+
-                "domain=%s\n", info.owner, domain?domain:"<null>");
608-
632+
-        sid_len = 0;
609-
633+
-        status = map_name_2_sid(OWNER_SECURITY_INFORMATION, &sid_len, &osid, info.owner);
610-
634+
-        if (status)
611-
635+
-            goto out;
612-
636+
-        status = SetSecurityDescriptorOwner(&sec_desc, osid, TRUE);
613-
637+
+        dprintf(ACLLVL, "handle_getacl: OWNER_SECURITY_INFORMATION: for user=%s "
614-
638+
+                "domain=%s\n", info.owner, domain?domain:"<null>");
615-
639+
+        sid_len = 0;
616-
640+
+        status = map_name_2_sid(OWNER_SECURITY_INFORMATION, &sid_len, &osid, info.owner);
617-
641+
+        if (status)
618-
642+
+            goto out;
619-
643+
+        status = SetSecurityDescriptorOwner(&sec_desc, osid, TRUE);
620-
644+
         if (!status) {
621-
645+
             status = GetLastError();
622-
646+
             eprintf("handle_getacl: SetSecurityDescriptorOwner failed with "
623-
647+
                     "%d\n", status);
624-
648+
-            goto out;
625-
649+
-        }
626-
650+
-    }
627-
651+
-
628-
652+
-    if (args->query & GROUP_SECURITY_INFORMATION) {
629-
653+
-        convert_nfs4name_2_user_domain(info.owner_group, &domain);
630-
654+
-        dprintf(ACLLVL, "handle_getacl: GROUP_SECURITY_INFORMATION: for %s "
631-
655+
-                "domain=%s\n", info.owner_group, domain?domain:"<null>");
632-
656+
-        sid_len = 0;
633-
657+
-        status = map_name_2_sid(GROUP_SECURITY_INFORMATION, &sid_len, &gsid, info.owner_group);
634-
658+
-        if (status)
635-
659+
-            goto out;
636-
660+
-        status = SetSecurityDescriptorGroup(&sec_desc, gsid, TRUE);
637-
661+
+            goto out;
638-
662+
+        }
639-
663+
+    }
640-
664+
+
641-
665+
+    if (args->query & GROUP_SECURITY_INFORMATION) {
642-
666+
+        convert_nfs4name_2_user_domain(info.owner_group, &domain);
643-
667+
+        dprintf(ACLLVL, "handle_getacl: GROUP_SECURITY_INFORMATION: for %s "
644-
668+
+                "domain=%s\n", info.owner_group, domain?domain:"<null>");
645-
669+
+        sid_len = 0;
646-
670+
+        status = map_name_2_sid(GROUP_SECURITY_INFORMATION, &sid_len, &gsid, info.owner_group);
647-
671+
+        if (status)
648-
672+
+            goto out;
649-
673+
+        status = SetSecurityDescriptorGroup(&sec_desc, gsid, TRUE);
650-
674+
         if (!status) {
651-
675+
             status = GetLastError();
652-
676+
             eprintf("handle_getacl: SetSecurityDescriptorGroup failed with "
653-
677+
@@ -1018,7 +1006,7 @@ static int marshall_setacl(unsigned char *buffer, uint32_t *length, nfs41_upcall
654-
678+
 }
655679
656-
680+
 const nfs41_upcall_op nfs41_op_setacl = {
657-
681+
-    parse_setacl,
658-
682+
-    handle_setacl,
659-
683+
-    marshall_setacl
660-
684+
-};
661-
685+
+    parse_setacl,
662-
686+
+    handle_setacl,
663-
687+
+    marshall_setacl
664-
688+
+};
665-
689+
diff --git a/daemon/idmap.c b/daemon/idmap.c
666-
690+
index 0dfa8ef..8df1271 100644
667-
691+
--- a/daemon/idmap.c
668-
692+
+++ b/daemon/idmap.c
669-
693+
@@ -31,6 +31,7 @@
670-
694+
 #include "list.h"
671-
695+
 #include "daemon_debug.h"
672696
673-
697+
+#define CYGWIN_GETENT_USERDATA 1
674698
675-
699+
 #define IDLVL 2 /* dprintf level for idmap logging */
676700
677-
701+
@@ -375,6 +376,221 @@ out:
678-
702+
     return status;
679-
703+
 }
680704
681-
705+
+#ifdef CYGWIN_GETENT_USERDATA
682-
706+
+int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid, gid_t *res_gid)
683-
707+
+{
684-
708+
+    char cmdbuff[1024];
685-
709+
+    char passwd_line[1024];
686-
710+
+    FILE* getent_pipe = NULL;
687-
711+
+    int res = 1;
688-
712+
+    unsigned long uid = -1;
689-
713+
+    unsigned long gid = -1;
690-
714+
+    struct _cypwent {
691-
715+
+        char* loginname;
692-
716+
+        char* passwd;
693-
717+
+        char* uidstr;
694-
718+
+        char* gidstr;
695-
719+
+        char* comment;
696-
720+
+        char* homedir;
697-
721+
+        char* shell;
698-
722+
+    } pwent = { 0 };
699-
723+
+#define PWENT_ENTRY(var, prevvar) \
700-
724+
+    (((var) = strchr((prevvar), ':'))?(*(var)++ = '\0',(var)):(NULL))
701-
725+
+
702-
726+
+#if 1
703-
727+
+    /* hack for testing, map "roland_mainz" to rmainz account */
704-
728+
+    if ((!_stricmp(name, "rmainz")) || (!stricmp(name, "1616"))) {
705-
729+
+        uid = 1616;
706-
730+
+        gid = 1616;
707-
731+
+        pwent.loginname = "rmainz";
708-
732+
+        goto found;
709-
733+
+    }
710-
734+
+    if ((!_stricmp(name, "nobody")) || (!stricmp(name, "65534"))) {
711-
735+
+        uid = 65534;
712-
736+
+        gid = 65534;
713-
737+
+        pwent.loginname = "nobody";
714-
738+
+        goto found;
715-
739+
+    }
716-
740+
+    if ((!_stricmp(name, "root")) || (!stricmp(name, "0"))) {
717-
741+
+        uid = 0;
718-
742+
+        gid = 0;
719-
743+
+        pwent.loginname = "root";
720-
744+
+        goto found;
721-
745+
+    }
722-
746+
+    if ((!_stricmp(name, "iam")) || (!stricmp(name, "2010"))) {
723-
747+
+        uid = 2010;
724-
748+
+        gid = 2010;
725-
749+
+        pwent.loginname = "iam";
726-
750+
+        goto found;
727-
751+
+    }
728-
752+
+    if ((!_stricmp(name, "swulsch")) || (!stricmp(name, "1818"))) {
729-
753+
+        uid = 1818;
730-
754+
+        gid = 1818;
731-
755+
+        pwent.loginname = "swulsch";
732-
756+
+        goto found;
733-
757+
+    }
734-
758+
+    if ((!_stricmp(name, "mwenzel")) || (!stricmp(name, "8239"))) {
735-
759+
+        uid = 8239;
736-
760+
+        gid = 8239;
737-
761+
+        pwent.loginname = "mwenzel";
738-
762+
+        goto found;
739-
763+
+    }
740-
764+
+#endif
741-
765+
+
742-
766+
+    /* fixme: better quoting for |name| needed */
743-
767+
+    (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s passwd \"%s\"",
744-
768+
+        "C:\\cygwin64\\bin\\getent.exe",
745-
769+
+        name);
746-
770+
+    if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL) {
747-
771+
+        (void)perror("cygwin_getent_passwd: getent failed");
748-
772+
+        return 1;
749-
773+
+    }
750-
774+
+
751-
775+
+    if (fgets(passwd_line, sizeof(passwd_line), getent_pipe)) {
752-
776+
+        pwent.loginname = passwd_line;
753-
777+
+        if (!PWENT_ENTRY(pwent.passwd, pwent.loginname)) goto fail;
754-
778+
+        if (!PWENT_ENTRY(pwent.uidstr, pwent.passwd)) goto fail;
755-
779+
+        if (!PWENT_ENTRY(pwent.gidstr, pwent.uidstr)) goto fail;
756-
780+
+        if (!PWENT_ENTRY(pwent.comment, pwent.gidstr)) goto fail;
757-
781+
+        if (!PWENT_ENTRY(pwent.homedir, pwent.comment)) goto fail;
758-
782+
+        PWENT_ENTRY(pwent.shell, pwent.homedir);
759-
783+
+
760-
784+
+        errno = 0;
761-
785+
+        uid = strtol(pwent.uidstr, NULL, 10);
762-
786+
+        if (errno != 0)
763-
787+
+            goto fail;
764-
788+
+
765-
789+
+        errno = 0;
766-
790+
+        gid = strtol(pwent.gidstr, NULL, 10);
767-
791+
+        if (errno != 0)
768-
792+
+            goto fail;
769-
793+
+
770-
794+
+
771-
795+
+#if 1
772-
796+
+        (void)printf("cygwin_getent_passwd(): name='%s'\n", name);
773-
797+
+        (void)printf("loginname\t='%s'\n", pwent.loginname);
774-
798+
+        (void)printf("passwd\t='%s'\n", pwent.passwd);
775-
799+
+        (void)printf("uidstr\t='%s' (%lu)\n", pwent.uidstr, (unsigned long)uid);
776-
800+
+        (void)printf("gidstr\t='%s' (%lu)\n", pwent.gidstr, (unsigned long)gid);
777-
801+
+        (void)printf("comment\t='%s'\n", pwent.comment);
778-
802+
+        (void)printf("homedir\t='%s'\n", pwent.homedir);
779-
803+
+        (void)printf("shell\t='%s'\n", pwent.shell);
780-
804+
+#endif
781-
805+
+
782-
806+
+found:
783-
807+
+        if (res_loginname)
784-
808+
+            (void)strcpy_s(res_loginname, VAL_LEN, pwent.loginname);
785-
809+
+        *res_uid = uid;
786-
810+
+        *res_gid = gid;
787-
811+
+        res = 0;
788-
812+
+    }
789-
813+
+
790-
814+
+
791-
815+
+fail:
792-
816+
+    if (getent_pipe)
793-
817+
+        (void)_pclose(getent_pipe);
794-
818+
+
795-
819+
+    if (res != 0) {
796-
820+
+        (void)printf("cygwin_getent_passwd(): NO MATCH FOR name='%s'\n", name);
797-
821+
+    }
798-
822+
+
799-
823+
+    return res;
800-
824+
+}
801-
825+
+
802-
826+
+int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid)
803-
827+
+{
804-
828+
+    char cmdbuff[1024];
805-
829+
+    char group_line[1024];
806-
830+
+    FILE* getent_pipe = NULL;
807-
831+
+    int res = 1;
808-
832+
+    unsigned long gid = -1;
809-
833+
+    struct _cygrent
810-
834+
+    {
811-
835+
+        char* group_name;
812-
836+
+        char* passwd;
813-
837+
+        char* gidstr;
814-
838+
+        char* userlist;
815-
839+
+    } grent = { 0 };
816-
840+
+
817-
841+
+#if 1
818-
842+
+    if ((!_stricmp(name, "rmainz")) || (!stricmp(name, "1616"))) {
819-
843+
+        gid = 1616;
820-
844+
+        grent.group_name = "rmainz";
821-
845+
+        goto found;
822-
846+
+    }
823-
847+
+    if ((!_stricmp(name, "nogroup")) || (!stricmp(name, "65534"))) {
824-
848+
+        gid = 65534;
825-
849+
+        grent.group_name = "nogroup";
826-
850+
+        goto found;
827-
851+
+    }
828-
852+
+    if ((!_stricmp(name, "root")) || (!stricmp(name, "0"))) {
829-
853+
+        gid = 0;
830-
854+
+        grent.group_name = "root";
831-
855+
+        goto found;
832-
856+
+    }
833-
857+
+    if ((!_stricmp(name, "iam")) || (!stricmp(name, "2010"))) {
834-
858+
+        gid = 2010;
835-
859+
+        grent.group_name = "iam";
836-
860+
+        goto found;
837-
861+
+    }
838-
862+
+    if ((!_stricmp(name, "swulsch")) || (!stricmp(name, "1818"))) {
839-
863+
+        gid = 1818;
840-
864+
+        grent.group_name = "swulsch";
841-
865+
+        goto found;
842-
866+
+    }
843-
867+
+    if ((!_stricmp(name, "mwenzel")) || (!stricmp(name, "8239"))) {
844-
868+
+        gid = 8239;
845-
869+
+        grent.group_name = "mwenzel";
846-
870+
+        goto found;
847-
871+
+    }
848-
872+
+#endif
849-
873+
+
850-
874+
+    /* fixme: better quoting for |name| needed */
851-
875+
+    (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s group \"%s\"",
852-
876+
+        "C:\\cygwin64\\bin\\getent.exe",
853-
877+
+        name);
854-
878+
+    if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL)
855-
879+
+    {
856-
880+
+        (void)perror("getent failed");
857-
881+
+        return 1;
858-
882+
+    }
859-
883+
+
860-
884+
+    if (fgets(group_line, sizeof(group_line), getent_pipe))
861-
885+
+    {
862-
886+
+        grent.group_name = group_line;
863-
887+
+        if (!PWENT_ENTRY(grent.passwd, grent.group_name)) goto fail;
864-
888+
+        if (!PWENT_ENTRY(grent.gidstr, grent.passwd)) goto fail;
865-
889+
+        PWENT_ENTRY(grent.userlist, grent.gidstr);
866-
890+
+
867-
891+
+        errno = 0;
868-
892+
+        gid = strtol(grent.gidstr, NULL, 10);
869-
893+
+        if (errno != 0)
870-
894+
+            goto fail;
871-
895+
+
872-
896+
+        (void)printf("cygwin_getent_group(): name='%s'\n", name);
873-
897+
+        (void)printf("group_name\t='%s'\n", grent.group_name);
874-
898+
+        (void)printf("passwd\t='%s'\n", grent.passwd);
875-
899+
+        (void)printf("gidstr\t='%s' (%lu)\n", grent.gidstr, (unsigned long)gid);
876-
900+
+        (void)printf("userlist\t='%s'\n", grent.userlist);
877-
901+
+
878-
902+
+found:
879-
903+
+        if (res_group_name)
880-
904+
+            (void)strcpy_s(res_group_name, VAL_LEN, grent.group_name);
881-
905+
+        *res_gid = gid;
882-
906+
+        res = 0;
883-
907+
+    }
884-
908+
+
885-
909+
+fail:
886-
910+
+    if (getent_pipe)
887-
911+
+        (void)_pclose(getent_pipe);
888-
912+
+
889-
913+
+    if (res != 0) {
890-
914+
+        (void)printf("cygwin_getent_group(): NO MATCH FOR name='%s'\n", name);
891-
915+
+    }
892-
916+
+
893-
917+
+    return res;
894-
918+
+}
895-
919+
+#endif /* CYGWIN_GETENT_USERDATA */
896920
897-
921+
 /* generic cache */
898-
922+
 typedef struct list_entry* (*entry_alloc_fn)();
899-
923+
@@ -665,10 +881,10 @@ static int idmap_lookup_user(
900-
924+
     if (status == NO_ERROR) {
901-
925+
         /* don't return expired entries; query new attributes
902-
926+
          * and overwrite the entry with cache_insert() */
903-
927+
-        if (time(NULL) - user->last_updated < context->config.cache_ttl)
904-
928+
+        if ((time(NULL) - user->last_updated) < context->config.cache_ttl)
905-
929+
             goto out;
906-
930+
     }
907-
931+
-
908-
932+
+#if 0
909-
933+
     /* send the query to the ldap server */
910-
934+
     status = idmap_query_attrs(context, lookup,
911-
935+
         attributes, optional, values, NUM_ATTRIBUTES);
912-
936+
@@ -705,7 +921,91 @@ static int idmap_lookup_user(
913-
937+
         goto out_free_values;
914-
938+
     }
915-
939+
     user->last_updated = time(NULL);
916-
940+
-
917-
941+
+#else
918-
942+
+    if (lookup->attr == ATTR_USER_NAME) {
919-
943+
+	char principal_name[VAL_LEN];
920-
944+
+	uid_t cy_uid = 0;
921-
945+
+	gid_t cy_gid = 0;
922-
946+
+
923-
947+
+	status = ERROR_NOT_FOUND;
924-
948+
+
925-
949+
+        if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) {
926-
950+
+            eprintf("# ATTR_USER_NAME: cygwin_getent_passwd: returned '%s', uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid);
927-
951+
+	    (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC");
928-
952+
+            StringCchCopyA(user->username, VAL_LEN, lookup->value);
929-
953+
+            StringCchCopyA(user->principal, VAL_LEN, principal_name);
930-
954+
+            user->uid = cy_uid;
931-
955+
+            user->gid = cy_gid;
932-
956+
+	    status = 0;
933-
957+
+	}
934-
958+
+    }
935-
959+
+    else if (lookup->attr == ATTR_PRINCIPAL) {
936-
960+
+	char search_name[VAL_LEN];
937-
961+
+	char principal_name[VAL_LEN];
938-
962+
+	char *s;
939-
963+
+	uid_t cy_uid = 0;
940-
964+
+	gid_t cy_gid = 0;
941-
965+
+
942-
966+
+	status = ERROR_NOT_FOUND;
943-
967+
+
944-
968+
+	/*
945-
969+
+	 * strip '@' from principal name and use that for getent
946-
970+
+	 * fixme: This does not work with multiple domains
947-
971+
+	 */
948-
972+
+	(void)strcpy_s(search_name, sizeof(search_name), lookup->value);
949-
973+
+	if (s = strchr(search_name, '@'))
950-
974+
+	    *s = '\0';
951-
975+
+
952-
976+
+        if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) {
953-
977+
+            eprintf("# ATTR_PRINCIPAL: cygwin_getent_passwd: returned '%s', uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid);
954-
978+
+	    (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC");
955-
979+
+
956-
980+
+	    if (!_stricmp(principal_name, lookup->value)) {
957-
981+
+                StringCchCopyA(user->username, VAL_LEN, search_name);
958-
982+
+                StringCchCopyA(user->principal, VAL_LEN, principal_name);

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