pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for cp -p/mv/chown/chgrp error code propagation, nfs_mount.exe printing nfs://-URLs + misc, 2024-02-12
Posted by Anonymous on Mon 12th Feb 2024 15:50
raw | new post

  1. From 7a23c6a197ea15d5411a31bda7b127e5ae608edb Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 12 Feb 2024 08:05:06 +0100
  4. Subject: [PATCH 1/5] daemon, sys: Propagate |ERROR_NONE_MAPPED| correctly and
  5.  add more ACL debug output
  6.  
  7. Propagate SETACL |ERROR_NONE_MAPPED| correctly and add more debug output
  8. to ACL codepath.
  9.  
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. daemon/acl.c       | 81 +++++++++++++++++++++++++++++-----------------
  13.  sys/nfs41_driver.c |  1 +
  14.  2 files changed, 52 insertions(+), 30 deletions(-)
  15.  
  16. diff --git a/daemon/acl.c b/daemon/acl.c
  17. index 67ceb1a..499085e 100644
  18. --- a/daemon/acl.c
  19. +++ b/daemon/acl.c
  20. @@ -459,12 +459,14 @@ static void map_acemask(ACCESS_MASK mask, int file_type, uint32_t *nfs4_mask)
  21.  
  22.  static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_out, char *domain)
  23.  {
  24. -    int status = ERROR_INTERNAL_ERROR;
  25. +    int status;
  26.      DWORD size = 0, tmp_size = 0;
  27.      SID_NAME_USE sid_type;
  28.      LPSTR tmp_buf = NULL, who = NULL;
  29.      LPSTR sidstr = NULL;
  30.  
  31. +    DPRINTF(ACLLVL, ("--> map_nfs4ace_who(sid=0x%p,owner_sid=0x%p, group_sid=0x%p)\n"));
  32. +
  33.      /* for ace mapping, we want to map owner's sid into "owner@"
  34.       * but for set_owner attribute we want to map owner into a user name
  35.       * same applies to group
  36. @@ -474,14 +476,16 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  37.          if (EqualSid(sid, owner_sid)) {
  38.              DPRINTF(ACLLVL, ("map_nfs4ace_who: this is owner's sid\n"));
  39.              memcpy(who_out, ACE4_OWNER, strlen(ACE4_OWNER)+1);
  40. -            return ERROR_SUCCESS;
  41. +            status = ERROR_SUCCESS;
  42. +            goto out;
  43.          }
  44.      }
  45.      if (group_sid) {
  46.          if (EqualSid(sid, group_sid)) {
  47.              DPRINTF(ACLLVL, ("map_nfs4ace_who: this is group's sid\n"));
  48.              memcpy(who_out, ACE4_GROUP, strlen(ACE4_GROUP)+1);
  49. -            return ERROR_SUCCESS;
  50. +            status = ERROR_SUCCESS;
  51. +            goto out;
  52.          }
  53.      }
  54.      status = is_well_known_sid(sid, who_out);
  55. @@ -490,8 +494,9 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  56.              size = (DWORD)strlen(ACE4_NOBODY);
  57.              goto add_domain;
  58.          }
  59. -        else
  60. -            return ERROR_SUCCESS;
  61. +
  62. +        status = ERROR_SUCCESS;
  63. +        goto out;
  64.      }
  65.  
  66.      if (!ConvertSidToStringSidA(sid, &sidstr)) {
  67. @@ -533,8 +538,18 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  68.      }
  69.  
  70.      status = GetLastError();
  71. -    if (status != ERROR_INSUFFICIENT_BUFFER)
  72. -        return ERROR_INTERNAL_ERROR;
  73. +    if (status == ERROR_NONE_MAPPED) {
  74. +        DPRINTF(1, ("LookupAccountSidA() returned success, "
  75. +            "GetLastError() returned ERROR_NONE_MAPPED\n"));
  76. +        goto out;
  77. +    }
  78. +
  79. +    if (status != ERROR_INSUFFICIENT_BUFFER) {
  80. +        DPRINTF(1, ("LookupAccountSidA() returned success, "
  81. +            "GetLastError() returned %d\n", status));
  82. +        status = ERROR_INTERNAL_ERROR;
  83. +        goto out;
  84. +    }
  85.      who = malloc(size);
  86.      if (who == NULL) {
  87.          status = GetLastError();
  88. @@ -559,6 +574,7 @@ add_domain:
  89.      if (who) free(who);
  90.      status = ERROR_SUCCESS;
  91.  out:
  92. +    DPRINTF(ACLLVL, ("<-- map_nfs4ace_who() returns %d\n", status));
  93.      if (sidstr)
  94.          LocalFree(sidstr);
  95.      return status;
  96. @@ -654,44 +670,49 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  97.      nfsacl41 nfs4_acl = { 0 };
  98.      PSID sid = NULL, gsid = NULL;
  99.      BOOL sid_default, gsid_default;
  100. +    char ownerbuf[NFS4_OPAQUE_LIMIT+1];
  101. +    char groupbuf[NFS4_OPAQUE_LIMIT+1];
  102. +
  103. +    DPRINTF(ACLLVL, ("--> handle_setacl()\n"));
  104.  
  105.      if (args->query & OWNER_SECURITY_INFORMATION) {
  106. -        char owner[NFS4_OPAQUE_LIMIT];
  107.          DPRINTF(ACLLVL, ("handle_setacl: OWNER_SECURITY_INFORMATION\n"));
  108.          status = GetSecurityDescriptorOwner(args->sec_desc, &sid, &sid_default);
  109.          if (!status) {
  110.              status = GetLastError();
  111. -            eprintf("GetSecurityDescriptorOwner failed with %d\n", status);
  112. +            eprintf("handle_setacl: GetSecurityDescriptorOwner failed with %d\n", status);
  113.              goto out;
  114.          }
  115. -        info.owner = owner;
  116. -        status = map_nfs4ace_who(sid, NULL, NULL, info.owner, nfs41dg->localdomain_name);
  117. +
  118. +        status = map_nfs4ace_who(sid, NULL, NULL, ownerbuf,
  119. +            nfs41dg->localdomain_name);
  120.          if (status)
  121.              goto out;
  122. -        else {
  123. -            info.attrmask.arr[1] |= FATTR4_WORD1_OWNER;
  124. -            info.attrmask.count = 2;
  125. -        }
  126. +
  127. +        info.owner = ownerbuf;
  128. +        info.attrmask.arr[1] |= FATTR4_WORD1_OWNER;
  129. +        info.attrmask.count = 2;
  130.      }
  131. +
  132.      if (args->query & GROUP_SECURITY_INFORMATION) {
  133. -        char group[NFS4_OPAQUE_LIMIT];
  134.          DPRINTF(ACLLVL, ("handle_setacl: GROUP_SECURITY_INFORMATION\n"));
  135.          status = GetSecurityDescriptorGroup(args->sec_desc, &sid, &sid_default);
  136.          if (!status) {
  137.              status = GetLastError();
  138. -            eprintf("GetSecurityDescriptorOwner failed with %d\n", status);
  139. +            eprintf("handle_setacl: GetSecurityDescriptorOwner failed with %d\n", status);
  140.              goto out;
  141.          }
  142. -        info.owner_group = group;
  143. -        status = map_nfs4ace_who(sid, NULL, NULL, info.owner_group,
  144. -                                 nfs41dg->localdomain_name);
  145. +
  146. +        status = map_nfs4ace_who(sid, NULL, NULL, groupbuf,
  147. +            nfs41dg->localdomain_name);
  148.          if (status)
  149.              goto out;
  150. -        else {
  151. -            info.attrmask.arr[1] |= FATTR4_WORD1_OWNER_GROUP;
  152. -            info.attrmask.count = 2;
  153. -        }
  154. +
  155. +        info.owner_group = groupbuf;
  156. +        info.attrmask.arr[1] |= FATTR4_WORD1_OWNER_GROUP;
  157. +        info.attrmask.count = 2;
  158.      }
  159. +
  160.      if (args->query & DACL_SECURITY_INFORMATION) {
  161.          BOOL dacl_present, dacl_default;
  162.          PACL acl;
  163. @@ -719,12 +740,11 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  164.                                      nfs41dg->localdomain_name);
  165.          if (status)
  166.              goto out;
  167. -        else {
  168. -            info.acl = &nfs4_acl;
  169. -            info.attrmask.arr[0] |= FATTR4_WORD0_ACL;
  170. -            if (!info.attrmask.count)
  171. -                info.attrmask.count = 1;
  172. -        }
  173. +
  174. +        info.acl = &nfs4_acl;
  175. +        info.attrmask.arr[0] |= FATTR4_WORD0_ACL;
  176. +        if (!info.attrmask.count)
  177. +            info.attrmask.count = 1;
  178.      }
  179.  
  180.      /* break read delegations before SETATTR */
  181. @@ -742,6 +762,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  182.      if (args->query & DACL_SECURITY_INFORMATION)
  183.          free(nfs4_acl.aces);
  184.  out:
  185. +    DPRINTF(ACLLVL, ("<-- handle_setacl() returning %d\n", status));
  186.      return status;
  187.  }
  188.  
  189. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  190. index b102aab..b8bfb61 100644
  191. --- a/sys/nfs41_driver.c
  192. +++ b/sys/nfs41_driver.c
  193. @@ -5192,6 +5192,7 @@ NTSTATUS map_query_acl_error(
  194.      switch (error) {
  195.      case NO_ERROR:                  return STATUS_SUCCESS;
  196.      case ERROR_NOT_SUPPORTED:       return STATUS_NOT_SUPPORTED;
  197. +    case ERROR_NONE_MAPPED:         return STATUS_NONE_MAPPED;
  198.      case ERROR_ACCESS_DENIED:       return STATUS_ACCESS_DENIED;
  199.      case ERROR_FILE_NOT_FOUND:      return STATUS_OBJECT_NAME_NOT_FOUND;
  200.      case ERROR_INVALID_PARAMETER:   return STATUS_INVALID_PARAMETER;
  201. --
  202. 2.43.0
  203.  
  204. From 80d750bd1c24130a57e16b20c97089015c1d93ca Mon Sep 17 00:00:00 2001
  205. From: Roland Mainz <roland.mainz@nrubsig.org>
  206. Date: Mon, 12 Feb 2024 08:34:06 +0100
  207. Subject: [PATCH 2/5] daemon: Add |print_sid()| debug function to print SID
  208.  string value
  209.  
  210. Add |print_sid()| debug function to print SID string value with a text
  211. label to debug output.
  212.  
  213. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  214. ---
  215. daemon/acl.c          |  8 ++++++++
  216.  daemon/daemon_debug.c | 18 ++++++++++++++++++
  217.  daemon/daemon_debug.h |  2 ++
  218.  3 files changed, 28 insertions(+)
  219.  
  220. diff --git a/daemon/acl.c b/daemon/acl.c
  221. index 499085e..6abe530 100644
  222. --- a/daemon/acl.c
  223. +++ b/daemon/acl.c
  224. @@ -473,6 +473,10 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  225.       */
  226.      status = 0;
  227.      if (owner_sid) {
  228. +        if (DPRINTF_LEVEL_ENABLED(ACLLVL)) {
  229. +            print_sid("owner_sid", owner_sid);
  230. +        }
  231. +
  232.          if (EqualSid(sid, owner_sid)) {
  233.              DPRINTF(ACLLVL, ("map_nfs4ace_who: this is owner's sid\n"));
  234.              memcpy(who_out, ACE4_OWNER, strlen(ACE4_OWNER)+1);
  235. @@ -481,6 +485,10 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  236.          }
  237.      }
  238.      if (group_sid) {
  239. +        if (DPRINTF_LEVEL_ENABLED(ACLLVL)) {
  240. +            print_sid("group_sid", group_sid);
  241. +        }
  242. +
  243.          if (EqualSid(sid, group_sid)) {
  244.              DPRINTF(ACLLVL, ("map_nfs4ace_who: this is group's sid\n"));
  245.              memcpy(who_out, ACE4_GROUP, strlen(ACE4_GROUP)+1);
  246. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  247. index 4187b91..e632233 100644
  248. --- a/daemon/daemon_debug.c
  249. +++ b/daemon/daemon_debug.c
  250. @@ -22,6 +22,7 @@
  251.  
  252.  #include <windows.h>
  253.  #include <stdio.h>
  254. +#include <sddl.h>
  255.  
  256.  #include "daemon_debug.h"
  257.  #include "from_kernel.h"
  258. @@ -297,6 +298,23 @@ void print_file_id_both_dir_info(int level, FILE_ID_BOTH_DIR_INFO *pboth_dir_inf
  259.          pboth_dir_info->FileName);
  260.  }
  261.  
  262. +void print_sid(const char *label, PSID sid)
  263. +{
  264. +    PSTR sidstr = NULL;
  265. +
  266. +    if (ConvertSidToStringSidA(sid, &sidstr)) {
  267. +        dprintf_out("%s=SID('%s')\n", label, sidstr);
  268. +        LocalFree(sidstr);
  269. +    }
  270. +    else {
  271. +        int status;
  272. +
  273. +        status = GetLastError();
  274. +        dprintf_out("%s=<ConvertSidToStringSidA() failed error=%d>\n",
  275. +            label, status);
  276. +    }
  277. +}
  278. +
  279.  const char* opcode2string(DWORD opcode)
  280.  {
  281.      switch(opcode) {
  282. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  283. index b89c1d9..65e7d2a 100644
  284. --- a/daemon/daemon_debug.h
  285. +++ b/daemon/daemon_debug.h
  286. @@ -3,6 +3,7 @@
  287.   *
  288.   * Olga Kornievskaia <aglo@umich.edu>
  289.   * Casey Bodley <cbodley@umich.edu>
  290. + * Roland Mainz <roland.mainz@nrubsig.org>
  291.   *
  292.   * This library is free software; you can redistribute it and/or modify it
  293.   * under the terms of the GNU Lesser General Public License as published by
  294. @@ -90,6 +91,7 @@ void print_disposition(int level, DWORD disposition);
  295.  void print_access_mask(int level, DWORD access_mask);
  296.  void print_share_mode(int level, DWORD mode);
  297.  void print_file_id_both_dir_info(int level, FILE_ID_BOTH_DIR_INFO *p);
  298. +void print_sid(const char *label, PSID sid);
  299.  const char* opcode2string(DWORD opcode);
  300.  const char* nfs_opnum_to_string(int opnum);
  301.  const char* nfs_error_string(int status);
  302. --
  303. 2.43.0
  304.  
  305. From b727d65785205a16909e7e385d248c825af87cc0 Mon Sep 17 00:00:00 2001
  306. From: Roland Mainz <roland.mainz@nrubsig.org>
  307. Date: Mon, 12 Feb 2024 10:54:38 +0100
  308. Subject: [PATCH 3/5] tests: Add chown/chgrp/cp -p/mv tests to
  309.  manual_testing.txt until we have a test suite
  310.  
  311. Add chown/chgrp/cp -p/mv tests to manual_testing.txt until we have a test
  312. suite.
  313.  
  314. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  315. ---
  316. tests/manual_testing.txt | 16 +++++++++++++++-
  317.  1 file changed, 15 insertions(+), 1 deletion(-)
  318.  
  319. diff --git a/tests/manual_testing.txt b/tests/manual_testing.txt
  320. index 9d33d90..83407a9 100644
  321. --- a/tests/manual_testing.txt
  322. +++ b/tests/manual_testing.txt
  323. @@ -1,5 +1,5 @@
  324.  #
  325. -# ms-nfs41-client manual testing sequence, 2024-01-05
  326. +# ms-nfs41-client manual testing sequence, 2024-02-12
  327.  #
  328.  # Draft version, needs to be turned into automated tests
  329.  # if possible
  330. @@ -11,6 +11,20 @@
  331.  # net start cygserver
  332.  # sc query cygserver
  333.  
  334. +#
  335. +# Tests for cp -p/mv/chmod/chgrp
  336. +# Testcases, all should print *ONLY* "OK" on stdout, nothing on stderr
  337. +---- snip ----
  338. +ksh93 -c 'builtin mv ; rm -f /tmp/x y ; touch /tmp/x ; mv /tmp/x y && print OK ; true'
  339. +ksh93 -c 'builtin mv ; rm -f /tmp/x y ; touch /tmp/x ; cp -p /tmp/x y && print OK ; true'
  340. +ksh93 -c 'builtin cp ; rm -f /tmp/x y ; touch /tmp/x ; cp -p /tmp/x y && print OK ; true'
  341. +ksh93 -c 'builtin cp ; rm -f x y ; touch x ; cp -p /tmp/x y && print OK ; true'
  342. +ksh93 -c 'builtin cp ; rm -f x y ; touch x ; cp -p x y && print OK ; true'
  343. +ksh93 -c 'builtin cp ; rm -f x y ; touch x ; /usr/bin/cp -p x y && print OK ; true'
  344. +ksh93 -c 'builtin id ; rm -f x ; touch x ; chown "$(id -u -n):$(id -g -n)" x && print OK'
  345. +ksh93 -c 'builtin id ; rm -f x ; touch x ; chgrp "$(id -g -n)" x && print OK'
  346. +---- snip ----
  347. +
  348.  
  349.  #
  350.  # Compile each of the following package
  351. --
  352. 2.43.0
  353.  
  354. From 43f3bc86adfdfe82bbe55183201f821a6e7330c2 Mon Sep 17 00:00:00 2001
  355. From: Roland Mainz <roland.mainz@nrubsig.org>
  356. Date: Mon, 12 Feb 2024 15:15:58 +0100
  357. Subject: [PATCH 4/5] daemon: Move SID cache build config to
  358.  "nfs41_build_features.h"
  359.  
  360. Add |NFS41_DRIVER_SID_CACHE| config flag to "nfs41_build_features.h"
  361. to control whether we build the username/groupname-to-SID cache
  362.  
  363. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  364. ---
  365. daemon/nfs41_daemon.c  |  4 ++++
  366.  daemon/sid.c           | 20 ++++++++------------
  367.  nfs41_build_features.h | 11 ++++++++---
  368.  3 files changed, 20 insertions(+), 15 deletions(-)
  369.  
  370. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  371. index b5edc25..49567c6 100644
  372. --- a/daemon/nfs41_daemon.c
  373. +++ b/daemon/nfs41_daemon.c
  374. @@ -525,7 +525,11 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  375.      set_debug_level(cmd_args.debug_level);
  376.      open_log_files();
  377.      nfsd_crt_debug_init();
  378. +#ifdef NFS41_DRIVER_SID_CACHE
  379.      sidcache_init();
  380. +#else
  381. +    DPRINTF(0, ("SID cache disabled\n"));
  382. +#endif /* NFS41_DRIVER_SID_CACHE */
  383.  
  384.      /* acquire and store in global memory current dns domain name.
  385.       * needed for acls */
  386. diff --git a/daemon/sid.c b/daemon/sid.c
  387. index b522232..f0091af 100644
  388. --- a/daemon/sid.c
  389. +++ b/daemon/sid.c
  390. @@ -176,11 +176,7 @@ BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
  391.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  392.  
  393.  
  394. -/* fixme: should be in sys/nfs41_build_features.h */
  395. -#define USE_SID_CACHE 1
  396. -
  397. -
  398. -#ifdef USE_SID_CACHE
  399. +#ifdef NFS41_DRIVER_SID_CACHE
  400.  #define SIDCACHE_SIZE 20
  401.  #define SIDCACHE_TTL 600
  402.  
  403. @@ -305,7 +301,7 @@ done:
  404.      LeaveCriticalSection(&cache->lock);
  405.      return ret_sid;
  406.  }
  407. -#endif /* USE_SID_CACHE */
  408. +#endif /* NFS41_DRIVER_SID_CACHE */
  409.  
  410.  
  411.  int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *sid_len, PSID *sid, LPCSTR name)
  412. @@ -328,17 +324,17 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  413.          uid_t udummy = -1;
  414.          gid_t gdummy = -1;
  415.  
  416. -#ifdef USE_SID_CACHE
  417. +#ifdef NFS41_DRIVER_SID_CACHE
  418.          if (*sid = sidcache_getcached(&user_sidcache, name)) {
  419.              *sid_len = GetLengthSid(*sid);
  420.              DPRINTF(1, ("map_nfs4servername_2_sid: returning cached sid for '%s'\n", name));
  421.              return 0;
  422.          }
  423. -#endif /* USE_SID_CACHE */
  424. +#endif /* NFS41_DRIVER_SID_CACHE */
  425.  
  426. -#ifndef USE_SID_CACHE
  427. +#ifndef NFS41_DRIVER_SID_CACHE
  428.          /* gisburn: fixme: We must cache this, or the performance impact will be devastating!! */
  429. -#endif /* !USE_SID_CACHE */
  430. +#endif /* !NFS41_DRIVER_SID_CACHE */
  431.          if (!cygwin_getent_passwd(name, name_buff, &udummy, &gdummy)) {
  432.              if (strcmp(name, name_buff)) {
  433.                  DPRINTF(1,
  434. @@ -486,14 +482,14 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  435.          break;
  436.      }
  437.  out:
  438. -#ifdef USE_SID_CACHE
  439. +#ifdef NFS41_DRIVER_SID_CACHE
  440.      if (*sid) {
  441.          /* fixme: No other flags in |query| must be set!! */
  442.          if (query & OWNER_SECURITY_INFORMATION) {
  443.              sidcache_add(&user_sidcache, orig_name, *sid);
  444.          }
  445.      }
  446. -#endif /* USE_SID_CACHE */
  447. +#endif /* NFS41_DRIVER_SID_CACHE */
  448.  
  449.      return status;
  450.  out_free_sid:
  451. diff --git a/nfs41_build_features.h b/nfs41_build_features.h
  452. index 3fdbe05..bb87fc0 100644
  453. --- a/nfs41_build_features.h
  454. +++ b/nfs41_build_features.h
  455. @@ -48,10 +48,9 @@
  456.  #define NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN 1
  457.  
  458.  /*
  459. - * NFS41_DRIVER_STABILITY_HACKS - use horrible
  460. - * hacks to improve stabilty
  461. + * Enable cache for username/groupname to SID
  462.   */
  463. -#define NFS41_DRIVER_STABILITY_HACKS 1
  464. +#define NFS41_DRIVER_SID_CACHE 1
  465.  
  466.  /*
  467.   * NFS41_DRIVER_MOUNT_DOES_NFS4_PREFIX - nfs_mount.exe and
  468. @@ -64,4 +63,10 @@
  469.   */
  470.  #define NFS41_DRIVER_MOUNT_DOES_NFS4_PREFIX 1
  471.  
  472. +/*
  473. + * NFS41_DRIVER_STABILITY_HACKS - use horrible
  474. + * hacks to improve stabilty
  475. + */
  476. +#define NFS41_DRIVER_STABILITY_HACKS 1
  477. +
  478.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  479. --
  480. 2.43.0
  481.  
  482. From 8c96f9a37f87c2e7c42f466b8f9ebadde9f99f8c Mon Sep 17 00:00:00 2001
  483. From: Roland Mainz <roland.mainz@nrubsig.org>
  484. Date: Mon, 12 Feb 2024 16:25:34 +0100
  485. Subject: [PATCH 5/5] mount: nfs_mount should print nfs://-URL when listing all
  486.  mounted nfs4 fs
  487.  
  488. nfs_mount.exe should print nfs://-URL when listing all mounted nfs4
  489. filesystems.
  490.  
  491. ToDo:
  492. In the future the default output should be better formatted and
  493. have an option to select which information should be presented.
  494.  
  495. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  496. ---
  497. mount/enum.c  | 116 +++++++++++++++++++++++++++++++++++++++++++++-----
  498.  mount/mount.c |   1 -
  499.  2 files changed, 105 insertions(+), 12 deletions(-)
  500.  
  501. diff --git a/mount/enum.c b/mount/enum.c
  502. index c9a6e38..5473a71 100644
  503. --- a/mount/enum.c
  504. +++ b/mount/enum.c
  505. @@ -27,24 +27,31 @@
  506.  #include "nfs41_build_features.h"
  507.  #include "nfs41_driver.h" /* NFS41_PROVIDER_NAME_A */
  508.  
  509. +/* prototypes */
  510. +char *wcs2utf8str(const wchar_t *wstr);
  511. +void PrintErrorMessage(IN DWORD dwError);
  512.  
  513. -void PrintErrorMessage(
  514. -    IN DWORD dwError);
  515. -
  516. +/* fixme: this function needs a cleanup */
  517.  static __inline
  518.  void PrintMountLine(
  519.      LPCTSTR local,
  520.      LPCTSTR remote)
  521.  {
  522.      TCHAR *cygwin_unc_buffer = alloca((_tcslen(remote)+32)*sizeof(TCHAR));
  523. -    TCHAR *b = cygwin_unc_buffer;
  524. -    LPCTSTR s = remote;
  525. +    char *cygwin_nfsurl_buffer = alloca(((_tcslen(remote)+32)*3));
  526. +    TCHAR *b;
  527. +    LPCTSTR s;
  528.      TCHAR sc;
  529.  #ifndef NFS41_DRIVER_MOUNT_DOES_NFS4_PREFIX
  530. -    unsigned int backslash_counter = 0;
  531. +    unsigned int backslash_counter;
  532.  #endif
  533.  
  534. -    while((sc = *s++) != TEXT('\0')) {
  535. +    for(b = cygwin_unc_buffer, s = remote
  536. +#ifndef NFS41_DRIVER_MOUNT_DOES_NFS4_PREFIX
  537. +     , backslash_counter = 0
  538. +#endif
  539. +     ;
  540. +        (sc = *s++) != TEXT('\0') ; ) {
  541.          switch(sc) {
  542.              case TEXT('\\'):
  543.                  *b++ = TEXT('/');
  544. @@ -61,8 +68,93 @@ void PrintMountLine(
  545.          }
  546.      }
  547.      *b = TEXT('\0');
  548. -// FIXME: We should print the URL
  549. -    _tprintf(TEXT("%-8s\t%-40s\t%s\n"), local, remote, cygwin_unc_buffer);
  550. +
  551. +
  552. +    /*
  553. +     * print nfs://-URL
  554. +     */
  555. +/*
  556. + * From RFC 1738 ("Uniform Resource Locators (URL)"):
  557. + * unsafe characters in URLS:
  558. + * "{", "}", "|", "\", "^", "~", "[", "]", and "`"
  559. + * characters which must always be encoded:
  560. + * "#", "%"
  561. + * characters which must be encoded because they have a special meaning:
  562. + * ";", "/", "?", ":", "@", "=" and "&"
  563. + * Only alphanumerics, "$-_.+!*'()," and reserved characters
  564. + * ("/" for nfs://-URLS) are allowed
  565. + */
  566. +#define ISVALIDURLCHAR(c) \
  567. +       ( \
  568. +            ((c) >= '0' && (c) <= '9') || \
  569. +           ((c) >= 'a' && (c) <= 'z') || \
  570. +           ((c) >= 'A' && (c) <= 'Z') || \
  571. +            ((c) == '$') || ((c) == '-') || ((c) == '_') || ((c) == '.') || \
  572. +            ((c) == '+') || ((c) == '!') || ((c) == '*') || ((c) == '\'') || \
  573. +            ((c) == '(') || ((c) == ')') || ((c) == ',') || ((c) == '/') \
  574. +        )
  575. +
  576. +    unsigned int slash_counter = 0;
  577. +    char *utf8unc = wcs2utf8str(cygwin_unc_buffer);
  578. +    if (!utf8unc)
  579. +        return;
  580. +    char *utf8unc_p = utf8unc;
  581. +    char *us = cygwin_nfsurl_buffer;
  582. +
  583. +#pragma warning( push )
  584. +    /*
  585. +     * Disable "'strcpy': This function or variable may be unsafe",
  586. +     * in this context it is safe to use
  587. +     */
  588. +#pragma warning (disable : 4996)
  589. +    (void)strcpy(us, "nfs://");
  590. +#pragma warning( pop )
  591. +    us+=6;
  592. +
  593. +    /* skip leading "//" */
  594. +    utf8unc_p += 2;
  595. +
  596. +    for ( ; *utf8unc_p != '\0' ; ) {
  597. +        char uc = *utf8unc_p++;
  598. +
  599. +        if (uc == '/')
  600. +            slash_counter++;
  601. +
  602. +        /*
  603. +         * Skip "nfs4", but not the last '/' to make the nfs://-URL
  604. +         * an absolute URL, not a relative nfs://-URL.
  605. +         * (This assumes that all input strings have "nfs4/"!)
  606. +         */
  607. +        if (slash_counter == 1) {
  608. +            *us++ = uc;
  609. +            utf8unc_p+=4;
  610. +            continue;
  611. +        }
  612. +
  613. +        if ((uc == '@') && (slash_counter == 0)) {
  614. +            *us++ = ':';
  615. +        }
  616. +        else if (ISVALIDURLCHAR(uc)) {
  617. +            *us++ = uc;
  618. +        }
  619. +        else {
  620. +#pragma warning( push )
  621. +    /*
  622. +     * Disable "'sprintf': This function or variable may be unsafe",
  623. +     * in this context it is safe to use
  624. +     */
  625. +#pragma warning (disable : 4996)
  626. +            (void)sprintf(us, "%%%2.2x", uc);
  627. +#pragma warning( pop )
  628. +            us+=3;
  629. +        }
  630. +    }
  631. +    *us = '\0';
  632. +
  633. +    (void)_tprintf(TEXT("%-8s\t%-50s\t%-50s\t%-50S\n"),
  634. +        local, remote, cygwin_unc_buffer, cygwin_nfsurl_buffer);
  635. +
  636. +    free(utf8unc);
  637.  }
  638.  
  639.  /* ENUM_RESOURCE_BUFFER_SIZE
  640. @@ -94,8 +186,10 @@ DWORD EnumMounts(
  641.      if (result)
  642.          goto out_free;
  643.  
  644. -    _tprintf(TEXT("Listing '%s' mounts:\n\n"), TEXT(NFS41_PROVIDER_NAME_A));
  645. -    _tprintf(TEXT("%-8s\t%-40s\t%s\n"), TEXT("Volume"), TEXT("Remote path"), TEXT("Cygwin UNC path"));
  646. +    (void)_tprintf(TEXT("Listing '%s' mounts:\n\n"),
  647. +        TEXT(NFS41_PROVIDER_NAME_A));
  648. +    (void)_tprintf(TEXT("%-8s\t%-50s\t%-50s\t%-50S\n"),
  649. +        TEXT("Volume"), TEXT("Remote path"), TEXT("Cygwin UNC path"), "URL");
  650.  
  651.      do
  652.      {
  653. diff --git a/mount/mount.c b/mount/mount.c
  654. index 01e5890..d480d05 100644
  655. --- a/mount/mount.c
  656. +++ b/mount/mount.c
  657. @@ -293,7 +293,6 @@ static void ConvertUnixSlashes(
  658.  }
  659.  
  660.  
  661. -static
  662.  char *wcs2utf8str(const wchar_t *wstr)
  663.  {
  664.      char *utf8str;
  665. --
  666. 2.43.0

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