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