Difference between
modified post c8dfa790 by Anonymous on Tue 19th Sep 2023 13:52
original post 7923b0b by Anonymous on Sat 16th Sep 2023 13:43
Download diff
Show
old version |
new version |
both versions
| 1 | - | diff --git a/daemon/idmap.c b/daemon/idmap.c | |
| 1 | + | diff --git a/daemon/acl.c b/daemon/acl.c | |
| 2 | - | index 0dfa8ef..b50f4e2 100644 | |
| 2 | + | index 3a86735..61a737d 100644 | |
| 3 | - | --- a/daemon/idmap.c | |
| 3 | + | --- a/daemon/acl.c | |
| 4 | - | +++ b/daemon/idmap.c | |
| 4 | + | +++ b/daemon/acl.c | |
| 5 | - | @@ -31,6 +31,7 @@ | |
| 5 | + | @@ -65,6 +65,9 @@ static int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid, | |
| 6 | - | #include "list.h" | |
| 6 | + | status = GetLastError(); | |
| 7 | - | #include "daemon_debug.h" | |
| 7 | + | if (status != ERROR_INSUFFICIENT_BUFFER) | |
| 14 | 8 | return status; | |
| 15 | - | } | |
| 9 | + | +#if 1 | |
| 10 | + | +*sid_len += 256; | |
| 16 | 18 | ||
| 17 | - | +#ifdef CYGWIN_GETENT_USERDATA | |
| 19 | + | +#if 1 | |
| 18 | - | +int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid, gid_t *res_gid) | |
| 20 | + | + /* test mapping: Map UNIX user "rmainz" to Windows user "roland_mainz" */ | |
| 19 | - | +{ | |
| 21 | + | + if (!_stricmp(name, "rmainz")) | |
| 20 | - | + char cmdbuff[1024]; | |
| 22 | + | + name = "roland_mainz"; | |
| 21 | - | + char passwd_line[1024]; | |
| 23 | + | +#endif | |
| 22 | - | + FILE* getent_pipe; | |
| 24 | + | status = LookupAccountName(NULL, name, NULL, sid_len, NULL, &tmp, &sid_type); | |
| 23 | - | + int res = 1; | |
| 25 | + | dprintf(ACLLVL, "map_name_2_sid: LookupAccountName for %s returned %d " | |
| 24 | - | + | |
| 26 | + | "GetLastError %d name len %d domain len %d\n", name, status, | |
| 25 | - | + /* fixme: better quoting for |name| needed */ | |
| 27 | + | @@ -107,6 +115,9 @@ static int map_name_2_sid(DWORD *sid_len, PSID *sid, LPCSTR name) | |
| 26 | - | + (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s passwd \"%s\"", | |
| 28 | + | status = GetLastError(); | |
| 27 | - | + "C:\\cygwin64\\bin\\getent.exe", | |
| 29 | + | switch(status) { | |
| 28 | - | + name); | |
| 30 | + | case ERROR_INSUFFICIENT_BUFFER: | |
| 29 | - | + if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL) | |
| 31 | + | +#if 1 | |
| 30 | - | + { | |
| 32 | + | +*sid_len += 256; | |
| 31 | - | + (void)perror("getent failed"); | |
| 33 | + | +#endif | |
| 32 | - | + return 1; | |
| 34 | + | *sid = malloc(*sid_len); | |
| 33 | - | + } | |
| 35 | + | if (*sid == NULL) { | |
| 34 | - | + | |
| 36 | + | status = GetLastError(); | |
| 35 | - | + if (fgets(passwd_line, sizeof(passwd_line), getent_pipe)) | |
| 37 | + | @@ -798,4 +809,4 @@ const nfs41_upcall_op nfs41_op_setacl = { | |
| 36 | - | + { | |
| 38 | + | parse_setacl, | |
| 37 | - | + struct _cypwent | |
| 39 | + | handle_setacl, | |
| 38 | - | + { | |
| 40 | + | marshall_setacl | |
| 39 | - | + char* loginname; | |
| 41 | + | -}; | |
| 40 | - | + char* passwd; | |
| 42 | + | \ No newline at end of file | |
| 41 | - | + char* uidstr; | |
| 43 | + | +}; | |
| 42 | - | + char* gidstr; | |
| 44 | + | diff --git a/daemon/idmap.c b/daemon/idmap.c | |
| 43 | - | + char* comment; | |
| 45 | + | index 0dfa8ef..b50f4e2 100644 | |
| 44 | - | + char* homedir; | |
| 46 | + | --- a/daemon/idmap.c | |
| 45 | - | + char* shell; | |
| 47 | + | +++ b/daemon/idmap.c | |
| 46 | - | + } pwent = { 0 }; | |
| 48 | + | @@ -31,6 +31,7 @@ | |
| 47 | - | +#define PWENT_ENTRY(var, prevvar) \ | |
| 49 | + | #include "list.h" | |
| 48 | - | + (((var) = strchr((prevvar), ':'))?(*(var)++ = '\0',(var)):(NULL)) | |
| 50 | + | #include "daemon_debug.h" | |
| 49 | - | + | |
| 51 | + | ||
| 50 | - | + pwent.loginname = passwd_line; | |
| 52 | + | +#define CYGWIN_GETENT_USERDATA 1 | |
| 51 | - | + if (!PWENT_ENTRY(pwent.passwd, pwent.loginname)) goto fail; | |
| 53 | + | ||
| 52 | - | + if (!PWENT_ENTRY(pwent.uidstr, pwent.passwd)) goto fail; | |
| 54 | + | #define IDLVL 2 /* dprintf level for idmap logging */ | |
| 53 | - | + if (!PWENT_ENTRY(pwent.gidstr, pwent.uidstr)) goto fail; | |
| 55 | + | ||
| 54 | - | + if (!PWENT_ENTRY(pwent.comment, pwent.gidstr)) goto fail; | |
| 56 | + | @@ -375,6 +376,156 @@ out: | |
| 55 | - | + if (!PWENT_ENTRY(pwent.homedir, pwent.comment)) goto fail; | |
| 57 | + | return status; | |
| 56 | - | + PWENT_ENTRY(pwent.shell, pwent.homedir); | |
| 58 | + | } | |
| 59 | + | ||
| 57 | 67 | + | |
| 58 | - | + unsigned long uid; | |
| 68 | + | + /* fixme: better quoting for |name| needed */ | |
| 59 | - | + unsigned long gid; | |
| 69 | + | + (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s passwd \"%s\"", | |
| 70 | + | + "C:\\cygwin64\\bin\\getent.exe", | |
| 60 | 77 | + | |
| 61 | - | + errno = 0; | |
| 78 | + | + if (fgets(passwd_line, sizeof(passwd_line), getent_pipe)) | |
| 62 | - | + uid = strtol(pwent.uidstr, NULL, 10); | |
| 79 | + | + { | |
| 63 | - | + if (errno != 0) | |
| 80 | + | + struct _cypwent | |
| 64 | - | + goto fail; | |
| 81 | + | + { | |
| 65 | - | + | |
| 82 | + | + char* loginname; | |
| 66 | - | + errno = 0; | |
| 83 | + | + char* passwd; | |
| 67 | - | + gid = strtol(pwent.gidstr, NULL, 10); | |
| 84 | + | + char* uidstr; | |
| 68 | - | + if (errno != 0) | |
| 85 | + | + char* gidstr; | |
| 69 | - | + goto fail; | |
| 86 | + | + char* comment; | |
| 87 | + | + char* homedir; | |
| 70 | 92 | + | |
| 71 | - | +#if 1 | |
| 93 | + | + pwent.loginname = passwd_line; | |
| 72 | - | + /* hack for testing, map "roland_mainz" to rmainz account */ | |
| 94 | + | + if (!PWENT_ENTRY(pwent.passwd, pwent.loginname)) goto fail; | |
| 73 | - | + if (!_stricmp(pwent.loginname, "roland_mainz")) { | |
| 95 | + | + if (!PWENT_ENTRY(pwent.uidstr, pwent.passwd)) goto fail; | |
| 74 | - | + uid = 1616; | |
| 96 | + | + if (!PWENT_ENTRY(pwent.gidstr, pwent.uidstr)) goto fail; | |
| 75 | - | + gid = 1616; | |
| 97 | + | + if (!PWENT_ENTRY(pwent.comment, pwent.gidstr)) goto fail; | |
| 76 | - | + } | |
| 98 | + | + if (!PWENT_ENTRY(pwent.homedir, pwent.comment)) goto fail; | |
| 77 | - | +#endif | |
| 99 | + | + PWENT_ENTRY(pwent.shell, pwent.homedir); | |
| 78 | - | +#if 0 | |
| 100 | + | + | |
| 79 | - | + (void)printf("loginname\t=%s\n", pwent.loginname); | |
| 101 | + | + unsigned long uid; | |
| 80 | - | + (void)printf("passwd\t=%s\n", pwent.passwd); | |
| 102 | + | + unsigned long gid; | |
| 81 | - | + (void)printf("uidstr\t=%s (%lu)\n", pwent.uidstr, (unsigned long)uid); | |
| 103 | + | + | |
| 82 | - | + (void)printf("gidstr\t=%s (%lu)\n", pwent.gidstr, (unsigned long)gid); | |
| 104 | + | + errno = 0; | |
| 83 | - | + (void)printf("comment\t=%s\n", pwent.comment); | |
| 105 | + | + uid = strtol(pwent.uidstr, NULL, 10); | |
| 84 | - | + (void)printf("homedir\t=%s\n", pwent.homedir); | |
| 106 | + | + if (errno != 0) | |
| 85 | - | + (void)printf("shell\t=%s\n", pwent.shell); | |
| 107 | + | + goto fail; | |
| 93 | 108 | + | |
| 94 | - | +fail: | |
| 109 | + | + errno = 0; | |
| 95 | - | + (void)_pclose(getent_pipe); | |
| 110 | + | + gid = strtol(pwent.gidstr, NULL, 10); | |
| 111 | + | + if (errno != 0) | |
| 96 | 113 | + | |
| 97 | - | + return res; | |
| 114 | + | +#if 1 | |
| 98 | - | +} | |
| 115 | + | + /* hack for testing, map "roland_mainz" to rmainz account */ | |
| 99 | - | + | |
| 116 | + | + if (!_stricmp(pwent.loginname, "roland_mainz")) { | |
| 100 | - | +int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid) | |
| 117 | + | + uid = 1616; | |
| 101 | - | +{ | |
| 118 | + | + gid = 1616; | |
| 102 | - | + char cmdbuff[1024]; | |
| 119 | + | + } | |
| 103 | - | + char group_line[1024]; | |
| 120 | + | +#endif | |
| 104 | - | + FILE* getent_pipe; | |
| 121 | + | +#if 0 | |
| 105 | - | + int res = 1; | |
| 122 | + | + (void)printf("loginname\t=%s\n", pwent.loginname); | |
| 106 | - | + | |
| 123 | + | + (void)printf("passwd\t=%s\n", pwent.passwd); | |
| 107 | - | + /* fixme: better quoting for |name| needed */ | |
| 124 | + | + (void)printf("uidstr\t=%s (%lu)\n", pwent.uidstr, (unsigned long)uid); | |
| 108 | - | + (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s group \"%s\"", | |
| 125 | + | + (void)printf("gidstr\t=%s (%lu)\n", pwent.gidstr, (unsigned long)gid); | |
| 109 | - | + "C:\\cygwin64\\bin\\getent.exe", | |
| 126 | + | + (void)printf("comment\t=%s\n", pwent.comment); | |
| 110 | - | + name); | |
| 127 | + | + (void)printf("homedir\t=%s\n", pwent.homedir); | |
| 111 | - | + if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL) | |
| 128 | + | + (void)printf("shell\t=%s\n", pwent.shell); | |
| 112 | - | + { | |
| 129 | + | +#endif | |
| 113 | - | + (void)perror("getent failed"); | |
| 130 | + | + if (res_loginname) | |
| 114 | - | + return 1; | |
| 131 | + | + (void)strcpy_s(res_loginname, VAL_LEN, pwent.loginname); | |
| 132 | + | + *res_uid = uid; | |
| 115 | 135 | + } | |
| 116 | 136 | + | |
| 117 | - | + if (fgets(group_line, sizeof(group_line), getent_pipe)) | |
| 137 | + | +fail: | |
| 118 | - | + { | |
| 138 | + | + (void)_pclose(getent_pipe); | |
| 126 | 139 | + | |
| 127 | - | + grent.group_name = group_line; | |
| 140 | + | + return res; | |
| 128 | - | + if (!PWENT_ENTRY(grent.passwd, grent.group_name)) goto fail; | |
| 141 | + | +} | |
| 131 | 142 | + | |
| 132 | - | + unsigned long gid; | |
| 143 | + | +int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid) | |
| 144 | + | +{ | |
| 133 | 149 | + | |
| 134 | - | + errno = 0; | |
| 150 | + | + /* fixme: better quoting for |name| needed */ | |
| 135 | - | + gid = strtol(grent.gidstr, NULL, 10); | |
| 151 | + | + (void)snprintf(cmdbuff, sizeof(cmdbuff), "%s group \"%s\"", | |
| 136 | - | + if (errno != 0) | |
| 152 | + | + "C:\\cygwin64\\bin\\getent.exe", | |
| 137 | - | + goto fail; | |
| 153 | + | + name); | |
| 154 | + | + if ((getent_pipe = _popen(cmdbuff, "rt")) == NULL) | |
| 138 | 159 | + | |
| 139 | - | +#if 1 | |
| 160 | + | + if (fgets(group_line, sizeof(group_line), getent_pipe)) | |
| 140 | - | + /* hack for testing, map "roland_mainz" to rmainz account */ | |
| 161 | + | + { | |
| 141 | - | + if (!_stricmp(grent.group_name, "roland_mainz")) { | |
| 162 | + | + struct _cygrent | |
| 142 | - | + gid = 1616; | |
| 163 | + | + { | |
| 143 | - | + } | |
| 164 | + | + char* group_name; | |
| 144 | - | +#endif | |
| 165 | + | + char* passwd; | |
| 166 | + | + char* gidstr; | |
| 145 | 169 | + | |
| 146 | - | + (void)printf("group_name\t=%s\n", grent.group_name); | |
| 170 | + | + grent.group_name = group_line; | |
| 147 | - | + (void)printf("passwd\t=%s\n", grent.passwd); | |
| 171 | + | + if (!PWENT_ENTRY(grent.passwd, grent.group_name)) goto fail; | |
| 148 | - | + (void)printf("gidstr\t=%s (%lu)\n", grent.gidstr, (unsigned long)gid); | |
| 172 | + | + if (!PWENT_ENTRY(grent.gidstr, grent.passwd)) goto fail; | |
| 149 | - | + (void)printf("userlist\t=%s\n", grent.userlist); | |
| 173 | + | + PWENT_ENTRY(grent.userlist, grent.gidstr); | |
| 150 | 174 | + | |
| 151 | - | + if (res_group_name) | |
| 175 | + | + unsigned long gid; | |
| 160 | 176 | + | |
| 161 | - | +fail: | |
| 177 | + | + errno = 0; | |
| 162 | - | + (void)_pclose(getent_pipe); | |
| 178 | + | + gid = strtol(grent.gidstr, NULL, 10); | |
| 179 | + | + if (errno != 0) | |
| 163 | 181 | + | |
| 164 | - | + return res; | |
| 182 | + | +#if 1 | |
| 165 | - | +} | |
| 183 | + | + /* hack for testing, map "roland_mainz" to rmainz account */ | |
| 166 | - | +#endif /* CYGWIN_GETENT_USERDATA */ | |
| 184 | + | + if (!_stricmp(grent.group_name, "roland_mainz")) { | |
| 167 | - | ||
| 185 | + | + gid = 1616; | |
| 168 | - | /* generic cache */ | |
| 186 | + | + } | |
| 169 | - | typedef struct list_entry* (*entry_alloc_fn)(); | |
| 187 | + | +#endif | |
| 170 | - | @@ -665,10 +816,10 @@ static int idmap_lookup_user( | |
| 188 | + | + | |
| 171 | - | if (status == NO_ERROR) { | |
| 189 | + | + (void)printf("group_name\t=%s\n", grent.group_name); | |
| 172 | - | /* don't return expired entries; query new attributes | |
| 190 | + | + (void)printf("passwd\t=%s\n", grent.passwd); | |
| 173 | - | * and overwrite the entry with cache_insert() */ | |
| 191 | + | + (void)printf("gidstr\t=%s (%lu)\n", grent.gidstr, (unsigned long)gid); | |
| 174 | - | - if (time(NULL) - user->last_updated < context->config.cache_ttl) | |
| 192 | + | + (void)printf("userlist\t=%s\n", grent.userlist); | |
| 175 | - | + if ((time(NULL) - user->last_updated) < context->config.cache_ttl) | |
| 193 | + | + | |
| 176 | - | goto out; | |
| 194 | + | + if (res_group_name) | |
| 177 | - | } | |
| 195 | + | + (void)strcpy_s(res_group_name, VAL_LEN, grent.group_name); | |
| 178 | - | - | |
| 196 | + | + *res_gid = gid; | |
| 179 | - | +#if 0 | |
| 197 | + | + res = 0; | |
| 180 | - | /* send the query to the ldap server */ | |
| 198 | + | + } | |
| 181 | - | status = idmap_query_attrs(context, lookup, | |
| 199 | + | + else | |
| 182 | - | attributes, optional, values, NUM_ATTRIBUTES); | |
| 200 | + | + { | |
| 183 | - | @@ -705,7 +856,91 @@ static int idmap_lookup_user( | |
| 201 | + | + (void)puts("no match for group"); | |
| 184 | - | goto out_free_values; | |
| 202 | + | + } | |
| 193 | 203 | + | |
| 194 | - | + status = ERROR_NOT_FOUND; | |
| 204 | + | +fail: | |
| 205 | + | + (void)_pclose(getent_pipe); | |
| 195 | 206 | + | |
| 196 | - | + if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) { | |
| 207 | + | + return res; | |
| 197 | - | + eprintf("# ATTR_USER_NAME: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid); | |
| 208 | + | +} | |
| 198 | - | + (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC"); | |
| 209 | + | +#endif /* CYGWIN_GETENT_USERDATA */ | |
| 199 | - | + StringCchCopyA(user->username, VAL_LEN, lookup->value); | |
| 210 | + | ||
| 200 | - | + StringCchCopyA(user->principal, VAL_LEN, principal_name); | |
| 211 | + | /* generic cache */ | |
| 201 | - | + user->uid = cy_uid; | |
| 212 | + | typedef struct list_entry* (*entry_alloc_fn)(); | |
| 202 | - | + user->gid = cy_gid; | |
| 213 | + | @@ -665,10 +816,10 @@ static int idmap_lookup_user( | |
| 203 | - | + status = 0; | |
| 214 | + | if (status == NO_ERROR) { | |
| 204 | - | + } | |
| 215 | + | /* don't return expired entries; query new attributes | |
| 205 | - | + } | |
| 216 | + | * and overwrite the entry with cache_insert() */ | |
| 206 | - | + else if (lookup->attr == ATTR_PRINCIPAL) { | |
| 217 | + | - if (time(NULL) - user->last_updated < context->config.cache_ttl) | |
| 207 | - | + char search_name[VAL_LEN]; | |
| 218 | + | + if ((time(NULL) - user->last_updated) < context->config.cache_ttl) | |
| 208 | - | + char principal_name[VAL_LEN]; | |
| 219 | + | goto out; | |
| 209 | - | + char *s; | |
| 220 | + | } | |
| 210 | - | + uid_t cy_uid = 0; | |
| 221 | + | - | |
| 211 | - | + gid_t cy_gid = 0; | |
| 222 | + | +#if 0 | |
| 212 | - | + | |
| 223 | + | /* send the query to the ldap server */ | |
| 213 | - | + status = ERROR_NOT_FOUND; | |
| 224 | + | status = idmap_query_attrs(context, lookup, | |
| 214 | - | + | |
| 225 | + | attributes, optional, values, NUM_ATTRIBUTES); | |
| 215 | - | + /* | |
| 226 | + | @@ -705,7 +856,91 @@ static int idmap_lookup_user( | |
| 216 | - | + * strip '@' from principal name and use that for getent | |
| 227 | + | goto out_free_values; | |
| 217 | - | + * fixme: This does not work with multiple domains | |
| 228 | + | } | |
| 218 | - | + */ | |
| 229 | + | user->last_updated = time(NULL); | |
| 219 | - | + (void)strcpy_s(search_name, sizeof(search_name), lookup->value); | |
| 230 | + | - | |
| 220 | - | + if (s = strchr(search_name, '@')) | |
| 231 | + | +#else | |
| 221 | - | + *s = '\0'; | |
| 232 | + | + if (lookup->attr == ATTR_USER_NAME) { | |
| 233 | + | + char principal_name[VAL_LEN]; | |
| 222 | 236 | + | |
| 223 | - | + if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) { | |
| 237 | + | + status = ERROR_NOT_FOUND; | |
| 226 | 238 | + | |
| 227 | - | + if (!_stricmp(principal_name, lookup->value)) { | |
| 239 | + | + if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) { | |
| 228 | - | + StringCchCopyA(user->username, VAL_LEN, search_name); | |
| 240 | + | + eprintf("# ATTR_USER_NAME: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid); | |
| 229 | - | + StringCchCopyA(user->principal, VAL_LEN, principal_name); | |
| 241 | + | + (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC"); | |
| 230 | - | + user->uid = cy_uid; | |
| 242 | + | + StringCchCopyA(user->username, VAL_LEN, lookup->value); | |
| 231 | - | + user->gid = cy_gid; | |
| 243 | + | + StringCchCopyA(user->principal, VAL_LEN, principal_name); | |
| 232 | - | + status = 0; | |
| 244 | + | + user->uid = cy_uid; | |
| 233 | - | + } | |
| 245 | + | + user->gid = cy_gid; | |
| 246 | + | + status = 0; | |
| 234 | 247 | + } | |
| 235 | 248 | + } | |
| 236 | - | + else if (lookup->attr == ATTR_UID) { | |
| 249 | + | + else if (lookup->attr == ATTR_PRINCIPAL) { | |
| 238 | 250 | + char search_name[VAL_LEN]; | |
| 240 | 251 | + char principal_name[VAL_LEN]; | |
| 252 | + | + char *s; | |
| 241 | 253 | + uid_t cy_uid = 0; | |
| 242 | 254 | + gid_t cy_gid = 0; | |
| 243 | 255 | + | |
| 244 | 256 | + status = ERROR_NOT_FOUND; | |
| 245 | 257 | + | |
| 246 | - | + (void)snprintf(search_name, sizeof(search_name), "%lu", (unsigned long)search_uid); | |
| 258 | + | + /* | |
| 259 | + | + * strip '@' from principal name and use that for getent | |
| 247 | 265 | + | |
| 248 | - | + if (!cygwin_getent_passwd(search_name, res_username, &cy_uid, &cy_gid)) { | |
| 266 | + | + if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) { | |
| 249 | - | + eprintf("# ATTR_UID: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", res_username, (int)cy_uid, (int)cy_gid); | |
| 267 | + | + eprintf("# ATTR_PRINCIPAL: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", lookup->value, (int)cy_uid, (int)cy_gid); | |
| 250 | - | + (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", res_username, "GLOBAL.LOC"); | |
| 268 | + | + (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", lookup->value, "GLOBAL.LOC"); | |
| 251 | 269 | + | |
| 252 | - | + StringCchCopyA(user->username, VAL_LEN, res_username); | |
| 270 | + | + if (!_stricmp(principal_name, lookup->value)) { | |
| 253 | - | + StringCchCopyA(user->principal, VAL_LEN, principal_name); | |
| 271 | + | + StringCchCopyA(user->username, VAL_LEN, search_name); | |
| 254 | - | + user->uid = cy_uid; | |
| 272 | + | + StringCchCopyA(user->principal, VAL_LEN, principal_name); | |
| 255 | - | + user->gid = cy_gid; | |
| 273 | + | + user->uid = cy_uid; | |
| 256 | - | + status = 0; | |
| 274 | + | + user->gid = cy_gid; | |
| 275 | + | + status = 0; | |
| 257 | 277 | + } | |
| 258 | 278 | + } | |
| 259 | - | + else | |
| 279 | + | + else if (lookup->attr == ATTR_UID) { | |
| 260 | - | + { | |
| 280 | + | + uid_t search_uid = (uid_t)(lookup->value); | |
| 261 | - | + status = ERROR_NOT_FOUND; | |
| 281 | + | + char search_name[VAL_LEN]; | |
| 262 | - | + } | |
| 282 | + | + char res_username[VAL_LEN]; | |
| 283 | + | + char principal_name[VAL_LEN]; | |
| 263 | 286 | + | |
| 264 | - | + if (status == 0) { | |
| 287 | + | + status = ERROR_NOT_FOUND; | |
| 265 | - | + user->last_updated = time(NULL); | |
| 288 | + | + | |
| 266 | - | + eprintf("## idmap_lookup_user: found username='%s', principal='%s', uid=%lu, gid=%lu\n", | |
| 289 | + | + (void)snprintf(search_name, sizeof(search_name), "%lu", (unsigned long)search_uid); | |
| 267 | - | + user->username, | |
| 290 | + | + | |
| 268 | - | + user->principal, | |
| 291 | + | + if (!cygwin_getent_passwd(search_name, res_username, &cy_uid, &cy_gid)) { | |
| 269 | - | + (unsigned long)user->uid, | |
| 292 | + | + eprintf("# ATTR_UID: cygwin_getent_passwd: returned %s, uid=%d, gid=%d\n", res_username, (int)cy_uid, (int)cy_gid); | |
| 270 | - | + (unsigned long)user->gid); | |
| 293 | + | + (void)snprintf(principal_name, sizeof(principal_name), "%s@%s", res_username, "GLOBAL.LOC"); | |
| 294 | + | + | |
| 271 | 301 | + } | |
| 272 | - | +#endif | |
| 302 | + | + else | |
| 273 | - | if (context->config.cache_ttl) { | |
| 303 | + | + { | |
| 274 | - | /* insert the entry into the cache */ | |
| 304 | + | + status = ERROR_NOT_FOUND; | |
| 275 | - | cache_insert(&context->users, lookup, &user->entry); | |
| 305 | + | + } | |
| 276 | - | @@ -732,10 +967,10 @@ static int idmap_lookup_group( | |
| 306 | + | + | |
| 277 | - | if (status == NO_ERROR) { | |
| 307 | + | + if (status == 0) { | |
| 278 | - | /* don't return expired entries; query new attributes | |
| 308 | + | + user->last_updated = time(NULL); | |
| 279 | - | * and overwrite the entry with cache_insert() */ | |
| 309 | + | + eprintf("## idmap_lookup_user: found username='%s', principal='%s', uid=%lu, gid=%lu\n", | |
| 280 | - | - if (time(NULL) - group->last_updated < context->config.cache_ttl) | |
| 310 | + | + user->username, | |
| 281 | - | + if ((time(NULL) - group->last_updated) < context->config.cache_ttl) | |
| 311 | + | + user->principal, | |
| 282 | - | goto out; | |
| 312 | + | + (unsigned long)user->uid, | |
| 283 | - | } | |
| 313 | + | + (unsigned long)user->gid); | |
| 284 | - | - | |
| 314 | + | + } | |
| 285 | - | +#if 0 | |
| 315 | + | +#endif | |
| 286 | - | /* send the query to the ldap server */ | |
| 316 | + | if (context->config.cache_ttl) { | |
| 287 | - | status = idmap_query_attrs(context, lookup, | |
| 317 | + | /* insert the entry into the cache */ | |
| 288 | - | attributes, 0, values, NUM_ATTRIBUTES); | |
| 318 | + | cache_insert(&context->users, lookup, &user->entry); | |
| 289 | - | @@ -758,7 +993,48 @@ static int idmap_lookup_group( | |
| 319 | + | @@ -732,10 +967,10 @@ static int idmap_lookup_group( | |
| 290 | - | goto out_free_values; | |
| 320 | + | if (status == NO_ERROR) { | |
| 321 | + | /* don't return expired entries; query new attributes | |
| 291 | 326 | } | |
| 327 | + | - | |
| 292 | 335 | group->last_updated = time(NULL); | |
| 293 | 336 | +#else | |
| 294 | 337 | + if (lookup->attr == ATTR_GROUP_NAME) { | |
| 295 | 338 | + gid_t cy_gid = 0; | |
| 296 | 339 | + | |
| 297 | 340 | + status = ERROR_NOT_FOUND; | |
| 298 | 341 | + | |
| 299 | 342 | + if (!cygwin_getent_group(lookup->value, NULL, &cy_gid)) { | |
| 300 | 343 | + eprintf("# ATTR_GROUP_NAME: cygwin_getent_group: returned %s, gid=%d\n", lookup->value, (int)cy_gid); | |
| 301 | 344 | + StringCchCopyA(group->name, VAL_LEN, lookup->value); | |
| 302 | 345 | + group->gid = cy_gid; | |
| 303 | 346 | + status = 0; | |
| 304 | 347 | + } | |
| 305 | 348 | + } | |
| 306 | 349 | + else if (lookup->attr == ATTR_GID) { | |
| 307 | 350 | + gid_t search_gid = (gid_t)(lookup->value); | |
| 308 | 351 | + char search_name[VAL_LEN]; | |
| 309 | 352 | + char res_groupname[VAL_LEN]; | |
| 310 | 353 | + gid_t cy_gid = 0; | |
| 311 | 354 | + | |
| 312 | 355 | + status = ERROR_NOT_FOUND; | |
| 313 | 356 | + | |
| 314 | 357 | + (void)snprintf(search_name, sizeof(search_name), "%lu", (unsigned long)search_gid); | |
| 315 | 358 | + | |
| 316 | 359 | + if (!cygwin_getent_group(search_name, res_groupname, &cy_gid)) { | |
| 317 | 360 | + eprintf("# ATTR_GID: cygwin_getent_group: returned %s, gid=%d\n", res_groupname, (int)cy_gid); | |
| 318 | 361 | + StringCchCopyA(group->name, VAL_LEN, res_groupname); | |
| 319 | 362 | + group->gid = cy_gid; | |
| 320 | 363 | + status = 0; | |
| 321 | 364 | + } | |
| 322 | 365 | + } | |
| 323 | 366 | + else | |
| 324 | 367 | + { | |
| 325 | 368 | + status = ERROR_NOT_FOUND; | |
| 326 | 369 | + } | |
| 327 | 370 | ||
| 328 | 371 | + if (status == 0) { | |
| 329 | 372 | + group->last_updated = time(NULL); | |
| 330 | 373 | + eprintf("## idmap_lookup_group: found name='%s', gid=%lu\n", | |
| 331 | 374 | + group->name, | |
| 332 | 375 | + (unsigned long)group->gid); | |
| 333 | 376 | + } | |
| 334 | 377 | +#endif | |
| 335 | 378 | if (context->config.cache_ttl) { | |
| 336 | 379 | /* insert the entry into the cache */ | |
| 337 | 380 | cache_insert(&context->groups, lookup, &group->entry); | |
| 338 | 381 | @@ -795,6 +1071,7 @@ int nfs41_idmap_create( | |
| 339 | 382 | goto out_err_free; | |
| 340 | 383 | } | |
| 341 | 384 | ||
| 342 | 385 | +#if 0 | |
| 343 | 386 | /* initialize ldap and configure options */ | |
| 344 | 387 | context->ldap = ldap_init(context->config.hostname, context->config.port); | |
| 345 | 388 | if (context->ldap == NULL) { | |
| 346 | 389 | @@ -824,6 +1101,10 @@ int nfs41_idmap_create( | |
| 347 | 390 | goto out_err_free; | |
| 348 | 391 | } | |
| 349 | 392 | } | |
| 350 | 393 | +#else | |
| 351 | 394 | + eprintf("nfs41_idmap_create: Force context->config.timeout = 6000;\n"); | |
| 352 | 395 | + context->config.timeout = 6000; | |
| 353 | 396 | +#endif | |
| 354 | 397 | ||
| 355 | 398 | *context_out = context; | |
| 356 | 399 | out: | |
| 357 | 400 | diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c | |
| 358 | - | index 599f246..895d488 100644 | |
| 401 | + | index bb485cb..25ca6eb 100644 | |
| 359 | 402 | --- a/daemon/nfs41_daemon.c | |
| 360 | 403 | +++ b/daemon/nfs41_daemon.c | |
| 361 | - | @@ -384,9 +384,15 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv) | |
| 404 | + | @@ -389,6 +389,11 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv) | |
| 362 | - | #endif | |
| 405 | + | exit(1); | |
| 363 | - | /* acquire and store in global memory current dns domain name. | |
| 406 | + | } | |
| 371 | 407 | ||
| 372 | 408 | +#if 1 | |
| 373 | 409 | + /* force enable for cygwin getent passwd/group testing */ | |
| 374 | 410 | + cmd_args.ldap_enable = TRUE; | |
| 375 | 411 | +#endif | |
| 412 | + | + | |
| 376 | 413 | nfs41_server_list_init(); | |
| 377 | 414 | ||
| 378 | 415 | if (cmd_args.ldap_enable) { | |
| 379 | 416 |
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.
rovema.kpaste.net RSS