- diff --git a/daemon/sid.c b/daemon/sid.c
- index baaf95a..36500e9 100644
- --- a/daemon/sid.c
- +++ b/daemon/sid.c
- @@ -227,6 +227,7 @@ typedef struct _sidcache_entry
- {
- #define SIDCACHE_ENTRY_NAME_SIZE (UNLEN + 1)
- char win32name[SIDCACHE_ENTRY_NAME_SIZE]; /* must fit something like "user@domain" */
- + char aliasname[SIDCACHE_ENTRY_NAME_SIZE];
- PSID sid;
- DWORD sid_len;
- #pragma warning( push )
- @@ -254,8 +255,13 @@ void sidcache_init(void)
- InitializeCriticalSection(&group_sidcache.lock);
- }
- -/* copy SID |value| into cache */
- void sidcache_add(sidcache *cache, const char* win32name, PSID value)
- +{
- + sidcache_addwithalias(cache, win32name, NULL, value);
- +}
- +
- +/* copy SID |value| into cache */
- +void sidcache_addwithalias(sidcache *cache, const char *win32name, const char *aliasname, PSID value)
- {
- int i;
- ssize_t freeEntryIndex;
- @@ -271,9 +277,10 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
- sidcache_entry *e = &cache->entries[i];
- if ((e->sid != NULL) &&
- - (e->timestamp < (currentTimestamp - SIDCACHE_TTL))) {
- + ((currentTimestamp - e->timestamp) >= SIDCACHE_TTL)) {
- e->sid = NULL;
- e->win32name[0] = '\0';
- + e->aliasname[0] = '\0';
- e->sid_len = 0;
- }
- }
- @@ -281,9 +288,26 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
- /* Find the oldest valid cache entry */
- freeEntryIndex = -1;
- for (i = 0; i < SIDCACHE_SIZE; i++) {
- - if (cache->entries[i].sid) {
- + sidcache_entry *e = &cache->entries[i];
- + if (e->sid) {
- /* Same name ? Then reuse this slot... */
- - if (!strcmp(cache->entries[i].win32name, win32name)) {
- + if (!strcmp(e->win32name, win32name)) {
- + freeEntryIndex = i;
- + break;
- + }
- + if (aliasname) {
- + if (!strcmp(e->win32name, aliasname)) {
- + freeEntryIndex = i;
- + break;
- + }
- + if ((e->aliasname[0] != '\0') &&
- + (!strcmp(e->aliasname, aliasname))) {
- + freeEntryIndex = i;
- + break;
- + }
- + }
- + if ((e->aliasname[0] != '\0') &&
- + (!strcmp(e->aliasname, win32name))) {
- freeEntryIndex = i;
- break;
- }
- @@ -308,12 +332,17 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
- if (!CopySid(sid_len, e->sid, value)) {
- e->sid = NULL;
- e->win32name[0] = '\0';
- + e->aliasname[0] = '\0';
- e->sid_len = 0;
- goto done;
- }
- e->sid_len = sid_len;
- (void)strcpy(e->win32name, win32name);
- + if (aliasname)
- + (void)strcpy(e->aliasname, aliasname);
- + else
- + e->aliasname[0] = '\0';
- e->timestamp = currentTimestamp;
- cache->cacheIndex = (cache->cacheIndex + 1) % SIDCACHE_SIZE;
- @@ -337,7 +366,8 @@ PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name)
- e = &cache->entries[i];
- if ((e->sid != NULL) &&
- - (!strcmp(e->win32name, win32name)) &&
- + ((!strcmp(e->win32name, win32name)) ||
- + ((e->aliasname[0] != '\0') && (!strcmp(e->aliasname, win32name)))) &&
- ((currentTimestamp - e->timestamp) < SIDCACHE_TTL)) {
- PSID malloced_sid = malloc(e->sid_len);
- if (!malloced_sid)
- @@ -374,7 +404,6 @@ bool sidcache_getcached_bysid(sidcache *cache, PSID sid, char *out_win32name)
- if ((e->sid != NULL) &&
- (EqualSid(sid, e->sid) &&
- ((currentTimestamp - e->timestamp) < SIDCACHE_TTL))) {
- -
- (void)strcpy(out_win32name, e->win32name);
- ret = true;
- @@ -528,7 +557,7 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
- user_uid = map_uid;
- }
- else {
- - DPRINTF(1,
- + DPRINTF(0,
- ("map_nfs4servername_2_sid(query=%x,name='%s'): "
- "nfs41_idmap_name_to_uid() failed\n",
- query, nfsname));
- @@ -546,7 +575,7 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
- group_gid = map_gid;
- }
- else {
- - DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
- + DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
- query, nfsname));
- /* fixme: try harder here, "1234" should to to |atol()| */
- }
- @@ -635,10 +664,26 @@ out_cache:
- switch (sid_type) {
- case SidTypeUser:
- - sidcache_add(&user_sidcache, orig_nfsname, *sid);
- + if (isdigit(orig_nfsname[0])) {
- + DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
- + "adding usercache nfsname='%s' orig_nfsname='%s'\n",
- + query, orig_nfsname, nfsname, orig_nfsname));
- + sidcache_addwithalias(&user_sidcache, nfsname, orig_nfsname, *sid);
- + }
- + else {
- + sidcache_add(&user_sidcache, orig_nfsname, *sid);
- + }
- break;
- case SidTypeGroup:
- - sidcache_add(&group_sidcache, orig_nfsname, *sid);
- + if (isdigit(orig_nfsname[0])) {
- + DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
- + "adding groupcache nfsname='%s' orig_nfsname='%s'\n",
- + query, orig_nfsname, nfsname, orig_nfsname));
- + sidcache_addwithalias(&group_sidcache, nfsname, orig_nfsname, *sid);
- + }
- + else {
- + sidcache_add(&group_sidcache, orig_nfsname, *sid);
- + }
- break;
- default:
- eprintf("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
- diff --git a/daemon/sid.h b/daemon/sid.h
- index 57edfc7..70fc910 100644
- --- a/daemon/sid.h
- +++ b/daemon/sid.h
- @@ -58,6 +58,7 @@ bool unixgroup_sid2gid(PSID psid, gid_t *pgid);
- #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
- void sidcache_init(void);
- void sidcache_add(sidcache *cache, const char* win32name, PSID value);
- +void sidcache_addwithalias(sidcache *cache, const char *win32name, const char *aliasname, PSID value);
- PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name);
- bool sidcache_getcached_bysid(sidcache *cache, PSID sid, char *out_win32name);
sid alias cache support
Posted by Anonymous on Mon 11th Nov 2024 17:00
raw | new post
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.