pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for skipping WinNULL/nobody ACEs in ACLs, debug improvements, cleanup+misc, 2024-07-02
Posted by Anonymous on Tue 2nd Jul 2024 16:05
raw | new post

  1. From 51ed2e7c47b6fd658a5f6368b9648ddd471f2749 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 1 Jul 2024 17:01:38 +0200
  4. Subject: [PATCH 1/5] daemon,nfs41_build_features.h: Skip ACEs with
  5.  SID==|WinNullSid|/user "nobody"
  6.  
  7. Cygwin generates artificial ACEs with SID user |WinNullSid| to encode
  8. permission information (follow |CYG_ACE_ISBITS_TO_POSIX()| in
  9. Cygwin newlib-cygwin/winsup/cygwin/sec/acl.cc
  10.  
  11. This assumes that the filesystem which stores the ACL data leaves
  12. them 1:1 intact - which is not the case for the Linux NFSv4.1
  13. server (tested with Linux 6.6.32), which transforms the NFSv4.1
  14. ACLs into POSIX ACLs at setacl time, and the POSIX ACLs back to
  15. NFSv4 ACLs at getacl time.
  16. And this lossy transformation screws-up Cygwin completly.
  17. The best we can do for now is to skip such ACEs, as we have no way
  18. to detect whether the NFS server supports full NFSv4 ACLs, or
  19. only POSIX ACLs disguised as NFSv4 ACLs.
  20.  
  21. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  22. ---
  23. daemon/acl.c           | 187 +++++++++++++++++++++++++++++------------
  24.  nfs41_build_features.h |  20 +++++
  25.  2 files changed, 153 insertions(+), 54 deletions(-)
  26.  
  27. diff --git a/daemon/acl.c b/daemon/acl.c
  28. index 331fc8e..937cb36 100644
  29. --- a/daemon/acl.c
  30. +++ b/daemon/acl.c
  31. @@ -117,7 +117,7 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  32.      bool named_attr_support)
  33.  {
  34.      int status = ERROR_NOT_SUPPORTED, size = 0;
  35. -    uint32_t i;
  36. +    uint32_t nfs_i = 0, win_i = 0;
  37.      DWORD sid_len;
  38.      PSID *sids;
  39.      PACL dacl;
  40. @@ -129,42 +129,71 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  41.          acl, map_nfs_ftype2str(file_type), file_type,
  42.          (int)named_attr_support));
  43.  
  44. -    sids = malloc(acl->count * sizeof(PSID));
  45. +    bool *skip_aces = _alloca(acl->count * sizeof(bool));
  46. +
  47. +    /*
  48. +     * We use |calloc()| here to get |NULL| pointer for unallocated
  49. +     * slots in case of error codepaths below...
  50. +     */
  51. +    sids = calloc(acl->count, sizeof(PSID));
  52.      if (sids == NULL) {
  53.          status = GetLastError();
  54.          goto out;
  55.      }
  56. -    for (i = 0; i < acl->count; i++) {
  57. -        convert_nfs4name_2_user_domain(acl->aces[i].who, &domain);
  58. +    for (nfs_i = win_i = 0; nfs_i < acl->count; nfs_i++) {
  59. +        nfsace4 *curr_nfsace = &acl->aces[nfs_i];
  60. +
  61. +        skip_aces[nfs_i] = false;
  62. +
  63. +        convert_nfs4name_2_user_domain(curr_nfsace->who, &domain);
  64.          DPRINTF(ACLLVL2, ("convert_nfs4acl_2_dacl: for user='%s' domain='%s'\n",
  65. -                acl->aces[i].who, domain?domain:"<null>"));
  66. -        status = check_4_special_identifiers(acl->aces[i].who, &sids[i],
  67. +                curr_nfsace->who, domain?domain:"<null>"));
  68. +
  69. +#ifdef NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES
  70. +        /*
  71. +         * Skip "nobody" ACEs - Cygwin uses |WinNullSid| ACEs (mapped
  72. +         * to NFS user "nobody") to store special data.
  73. +         * We skip these here, because we cannot use them, as Linux nfsd
  74. +         * only supports POSIX ACLs translated to NFSv4 ACLs, which
  75. +         * corrupts the Cygwin data.
  76. +         */
  77. +        if (!strcmp(curr_nfsace->who, ACE4_NOBODY)) {
  78. +            DPRINTF(ACLLVL3, ("Skipping 'nobody' ACE, "
  79. +                "win_i=%d nfs_i=%d\n", (int)win_i, (int)nfs_i));
  80. +            skip_aces[nfs_i] = true;
  81. +            continue;
  82. +        }
  83. +#endif /* NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES */
  84. +
  85. +        status = check_4_special_identifiers(curr_nfsace->who, &sids[win_i],
  86.                                               &sid_len, &flag);
  87.          if (status) {
  88. -            free_sids(sids, i);
  89. +            free_sids(sids, win_i);
  90.              goto out;
  91.          }
  92.          if (!flag) {
  93. -            bool isgroupacl = (acl->aces[i].aceflag & ACE4_IDENTIFIER_GROUP)?true:false;
  94. +            bool isgroupacl = (curr_nfsace->aceflag & ACE4_IDENTIFIER_GROUP)?true:false;
  95.  
  96.              if (isgroupacl) {
  97.                  DPRINTF(ACLLVL2,
  98.                      ("convert_nfs4acl_2_dacl: aces[%d].who='%s': "
  99.                      "Setting group flag\n",
  100. -                    i, acl->aces[i].who));
  101. +                    nfs_i, curr_nfsace->who));
  102.              }
  103.  
  104.              status = map_nfs4servername_2_sid(nfs41dg,
  105.                  (isgroupacl?GROUP_SECURITY_INFORMATION:OWNER_SECURITY_INFORMATION),
  106. -                &sid_len, &sids[i], acl->aces[i].who);
  107. +                &sid_len, &sids[win_i], curr_nfsace->who);
  108.              if (status) {
  109. -                free_sids(sids, i);
  110. +                free_sids(sids, win_i);
  111.                  goto out;
  112.              }
  113.          }
  114.          size += sid_len - sizeof(DWORD);
  115. +
  116. +        win_i++;
  117.      }
  118. -    size += sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE)*acl->count);
  119. +    size += sizeof(ACL) + (sizeof(ACCESS_ALLOWED_ACE)*win_i);
  120.      size = align8(size); // align size on |DWORD| boundry
  121.      dacl = malloc(size);
  122.      if (dacl == NULL)
  123. @@ -174,10 +203,15 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  124.          ACCESS_MASK mask;
  125.          DWORD win_aceflags;
  126.  
  127. -        for (i = 0; i < acl->count; i++) {
  128. -            map_nfs4aceflags2winaceflags(acl->aces[i].aceflag,
  129. +        for (nfs_i = win_i = 0; nfs_i < acl->count; nfs_i++) {
  130. +            nfsace4 *curr_nfsace = &acl->aces[nfs_i];
  131. +
  132. +            if (skip_aces[nfs_i])
  133. +                continue;
  134. +
  135. +            map_nfs4aceflags2winaceflags(curr_nfsace->aceflag,
  136.                  &win_aceflags);
  137. -            map_nfs4acemask2winaccessmask(acl->aces[i].acemask,
  138. +            map_nfs4acemask2winaccessmask(curr_nfsace->acemask,
  139.                  file_type, named_attr_support, &mask);
  140.  
  141.              if (DPRINTF_LEVEL_ENABLED(ACLLVL1)) {
  142. @@ -185,19 +219,20 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  143.                      "acetype='%s', "
  144.                      "nfs_acemask=0x%lx, win_mask=0x%lx, "
  145.                      "win_aceflags=0x%lx\n",
  146. -                    i, acl->aces[i].who,
  147. -                    map_nfs_acetype2str(acl->aces[i].acetype),
  148. -                    (long)acl->aces[i].acemask,
  149. +                    nfs_i, curr_nfsace->who,
  150. +                    map_nfs_acetype2str(curr_nfsace->acetype),
  151. +                    (long)curr_nfsace->acemask,
  152.                      (long)mask,
  153.                      (long)win_aceflags);
  154.  
  155. -                print_nfs_access_mask(acl->aces[i].who,
  156. -                    acl->aces[i].acemask);
  157. -                print_windows_access_mask(acl->aces[i].who, mask);
  158. +                print_nfs_access_mask(curr_nfsace->who,
  159. +                    curr_nfsace->acemask);
  160. +                print_windows_access_mask(curr_nfsace->who, mask);
  161.              }
  162.  
  163. -            if (acl->aces[i].acetype == ACE4_ACCESS_ALLOWED_ACE_TYPE) {
  164. -                status = AddAccessAllowedAceEx(dacl, ACL_REVISION, win_aceflags, mask, sids[i]);
  165. +            if (curr_nfsace->acetype == ACE4_ACCESS_ALLOWED_ACE_TYPE) {
  166. +                status = AddAccessAllowedAceEx(dacl, ACL_REVISION,
  167. +                    win_aceflags, mask, sids[win_i]);
  168.                  if (!status) {
  169.                      eprintf("convert_nfs4acl_2_dacl: "
  170.                          "AddAccessAllowedAceEx(dacl=0x%p,win_aceflags=0x%x,mask=0x%x) failed "
  171. @@ -206,8 +241,9 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  172.                      goto out_free_dacl;
  173.                  }
  174.                  else status = ERROR_SUCCESS;
  175. -            } else if (acl->aces[i].acetype == ACE4_ACCESS_DENIED_ACE_TYPE) {
  176. -                status = AddAccessDeniedAceEx(dacl, ACL_REVISION, win_aceflags, mask, sids[i]);
  177. +            } else if (curr_nfsace->acetype == ACE4_ACCESS_DENIED_ACE_TYPE) {
  178. +                status = AddAccessDeniedAceEx(dacl, ACL_REVISION,
  179. +                    win_aceflags, mask, sids[win_i]);
  180.                  if (!status) {
  181.                      eprintf("convert_nfs4acl_2_dacl: "
  182.                          "AddAccessDeniedAceEx(dacl=0x%p,win_aceflags=0x%x,mask=0x%x) failed "
  183. @@ -218,12 +254,14 @@ static int convert_nfs4acl_2_dacl(nfs41_daemon_globals *nfs41dg,
  184.                  else status = ERROR_SUCCESS;
  185.              } else {
  186.                  eprintf("convert_nfs4acl_2_dacl: unknown acetype %d\n",
  187. -                        acl->aces[i].acetype);
  188. +                        curr_nfsace->acetype);
  189.                  status = ERROR_INTERNAL_ERROR;
  190.                  free(dacl);
  191. -                free_sids(sids, acl->count);
  192. +                free_sids(sids, win_i);
  193.                  goto out;
  194.              }
  195. +
  196. +            win_i++;
  197.          }
  198.      } else {
  199.          eprintf("convert_nfs4acl_2_dacl: InitializeAcl failed with %d\n", status);
  200. @@ -240,7 +278,7 @@ out:
  201.  out_free_dacl:
  202.      free(dacl);
  203.  out_free_sids:
  204. -    free_sids(sids, acl->count);
  205. +    free_sids(sids, win_i);
  206.      status = GetLastError();
  207.      goto out;
  208.  }
  209. @@ -1026,7 +1064,7 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  210.          }
  211.          nfs4_acl->aces->aceflag = 0;
  212.      } else {
  213. -        int i;
  214. +        int win_i, nfs_i;
  215.          PACE_HEADER ace;
  216.          PBYTE tmp_pointer;
  217.          SID_NAME_USE who_sid_type = 0;
  218. @@ -1037,15 +1075,18 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  219.              print_hexbuf_no_asci("ACL\n",
  220.                  (const unsigned char *)acl, acl->AclSize);
  221.          }
  222. -        nfs4_acl->count = acl->AceCount;
  223. -        nfs4_acl->aces = calloc(nfs4_acl->count, sizeof(nfsace4));
  224. +
  225. +        nfs4_acl->aces = calloc(acl->AceCount, sizeof(nfsace4));
  226.          if (nfs4_acl->aces == NULL) {
  227.              status = GetLastError();
  228.              goto out;
  229.          }
  230.          nfs4_acl->flag = 0;
  231. -        for (i = 0; i < acl->AceCount; i++) {
  232. -            status = GetAce(acl, i, &ace);
  233. +        for (win_i = nfs_i = 0; win_i < acl->AceCount; win_i++) {
  234. +            nfsace4 *curr_nfsace = &nfs4_acl->aces[nfs_i];
  235. +            PSID ace_sid;
  236. +
  237. +            status = GetAce(acl, win_i, &ace);
  238.              if (!status) {
  239.                  status = GetLastError();
  240.                  eprintf("map_dacl_2_nfs4acl: GetAce failed with %d\n", status);
  241. @@ -1058,9 +1099,9 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  242.              }
  243.              DPRINTF(ACLLVL3, ("ACE TYPE: %x\n", ace->AceType));
  244.              if (ace->AceType == ACCESS_ALLOWED_ACE_TYPE)
  245. -                nfs4_acl->aces[i].acetype = ACE4_ACCESS_ALLOWED_ACE_TYPE;
  246. +                curr_nfsace->acetype = ACE4_ACCESS_ALLOWED_ACE_TYPE;
  247.              else if (ace->AceType == ACCESS_DENIED_ACE_TYPE)
  248. -                nfs4_acl->aces[i].acetype = ACE4_ACCESS_DENIED_ACE_TYPE;
  249. +                curr_nfsace->acetype = ACE4_ACCESS_DENIED_ACE_TYPE;
  250.              else {
  251.                  eprintf("map_dacl_2_nfs4acl: unsupported ACE type %d\n",
  252.                      ace->AceType);
  253. @@ -1069,8 +1110,40 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  254.              }
  255.  
  256.              tmp_pointer += sizeof(ACCESS_MASK) + sizeof(ACE_HEADER);
  257. +            ace_sid = tmp_pointer;
  258. +
  259. +#ifdef NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES
  260. +            if (IsWellKnownSid(ace_sid, WinNullSid)) {
  261. +                /*
  262. +                 * Skip ACEs with SID==|WinNullSid|
  263. +                 *
  264. +                 * Cygwin generates artificial ACEs with SID user
  265. +                 * |WinNullSid| to encode permission information
  266. +                 * (see |CYG_ACE_ISBITS_TO_POSIX()| in
  267. +                 * Cygwin newlib-cygwin/winsup/cygwin/sec/acl.cc
  268. +                 *
  269. +                 * This assumes that the filesystem which stores
  270. +                 * the ACL data leaves them 1:1 intact - which is
  271. +                 * not the case for the Linux NFSv4.1 server
  272. +                 * (tested with Linux 6.6.32), which transforms the
  273. +                 * NFSv4.1 ACLs into POSIX ACLs at setacl time,
  274. +                 * and the POSIX ACLs back to NFSv4 ACLs at getacl
  275. +                 * time.
  276. +                 * And this lossy transformation screws-up Cygwin
  277. +                 * completly.
  278. +                 * The best we can do for now is to skip such
  279. +                 * ACEs, as we have no way to detect whether
  280. +                 * the NFS server supports full NFSv4 ACLs, or
  281. +                 * only POSIX ACLs disguised as NFSv4 ACLs.
  282. +                 */
  283. +                DPRINTF(ACLLVL3, ("Skipping WinNullSid ACE, "
  284. +                    "win_i=%d nfs_i=%d\n", (int)win_i, (int)nfs_i));
  285. +                continue;
  286. +            }
  287. +#endif /* NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES */
  288.  
  289. -            status = map_nfs4ace_who(tmp_pointer, sid, gsid, nfs4_acl->aces[i].who,
  290. +            status = map_nfs4ace_who(ace_sid, sid, gsid,
  291. +                curr_nfsace->who,
  292.                                       domain, &who_sid_type);
  293.              if (status)
  294.                  goto out_free;
  295. @@ -1078,10 +1151,10 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  296.              win_mask = *(PACCESS_MASK)(ace + 1);
  297.  
  298.              map_winace2nfs4aceflags(ace->AceFlags,
  299. -                &nfs4_acl->aces[i].aceflag);
  300. +                &curr_nfsace->aceflag);
  301.              map_winaccessmask2nfs4acemask(win_mask,
  302.                  file_type, named_attr_support,
  303. -                &nfs4_acl->aces[i].acemask);
  304. +                &curr_nfsace->acemask);
  305.  
  306.              /*
  307.               * Clear |ACE4_INHERITED_ACE|
  308. @@ -1104,8 +1177,8 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  309.               * icacls(1win) if the parent directory has inheritance
  310.               * ACLs.
  311.               */
  312. -            if (nfs4_acl->aces[i].aceflag & ACE4_INHERITED_ACE) {
  313. -                nfs4_acl->aces[i].aceflag &= ~ACE4_INHERITED_ACE;
  314. +            if (curr_nfsace->aceflag & ACE4_INHERITED_ACE) {
  315. +                curr_nfsace->aceflag &= ~ACE4_INHERITED_ACE;
  316.                  DPRINTF(ACLLVL3, ("clearning ACE4_INHERITED_ACE\n"));
  317.              }
  318.  
  319. @@ -1125,8 +1198,8 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  320.                      "aces[%d].who='%s': "
  321.                      "setting group flag\n",
  322.                      map_SID_NAME_USE2str(who_sid_type),
  323. -                    i, nfs4_acl->aces[i].who));
  324. -                nfs4_acl->aces[i].aceflag |= ACE4_IDENTIFIER_GROUP;
  325. +                    nfs_i, curr_nfsace->who));
  326. +                curr_nfsace->aceflag |= ACE4_IDENTIFIER_GROUP;
  327.              }
  328.  
  329.              if (DPRINTF_LEVEL_ENABLED(ACLLVL1)) {
  330. @@ -1134,24 +1207,30 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  331.                      "acetype='%s', "
  332.                      "aceflag='%s'/0x%lx, "
  333.                      "acemask='%s'/0x%lx(=win_mask=0x%lx)), "
  334. -                    "who_sid_type='%s'\n",
  335. -                    i,
  336. -                    nfs4_acl->aces[i].who,
  337. -                    map_nfs_acetype2str(nfs4_acl->aces[i].acetype),
  338. -                    nfs_aceflag2shortname(nfs4_acl->aces[i].aceflag),
  339. -                    nfs4_acl->aces[i].aceflag,
  340. -                    nfs_mask2shortname(nfs4_acl->aces[i].acemask),
  341. -                    (long)nfs4_acl->aces[i].acemask,
  342. +                    "who_sid_type='%s', "
  343. +                    "win_i=%d\n",
  344. +                    nfs_i,
  345. +                    curr_nfsace->who,
  346. +                    map_nfs_acetype2str(curr_nfsace->acetype),
  347. +                    nfs_aceflag2shortname(curr_nfsace->aceflag),
  348. +                    curr_nfsace->aceflag,
  349. +                    nfs_mask2shortname(curr_nfsace->acemask),
  350. +                    (long)curr_nfsace->acemask,
  351.                      (long)win_mask,
  352. -                    map_SID_NAME_USE2str(who_sid_type));
  353. +                    map_SID_NAME_USE2str(who_sid_type),
  354. +                    (int)win_i);
  355.                  if (DPRINTF_LEVEL_ENABLED(ACLLVL2)) {
  356. -                    print_windows_access_mask(nfs4_acl->aces[i].who,
  357. +                    print_windows_access_mask(curr_nfsace->who,
  358.                          win_mask);
  359. -                    print_nfs_access_mask(nfs4_acl->aces[i].who,
  360. -                        nfs4_acl->aces[i].acemask);
  361. +                    print_nfs_access_mask(curr_nfsace->who,
  362. +                        curr_nfsace->acemask);
  363.                  }
  364.              }
  365. +
  366. +            nfs_i++;
  367.          }
  368. +
  369. +        nfs4_acl->count = nfs_i;
  370.      }
  371.      status = ERROR_SUCCESS;
  372.  out:
  373. diff --git a/nfs41_build_features.h b/nfs41_build_features.h
  374. index 0fb2882..37c5995 100644
  375. --- a/nfs41_build_features.h
  376. +++ b/nfs41_build_features.h
  377. @@ -133,4 +133,24 @@
  378.   */
  379.  #define NFS41_DRIVER_DEBUG_FS_NAME 1
  380.  
  381. +/*
  382. + * NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES - Skip ACEs
  383. + * with SID==|WinNullSid|
  384. + *
  385. + * Cygwin generates artificial ACEs with SID user |WinNullSid| to
  386. + * encode permission information (follow |CYG_ACE_ISBITS_TO_POSIX()|
  387. + * in Cygwin newlib-cygwin/winsup/cygwin/sec/acl.cc
  388. + *
  389. + * This assumes that the filesystem which storesthe ACL data leaves
  390. + * them 1:1 intact - which is not the case for the Linux NFSv4.1
  391. + * server (tested with Linux 6.6.32), which transforms the NFSv4.1
  392. + * ACLs into POSIX ACLs at setacl time, and the POSIX ACLs back to
  393. + * NFSv4 ACLs at getacl time.
  394. + * And this lossy transformation screws-up Cygwin completly.
  395. + * The best we can do for now is to skip such ACEs, as we have no
  396. + * way to detect whether the NFS server supports full NFSv4 ACLs,
  397. + * or only POSIX ACLs disguised as NFSv4 ACLs.
  398. + */
  399. +#define NFS41_DRIVER_ACLS_SETACL_SKIP_WINNULLSID_ACES 1
  400. +
  401.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  402. --
  403. 2.45.1
  404.  
  405. From 4bba02ccd7b34d8ea12cb6874072de91470e6154 Mon Sep 17 00:00:00 2001
  406. From: Roland Mainz <roland.mainz@nrubsig.org>
  407. Date: Mon, 1 Jul 2024 17:05:55 +0200
  408. Subject: [PATCH 2/5] daemon: Add assert |(table->highest_used <
  409.  NFS41_MAX_NUM_SLOTS)|
  410.  
  411. Add assert |(table->highest_used < NFS41_MAX_NUM_SLOTS)| to monitor
  412. this code. It looks OK, but static code analysis tools keep
  413. complaining.
  414.  
  415. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  416. ---
  417. daemon/nfs41_session.c | 3 +++
  418.  1 file changed, 3 insertions(+)
  419.  
  420. diff --git a/daemon/nfs41_session.c b/daemon/nfs41_session.c
  421. index 98a2ccb..92741e7 100644
  422. --- a/daemon/nfs41_session.c
  423. +++ b/daemon/nfs41_session.c
  424. @@ -117,6 +117,9 @@ void nfs41_session_free_slot(
  425.      }
  426.      /* update highest_used if necessary */
  427.      if (slotid == table->highest_used) {
  428. +        EASSERT_MSG((table->highest_used < NFS41_MAX_NUM_SLOTS),
  429. +            ("table->highest_used=%lu\n",
  430. +            (unsigned long)table->highest_used));
  431.          while (table->highest_used && !table->used_slots[table->highest_used])
  432.              table->highest_used--;
  433.      }
  434. --
  435. 2.45.1
  436.  
  437. From d2560f91f59c4d4b7ad8e66487e8da4ec98f4f28 Mon Sep 17 00:00:00 2001
  438. From: Roland Mainz <roland.mainz@nrubsig.org>
  439. Date: Mon, 1 Jul 2024 17:23:27 +0200
  440. Subject: [PATCH 3/5] daemon,sys: Debug: Always print login_id |LUID| as
  441.  HighPart.LowPart
  442.  
  443. Debug: Always print login_id |LUID| as HighPart.LowPart
  444.  
  445. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  446. ---
  447. daemon/mount.c        | 14 +++++++-------
  448.  daemon/nfs41_client.c | 10 +++++-----
  449.  sys/nfs41_driver.c    | 33 +++++++++++++++++++++++++--------
  450.  3 files changed, 37 insertions(+), 20 deletions(-)
  451.  
  452. diff --git a/daemon/mount.c b/daemon/mount.c
  453. index 10f0791..cc9053b 100644
  454. --- a/daemon/mount.c
  455. +++ b/daemon/mount.c
  456. @@ -84,11 +84,11 @@ static int handle_mount(void *daemon_context, nfs41_upcall *upcall)
  457.          &authenticationid);
  458.  
  459.      logprintf("mount(hostport='%s', path='%s', "
  460. -        "authid=(0x%x.0x%lx)) request\n",
  461. +        "authid=(0x%lx.0x%lx)) request\n",
  462.          args->hostport?args->hostport:"<NULL>",
  463.          args->path?args->path:"<NULL>",
  464. -        (int)authenticationid.LowPart,
  465. -        (long)authenticationid.HighPart);
  466. +        (long)authenticationid.HighPart,
  467. +        (long)authenticationid.LowPart);
  468.  #else
  469.      logprintf("mount(hostport='%s', path='%s') request\n",
  470.          args->hostport?args->hostport:"<NULL>",
  471. @@ -188,11 +188,11 @@ out:
  472.      if (status == 0) {
  473.  #ifdef NFS41_DRIVER_USE_AUTHENTICATIONID_FOR_MOUNT_NAMESPACE
  474.          logprintf("mount(hostport='%s', path='%s', "
  475. -            "authid=(0x%x.0x%lx)) success, root=0x%p\n",
  476. +            "authid=(0x%lx.0x%lx)) success, root=0x%p\n",
  477.              args->hostport?args->hostport:"<NULL>",
  478.              args->path?args->path:"<NULL>",
  479. -            (int)authenticationid.LowPart,
  480.              (long)authenticationid.HighPart,
  481. +            (long)authenticationid.LowPart,
  482.              root);
  483.  #else
  484.          logprintf("mount(hostport='%s', path='%s') success, root=0x%p\n",
  485. @@ -204,11 +204,11 @@ out:
  486.      else {
  487.  #ifdef NFS41_DRIVER_USE_AUTHENTICATIONID_FOR_MOUNT_NAMESPACE
  488.          logprintf("mount(hostport='%s', path='%s', "
  489. -            "authid=(0x%x.0x%lx))) failed, status=%d\n",
  490. +            "authid=(0x%lx.0x%lx))) failed, status=%d\n",
  491.              args->hostport?args->hostport:"<NULL>",
  492.              args->path?args->path:"<NULL>",
  493. -            (int)authenticationid.LowPart,
  494.              (long)authenticationid.HighPart,
  495. +            (long)authenticationid.LowPart,
  496.              (int)status);
  497.  #else
  498.          logprintf("mount(hostport='%s', path='%s') failed, status=%d\n",
  499. diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
  500. index b265c71..847aa0c 100644
  501. --- a/daemon/nfs41_client.c
  502. +++ b/daemon/nfs41_client.c
  503. @@ -398,10 +398,10 @@ int nfs41_client_owner(
  504.      }
  505.  
  506.      DPRINTF(1, ("nfs41_client_owner: "
  507. -        "username='%s' authid=(0x%x.0x%lx)\n",
  508. +        "username='%s' authid=(0x%lx.0x%lx)\n",
  509.          username,
  510. -        (int)authenticationid.LowPart,
  511. -        (long)authenticationid.HighPart));
  512. +        (long)authenticationid.HighPart,
  513. +        (long)authenticationid.LowPart));
  514.  #endif /* NFS41_DRIVER_USE_AUTHENTICATIONID_FOR_MOUNT_NAMESPACE */
  515.  
  516.      /* owner.verifier = "time created" */
  517. @@ -443,13 +443,13 @@ int nfs41_client_owner(
  518.       * |LUID| may have (hidden) padding fields, so we hash each
  519.       * member seperately
  520.       */
  521. -    if (!CryptHashData(hash, (const BYTE*)&authenticationid.LowPart, (DWORD)sizeof(DWORD), 0)) {
  522. +    if (!CryptHashData(hash, (const BYTE*)&authenticationid.HighPart, (DWORD)sizeof(LONG), 0)) {
  523.          status = GetLastError();
  524.          eprintf("CryptHashData() failed with %d\n", status);
  525.          goto out_hash;
  526.      }
  527.  
  528. -    if (!CryptHashData(hash, (const BYTE*)&authenticationid.HighPart, (DWORD)sizeof(LONG), 0)) {
  529. +    if (!CryptHashData(hash, (const BYTE*)&authenticationid.LowPart, (DWORD)sizeof(DWORD), 0)) {
  530.          status = GetLastError();
  531.          eprintf("CryptHashData() failed with %d\n", status);
  532.          goto out_hash;
  533. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  534. index 327f2ac..bddbe30 100644
  535. --- a/sys/nfs41_driver.c
  536. +++ b/sys/nfs41_driver.c
  537. @@ -61,7 +61,7 @@
  538.  //#define DEBUG_LOCK
  539.  #define DEBUG_FSCTL
  540.  #define DEBUG_TIME_BASED_COHERENCY
  541. -//#define DEBUG_MOUNT
  542. +#define DEBUG_MOUNT
  543.  //#define DEBUG_VOLUME_QUERY
  544.  
  545.  //#define ENABLE_TIMINGS
  546. @@ -3337,6 +3337,11 @@ NTSTATUS nfs41_CreateVNetRoot(
  547.          if (status)
  548.              goto out_free;
  549.  
  550. +#ifdef DEBUG_MOUNT
  551. +        DbgP("UNC path LUID 0x%lx.0x%lx\n",
  552. +            (long)luid.HighPart, (long)luid.LowPart);
  553. +#endif
  554. +
  555.          PLIST_ENTRY pEntry;
  556.  
  557.          status = STATUS_NFS_SHARE_NOT_MOUNTED;
  558. @@ -3348,10 +3353,21 @@ NTSTATUS nfs41_CreateVNetRoot(
  559.              existing_mount = (nfs41_mount_entry *)CONTAINING_RECORD(pEntry,
  560.                      nfs41_mount_entry, next);
  561.  
  562. +#ifdef DEBUG_MOUNT
  563. +            DbgP("finding mount config: "
  564. +                "comparing luid=(0x%lx.0x%lx) with "
  565. +                "existing_mount->login_id=(0x%lx.0x%lx)\n",
  566. +                (long)luid.HighPart, (long)luid.LowPart,
  567. +                (long)existing_mount->login_id.HighPart,
  568. +                (long)existing_mount->login_id.LowPart);
  569. +#endif
  570. +
  571.              if (RtlEqualLuid(&luid, &existing_mount->login_id)) {
  572.                  /* found existing mount */
  573.                  copy_nfs41_mount_config(Config, &existing_mount->Config);
  574. -                DbgP("Found existing mount: Entry Config->MntPt='%wZ'\n",
  575. +                DbgP("Found existing mount: LUID=(0x%lx.0x%lx) Entry Config->MntPt='%wZ'\n",
  576. +                    (long)existing_mount->login_id.HighPart,
  577. +                    (long)existing_mount->login_id.LowPart,
  578.                      &Config->MntPt);
  579.                  status = STATUS_SUCCESS;
  580.                  break;
  581. @@ -3426,10 +3442,10 @@ NTSTATUS nfs41_CreateVNetRoot(
  582.              existing_mount = (nfs41_mount_entry *)CONTAINING_RECORD(pEntry,
  583.                      nfs41_mount_entry, next);
  584.  #ifdef DEBUG_MOUNT
  585. -            DbgP("comparing 0x%x.0x%x with 0x%x.0x%x\n",
  586. -                luid.HighPart, luid.LowPart,
  587. -                existing_mount->login_id.HighPart,
  588. -                existing_mount->login_id.LowPart);
  589. +            DbgP("comparing 0x%lx.0x%lx with 0x%lx.0x%lx\n",
  590. +                (long)luid.HighPart, (long)luid.LowPart,
  591. +                (long)existing_mount->login_id.HighPart,
  592. +                (long)existing_mount->login_id.LowPart);
  593.  #endif
  594.              if (RtlEqualLuid(&luid, &existing_mount->login_id)) {
  595.  #ifdef DEBUG_MOUNT
  596. @@ -3654,8 +3670,9 @@ NTSTATUS nfs41_FinalizeNetRoot(
  597.          if (mount_tmp == NULL)
  598.              break;
  599.  #ifdef DEBUG_MOUNT
  600. -        DbgP("Removing entry luid 0x%x.0x%x from mount list\n",
  601. -            mount_tmp->login_id.HighPart, mount_tmp->login_id.LowPart);
  602. +        DbgP("Removing entry luid 0x%lx.0x%lx from mount list\n",
  603. +            (long)mount_tmp->login_id.HighPart,
  604. +            (long)mount_tmp->login_id.LowPart);
  605.  #endif
  606.          if (mount_tmp->authsys_session != INVALID_HANDLE_VALUE) {
  607.              status = nfs41_unmount(mount_tmp->authsys_session,
  608. --
  609. 2.45.1
  610.  
  611. From ce8ae3b576c126c6d8f21e8c7169cd0cc66d6cae Mon Sep 17 00:00:00 2001
  612. From: Roland Mainz <roland.mainz@nrubsig.org>
  613. Date: Tue, 2 Jul 2024 11:25:06 +0200
  614. Subject: [PATCH 4/5] sys: Fix experimental |USE_ENTIRE_PATH| codepath+rename
  615.  to |USE_ENTIRE_PATH_FOR_NETROOT|
  616.  
  617. Fix experimental |USE_ENTIRE_PATH| codepath+rename it to
  618. |USE_ENTIRE_PATH_FOR_NETROOT|. Off by default, as it does not work
  619. properly yet, any mount ends-up in the NFS root dir, and the path to
  620. the mount target is ignored.
  621.  
  622. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  623. ---
  624. sys/nfs41_driver.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
  625.  1 file changed, 42 insertions(+), 2 deletions(-)
  626.  
  627. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  628. index bddbe30..cf6207f 100644
  629. --- a/sys/nfs41_driver.c
  630. +++ b/sys/nfs41_driver.c
  631. @@ -40,6 +40,7 @@
  632.  #include "nfs41_debug.h"
  633.  #include "nfs41_build_features.h"
  634.  
  635. +// #define USE_ENTIRE_PATH_FOR_NETROOT 1
  636.  
  637.  /* debugging printout defines */
  638.  #define DEBUG_MARSHAL_HEADER
  639. @@ -3110,6 +3111,42 @@ NTSTATUS has_nfs_prefix(
  640.  {
  641.      NTSTATUS status = STATUS_BAD_NETWORK_NAME;
  642.  
  643. +#ifdef USE_ENTIRE_PATH_FOR_NETROOT
  644. +    if (NetRootName->Length >=
  645. +        (SrvCallName->Length + NfsPrefix.Length)) {
  646. +        size_t len = NetRootName->Length / 2;
  647. +        size_t i;
  648. +        int state = 0;
  649. +
  650. +        /* Scan \hostname@port\nfs4 */
  651. +        for (i = 0 ; i < len ; i++) {
  652. +            wchar_t ch = NetRootName->Buffer[i];
  653. +
  654. +            if ((ch == L'\\') && (state == 0)) {
  655. +                state = 1;
  656. +                continue;
  657. +            }
  658. +            else if ((ch == L'@') && (state == 1)) {
  659. +                state = 2;
  660. +                continue;
  661. +            }
  662. +            else if ((ch == L'\\') && (state == 2)) {
  663. +                state = 3;
  664. +                break;
  665. +            }
  666. +            else if (ch == L'\\') {
  667. +                /* Abort, '\\' with wrong state */
  668. +                break;
  669. +            }
  670. +        }
  671. +
  672. +        if ((state == 3) &&
  673. +            (!memcmp(&NetRootName->Buffer[i], L"\\nfs4",
  674. +                (4*sizeof(wchar_t))))) {
  675. +            status = STATUS_SUCCESS;
  676. +        }
  677. +    }
  678. +#else
  679.      if (NetRootName->Length == SrvCallName->Length + NfsPrefix.Length) {
  680.          const UNICODE_STRING NetRootPrefix = {
  681.              NfsPrefix.Length,
  682. @@ -3119,6 +3156,7 @@ NTSTATUS has_nfs_prefix(
  683.          if (RtlCompareUnicodeString(&NetRootPrefix, &NfsPrefix, FALSE) == 0)
  684.              status = STATUS_SUCCESS;
  685.      }
  686. +#endif
  687.      return status;
  688.  }
  689.  
  690. @@ -3585,7 +3623,7 @@ VOID nfs41_ExtractNetRootName(
  691.      w += (SrvCall->pSrvCallName->Length/sizeof(WCHAR));
  692.      NetRootName->Buffer = wlow = w;
  693.      /* parse the entire path into NetRootName */
  694. -#if USE_ENTIRE_PATH
  695. +#if USE_ENTIRE_PATH_FOR_NETROOT
  696.      w = wlimit;
  697.  #else
  698.      for (;;) {
  699. @@ -3599,7 +3637,9 @@ VOID nfs41_ExtractNetRootName(
  700.      NetRootName->Length = NetRootName->MaximumLength
  701.                  = (USHORT)((PCHAR)w - (PCHAR)wlow);
  702.  #ifdef DEBUG_MOUNT
  703. -    DbgP("In: pSrvCall 0x%p PathName='%wZ' SrvCallName='%wZ' Out: NetRootName='%wZ'\n",
  704. +    DbgP("nfs41_ExtractNetRootName: "
  705. +        "In: pSrvCall 0x%p PathName='%wZ' SrvCallName='%wZ' "
  706. +        "Out: NetRootName='%wZ'\n",
  707.          SrvCall, FilePathName, SrvCall->pSrvCallName, NetRootName);
  708.  #endif
  709.      return;
  710. --
  711. 2.45.1
  712.  
  713. From 6f4b62c83705a63b06079365bddd214829be40e8 Mon Sep 17 00:00:00 2001
  714. From: Roland Mainz <roland.mainz@nrubsig.org>
  715. Date: Tue, 2 Jul 2024 11:50:01 +0200
  716. Subject: [PATCH 5/5] cygwin: make clean does not clean nfs_ea.exe
  717.  
  718. make clean should execute the "clean" target in the tests/ea/
  719. subdir too.
  720.  
  721. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  722. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  723. ---
  724. cygwin/Makefile | 1 +
  725.  1 file changed, 1 insertion(+)
  726.  
  727. diff --git a/cygwin/Makefile b/cygwin/Makefile
  728. index a814d3f..15d5336 100644
  729. --- a/cygwin/Makefile
  730. +++ b/cygwin/Makefile
  731. @@ -66,6 +66,7 @@ build: build_32bit_release build_32bit_debug build_64bit_release build_64bit_deb
  732.  #
  733.  clean:
  734.         rm -vRf $$(find "$(PROJECT_BASEDIR_DIR)/build.vc19" -name Debug -o -name Release)
  735. +       (cd "$(PROJECT_BASEDIR_DIR)/tests/ea" && make clean)
  736.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make clean)
  737.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winsg" && make clean)
  738.  
  739. --
  740. 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