pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


msnfs41client: owner/group name caching prototype
Posted by Anonymous on Thu 19th Oct 2023 20:51
raw | new post
view followups (newest first): msnfs41client: owner/group name caching prototype by Anonymous
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..b77e7d7 100644
  27. --- a/daemon/daemon_debug.h
  28. +++ b/daemon/daemon_debug.h
  29. @@ -34,6 +34,11 @@
  30.  #define DEFAULT_DEBUG_LEVEL 1
  31.  
  32.  
  33. +#define DASSERT(exp) \
  34. +    if (!(exp)) { \
  35. +        eprintf("ASSERTION '%s' in '%s'/%ld failed.\n", \
  36. +            ""#exp"", __FILE__, (long)__LINE__); }
  37. +
  38.  /* daemon_debug.h */
  39.  void set_debug_level(int level);
  40.  void dprintf(int level, LPCSTR format, ...);
  41. diff --git a/daemon/lookup.c b/daemon/lookup.c
  42. index ea0a9d2..f72afe5 100644
  43. --- a/daemon/lookup.c
  44. +++ b/daemon/lookup.c
  45. @@ -85,7 +85,8 @@ static void init_component_args(
  46.      args->attr_request.arr[1] = FATTR4_WORD1_MODE
  47.          | FATTR4_WORD1_NUMLINKS | FATTR4_WORD1_SYSTEM
  48.          | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_CREATE
  49. -        | FATTR4_WORD1_TIME_MODIFY;
  50. +        | FATTR4_WORD1_TIME_MODIFY
  51. +        | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  52.  
  53.      args->getrootattr.attr_request = &args->attr_request;
  54.      res->root.path = path;
  55. @@ -210,8 +211,12 @@ static int server_lookup(
  56.      if (count == 0) {
  57.          if (target_out)
  58.              *target_out = dir;
  59. -        if (info_out)
  60. +        if (info_out) {
  61. +            /* fixme: need |copy_nfs41_file_info()| */
  62.              memcpy(info_out, res->getrootattr.info, sizeof(nfs41_file_info));
  63. +            info_out->owner = info_out->owner_buf;
  64. +            info_out->owner_group = info_out->owner_group_buf;
  65. +        }
  66.      } else if (count == 1) {
  67.          if (parent_out)
  68.              *parent_out = dir;
  69. @@ -258,8 +263,12 @@ static int server_lookup(
  70.          if (i == count-1) {
  71.              if (target_out)
  72.                  *target_out = file;
  73. -            if (info_out)
  74. +            if (info_out) {
  75. +                /* fixme: need |copy_nfs41_file_info()| */
  76.                  memcpy(info_out, res->getattr[i].info, sizeof(nfs41_file_info));
  77. +                info_out->owner = info_out->owner_buf;
  78. +                info_out->owner_group = info_out->owner_group_buf;
  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..2b7c257 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. +            DASSERT(info->owner != NULL);
  102. +            (void)strcpy(entry->owner, info->owner);
  103. +        }
  104. +        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  105. +            DASSERT(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,14 @@ static void copy_attrs(
  112.      dst->type = src->type;
  113.      dst->numlinks = src->numlinks;
  114.      dst->mode = src->mode;
  115. +    DASSERT(src->owner != NULL);
  116. +//    if (dst->owner == NULL)
  117. +        dst->owner = dst->owner_buf;
  118. +    (void)strcpy(dst->owner, src->owner);
  119. +    DASSERT(src->owner_group != NULL);
  120. +//    if (dst->owner_group == NULL)
  121. +        dst->owner_group = dst->owner_group_buf;
  122. +    (void)strcpy(dst->owner_group, src->owner_group);
  123.      dst->fileid = src->fileid;
  124.      dst->hidden = src->hidden;
  125.      dst->system = src->system;
  126. @@ -353,7 +371,8 @@ static void copy_attrs(
  127.      dst->attrmask.arr[1] = FATTR4_WORD1_MODE
  128.          | FATTR4_WORD1_NUMLINKS | FATTR4_WORD1_TIME_ACCESS
  129.          | FATTR4_WORD1_TIME_CREATE | FATTR4_WORD1_TIME_MODIFY
  130. -        | FATTR4_WORD1_SYSTEM;
  131. +        | FATTR4_WORD1_SYSTEM
  132. +        | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  133.  }
  134.  
  135.  
  136. @@ -401,7 +420,11 @@ struct nfs41_name_cache {
  137.  static __inline bool_t name_cache_enabled(
  138.      IN struct nfs41_name_cache *cache)
  139.  {
  140. +#if 0
  141. +    return 0; /* fixme: caching of owner/owner_group not supported yet */
  142. +#else
  143.      return cache->expiration > 0;
  144. +#endif
  145.  }
  146.  
  147.  static __inline void name_cache_entry_rename(
  148. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  149. index 42bfc6c..bc69fa8 100644
  150. --- a/daemon/nfs41_daemon.c
  151. +++ b/daemon/nfs41_daemon.c
  152. @@ -402,6 +402,7 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  153.  #ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  154.      /* force enable for cygwin getent passwd/group testing */
  155.      cmd_args.ldap_enable = TRUE;
  156. +    DASSERT(cmd_args.ldap_enable == FALSE);
  157.  #endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  158.  
  159.      nfs41_server_list_init();
  160. diff --git a/daemon/nfs41_types.h b/daemon/nfs41_types.h
  161. index c5bad79..18a763a 100644
  162. --- a/daemon/nfs41_types.h
  163. +++ b/daemon/nfs41_types.h
  164. @@ -236,6 +236,10 @@ typedef struct __nfs41_file_info {
  165.      char                    *owner;
  166.      char                    *owner_group;
  167.      uint32_t                aclsupport;
  168. +
  169. +    /* Buffers */
  170. +    char owner_buf[NFS4_OPAQUE_LIMIT+1];
  171. +    char owner_group_buf[NFS4_OPAQUE_LIMIT+1];
  172.  } nfs41_file_info;
  173.  
  174.  #endif /* !__NFS41_DAEMON_TYPES_H__ */
  175. diff --git a/daemon/nfs41_xdr.c b/daemon/nfs41_xdr.c
  176. index 176b613..67c9bf6 100644
  177. --- a/daemon/nfs41_xdr.c
  178. +++ b/daemon/nfs41_xdr.c
  179. @@ -1802,19 +1802,33 @@ static bool_t decode_file_attrs(
  180.                  return FALSE;
  181.          }
  182.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_OWNER) {
  183. -            char *ptr = &info->owner[0];
  184. +            if (info->owner == NULL)
  185. +                info->owner = info->owner_buf;
  186. +
  187. +            char *ptr = info->owner;
  188.              uint32_t owner_len;
  189.              if (!xdr_bytes(xdr, &ptr, &owner_len,
  190. -                            NFS4_OPAQUE_LIMIT))
  191. +                            NFS4_OPAQUE_LIMIT)) {
  192. +                info->owner = NULL;
  193.                  return FALSE;
  194. +            }
  195. +            DASSERT(owner_len > 0);
  196. +            DASSERT(owner_len < sizeof(info->owner_group_buf));
  197.              info->owner[owner_len] = '\0';
  198.          }
  199.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  200. -            char *ptr = &info->owner_group[0];
  201. +            if (info->owner_group == NULL)
  202. +                info->owner_group = info->owner_group_buf;
  203. +
  204. +            char *ptr = info->owner_group;
  205.              uint32_t owner_group_len;
  206.              if (!xdr_bytes(xdr, &ptr, &owner_group_len,
  207. -                            NFS4_OPAQUE_LIMIT))
  208. +                            NFS4_OPAQUE_LIMIT)) {
  209. +                info->owner_group = NULL;
  210.                  return FALSE;
  211. +            }
  212. +            DASSERT(owner_group_len > 0);
  213. +            DASSERT(owner_group_len < sizeof(info->owner_group_buf));
  214.              info->owner_group[owner_group_len] = '\0';
  215.          }
  216.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_SPACE_AVAIL) {
  217. diff --git a/daemon/open.c b/daemon/open.c
  218. index 13e82b2..f1d7f20 100644
  219. --- a/daemon/open.c
  220. +++ b/daemon/open.c
  221. @@ -629,7 +629,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  222.          status = NO_ERROR;
  223.      } else if (args->symlink.len) {
  224.          /* handle cygwin symlinks */
  225. -        nfs41_file_info createattrs;
  226. +        nfs41_file_info createattrs = { 0 };
  227.          createattrs.attrmask.count = 2;
  228.          createattrs.attrmask.arr[0] = 0;
  229.          createattrs.attrmask.arr[1] = FATTR4_WORD1_MODE;
  230. @@ -663,33 +663,21 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  231.          args->changeattr = info.change;
  232.  
  233.  #ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
  234. -        bitmap4 og_attr_request = { 0 };
  235. -        nfs41_file_info og_info = { 0 };
  236. -        char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
  237. -        nfsacl41 acl = { 0 };
  238. -
  239. -        /*
  240. -         * gisburn:
  241. -         * 1. We should cache owner/group information
  242. -         * 2. We should always ask for
  243. -         * FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP with the other
  244. -         * attributes
  245. -         */
  246. -        og_attr_request.count = 2;
  247. -        og_attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  248. -        og_info.owner = owner;
  249. -        og_info.owner_group = group;
  250. -        status = nfs41_getattr(state->session, &state->file, &og_attr_request, &og_info);
  251. -        if (status) {
  252. -            eprintf("get_stat_data: nfs41_cached_getattr() failed with %d\n",
  253. -            status);
  254. -        }
  255. -
  256. +        char owner[NFS4_OPAQUE_LIMIT], owner_group[NFS4_OPAQUE_LIMIT];
  257.          uid_t map_uid = -1;
  258.          gid_t gid_dummy = -1;
  259.          gid_t map_gid = -1;
  260.          char *at_ch; /* pointer to '@' */
  261.          
  262. +        DASSERT((info.attrmask.arr[1] & FATTR4_WORD1_OWNER) != 0);
  263. +        DASSERT((info.attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) != 0);
  264. +        DASSERT(info.owner != NULL);
  265. +        DASSERT(info.owner_group != NULL);
  266. +        DASSERT(info.owner == info.owner_buf);
  267. +        DASSERT(info.owner_group == info.owner_group_buf);
  268. +        (void)strcpy(owner, info.owner?info.owner:"<FIXME_OWNER>");
  269. +        (void)strcpy(owner_group, info.owner_group?info.owner_group:"<FIXME_GROUP>");
  270. +
  271.          /*
  272.           * Map owner to local uid
  273.           *
  274. @@ -697,12 +685,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  275.           *  ("gisburn") or username@domain ("gisburn@sun.com")
  276.           */
  277.          /* stomp over '@' */
  278. -        if (at_ch = strchr(og_info.owner, '@'))
  279. +        if (at_ch = strchr(owner, '@'))
  280.              *at_ch = '\0';
  281.  
  282.          if (nfs41_idmap_name_to_ids(
  283.              nfs41dg->idmapper,
  284. -            og_info.owner,
  285. +            owner,
  286.              &map_uid,
  287.              &gid_dummy) == 0) {
  288.               args->owner_local_uid = map_uid;
  289. @@ -711,7 +699,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  290.              args->owner_local_uid = NFS_USER_NOBODY_UID;
  291.              eprintf("get_stat_data: "
  292.                  "no username mapping for '%s', fake uid=%d\n",
  293. -                og_info.owner, args->owner_local_uid);
  294. +                owner, args->owner_local_uid);
  295.          }
  296.  
  297.          /*
  298. @@ -721,12 +709,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  299.           * ("gisgrp") or username@domain ("gisgrp@sun.com")
  300.           */
  301.          /* stomp over '@' */
  302. -        if (at_ch = strchr(og_info.owner_group, '@'))
  303. +        if (at_ch = strchr(owner_group, '@'))
  304.              *at_ch = '\0';
  305.  
  306.          if (nfs41_idmap_group_to_gid(
  307.              nfs41dg->idmapper,
  308. -            og_info.owner_group,
  309. +            owner_group,
  310.              &map_gid) == 0) {
  311.              args->owner_group_local_gid = map_gid;
  312.          }
  313. @@ -734,12 +722,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  314.              args->owner_group_local_gid = NFS_GROUP_NOGROUP_GID;
  315.              eprintf("get_stat_data: "
  316.                  "no group mapping for '%s', fake gid=%d\n",
  317. -                og_info.owner_group, args->owner_group_local_gid);
  318. +                owner_group, args->owner_group_local_gid);
  319.          }
  320.  
  321.          dprintf(1, "handle_open: stat: owner=%u/'%s', owner_group=%u/'%s'\n",
  322. -            (unsigned int)args->owner_local_uid, og_info.owner,
  323. -            (unsigned int)args->owner_group_local_gid, og_info.owner_group);
  324. +            (unsigned int)args->owner_local_uid, owner,
  325. +            (unsigned int)args->owner_group_local_gid, owner_group);
  326.  #endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
  327.      } else {
  328.          nfs41_file_info createattrs = { 0 };
  329. diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
  330. index 93ee7a9..d43334a 100644
  331. --- a/sys/nfs41_build_features.h
  332. +++ b/sys/nfs41_build_features.h
  333. @@ -32,19 +32,19 @@
  334.  /*
  335.   * NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES - return local uid/gid values
  336.   */
  337. -// #define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  338. +#define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  339.  
  340.  /*
  341.   * NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID - give NFS
  342.   * files which do not map to a local account a SID in the
  343.   * Unix_User+x/Unix_Group+x range
  344.   */
  345. -// #define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  346. +#define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  347.  
  348.  /*
  349.   * NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN - use Cygwin /usr/bin/getent
  350.   * as "name service"
  351.   */
  352. -// #define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  353. +#define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  354.  
  355.  #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