pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for SID cache, idmapper, Windows Server 2022 compatibility hacks+tests+misc, 2024-11-11
Posted by Anonymous on Mon 11th Nov 2024 17:38
raw | new post

  1. From 50dc084ae2d9933578644519a0a19dbb6d66f654 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 11 Nov 2024 14:09:00 +0100
  4. Subject: [PATCH 1/9] cygwin_idmapper.ksh,daemon: Wrong machine SID used by
  5.  cygwin_idmapper.ksh
  6.  
  7. cygwin_idmapper.ksh uses a hardcoded (and in the case of Windows
  8. Server 2022) wrong machine SID, which caused a failure in the machinery
  9. for l10n account+group names.
  10. As result the idmapper was returning "Unknown+User" and "Unknown+Group"
  11. names as valid user/group names, which caused further breakdowns.
  12.  
  13. Fix is to use the correct machine SID, disable the l10n account+group
  14. names if we cannot find l10n names, and add error messages in
  15. |cygwin_getent_passwd()|+|cygwin_getent_group()| if the idmapper
  16. script returns "Unknown+User"/"Unknown+Group".
  17.  
  18. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  19. ---
  20. cygwin_idmapper.ksh   | 150 ++++++++++++++++++++++++++----------------
  21.  daemon/idmap_cygwin.c |  24 +++++++
  22.  2 files changed, 117 insertions(+), 57 deletions(-)
  23.  
  24. diff --git a/cygwin_idmapper.ksh b/cygwin_idmapper.ksh
  25. index ab38245..0a41b1f 100644
  26. --- a/cygwin_idmapper.ksh
  27. +++ b/cygwin_idmapper.ksh
  28. @@ -40,56 +40,41 @@ typeset stdout
  29.  typeset -A c.localised_usernames
  30.  typeset -A c.localised_groupnames
  31.  
  32. +# fixme: Different Windows versions use different machine SIDs
  33. +# Windows 10+Windows Server 2019 use
  34. +# "S-1-5-21-3286904461-661230000-4220857270", but other Windows
  35. +# versions use different values
  36. +typeset machine_sid="$(mkgroup -l | sed -n 's/[^:]*:\(S-[-0-9]*\)-513:.*$//p')"
  37. +if [[ "$machine_sid" != ~(El)S-1-5-21- ]] ; then
  38. +       print -u2 -f "%s: Unexpected machine SID '%q'\n" \
  39. +               "$0" "$machine_sid"
  40. +       exit 1
  41. +fi
  42. +
  43.  # User "SYSTEM": de_DE: "SYSTEM" ...
  44.  stdout="$(getent passwd 'S-1-5-18')"
  45. -c.localised_usernames['SYSTEM']="${stdout%%:*}"
  46. +if (( $? == 0 )) && [[ "$stdout" != ~(El)Unknown\+User: ]] ; then
  47. +       c.localised_usernames['SYSTEM']="${stdout%%:*}"
  48. +fi
  49.  
  50.  # User "Adminstrator": fr_FR: "Administrateur" ...
  51. -stdout="$(getent passwd 'S-1-5-21-3286904461-661230000-4220857270-500')"
  52. -c.localised_usernames['Administrator']="${stdout%%:*}"
  53. +stdout="$(getent passwd "${machine_sid}-500")"
  54. +if (( $? == 0 )) && [[ "$stdout" != ~(El)Unknown\+User: ]] ; then
  55. +       c.localised_usernames['Administrator']="${stdout%%:*}"
  56. +
  57. +fi
  58.  
  59.  # Group "None": de_DE: "Kein", fr_FR: "Aucun" ...
  60. -stdout="$(getent group 'S-1-5-21-3286904461-661230000-4220857270-513')"
  61. -c.localised_groupnames['None']="${stdout%%:*}"
  62. +stdout="$(getent group "${machine_sid}-513")"
  63. +if (( $? == 0 )) && [[ "$stdout" != ~(El)Unknown\+Group: ]] ; then
  64. +       c.localised_groupnames['None']="${stdout%%:*}"
  65. +fi
  66.  
  67.  compound -A localusers=(
  68.         #
  69.         # System accounts
  70.         #
  71. -       ["${c.localised_usernames['Administrator']}"]=(
  72. -               localaccountname="${c.localised_usernames['Administrator']}"
  73. -               localuid=197108
  74. -               localgid=197121
  75. -       )
  76. -       ['Administrator']=(
  77. -               localaccountname="${c.localised_usernames['Administrator']}"
  78. -               localuid=197108
  79. -               localgid=197121
  80. -       )
  81. -       # French user "Administrator"
  82. -       ['Administrateur']=(
  83. -               localaccountname="${c.localised_usernames['Administrator']}"
  84. -               localuid=197108
  85. -               localgid=197121
  86. -       )
  87. -       ["${c.localised_usernames['SYSTEM']}"]=(
  88. -               localaccountname="${c.localised_usernames['SYSTEM']}"
  89. -               localuid=18
  90. -               localgid=18
  91. -       )
  92. -       ["SYSTEM"]=(
  93. -               localaccountname="${c.localised_usernames['SYSTEM']}"
  94. -               localuid=18
  95. -               localgid=18
  96. -       )
  97. -       # French user "SYSTEM"
  98. -       # FIXME: This should be $'Syst\u[e8]me', but ksh93 1.0.10
  99. -       # doesn't work
  100. -       [$'Syst\xc3\xa8me']=(
  101. -               localaccountname="${c.localised_usernames['SYSTEM']}"
  102. -               localuid=18
  103. -               localgid=18
  104. -       )
  105. +
  106.         #
  107.         # Site-specific users
  108.         #
  109. @@ -125,28 +110,55 @@ compound -A localusers=(
  110.         )
  111.  )
  112.  
  113. +if [[ -v c.localised_usernames['Administrator'] ]] ; then
  114. +       localusers+=(
  115. +               ["${c.localised_usernames['Administrator']}"]=(
  116. +                       localaccountname="${c.localised_usernames['Administrator']}"
  117. +                       localuid=197108
  118. +                       localgid=197121
  119. +               )
  120. +               ['Administrator']=(
  121. +                       localaccountname="${c.localised_usernames['Administrator']}"
  122. +                       localuid=197108
  123. +                       localgid=197121
  124. +               )
  125. +               # French user "Administrator"
  126. +               ['Administrateur']=(
  127. +                       localaccountname="${c.localised_usernames['Administrator']}"
  128. +                       localuid=197108
  129. +                       localgid=197121
  130. +               )
  131. +       )
  132. +fi
  133. +if [[ -v c.localised_usernames['SYSTEM'] ]] ; then
  134. +       localusers+=(
  135. +               ["${c.localised_usernames['SYSTEM']}"]=(
  136. +                       localaccountname="${c.localised_usernames['SYSTEM']}"
  137. +                       localuid=18
  138. +                       localgid=18
  139. +               )
  140. +               ["SYSTEM"]=(
  141. +                       localaccountname="${c.localised_usernames['SYSTEM']}"
  142. +                       localuid=18
  143. +                       localgid=18
  144. +               )
  145. +               # French user "SYSTEM"
  146. +               # FIXME: This should be $'Syst\u[e8]me', but ksh93 1.0.10
  147. +               # doesn't work
  148. +               [$'Syst\xc3\xa8me']=(
  149. +                       localaccountname="${c.localised_usernames['SYSTEM']}"
  150. +                       localuid=18
  151. +                       localgid=18
  152. +               )
  153. +       )
  154. +fi
  155. +
  156.  compound -A localgroups=(
  157.         #
  158.         # System accounts
  159.         #
  160. -       ["${c.localised_groupnames['None']}"]=(
  161. -               localgroupname="${c.localised_groupnames['None']}"
  162. -               localgid=197121
  163. -       )
  164. -       ["None"]=(
  165. -               localgroupname="${c.localised_groupnames['None']}"
  166. -               localgid=197121
  167. -       )
  168. -       # French Windows localised group name for "None"
  169. -       ['Aucun']=(
  170. -               localgroupname="${c.localised_groupnames['None']}"
  171. -               localgid=197121
  172. -       )
  173. -       # German Windows localised group name for "None"
  174. -       ["Kein"]=(
  175. -               localgroupname="${c.localised_groupnames['None']}"
  176. -               localgid=197121
  177. -       )
  178. +
  179. +
  180.         #
  181.         # Site-specific users
  182.         #
  183. @@ -168,6 +180,30 @@ compound -A localgroups=(
  184.         )
  185.  )
  186.  
  187. +if [[ -v c.localised_groupnames['None'] ]] ; then
  188. +       localgroups+=(
  189. +               ["${c.localised_groupnames['None']}"]=(
  190. +                       localgroupname="${c.localised_groupnames['None']}"
  191. +                       localgid=197121
  192. +               )
  193. +               ["None"]=(
  194. +                       localgroupname="${c.localised_groupnames['None']}"
  195. +                       localgid=197121
  196. +               )
  197. +               # French Windows localised group name for "None"
  198. +               ['Aucun']=(
  199. +                       localgroupname="${c.localised_groupnames['None']}"
  200. +                       localgid=197121
  201. +               )
  202. +               # German Windows localised group name for "None"
  203. +               ["Kein"]=(
  204. +                       localgroupname="${c.localised_groupnames['None']}"
  205. +                       localgid=197121
  206. +               )
  207. +       )
  208. +fi
  209. +
  210. +
  211.  case "${c.mode}" in
  212.         'nfsserver_owner2localaccount')
  213.                 #
  214. diff --git a/daemon/idmap_cygwin.c b/daemon/idmap_cygwin.c
  215. index 9f7af99..868bdee 100644
  216. --- a/daemon/idmap_cygwin.c
  217. +++ b/daemon/idmap_cygwin.c
  218. @@ -146,6 +146,18 @@ int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid,
  219.          }
  220.      }
  221.  
  222. +    /*
  223. +     * Cygwin /usr/bin/getent passwd can return "Unknown+User"
  224. +     * in cases when an SID is valid but does not match an account.
  225. +     * The idmapper script must never return this!
  226. +     */
  227. +    if (!strcmp(localaccountname, "Unknown+User")) {
  228. +        eprintf("cygwin_getent_passwd(name='%s'): "
  229. +            "idmapper returned illegal value '%s'\n",
  230. +            name, localaccountname);
  231. +        goto fail;
  232. +    }
  233. +
  234.      if (!localaccountname)
  235.          goto fail;
  236.  
  237. @@ -274,6 +286,18 @@ int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid)
  238.          }
  239.      }
  240.  
  241. +    /*
  242. +     * Cygwin /usr/bin/getent group can return "Unknown+Group"
  243. +     * in cases when an SID is valid but does not match an account.
  244. +     * The idmapper script must never return this!
  245. +     */
  246. +    if (!strcmp(localgroupname, "Unknown+Group")) {
  247. +        eprintf("cygwin_getent_group(name='%s'): "
  248. +            "idmapper returned illegal value '%s'\n",
  249. +            name, localgroupname);
  250. +        goto fail;
  251. +    }
  252. +
  253.      if (!localgroupname)
  254.          goto fail;
  255.  
  256. --
  257. 2.45.1
  258.  
  259. From 9c73bab9e0eb86455a0358000048a66162f55d97 Mon Sep 17 00:00:00 2001
  260. From: Roland Mainz <roland.mainz@nrubsig.org>
  261. Date: Mon, 11 Nov 2024 14:15:03 +0100
  262. Subject: [PATCH 2/9] tests: nfsbuildtest: Create missing /usr/local install
  263.  dir for "gcc build"
  264.  
  265. nfsbuildtest: Create missing /usr/local install dir for "gcc build"
  266.  
  267. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  268. ---
  269. tests/nfsbuildtest/nfsbuildtest.ksh93 | 21 ++++++++++++++++++---
  270.  1 file changed, 18 insertions(+), 3 deletions(-)
  271.  
  272. diff --git a/tests/nfsbuildtest/nfsbuildtest.ksh93 b/tests/nfsbuildtest/nfsbuildtest.ksh93
  273. index eb8bc02..4823005 100644
  274. --- a/tests/nfsbuildtest/nfsbuildtest.ksh93
  275. +++ b/tests/nfsbuildtest/nfsbuildtest.ksh93
  276. @@ -158,10 +158,25 @@ function gcc_build
  277.         fi
  278.  
  279.         #
  280. -       # build gcc
  281. +       # Create /usr/local/ dir in "$PWD/install_root/" because gcc's
  282. +       # make install will fail if the dir is missing
  283.         #
  284. -       time ksh93 -c 'export SHELL=/bin/ksh93 ; (yes | make --load-average 32 -j12 install)'
  285. -       echo $?
  286. +       mkdir -p -- "$PWD/install_root/usr/local"
  287. +
  288. +       #
  289. +       # build gcc
  290. +       # Notes:
  291. +       # - targets "all" and "install" must be called in sequence, as
  292. +       # a plain $ make -j32 install # can fail when tools build
  293. +       # during $ make -j32 all # missing
  294. +       #
  295. +       (
  296. +               set -o xtrace
  297. +               time ksh93 -c 'export SHELL=/bin/ksh93 ; (yes | make --load-average 32 -j12 all)'
  298. +               printf "######## gcc build make all returned %d\n" $?
  299. +               time ksh93 -c 'export SHELL=/bin/ksh93 ; (yes | make --load-average 32 -j12 install)'
  300. +               printf "######## gcc build make install returned %d\n" $?
  301. +       )
  302.  
  303.         echo "#Done."
  304.         return 0
  305. --
  306. 2.45.1
  307.  
  308. From ecfd0d4bc1e3d43246333150491d1e48ba24b1b8 Mon Sep 17 00:00:00 2001
  309. From: Roland Mainz <roland.mainz@nrubsig.org>
  310. Date: Mon, 11 Nov 2024 14:21:29 +0100
  311. Subject: [PATCH 3/9] daemon: ACE for Unix_User+/Unix_Group+ should use
  312.  uid/gid, not uid@domain/gid@domain
  313.  
  314. ACE for Unix_User+/Unix_Group+ should use uid/gid, not uid@domain/gid@domain
  315.  
  316. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  317. ---
  318. daemon/acl.c | 6 ++++--
  319.  1 file changed, 4 insertions(+), 2 deletions(-)
  320.  
  321. diff --git a/daemon/acl.c b/daemon/acl.c
  322. index 8622678..b122910 100644
  323. --- a/daemon/acl.c
  324. +++ b/daemon/acl.c
  325. @@ -1011,7 +1011,7 @@ int map_sid2nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid,
  326.                              "Unix_User+%d SID "
  327.                              "mapped to user '%s'\n",
  328.                              unixuser_uid, who_out));
  329. -                        goto add_domain;
  330. +                        goto no_add_domain;
  331.                      }
  332.  
  333.                      eprintf("map_sid2nfs4ace_who: "
  334. @@ -1032,7 +1032,7 @@ int map_sid2nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid,
  335.                              "Unix_Group+%d SID "
  336.                              "mapped to group '%s'\n",
  337.                              unixgroup_gid, who_out));
  338. -                        goto add_domain;
  339. +                        goto no_add_domain;
  340.                      }
  341.  
  342.                      eprintf("map_sid2nfs4ace_who: "
  343. @@ -1079,6 +1079,8 @@ err_none_mapped:
  344.  add_domain:
  345.      (void)memcpy(who_out+who_size, "@", sizeof(char));
  346.      (void)memcpy(who_out+who_size+1, domain, strlen(domain)+1);
  347. +
  348. +no_add_domain:
  349.      status = ERROR_SUCCESS;
  350.  out:
  351.      if (status) {
  352. --
  353. 2.45.1
  354.  
  355. From c6db0fd00c96b46fac48d214868b68577a8e7018 Mon Sep 17 00:00:00 2001
  356. From: Roland Mainz <roland.mainz@nrubsig.org>
  357. Date: Mon, 11 Nov 2024 14:49:51 +0100
  358. Subject: [PATCH 4/9] daemon,nfs41_build_features.h: Add experimental hacks for
  359.  WS2022 compatibility
  360.  
  361. Add experimental hacks for Windows Server NFSv4.1 server compatibility.
  362.  
  363. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  364. ---
  365. daemon/acl.c           | 42 ++++++++++++++++++++++++++++++++++++++++++
  366.  daemon/sid.c           | 12 ++++++++++++
  367.  nfs41_build_features.h |  6 ++++++
  368.  3 files changed, 60 insertions(+)
  369.  
  370. diff --git a/daemon/acl.c b/daemon/acl.c
  371. index b122910..ffdba35 100644
  372. --- a/daemon/acl.c
  373. +++ b/daemon/acl.c
  374. @@ -99,12 +99,24 @@ static int check_4_special_identifiers(char *who, PSID *sid, DWORD *sid_len,
  375.      *flag = TRUE;
  376.      if (!strncmp(who, ACE4_OWNER, strlen(ACE4_OWNER)-1))
  377.          type = WinCreatorOwnerSid;
  378. +#ifdef NFS41_DRIVER_WS2022_HACKS
  379. +    else if (!strncmp(who, "CREATOR OWNER@", strlen("CREATOR OWNER@")-1))
  380. +        type = WinCreatorOwnerSid;
  381. +#endif /* NFS41_DRIVER_WS2022_HACKS */
  382.      else if (!strncmp(who, ACE4_GROUP, strlen(ACE4_GROUP)-1))
  383.          type = WinCreatorGroupSid;
  384.      else if (!strncmp(who, ACE4_EVERYONE, strlen(ACE4_EVERYONE)-1))
  385.          type = WinWorldSid;
  386. +#ifdef NFS41_DRIVER_WS2022_HACKS
  387. +    else if (!strncmp(who, "Everyone@", strlen("Everyone@")-1))
  388. +        type = WinWorldSid;
  389. +#endif /* NFS41_DRIVER_WS2022_HACKS */
  390.      else if (!strncmp(who, ACE4_NOBODY, strlen(ACE4_NOBODY)))
  391.          type = WinNullSid;
  392. +#ifdef NFS41_DRIVER_WS2022_HACKS
  393. +    else if (!strncmp(who, "NULL SID", strlen("NULL SID")))
  394. +        type = WinNullSid;
  395. +#endif /* NFS41_DRIVER_WS2022_HACKS */
  396.      else
  397.          *flag = FALSE;
  398.      if (*flag)
  399. @@ -174,6 +186,19 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  400.          if (!flag) {
  401.              bool isgroupacl = (curr_nfsace->aceflag & ACE4_IDENTIFIER_GROUP)?true:false;
  402.  
  403. +
  404. +#ifdef NFS41_DRIVER_WS2022_HACKS
  405. +            if ((isgroupacl == false) && domain &&
  406. +                (!strcmp(domain, "BUILTIN"))) {
  407. +                if ((!strcmp(curr_nfsace->who, "Users")) ||
  408. +                    (!strcmp(curr_nfsace->who, "Administrators"))) {
  409. +                    DPRINTF(1, ("convert_nfs4acl_2_dacl: "
  410. +                        "force isgroupacl=true for for user='%s'\n",
  411. +                        curr_nfsace->who));
  412. +                    isgroupacl = true;
  413. +                }
  414. +            }
  415. +#endif /* NFS41_DRIVER_WS2022_HACKS */
  416.              if (isgroupacl) {
  417.                  DPRINTF(ACLLVL2,
  418.                      ("convert_nfs4acl_2_dacl: aces[%d].who='%s': "
  419. @@ -1078,6 +1103,23 @@ err_none_mapped:
  420.      (void)memcpy(who_out, who_buf, who_size);
  421.  add_domain:
  422.      (void)memcpy(who_out+who_size, "@", sizeof(char));
  423. +
  424. +#ifdef NFS41_DRIVER_WS2022_HACKS
  425. +    /* Fixup |domain| for Windows Sever 2022 NFSv4.1 server */
  426. +    if ((!strncmp(who_out, "Users@", who_size+1)) ||
  427. +        (!strncmp(who_out, "Administrators@", who_size+1))) {
  428. +        domain = "BUILTIN";
  429. +        DPRINTF(1,
  430. +            ("map_sid2nfs4ace_who: Fixup '%*s' domain='%s'\n",
  431. +            (int)who_size+1, who_out, domain));
  432. +    }
  433. +    else if (!strncmp(who_out, "SYSTEM@", who_size+1)) {
  434. +        domain = "NT AUTHORITY";
  435. +        DPRINTF(1,
  436. +            ("map_sid2nfs4ace_who: Fixup '%*s' domain='%s'\n",
  437. +            (int)who_size+1, who_out, domain));
  438. +    }
  439. +#endif /* NFS41_DRIVER_WS2022_HACKS */
  440.      (void)memcpy(who_out+who_size+1, domain, strlen(domain)+1);
  441.  
  442.  no_add_domain:
  443. diff --git a/daemon/sid.c b/daemon/sid.c
  444. index 2a63763..0c8af81 100644
  445. --- a/daemon/sid.c
  446. +++ b/daemon/sid.c
  447. @@ -621,6 +621,18 @@ out_cache:
  448.              sid_type = SidTypeGroup;
  449.          }
  450.  
  451. +#ifdef NFS41_DRIVER_WS2022_HACKS
  452. +        if ((query & OWNER_SECURITY_INFORMATION) &&
  453. +            (sid_type == SidTypeWellKnownGroup)) {
  454. +            if (!strcmp(orig_nfsname, "SYSTEM")) {
  455. +                DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  456. +                    "SID_TYPE='SidTypeWellKnownGroup' mapped to 'SidTypeUser' for user\n",
  457. +                    query, orig_nfsname));
  458. +                sid_type = SidTypeUser;
  459. +            }
  460. +        }
  461. +#endif /* NFS41_DRIVER_WS2022_HACKS */
  462. +
  463.          switch (sid_type) {
  464.              case SidTypeUser:
  465.                  sidcache_add(&user_sidcache, orig_nfsname, *sid);
  466. diff --git a/nfs41_build_features.h b/nfs41_build_features.h
  467. index 34843e1..bcc765c 100644
  468. --- a/nfs41_build_features.h
  469. +++ b/nfs41_build_features.h
  470. @@ -167,4 +167,10 @@
  471.   */
  472.  #define NFS41_DRIVER_WSL_SUPPORT 1
  473.  
  474. +/*
  475. + * NFS41_DRIVER_WS2022_HACKS - Enable hacks for Windows Server 2022
  476. + * compatibility
  477. + */
  478. +#define NFS41_DRIVER_WS2022_HACKS 1
  479. +
  480.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  481. --
  482. 2.45.1
  483.  
  484. From 252540c08ededdd50e9c6ffb68cf66263b6651fc Mon Sep 17 00:00:00 2001
  485. From: Roland Mainz <roland.mainz@nrubsig.org>
  486. Date: Mon, 11 Nov 2024 15:01:13 +0100
  487. Subject: [PATCH 5/9] daemon: Fix number of |DPRINTF()| args in
  488.  |map_nfs4servername_2_sid()|
  489.  
  490. Fix number of |DPRINTF()| args in |map_nfs4servername_2_sid()|
  491.  
  492. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  493. ---
  494. daemon/sid.c | 2 +-
  495.  1 file changed, 1 insertion(+), 1 deletion(-)
  496.  
  497. diff --git a/daemon/sid.c b/daemon/sid.c
  498. index 0c8af81..baaf95a 100644
  499. --- a/daemon/sid.c
  500. +++ b/daemon/sid.c
  501. @@ -617,7 +617,7 @@ out_cache:
  502.               */
  503.              DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  504.                  "SID_TYPE='SidTypeAlias' mapped to 'SidTypeGroup'\n",
  505. -                query, orig_nfsname, sid_type));
  506. +                query, orig_nfsname));
  507.              sid_type = SidTypeGroup;
  508.          }
  509.  
  510. --
  511. 2.45.1
  512.  
  513. From 1169b9cd513d1617910ccdc16f870d193ed6f165 Mon Sep 17 00:00:00 2001
  514. From: Roland Mainz <roland.mainz@nrubsig.org>
  515. Date: Mon, 11 Nov 2024 15:03:20 +0100
  516. Subject: [PATCH 6/9] daemon: Add assert to |convert_nfs4acl_2_dacl()| if an
  517.  NFSv4 ACE who name contains numeric uid/gid
  518.  
  519. Add assert to |convert_nfs4acl_2_dacl()| if an NFSv4 ACE who name contains numeric uid/gid
  520.  
  521. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  522. ---
  523. daemon/acl.c | 4 ++++
  524.  1 file changed, 4 insertions(+)
  525.  
  526. diff --git a/daemon/acl.c b/daemon/acl.c
  527. index ffdba35..715a573 100644
  528. --- a/daemon/acl.c
  529. +++ b/daemon/acl.c
  530. @@ -161,6 +161,10 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  531.          DPRINTF(ACLLVL2, ("convert_nfs4acl_2_dacl: for user='%s' domain='%s'\n",
  532.                  curr_nfsace->who, domain?domain:"<null>"));
  533.  
  534. +        EASSERT_MSG(!isdigit(curr_nfsace->who[0]),
  535. +            ("convert_nfs4acl_2_dacl: aces[%d]->who='%s' uses numeric id",
  536. +            (int)nfs_i, curr_nfsace->who));
  537. +
  538.  #ifdef NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES
  539.          /*
  540.           * Skip "nobody" ACEs - Cygwin uses |WinNullSid| ACEs (mapped
  541. --
  542. 2.45.1
  543.  
  544. From ec9b10b7fb3b74bf5951722aedd86b9d4c3276ac Mon Sep 17 00:00:00 2001
  545. From: Roland Mainz <roland.mainz@nrubsig.org>
  546. Date: Mon, 11 Nov 2024 18:03:54 +0100
  547. Subject: [PATCH 7/9] daemon: |sidcache_add()|: Fix timestamp calculation used
  548.  for entry invalidation
  549.  
  550. Fix timestamp calculation in |sidcache_add()| used for entry invalidation
  551.  
  552. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  553. ---
  554. daemon/sid.c | 2 +-
  555.  1 file changed, 1 insertion(+), 1 deletion(-)
  556.  
  557. diff --git a/daemon/sid.c b/daemon/sid.c
  558. index baaf95a..8be1cae 100644
  559. --- a/daemon/sid.c
  560. +++ b/daemon/sid.c
  561. @@ -271,7 +271,7 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  562.          sidcache_entry *e = &cache->entries[i];
  563.  
  564.          if ((e->sid != NULL) &&
  565. -            (e->timestamp < (currentTimestamp - SIDCACHE_TTL))) {
  566. +            ((currentTimestamp - e->timestamp) >= SIDCACHE_TTL)) {
  567.              e->sid = NULL;
  568.              e->win32name[0] = '\0';
  569.              e->sid_len = 0;
  570. --
  571. 2.45.1
  572.  
  573. From c81fe9407d20da67eb3f5aca2f386e79b1d10419 Mon Sep 17 00:00:00 2001
  574. From: Roland Mainz <roland.mainz@nrubsig.org>
  575. Date: Mon, 11 Nov 2024 18:23:31 +0100
  576. Subject: [PATCH 8/9] daemon: Add |sidcache_addwithalias()| to store a numeric
  577.  uid/gid alongside Win32 owner/group name
  578.  
  579. Add |sidcache_addwithalias()| to store a numeric uid/gid alongside
  580. Win32 owner/group name.
  581. We use this as sort-of hack for NFSv4.1 servers which send numeric uid/gid
  582. values for owner/owner_group, so we can use the cache in such cases too.
  583.  
  584. FIXME: This mixes NFSv4.1 owner/owner_group namespace with Win32 account
  585. names namespace, and should be reworked once we have a bidirectional
  586. idmapper which cleanly seperates NFSv4.1 server account namespace+server
  587. uid/gid from NFSv4.1 Win32 account namespace+client uid/gid.
  588.  
  589. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  590. ---
  591. daemon/sid.c | 59 +++++++++++++++++++++++++++++++++++++++++++++-------
  592.  daemon/sid.h |  1 +
  593.  2 files changed, 53 insertions(+), 7 deletions(-)
  594.  
  595. diff --git a/daemon/sid.c b/daemon/sid.c
  596. index 8be1cae..dcf4680 100644
  597. --- a/daemon/sid.c
  598. +++ b/daemon/sid.c
  599. @@ -227,6 +227,7 @@ typedef struct _sidcache_entry
  600.  {
  601.  #define SIDCACHE_ENTRY_NAME_SIZE (UNLEN + 1)
  602.      char    win32name[SIDCACHE_ENTRY_NAME_SIZE]; /* must fit something like "user@domain" */
  603. +    char    aliasname[SIDCACHE_ENTRY_NAME_SIZE];
  604.      PSID    sid;
  605.      DWORD   sid_len;
  606.  #pragma warning( push )
  607. @@ -254,8 +255,13 @@ void sidcache_init(void)
  608.      InitializeCriticalSection(&group_sidcache.lock);
  609.  }
  610.  
  611. -/* copy SID |value| into cache */
  612.  void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  613. +{
  614. +    sidcache_addwithalias(cache, win32name, NULL, value);
  615. +}
  616. +
  617. +/* copy SID |value| into cache */
  618. +void sidcache_addwithalias(sidcache *cache, const char *win32name, const char *aliasname, PSID value)
  619.  {
  620.      int i;
  621.      ssize_t freeEntryIndex;
  622. @@ -274,6 +280,7 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  623.              ((currentTimestamp - e->timestamp) >= SIDCACHE_TTL)) {
  624.              e->sid = NULL;
  625.              e->win32name[0] = '\0';
  626. +            e->aliasname[0] = '\0';
  627.              e->sid_len = 0;
  628.          }
  629.      }
  630. @@ -281,9 +288,26 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  631.      /* Find the oldest valid cache entry */
  632.      freeEntryIndex = -1;
  633.      for (i = 0; i < SIDCACHE_SIZE; i++) {
  634. -        if (cache->entries[i].sid) {
  635. +        sidcache_entry *e = &cache->entries[i];
  636. +        if (e->sid) {
  637.              /* Same name ? Then reuse this slot... */
  638. -            if (!strcmp(cache->entries[i].win32name, win32name)) {
  639. +            if (!strcmp(e->win32name, win32name)) {
  640. +                freeEntryIndex = i;
  641. +                break;
  642. +            }
  643. +            if (aliasname) {
  644. +                if (!strcmp(e->win32name, aliasname)) {
  645. +                    freeEntryIndex = i;
  646. +                    break;
  647. +                }
  648. +                if ((e->aliasname[0] != '\0') &&
  649. +                    (!strcmp(e->aliasname, aliasname))) {
  650. +                    freeEntryIndex = i;
  651. +                    break;
  652. +                }
  653. +            }
  654. +            if ((e->aliasname[0] != '\0') &&
  655. +                (!strcmp(e->aliasname, win32name))) {
  656.                  freeEntryIndex = i;
  657.                  break;
  658.              }
  659. @@ -308,12 +332,17 @@ void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  660.      if (!CopySid(sid_len, e->sid, value)) {
  661.          e->sid = NULL;
  662.          e->win32name[0] = '\0';
  663. +        e->aliasname[0] = '\0';
  664.          e->sid_len = 0;
  665.          goto done;
  666.      }
  667.  
  668.      e->sid_len = sid_len;
  669.      (void)strcpy(e->win32name, win32name);
  670. +    if (aliasname)
  671. +        (void)strcpy(e->aliasname, aliasname);
  672. +    else
  673. +        e->aliasname[0] = '\0';
  674.      e->timestamp = currentTimestamp;
  675.  
  676.      cache->cacheIndex = (cache->cacheIndex + 1) % SIDCACHE_SIZE;
  677. @@ -337,7 +366,8 @@ PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name)
  678.          e = &cache->entries[i];
  679.  
  680.          if ((e->sid != NULL) &&
  681. -            (!strcmp(e->win32name, win32name)) &&
  682. +            ((!strcmp(e->win32name, win32name)) ||
  683. +                ((e->aliasname[0] != '\0') && (!strcmp(e->aliasname, win32name)))) &&
  684.              ((currentTimestamp - e->timestamp) < SIDCACHE_TTL)) {
  685.              PSID malloced_sid = malloc(e->sid_len);
  686.              if (!malloced_sid)
  687. @@ -374,7 +404,6 @@ bool sidcache_getcached_bysid(sidcache *cache, PSID sid, char *out_win32name)
  688.          if ((e->sid != NULL) &&
  689.              (EqualSid(sid, e->sid) &&
  690.              ((currentTimestamp - e->timestamp) < SIDCACHE_TTL))) {
  691. -
  692.              (void)strcpy(out_win32name, e->win32name);
  693.  
  694.              ret = true;
  695. @@ -635,10 +664,26 @@ out_cache:
  696.  
  697.          switch (sid_type) {
  698.              case SidTypeUser:
  699. -                sidcache_add(&user_sidcache, orig_nfsname, *sid);
  700. +                if (isdigit(orig_nfsname[0])) {
  701. +                    DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  702. +                        "adding usercache nfsname='%s' orig_nfsname='%s'\n",
  703. +                        query, orig_nfsname, nfsname, orig_nfsname));
  704. +                    sidcache_addwithalias(&user_sidcache, nfsname, orig_nfsname, *sid);
  705. +                }
  706. +                else {
  707. +                    sidcache_add(&user_sidcache, orig_nfsname, *sid);
  708. +                }
  709.                  break;
  710.              case SidTypeGroup:
  711. -                sidcache_add(&group_sidcache, orig_nfsname, *sid);
  712. +                if (isdigit(orig_nfsname[0])) {
  713. +                    DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  714. +                        "adding groupcache nfsname='%s' orig_nfsname='%s'\n",
  715. +                        query, orig_nfsname, nfsname, orig_nfsname));
  716. +                    sidcache_addwithalias(&group_sidcache, nfsname, orig_nfsname, *sid);
  717. +                }
  718. +                else {
  719. +                    sidcache_add(&group_sidcache, orig_nfsname, *sid);
  720. +                }
  721.                  break;
  722.              default:
  723.                  eprintf("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  724. diff --git a/daemon/sid.h b/daemon/sid.h
  725. index 57edfc7..70fc910 100644
  726. --- a/daemon/sid.h
  727. +++ b/daemon/sid.h
  728. @@ -58,6 +58,7 @@ bool unixgroup_sid2gid(PSID psid, gid_t *pgid);
  729.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  730.  void sidcache_init(void);
  731.  void sidcache_add(sidcache *cache, const char* win32name, PSID value);
  732. +void sidcache_addwithalias(sidcache *cache, const char *win32name, const char *aliasname, PSID value);
  733.  PSID *sidcache_getcached_byname(sidcache *cache, const char *win32name);
  734.  bool sidcache_getcached_bysid(sidcache *cache, PSID sid, char *out_win32name);
  735.  
  736. --
  737. 2.45.1
  738.  
  739. From f510500c3f08b05a72609e41c815d2a3c7339b59 Mon Sep 17 00:00:00 2001
  740. From: Roland Mainz <roland.mainz@nrubsig.org>
  741. Date: Mon, 11 Nov 2024 18:28:24 +0100
  742. Subject: [PATCH 9/9] daemon: Enable uid/gid fallback debug output in
  743.  |map_nfs4servername_2_sid()|
  744.  
  745. Enable uid/gid fallback debug output in |map_nfs4servername_2_sid()|
  746. by default.
  747.  
  748. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  749. ---
  750. daemon/sid.c | 4 ++--
  751.  1 file changed, 2 insertions(+), 2 deletions(-)
  752.  
  753. diff --git a/daemon/sid.c b/daemon/sid.c
  754. index dcf4680..b7d0736 100644
  755. --- a/daemon/sid.c
  756. +++ b/daemon/sid.c
  757. @@ -557,7 +557,7 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  758.                  user_uid = map_uid;
  759.              }
  760.              else {
  761. -                DPRINTF(1,
  762. +                DPRINTF(0,
  763.                      ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  764.                      "nfs41_idmap_name_to_uid() failed\n",
  765.                      query, nfsname));
  766. @@ -575,7 +575,7 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  767.                  group_gid = map_gid;
  768.              }
  769.              else {
  770. -                DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
  771. +                DPRINTF(0, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
  772.                      query, nfsname));
  773.                  /* fixme: try harder here, "1234" should to to |atol()| */
  774.              }
  775. --
  776. 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