pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


msnfs41client: owner/group name caching prototype
Posted by Anonymous on Fri 20th Oct 2023 14:23
raw | new post
modification of post by Anonymous (view diff)

  1. diff --git a/daemon/acl.c b/daemon/acl.c
  2. index 1d1eac4..9c30eeb 100644
  3. --- a/daemon/acl.c
  4. +++ b/daemon/acl.c
  5. @@ -223,6 +223,19 @@ static int map_name_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *sid_l
  6.              name = "roland_mainz";
  7.              dprintf(ACLLVL, "map_name_2_sid: remap 1616 --> roland_mainz\n");
  8.          }
  9. +        else if (!strcmp(name, "swulsch")) {
  10. +            name = "siegfried_wulsch";
  11. +            dprintf(ACLLVL, "map_name_2_sid: remap swulsch --> siegfried_wulsch\n");
  12. +        }
  13. +        else if (!strcmp(name, "197609")) {
  14. +            name = "siegfried_wulsch";
  15. +            dprintf(ACLLVL, "map_name_2_sid: remap 197609 --> siegfried_wulsch\n");
  16. +        }
  17. +        else if (!strcmp(name, "1818")) {
  18. +            name = "siegfried_wulsch";
  19. +            dprintf(ACLLVL, "map_name_2_sid: remap 1818 --> siegfried_wulsch\n");
  20. +        }
  21. +
  22.      }
  23.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  24.  
  25. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  26. index f484d58..17cf046 100644
  27. --- a/daemon/daemon_debug.h
  28. +++ b/daemon/daemon_debug.h
  29. @@ -34,6 +34,15 @@
  30.  #define DEFAULT_DEBUG_LEVEL 1
  31.  
  32.  
  33. +#define EASSERT(exp) \
  34. +    if (!(exp)) { \
  35. +        eprintf("ASSERTION '%s' in '%s'/%ld failed.\n", \
  36. +            ""#exp"", __FILE__, (long)__LINE__); }
  37. +#define DASSERT(exp, level) \
  38. +    if (!(exp)) { \
  39. +        dprintf((level), "ASSERTION '%s' in '%s'/%ld failed.\n", \
  40. +            ""#exp"", __FILE__, (long)__LINE__); }
  41. +
  42.  /* daemon_debug.h */
  43.  void set_debug_level(int level);
  44.  void dprintf(int level, LPCSTR format, ...);
  45. diff --git a/daemon/lookup.c b/daemon/lookup.c
  46. index ea0a9d2..b90c3bd 100644
  47. --- a/daemon/lookup.c
  48. +++ b/daemon/lookup.c
  49. @@ -85,7 +85,8 @@ static void init_component_args(
  50.      args->attr_request.arr[1] = FATTR4_WORD1_MODE
  51.          | FATTR4_WORD1_NUMLINKS | FATTR4_WORD1_SYSTEM
  52.          | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_CREATE
  53. -        | FATTR4_WORD1_TIME_MODIFY;
  54. +        | FATTR4_WORD1_TIME_MODIFY
  55. +        | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  56.  
  57.      args->getrootattr.attr_request = &args->attr_request;
  58.      res->root.path = path;
  59. @@ -210,8 +211,9 @@ static int server_lookup(
  60.      if (count == 0) {
  61.          if (target_out)
  62.              *target_out = dir;
  63. -        if (info_out)
  64. -            memcpy(info_out, res->getrootattr.info, sizeof(nfs41_file_info));
  65. +        if (info_out) {
  66. +            nfs41_file_info_cpy(info_out, res->getrootattr.info);
  67. +        }
  68.      } else if (count == 1) {
  69.          if (parent_out)
  70.              *parent_out = dir;
  71. @@ -258,8 +260,9 @@ static int server_lookup(
  72.          if (i == count-1) {
  73.              if (target_out)
  74.                  *target_out = file;
  75. -            if (info_out)
  76. -                memcpy(info_out, res->getattr[i].info, sizeof(nfs41_file_info));
  77. +            if (info_out) {
  78. +                nfs41_file_info_cpy(info_out, res->getattr[i].info);
  79. +            }
  80.          } else if (i == count-2) {
  81.              if (parent_out)
  82.                  *parent_out = file;
  83. diff --git a/daemon/name_cache.c b/daemon/name_cache.c
  84. index eaa0f36..89879a7 100644
  85. --- a/daemon/name_cache.c
  86. +++ b/daemon/name_cache.c
  87. @@ -99,6 +99,8 @@ struct attr_cache_entry {
  88.      unsigned                type : 4;
  89.      unsigned                invalidated : 1;
  90.      unsigned                delegated : 1;
  91. +    char                    owner[NFS4_OPAQUE_LIMIT+1];
  92. +    char                    owner_group[NFS4_OPAQUE_LIMIT+1];
  93.  };
  94.  #define ATTR_ENTRY_SIZE sizeof(struct attr_cache_entry)
  95.  
  96. @@ -304,6 +306,14 @@ static void attr_cache_update(
  97.      if (info->attrmask.count >= 2) {
  98.          if (info->attrmask.arr[1] & FATTR4_WORD1_MODE)
  99.              entry->mode = info->mode;
  100. +        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER) {
  101. +            EASSERT(info->owner != NULL);
  102. +            (void)strcpy(entry->owner, info->owner);
  103. +        }
  104. +        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  105. +            EASSERT(info->owner_group != NULL);
  106. +            (void)strcpy(entry->owner_group, info->owner_group);
  107. +        }
  108.          if (info->attrmask.arr[1] & FATTR4_WORD1_NUMLINKS)
  109.              entry->numlinks = info->numlinks;
  110.          if (info->attrmask.arr[1] & FATTR4_WORD1_TIME_ACCESS) {
  111. @@ -341,6 +351,12 @@ static void copy_attrs(
  112.      dst->type = src->type;
  113.      dst->numlinks = src->numlinks;
  114.      dst->mode = src->mode;
  115. +    EASSERT(src->owner != NULL);
  116. +    dst->owner = dst->owner_buf;
  117. +    (void)strcpy(dst->owner, src->owner);
  118. +    EASSERT(src->owner_group != NULL);
  119. +    dst->owner_group = dst->owner_group_buf;
  120. +    (void)strcpy(dst->owner_group, src->owner_group);
  121.      dst->fileid = src->fileid;
  122.      dst->hidden = src->hidden;
  123.      dst->system = src->system;
  124. @@ -353,7 +369,8 @@ static void copy_attrs(
  125.      dst->attrmask.arr[1] = FATTR4_WORD1_MODE
  126.          | FATTR4_WORD1_NUMLINKS | FATTR4_WORD1_TIME_ACCESS
  127.          | FATTR4_WORD1_TIME_CREATE | FATTR4_WORD1_TIME_MODIFY
  128. -        | FATTR4_WORD1_SYSTEM;
  129. +        | FATTR4_WORD1_SYSTEM
  130. +        | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  131.  }
  132.  
  133.  
  134. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  135. index 42bfc6c..dcb509e 100644
  136. --- a/daemon/nfs41_daemon.c
  137. +++ b/daemon/nfs41_daemon.c
  138. @@ -402,6 +402,7 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  139.  #ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  140.      /* force enable for cygwin getent passwd/group testing */
  141.      cmd_args.ldap_enable = TRUE;
  142. +    DASSERT(0/* test asserts*/, 0);
  143.  #endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  144.  
  145.      nfs41_server_list_init();
  146. diff --git a/daemon/nfs41_types.h b/daemon/nfs41_types.h
  147. index c5bad79..18a763a 100644
  148. --- a/daemon/nfs41_types.h
  149. +++ b/daemon/nfs41_types.h
  150. @@ -236,6 +236,10 @@ typedef struct __nfs41_file_info {
  151.      char                    *owner;
  152.      char                    *owner_group;
  153.      uint32_t                aclsupport;
  154. +
  155. +    /* Buffers */
  156. +    char owner_buf[NFS4_OPAQUE_LIMIT+1];
  157. +    char owner_group_buf[NFS4_OPAQUE_LIMIT+1];
  158.  } nfs41_file_info;
  159.  
  160.  #endif /* !__NFS41_DAEMON_TYPES_H__ */
  161. diff --git a/daemon/nfs41_xdr.c b/daemon/nfs41_xdr.c
  162. index 176b613..0261c54 100644
  163. --- a/daemon/nfs41_xdr.c
  164. +++ b/daemon/nfs41_xdr.c
  165. @@ -1802,19 +1802,33 @@ static bool_t decode_file_attrs(
  166.                  return FALSE;
  167.          }
  168.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_OWNER) {
  169. -            char *ptr = &info->owner[0];
  170. +            if (info->owner == NULL)
  171. +                info->owner = info->owner_buf;
  172. +
  173. +            char *ptr = info->owner;
  174.              uint32_t owner_len;
  175.              if (!xdr_bytes(xdr, &ptr, &owner_len,
  176. -                            NFS4_OPAQUE_LIMIT))
  177. +                            NFS4_OPAQUE_LIMIT)) {
  178. +                info->owner = NULL;
  179.                  return FALSE;
  180. +            }
  181. +            EASSERT(owner_len > 0);
  182. +            EASSERT(owner_len < sizeof(info->owner_group_buf));
  183.              info->owner[owner_len] = '\0';
  184.          }
  185.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  186. -            char *ptr = &info->owner_group[0];
  187. +            if (info->owner_group == NULL)
  188. +                info->owner_group = info->owner_group_buf;
  189. +
  190. +            char *ptr = info->owner_group;
  191.              uint32_t owner_group_len;
  192.              if (!xdr_bytes(xdr, &ptr, &owner_group_len,
  193. -                            NFS4_OPAQUE_LIMIT))
  194. +                            NFS4_OPAQUE_LIMIT)) {
  195. +                info->owner_group = NULL;
  196.                  return FALSE;
  197. +            }
  198. +            EASSERT(owner_group_len > 0);
  199. +            EASSERT(owner_group_len < sizeof(info->owner_group_buf));
  200.              info->owner_group[owner_group_len] = '\0';
  201.          }
  202.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_SPACE_AVAIL) {
  203. diff --git a/daemon/open.c b/daemon/open.c
  204. index 13e82b2..36f2fb2 100644
  205. --- a/daemon/open.c
  206. +++ b/daemon/open.c
  207. @@ -629,7 +629,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  208.          status = NO_ERROR;
  209.      } else if (args->symlink.len) {
  210.          /* handle cygwin symlinks */
  211. -        nfs41_file_info createattrs;
  212. +        nfs41_file_info createattrs = { 0 };
  213.          createattrs.attrmask.count = 2;
  214.          createattrs.attrmask.arr[0] = 0;
  215.          createattrs.attrmask.arr[1] = FATTR4_WORD1_MODE;
  216. @@ -663,33 +663,22 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  217.          args->changeattr = info.change;
  218.  
  219.  #ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
  220. -        bitmap4 og_attr_request = { 0 };
  221. -        nfs41_file_info og_info = { 0 };
  222. -        char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
  223. -        nfsacl41 acl = { 0 };
  224. -
  225. -        /*
  226. -         * gisburn:
  227. -         * 1. We should cache owner/group information
  228. -         * 2. We should always ask for
  229. -         * FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP with the other
  230. -         * attributes
  231. -         */
  232. -        og_attr_request.count = 2;
  233. -        og_attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  234. -        og_info.owner = owner;
  235. -        og_info.owner_group = group;
  236. -        status = nfs41_getattr(state->session, &state->file, &og_attr_request, &og_info);
  237. -        if (status) {
  238. -            eprintf("get_stat_data: nfs41_cached_getattr() failed with %d\n",
  239. -            status);
  240. -        }
  241. -
  242. +        char owner[NFS4_OPAQUE_LIMIT], owner_group[NFS4_OPAQUE_LIMIT];
  243.          uid_t map_uid = -1;
  244.          gid_t gid_dummy = -1;
  245.          gid_t map_gid = -1;
  246.          char *at_ch; /* pointer to '@' */
  247.          
  248. +        EASSERT((info.attrmask.arr[1] & FATTR4_WORD1_OWNER) != 0);
  249. +        EASSERT((info.attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) != 0);
  250. +        EASSERT(info.owner != NULL);
  251. +        EASSERT(info.owner_group != NULL);
  252. +        EASSERT(info.owner == info.owner_buf);
  253. +        EASSERT(info.owner_group == info.owner_group_buf);
  254. +        /* Make copies as we will modify  them */
  255. +        (void)strcpy(owner, info.owner);
  256. +        (void)strcpy(owner_group, info.owner_group);
  257. +
  258.          /*
  259.           * Map owner to local uid
  260.           *
  261. @@ -697,12 +686,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  262.           *  ("gisburn") or username@domain ("gisburn@sun.com")
  263.           */
  264.          /* stomp over '@' */
  265. -        if (at_ch = strchr(og_info.owner, '@'))
  266. +        if (at_ch = strchr(owner, '@'))
  267.              *at_ch = '\0';
  268.  
  269.          if (nfs41_idmap_name_to_ids(
  270.              nfs41dg->idmapper,
  271. -            og_info.owner,
  272. +            owner,
  273.              &map_uid,
  274.              &gid_dummy) == 0) {
  275.               args->owner_local_uid = map_uid;
  276. @@ -711,7 +700,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  277.              args->owner_local_uid = NFS_USER_NOBODY_UID;
  278.              eprintf("get_stat_data: "
  279.                  "no username mapping for '%s', fake uid=%d\n",
  280. -                og_info.owner, args->owner_local_uid);
  281. +                owner, args->owner_local_uid);
  282.          }
  283.  
  284.          /*
  285. @@ -721,12 +710,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  286.           * ("gisgrp") or username@domain ("gisgrp@sun.com")
  287.           */
  288.          /* stomp over '@' */
  289. -        if (at_ch = strchr(og_info.owner_group, '@'))
  290. +        if (at_ch = strchr(owner_group, '@'))
  291.              *at_ch = '\0';
  292.  
  293.          if (nfs41_idmap_group_to_gid(
  294.              nfs41dg->idmapper,
  295. -            og_info.owner_group,
  296. +            owner_group,
  297.              &map_gid) == 0) {
  298.              args->owner_group_local_gid = map_gid;
  299.          }
  300. @@ -734,12 +723,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  301.              args->owner_group_local_gid = NFS_GROUP_NOGROUP_GID;
  302.              eprintf("get_stat_data: "
  303.                  "no group mapping for '%s', fake gid=%d\n",
  304. -                og_info.owner_group, args->owner_group_local_gid);
  305. +                owner_group, args->owner_group_local_gid);
  306.          }
  307.  
  308.          dprintf(1, "handle_open: stat: owner=%u/'%s', owner_group=%u/'%s'\n",
  309. -            (unsigned int)args->owner_local_uid, og_info.owner,
  310. -            (unsigned int)args->owner_group_local_gid, og_info.owner_group);
  311. +            (unsigned int)args->owner_local_uid, owner,
  312. +            (unsigned int)args->owner_group_local_gid, owner_group);
  313.  #endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
  314.      } else {
  315.          nfs41_file_info createattrs = { 0 };
  316. diff --git a/daemon/util.c b/daemon/util.c
  317. index 35cfc5b..0b8cedf 100644
  318. --- a/daemon/util.c
  319. +++ b/daemon/util.c
  320. @@ -201,6 +201,16 @@ void nfs_to_network_openinfo(
  321.      net_out->FileAttributes = nfs_file_info_to_attributes(info);
  322.  }
  323.  
  324. +/* copy |nfs41_file_info| */
  325. +void nfs41_file_info_cpy(
  326. +    OUT nfs41_file_info *dest,
  327. +    IN const nfs41_file_info *src)
  328. +{
  329. +    (void)memcpy(dest, src, sizeof(nfs41_file_info));
  330. +    dest->owner = dest->owner_buf;
  331. +    dest->owner_group = dest->owner_group_buf;
  332. +}
  333. +
  334.  void get_file_time(
  335.      OUT PLARGE_INTEGER file_time)
  336.  {
  337. diff --git a/daemon/util.h b/daemon/util.h
  338. index fa0d32c..c4bc886 100644
  339. --- a/daemon/util.h
  340. +++ b/daemon/util.h
  341. @@ -106,6 +106,9 @@ void nfs_to_standard_info(
  342.  void nfs_to_network_openinfo(
  343.      IN const nfs41_file_info *info,
  344.      OUT PFILE_NETWORK_OPEN_INFORMATION std_out);
  345. +void nfs41_file_info_cpy(
  346. +    OUT nfs41_file_info *dest,
  347. +    IN const nfs41_file_info *src);
  348.  
  349.  /* http://msdn.microsoft.com/en-us/library/ms724290%28VS.85%29.aspx:
  350.   * A file time is a 64-bit value that represents the number of
  351. diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
  352. index 93ee7a9..d43334a 100644
  353. --- a/sys/nfs41_build_features.h
  354. +++ b/sys/nfs41_build_features.h
  355. @@ -32,19 +32,19 @@
  356.  /*
  357.   * NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES - return local uid/gid values
  358.   */
  359. -// #define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  360. +#define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  361.  
  362.  /*
  363.   * NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID - give NFS
  364.   * files which do not map to a local account a SID in the
  365.   * Unix_User+x/Unix_Group+x range
  366.   */
  367. -// #define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  368. +#define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  369.  
  370.  /*
  371.   * NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN - use Cygwin /usr/bin/getent
  372.   * as "name service"
  373.   */
  374. -// #define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  375. +#define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  376.  
  377.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */

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