pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


sid alias cache support
Posted by Anonymous on Mon 11th Nov 2024 17:00
raw | new post

  1. diff --git a/daemon/sid.c b/daemon/sid.c
  2. index baaf95a..36500e9 100644
  3. --- a/daemon/sid.c
  4. +++ b/daemon/sid.c
  5. @@ -227,6 +227,7 @@ typedef struct _sidcache_entry
  6.  {
  7.  #define SIDCACHE_ENTRY_NAME_SIZE (UNLEN + 1)
  8.      char    win32name[SIDCACHE_ENTRY_NAME_SIZE]; /* must fit something like "user@domain" */
  9. +    char    aliasname[SIDCACHE_ENTRY_NAME_SIZE];
  10.      PSID    sid;
  11.      DWORD   sid_len;
  12.  #pragma warning( push )
  13. @@ -254,8 +255,13 @@ void sidcache_init(void)
  14.      InitializeCriticalSection(&group_sidcache.lock);
  15.  }
  16.  
  17. -/* copy SID |value| into cache */
  18.  void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  19. +{
  20. +    sidcache_addwithalias(cache, win32name, NULL, value);
  21. +}
  22. +
  23. +/* copy SID |value| into cache */
  24. +void sidcache_addwithalias(sidcache *cache, const char *win32name, const char *aliasname, PSID value)
  25.  {
  26.      int i;
  27.      ssize_t freeEntryIndex;
  28. @@ -271,9 +277,10 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  29.          sidcache_entry *e = &cache->entries[i];
  30.  
  31.          if ((e->sid != NULL) &&
  32. -            (e->timestamp < (currentTimestamp - SIDCACHE_TTL))) {
  33. +            ((currentTimestamp - e->timestamp) >= SIDCACHE_TTL)) {
  34.              e->sid = NULL;
  35.              e->win32name[0] = '\0';
  36. +            e->aliasname[0] = '\0';
  37.              e->sid_len = 0;
  38.          }
  39.      }
  40. @@ -281,9 +288,26 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  41.      /* Find the oldest valid cache entry */
  42.      freeEntryIndex = -1;
  43.      for (i = 0; i < SIDCACHE_SIZE; i++) {
  44. -        if (cache->entries[i].sid) {
  45. +        sidcache_entry *e = &cache->entries[i];
  46. +        if (e->sid) {
  47.              /* Same name ? Then reuse this slot... */
  48. -            if (!strcmp(cache->entries[i].win32name, win32name)) {
  49. +            if (!strcmp(e->win32name, win32name)) {
  50. +                freeEntryIndex = i;
  51. +                break;
  52. +            }
  53. +            if (aliasname) {
  54. +                if (!strcmp(e->win32name, aliasname)) {
  55. +                    freeEntryIndex = i;
  56. +                    break;
  57. +                }
  58. +                if ((e->aliasname[0] != '\0') &&
  59. +                    (!strcmp(e->aliasname, aliasname))) {
  60. +                    freeEntryIndex = i;
  61. +                    break;
  62. +                }
  63. +            }
  64. +            if ((e->aliasname[0] != '\0') &&
  65. +                (!strcmp(e->aliasname, win32name))) {
  66.                  freeEntryIndex = i;
  67.                  break;
  68.              }
  69. @@ -308,12 +332,17 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  70.      if (!CopySid(sid_len, e->sid, value)) {
  71.          e->sid = NULL;
  72.          e->win32name[0] = '\0';
  73. +        e->aliasname[0] = '\0';
  74.          e->sid_len = 0;
  75.          goto done;
  76.      }
  77.  
  78.      e->sid_len = sid_len;
  79.      (void)strcpy(e->win32name, win32name);
  80. +    if (aliasname)
  81. +        (void)strcpy(e->aliasname, aliasname);
  82. +    else
  83. +        e->aliasname[0] = '\0';
  84.      e->timestamp = currentTimestamp;
  85.  
  86.      cache->cacheIndex = (cache->cacheIndex + 1) % SIDCACHE_SIZE;
  87. @@ -337,7 +366,8 @@ PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name)
  88.          e = &cache->entries[i];
  89.  
  90.          if ((e->sid != NULL) &&
  91. -            (!strcmp(e->win32name, win32name)) &&
  92. +            ((!strcmp(e->win32name, win32name)) ||
  93. +                ((e->aliasname[0] != '\0') && (!strcmp(e->aliasname, win32name)))) &&
  94.              ((currentTimestamp - e->timestamp) < SIDCACHE_TTL)) {
  95.              PSID malloced_sid = malloc(e->sid_len);
  96.              if (!malloced_sid)
  97. @@ -374,7 +404,6 @@ bool sidcache_getcached_bysid(sidcache *cache, PSID sid, char *out_win32name)
  98.          if ((e->sid != NULL) &&
  99.              (EqualSid(sid, e->sid) &&
  100.              ((currentTimestamp - e->timestamp) < SIDCACHE_TTL))) {
  101. -
  102.              (void)strcpy(out_win32name, e->win32name);
  103.  
  104.              ret = true;
  105. @@ -528,7 +557,7 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  106.                  user_uid = map_uid;
  107.              }
  108.              else {
  109. -                DPRINTF(1,
  110. +                DPRINTF(0,
  111.                      ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  112.                      "nfs41_idmap_name_to_uid() failed\n",
  113.                      query, nfsname));
  114. @@ -546,7 +575,7 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  115.                  group_gid = map_gid;
  116.              }
  117.              else {
  118. -                DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
  119. +                DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
  120.                      query, nfsname));
  121.                  /* fixme: try harder here, "1234" should to to |atol()| */
  122.              }
  123. @@ -635,10 +664,26 @@ out_cache:
  124.  
  125.          switch (sid_type) {
  126.              case SidTypeUser:
  127. -                sidcache_add(&user_sidcache, orig_nfsname, *sid);
  128. +                if (isdigit(orig_nfsname[0])) {
  129. +                    DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  130. +                        "adding usercache nfsname='%s' orig_nfsname='%s'\n",
  131. +                        query, orig_nfsname, nfsname, orig_nfsname));
  132. +                    sidcache_addwithalias(&user_sidcache, nfsname, orig_nfsname, *sid);
  133. +                }
  134. +                else {
  135. +                    sidcache_add(&user_sidcache, orig_nfsname, *sid);
  136. +                }
  137.                  break;
  138.              case SidTypeGroup:
  139. -                sidcache_add(&group_sidcache, orig_nfsname, *sid);
  140. +                if (isdigit(orig_nfsname[0])) {
  141. +                    DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  142. +                        "adding groupcache nfsname='%s' orig_nfsname='%s'\n",
  143. +                        query, orig_nfsname, nfsname, orig_nfsname));
  144. +                    sidcache_addwithalias(&group_sidcache, nfsname, orig_nfsname, *sid);
  145. +                }
  146. +                else {
  147. +                    sidcache_add(&group_sidcache, orig_nfsname, *sid);
  148. +                }
  149.                  break;
  150.              default:
  151.                  eprintf("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  152. diff --git a/daemon/sid.h b/daemon/sid.h
  153. index 57edfc7..70fc910 100644
  154. --- a/daemon/sid.h
  155. +++ b/daemon/sid.h
  156. @@ -58,6 +58,7 @@ bool unixgroup_sid2gid(PSID psid, gid_t *pgid);
  157.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  158.  void sidcache_init(void);
  159.  void sidcache_add(sidcache *cache, const char* win32name, PSID value);
  160. +void sidcache_addwithalias(sidcache *cache, const char *win32name, const char *aliasname, PSID value);
  161.  PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name);
  162.  bool sidcache_getcached_bysid(sidcache *cache, PSID sid, char *out_win32name);

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