pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for Unix_User+<uid>/Unix_Group+<gid> support in |map_sid2nfs4ace_who()|+misc, 2024-07-03
Posted by Anonymous on Wed 3rd Jul 2024 18:05
raw | new post

  1. From e9a4027f2b9dcb21f5743c1cef30e5acede16db6 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 3 Jul 2024 17:46:09 +0200
  4. Subject: [PATCH 1/2] cygwin: Implement Unix_User+<uid> and Unix_Group+<gid>
  5.  support in |map_nfs4ace_who()|
  6.  
  7. /usr/bin/patch failed patching a file, complaining that it cannot
  8. change the group of it's temporary file.
  9. This happened because Cygwin is generating Unix_Group+<gid> SIDs
  10. based on the Nfs3Attr EA |gid|, instead of taking the native SID
  11. returned by Windows.
  12. And some tools like patch(1) end-up just copying that SID, which
  13. our |map_nfs4ace_who()| did not support.
  14.  
  15. Implementing Unix_User+<uid> and Unix_Group+<gid> support in
  16. |map_nfs4ace_who()| fixes this.
  17.  
  18. See https://github.com/kofemann/ms-nfs41-client/issues/16
  19.  
  20. Fixes: Issue #16
  21. Reported-by: Mark Liam Brown <brownmarkliam@gmail.com>
  22. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  23. ---
  24. daemon/acl.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  25.  daemon/sid.h |  4 ++++
  26.  2 files changed, 71 insertions(+)
  27.  
  28. diff --git a/daemon/acl.c b/daemon/acl.c
  29. index 3ab4bf8..02f08b2 100644
  30. --- a/daemon/acl.c
  31. +++ b/daemon/acl.c
  32. @@ -980,11 +980,78 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  33.               * SIDs
  34.               */
  35.              case ERROR_NONE_MAPPED:
  36. +                /*
  37. +                 * This can happen for two reasons:
  38. +                 * 1. Someone copied a file from a NFS(v3) filesystem,
  39. +                 * and Cygwin generated an Unix_User+<uid> or
  40. +                 * Unix_Group+<gid> SID for the source file, which
  41. +                 * tools like Cygwin cp(1) just copy.
  42. +                 * 2. We have an uid/gid for which we do not have
  43. +                 * a user-/group-name mapped.
  44. +                 */
  45. +#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
  46. +                /* fixme: This should be a function argument */
  47. +                extern nfs41_daemon_globals nfs41_dg;
  48. +
  49. +                uid_t unixuser_uid = ~0U;
  50. +                gid_t unixgroup_gid = ~0U;
  51. +
  52. +                if (unixuser_sid2uid(sid, &unixuser_uid)) {
  53. +                    if (!nfs41_idmap_uid_to_name(nfs41_dg.idmapper,
  54. +                        unixuser_uid, who_out, UNLEN)) {
  55. +                        who_size = (DWORD)strlen(who_out);
  56. +                        sid_type = SidTypeUser;
  57. +                        status = ERROR_SUCCESS;
  58. +
  59. +                        DPRINTF(ACLLVL1, ("map_nfs4ace_who: "
  60. +                            "Unix_User+%d SID "
  61. +                            "mapped to user '%s'\n",
  62. +                            unixuser_uid, who_out));
  63. +                        goto add_domain;
  64. +                    }
  65. +
  66. +                    eprintf("map_nfs4ace_who: "
  67. +                        "unixuser_sid2uid(sid='%s',unixuser_uid=%d) "
  68. +                        "returned no mapping.\n",
  69. +                        sidstr, (int)unixuser_uid);
  70. +                    goto err_none_mapped;
  71. +                }
  72. +
  73. +                if (unixgroup_sid2gid(sid, &unixgroup_gid)) {
  74. +                    if (!nfs41_idmap_gid_to_group(nfs41_dg.idmapper,
  75. +                        unixgroup_gid, who_out, GNLEN)) {
  76. +                        who_size = (DWORD)strlen(who_out);
  77. +                        sid_type = SidTypeGroup;
  78. +                        status = ERROR_SUCCESS;
  79. +
  80. +                        DPRINTF(ACLLVL1, ("map_nfs4ace_who: "
  81. +                            "Unix_Group+%d SID "
  82. +                            "mapped to group '%s'\n",
  83. +                            unixgroup_gid, who_out));
  84. +                        goto add_domain;
  85. +                    }
  86. +
  87. +                    eprintf("map_nfs4ace_who: "
  88. +                        "unixgroup_sid2gid(sid='%s',unixgroup_gid=%d) "
  89. +                        "returned no mapping.\n",
  90. +                        sidstr, (int)unixgroup_gid);
  91. +                    goto err_none_mapped;
  92. +                }
  93. +
  94. +                eprintf("map_nfs4ace_who: LookupAccountSidA() "
  95. +                    "returned ERROR_NONE_MAPPED+no "
  96. +                    "Unix_@(User|Group)+ mapping for sidstr='%s'\n",
  97. +                    sidstr);
  98. +err_none_mapped:
  99. +                status = ERROR_NONE_MAPPED;
  100. +#else
  101.                  DPRINTF(ACLLVL2, ("map_nfs4ace_who: LookupAccountSidA() "
  102.                      "returned ERROR_NONE_MAPPED for sidstr='%s'\n",
  103.                      sidstr));
  104.                  status = lasterr;
  105.                  goto out;
  106. +#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  107. +
  108.              /* Catch other cases */
  109.              case ERROR_NO_SUCH_USER:
  110.              case ERROR_NO_SUCH_GROUP:
  111. diff --git a/daemon/sid.h b/daemon/sid.h
  112. index d310d88..57edfc7 100644
  113. --- a/daemon/sid.h
  114. +++ b/daemon/sid.h
  115. @@ -52,6 +52,10 @@ extern sidcache group_sidcache;
  116.  
  117.  /* prototypes */
  118.  int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid, DWORD *sid_len);
  119. +#ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
  120. +bool unixuser_sid2uid(PSID psid, uid_t *puid);
  121. +bool unixgroup_sid2gid(PSID psid, gid_t *pgid);
  122. +#endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  123.  void sidcache_init(void);
  124.  void sidcache_add(sidcache *cache, const char* win32name, PSID value);
  125.  PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name);
  126. --
  127. 2.45.1
  128.  
  129. From 159dc31356c794debb6a229617e7e82d9bd48aad Mon Sep 17 00:00:00 2001
  130. From: Roland Mainz <roland.mainz@nrubsig.org>
  131. Date: Wed, 3 Jul 2024 18:11:48 +0200
  132. Subject: [PATCH 2/2] daemon: Rename |map_nfs4ace_who()| to
  133.  |map_sid2nfs4ace_who()|+debug cleanup
  134.  
  135. Rename |map_nfs4ace_who()| to |map_sid2nfs4ace_who()|+debug cleanup.
  136.  
  137. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  138. ---
  139. daemon/acl.c | 53 ++++++++++++++++++++++++++++------------------------
  140.  1 file changed, 29 insertions(+), 24 deletions(-)
  141.  
  142. diff --git a/daemon/acl.c b/daemon/acl.c
  143. index 02f08b2..6facd54 100644
  144. --- a/daemon/acl.c
  145. +++ b/daemon/acl.c
  146. @@ -891,7 +891,9 @@ void map_nfs4acemask2winaccessmask(uint32_t nfs4_mask,
  147.  #endif
  148.  }
  149.  
  150. -static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_out, char *domain, SID_NAME_USE *sid_type_out)
  151. +static
  152. +int map_sid2nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid,
  153. +    char *who_out, char *domain, SID_NAME_USE *sid_type_out)
  154.  {
  155.      int status, lasterr;
  156.      SID_NAME_USE sid_type = 0;
  157. @@ -901,7 +903,9 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  158.      DWORD who_size = sizeof(who_buf), domain_size = sizeof(domain_buf);
  159.      LPSTR sidstr = NULL;
  160.  
  161. -    DPRINTF(ACLLVL2, ("--> map_nfs4ace_who(sid=0x%p,owner_sid=0x%p, group_sid=0x%p)\n"));
  162. +    DPRINTF(ACLLVL2, ("--> map_sid2nfs4ace_who("
  163. +        "sid=0x%p,owner_sid=0x%p, group_sid=0x%p)\n",
  164. +        sid, owner_sid, group_sid));
  165.  
  166.      if (DPRINTF_LEVEL_ENABLED(ACLLVL2)) {
  167.          print_sid("sid", sid);
  168. @@ -916,7 +920,7 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  169.      status = 0;
  170.      if (owner_sid) {
  171.          if (EqualSid(sid, owner_sid)) {
  172. -            DPRINTF(ACLLVL2, ("map_nfs4ace_who: this is owner's sid\n"));
  173. +            DPRINTF(ACLLVL2, ("this is owner's sid\n"));
  174.              memcpy(who_out, ACE4_OWNER, strlen(ACE4_OWNER)+1);
  175.              sid_type = SidTypeUser;
  176.              status = ERROR_SUCCESS;
  177. @@ -925,7 +929,7 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  178.      }
  179.      if (group_sid) {
  180.          if (EqualSid(sid, group_sid)) {
  181. -            DPRINTF(ACLLVL2, ("map_nfs4ace_who: this is group's sid\n"));
  182. +            DPRINTF(ACLLVL2, ("this is group's sid\n"));
  183.              memcpy(who_out, ACE4_GROUP, strlen(ACE4_GROUP)+1);
  184.              sid_type = SidTypeGroup;
  185.              status = ERROR_SUCCESS;
  186. @@ -946,8 +950,8 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  187.  
  188.      if (!ConvertSidToStringSidA(sid, &sidstr)) {
  189.          status = GetLastError();
  190. -        eprintf("map_nfs4ace_who: ConvertSidToStringSidA() failed, "
  191. -            "error=%d\n", status);
  192. +        eprintf("map_sid2nfs4ace_who: ConvertSidToStringSidA() "
  193. +            "failed, error=%d\n", status);
  194.          goto out;
  195.      }
  196.  
  197. @@ -956,7 +960,7 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  198.      lasterr = GetLastError();
  199.  
  200.      if (status) {
  201. -        DPRINTF(ACLLVL2, ("map_nfs4ace_who: "
  202. +        DPRINTF(ACLLVL2, ("map_sid2nfs4ace_who: "
  203.              "LookupAccountSid(sidtostr(sid)='%s', who_buf='%s', "
  204.              "who_size=%d, domain='%s', domain_size=%d) "
  205.              "returned success, status=%d, GetLastError=%d\n",
  206. @@ -964,7 +968,7 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  207.              domain_buf, domain_size, status, lasterr));
  208.      }
  209.      else {
  210. -        DPRINTF(ACLLVL2, ("map_nfs4ace_who: "
  211. +        DPRINTF(ACLLVL2, ("map_sid2nfs4ace_who: "
  212.              "LookupAccountSid(sidtostr(sid)='%s', who_size=%d, "
  213.              "domain_size=%d) returned failure, status=%d, "
  214.              "GetLastError=%d\n",
  215. @@ -1003,14 +1007,14 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  216.                          sid_type = SidTypeUser;
  217.                          status = ERROR_SUCCESS;
  218.  
  219. -                        DPRINTF(ACLLVL1, ("map_nfs4ace_who: "
  220. +                        DPRINTF(ACLLVL1, ("map_sid2nfs4ace_who: "
  221.                              "Unix_User+%d SID "
  222.                              "mapped to user '%s'\n",
  223.                              unixuser_uid, who_out));
  224.                          goto add_domain;
  225.                      }
  226.  
  227. -                    eprintf("map_nfs4ace_who: "
  228. +                    eprintf("map_sid2nfs4ace_who: "
  229.                          "unixuser_sid2uid(sid='%s',unixuser_uid=%d) "
  230.                          "returned no mapping.\n",
  231.                          sidstr, (int)unixuser_uid);
  232. @@ -1024,28 +1028,28 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  233.                          sid_type = SidTypeGroup;
  234.                          status = ERROR_SUCCESS;
  235.  
  236. -                        DPRINTF(ACLLVL1, ("map_nfs4ace_who: "
  237. +                        DPRINTF(ACLLVL1, ("map_sid2nfs4ace_who: "
  238.                              "Unix_Group+%d SID "
  239.                              "mapped to group '%s'\n",
  240.                              unixgroup_gid, who_out));
  241.                          goto add_domain;
  242.                      }
  243.  
  244. -                    eprintf("map_nfs4ace_who: "
  245. +                    eprintf("map_sid2nfs4ace_who: "
  246.                          "unixgroup_sid2gid(sid='%s',unixgroup_gid=%d) "
  247.                          "returned no mapping.\n",
  248.                          sidstr, (int)unixgroup_gid);
  249.                      goto err_none_mapped;
  250.                  }
  251.  
  252. -                eprintf("map_nfs4ace_who: LookupAccountSidA() "
  253. +                eprintf("map_sid2nfs4ace_who: LookupAccountSidA() "
  254.                      "returned ERROR_NONE_MAPPED+no "
  255.                      "Unix_@(User|Group)+ mapping for sidstr='%s'\n",
  256.                      sidstr);
  257.  err_none_mapped:
  258.                  status = ERROR_NONE_MAPPED;
  259.  #else
  260. -                DPRINTF(ACLLVL2, ("map_nfs4ace_who: LookupAccountSidA() "
  261. +                DPRINTF(ACLLVL2, ("map_sid2nfs4ace_who: LookupAccountSidA() "
  262.                      "returned ERROR_NONE_MAPPED for sidstr='%s'\n",
  263.                      sidstr));
  264.                  status = lasterr;
  265. @@ -1055,14 +1059,14 @@ err_none_mapped:
  266.              /* Catch other cases */
  267.              case ERROR_NO_SUCH_USER:
  268.              case ERROR_NO_SUCH_GROUP:
  269. -                eprintf("map_nfs4ace_who: LookupAccountSidA() "
  270. +                eprintf("map_sid2nfs4ace_who: LookupAccountSidA() "
  271.                      "returned ERROR_NO_SUCH_@(USER|GROUP) for "
  272.                      "sidstr='%s'\n",
  273.                      sidstr);
  274.                  status = lasterr;
  275.                  goto out;
  276.              default:
  277. -                eprintf("map_nfs4ace_who: Internal error, "
  278. +                eprintf("map_sid2nfs4ace_who: Internal error, "
  279.                      "LookupAccountSidA() returned unexpected ERROR_%d "
  280.                      "for sidstr='%s'\n",
  281.                      status, sidstr);
  282. @@ -1079,13 +1083,15 @@ add_domain:
  283.  out:
  284.      if (status) {
  285.          DPRINTF(ACLLVL2,
  286. -            ("<-- map_nfs4ace_who() returns %d\n", status));
  287. +            ("<-- map_sid2nfs4ace_who() returns %d\n", status));
  288.      }
  289.      else {
  290.          DPRINTF(ACLLVL2,
  291. -            ("<-- map_nfs4ace_who(who_out='%s', sid_type=%d) "
  292. +            ("<-- map_sid2nfs4ace_who(who_out='%s', sid_type='%s'/%d) "
  293.              "returns %d\n",
  294. -            who_out, sid_type, status));
  295. +            who_out,
  296. +            map_SID_NAME_USE2str(sid_type), sid_type,
  297. +            status));
  298.          if (sid_type_out) {
  299.              *sid_type_out = sid_type;
  300.          }
  301. @@ -1209,9 +1215,8 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  302.              }
  303.  #endif /* NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES */
  304.  
  305. -            status = map_nfs4ace_who(ace_sid, sid, gsid,
  306. -                curr_nfsace->who,
  307. -                                     domain, &who_sid_type);
  308. +            status = map_sid2nfs4ace_who(ace_sid, sid, gsid,
  309. +                curr_nfsace->who, domain, &who_sid_type);
  310.              if (status)
  311.                  goto out_free;
  312.  
  313. @@ -1333,7 +1338,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  314.              goto out;
  315.          }
  316.  
  317. -        status = map_nfs4ace_who(sid, NULL, NULL, ownerbuf,
  318. +        status = map_sid2nfs4ace_who(sid, NULL, NULL, ownerbuf,
  319.              nfs41dg->localdomain_name, NULL);
  320.          if (status)
  321.              goto out;
  322. @@ -1355,7 +1360,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  323.              goto out;
  324.          }
  325.  
  326. -        status = map_nfs4ace_who(sid, NULL, NULL, groupbuf,
  327. +        status = map_sid2nfs4ace_who(sid, NULL, NULL, groupbuf,
  328.              nfs41dg->localdomain_name, NULL);
  329.          if (status)
  330.              goto out;
  331. --
  332. 2.45.1

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