pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for nfs_mount, URL encoding methods, nfs_mount usage fixes+misc, 2024-12-05
Posted by Anonymous on Thu 5th Dec 2024 01:17
raw | new post

  1. From d8cb3ea640106245914e2d97808e4109286223f9 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Thu, 5 Dec 2024 01:47:36 +0100
  4. Subject: [PATCH 1/4] cygwin,mount: Implement multiple URL encoding methods
  5.  
  6. Implement multiple URL encoding methods in nfs_mount.exe
  7. and nfsurlconv.ksh
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. cygwin/utils/nfsurlconv/nfsurlconv.ksh | 20 +++++++--
  12.  mount/enum.c                           | 22 +++++-----
  13.  mount/mount.c                          | 58 ++++++++++++++++++++++----
  14.  3 files changed, 79 insertions(+), 21 deletions(-)
  15.  
  16. diff --git a/cygwin/utils/nfsurlconv/nfsurlconv.ksh b/cygwin/utils/nfsurlconv/nfsurlconv.ksh
  17. index 505fb56..f92792e 100644
  18. --- a/cygwin/utils/nfsurlconv/nfsurlconv.ksh
  19. +++ b/cygwin/utils/nfsurlconv/nfsurlconv.ksh
  20. @@ -287,12 +287,13 @@ function main
  21.  
  22.         # fixme: Need better text layout for $ nfsurlconv --man #
  23.         typeset -r nfsurlconv_usage=$'+
  24. -       [-?\n@(#)\$Id: nfsurlconv (Roland Mainz) 2024-11-25 \$\n]
  25. +       [-?\n@(#)\$Id: nfsurlconv (Roland Mainz) 2024-12-04 \$\n]
  26.         [-author?Roland Mainz <roland.mainz@nrubsig.org>]
  27.         [+NAME?nfsurlconv - convert hostname,port,path from/to a nfs://-URL]
  28.         [+DESCRIPTION?\bnfsurlconv\b convert { hostname, port, path } from/to a nfs://-URL.]
  29.         [D:debug?Enable debugging.]
  30. -       [S!:posixshellsafe?urlencode shell special characters.]
  31. +       [U:urlencoding?Encoding method used \brfc1738\b or
  32. +       \bposixshell\b/\bposixshellsafe\b (default).]:[encoding]
  33.  
  34.         hostnameportpath2nfsurl hostname port path
  35.         hostnamepath2nfsurl hostname path
  36. @@ -352,8 +353,19 @@ urlparameter=( name=param2 value=pvalue2 )
  37.                         'D')
  38.                                 # fixme: Implement debugging option
  39.                                 ;;
  40. -                       'S')
  41. -                               (( encode_posix_shell_safe=0 ))
  42. +                       'U')
  43. +                               case "$OPTARG" in
  44. +                                       'rfc1738')
  45. +                                               (( encode_posix_shell_safe=0 ))
  46. +                                               ;;
  47. +                                       'posixshell' | 'posixshellsafe' | 'default')
  48. +                                               (( encode_posix_shell_safe=1 ))
  49. +                                               ;;
  50. +                                       *)
  51. +                                               print -u2 -f $"%s: Unknown -U encoding %q\n" "$progname" "$OPTARG"
  52. +                                               return 1
  53. +                                               ;;
  54. +                               esac
  55.                                 ;;
  56.                         *)
  57.                                 usage "${progname}" "${nfsurlconv_usage}"
  58. diff --git a/mount/enum.c b/mount/enum.c
  59. index b2938ef..d3cec03 100644
  60. --- a/mount/enum.c
  61. +++ b/mount/enum.c
  62. @@ -43,8 +43,9 @@ void PrintErrorMessage(IN DWORD dwError);
  63.  /* fixme: this function needs a cleanup */
  64.  static __inline
  65.  void PrintMountLine(
  66. -    LPCWSTR local,
  67. -    LPCWSTR remote)
  68. +    IN LPCWSTR local,
  69. +    IN LPCWSTR remote,
  70. +    IN BOOL printURLShellSafe)
  71.  {
  72.      size_t remote_len = wcslen(remote);
  73.      wchar_t *cygwin_unc_buffer =
  74. @@ -106,9 +107,8 @@ void PrintMountLine(
  75.   * in POSIX shells, e.g. '!', '(', ')', '*', "'", "$".
  76.   * Fixme: This should be a command-line option
  77.   */
  78. -#define SHELL_SAFE_URLS 1
  79. -#ifdef SHELL_SAFE_URLS
  80. -#define ISVALIDURLCHAR(c) \
  81. +
  82. +#define ISVALIDSHELLSAFEURLCHAR(c) \
  83.         ( \
  84.              ((c) >= '0' && (c) <= '9') || \
  85.             ((c) >= 'a' && (c) <= 'z') || \
  86. @@ -116,7 +116,6 @@ void PrintMountLine(
  87.              ((c) == '-') || ((c) == '_') || ((c) == '.') || \
  88.              ((c) == '/') \
  89.          )
  90. -#else
  91.  #define ISVALIDURLCHAR(c) \
  92.         ( \
  93.              ((c) >= '0' && (c) <= '9') || \
  94. @@ -126,7 +125,6 @@ void PrintMountLine(
  95.              ((c) == '!') || ((c) == '*') || ((c) == '\'') || \
  96.              ((c) == '(') || ((c) == ')') || ((c) == ',') || ((c) == '/') \
  97.          )
  98. -#endif /* SHELL_SAFE_URLS */
  99.  
  100.      unsigned int slash_counter = 0;
  101.      char *utf8unc = wcs2utf8str(cygwin_unc_buffer);
  102. @@ -183,7 +181,9 @@ void PrintMountLine(
  103.          if ((uc == '@') && (slash_counter == 0)) {
  104.              *us++ = ':';
  105.          }
  106. -        else if (ISVALIDURLCHAR(uc)) {
  107. +        else if (printURLShellSafe?
  108. +                    (ISVALIDSHELLSAFEURLCHAR(uc)):
  109. +                    (ISVALIDURLCHAR(uc))) {
  110.              *us++ = uc;
  111.          }
  112.          else {
  113. @@ -227,7 +227,8 @@ void PrintMountLine(
  114.  #define ENUM_RESOURCE_BUFFER_SIZE (16*1024)
  115.  
  116.  DWORD EnumMounts(
  117. -    IN LPNETRESOURCEW pContainer)
  118. +    IN LPNETRESOURCEW pContainer,
  119. +    IN BOOL printURLShellSafe)
  120.  {
  121.      DWORD result = NO_ERROR;
  122.      LPNETRESOURCEW pResources;
  123. @@ -265,7 +266,8 @@ DWORD EnumMounts(
  124.                      NFS41_PROVIDER_NAME_U))
  125.                  {
  126.                      PrintMountLine(pResources[i].lpLocalName,
  127. -                        pResources[i].lpRemoteName);
  128. +                        pResources[i].lpRemoteName,
  129. +                        printURLShellSafe);
  130.                      dwTotal++;
  131.                  }
  132.              }
  133. diff --git a/mount/mount.c b/mount/mount.c
  134. index 5b872a2..2bc1ebb 100644
  135. --- a/mount/mount.c
  136. +++ b/mount/mount.c
  137. @@ -55,7 +55,8 @@
  138.  #define MOUNT_CONFIG_NFS_PORT_DEFAULT   2049
  139.  
  140.  DWORD EnumMounts(
  141. -    IN LPNETRESOURCEW pContainer);
  142. +    IN LPNETRESOURCEW pContainer,
  143. +    IN BOOL printURLShellSafe);
  144.  
  145.  static DWORD ParseRemoteName(
  146.      IN bool use_nfspubfh,
  147. @@ -101,6 +102,8 @@ void PrintMountUsage(LPWSTR pProcess)
  148.          "\t-o. --options <comma-separated mount options>\n"
  149.          "\t-r, --read-only\tAlias for -o ro (read-only mount)\n"
  150.          "\t-w, --rw, --read-write\tAlias for -o rw (read-write mount)\n"
  151. +        "\t-U, --urlencoding\tDefine encoding used by URLs\n"
  152. +        "\t\t('rfc1738', 'posixshell'/'posixshellsafe', 'default')\n"
  153.  
  154.          "* Mount options:\n"
  155.          "\tpublic\tconnect to the server using the public file handle lookup protocol.\n"
  156. @@ -556,17 +559,55 @@ out:
  157.  static
  158.  int list_nfs_mounts_main(int argc, wchar_t *argv[])
  159.  {
  160. -    DWORD result;
  161. +    int     i;
  162. +    DWORD   result = NO_ERROR;
  163. +    BOOL    bShellSafeURLEncoding = TRUE;
  164. +
  165. +    /*
  166. +     * parse command line
  167. +     * (-h, --help, /? is handled by |mount_main()|)
  168. +     */
  169. +    for (i = 1; i < argc; i++) {
  170. +        if ((!wcscmp(argv[i], L"-U")) ||
  171. +                (!wcscmp(argv[i], L"--urlencoding"))) {
  172. +            ++i;
  173. +            if (i >= argc) {
  174. +                result = ERROR_BAD_ARGUMENTS;
  175. +                (void)fwprintf(stderr, L"URL encoding type missing "
  176. +                    L"after '-U'/'--urlencoding'.\n");
  177. +                goto out;
  178. +            }
  179.  
  180. -    /* Unused for now */
  181. -    (void)argc;
  182. -    (void)argv;
  183. +            if (!wcscmp(argv[i], L"rfc1738")) {
  184. +                bShellSafeURLEncoding = FALSE;
  185. +            }
  186. +            else if ((!wcscmp(argv[i], L"posixshellsafe")) ||
  187. +                (!wcscmp(argv[i], L"posixshell")) ||
  188. +                (!wcscmp(argv[i], L"default"))) {
  189. +                bShellSafeURLEncoding = TRUE;
  190. +            }
  191. +            else {
  192. +                result = ERROR_BAD_ARGUMENTS;
  193. +                (void)fwprintf(stderr, L"URL encoding type '%ls' "
  194. +                    L"not supported.\n", argv[i]);
  195. +                goto out;
  196. +            }
  197. +        }
  198. +        else {
  199. +            (void)fwprintf(stderr, L"Unrecognized option "
  200. +                L"'%ls'.\n",
  201. +                argv[i]);
  202. +            result = ERROR_BAD_ARGUMENTS;
  203. +            goto out;
  204. +        }
  205. +    }
  206.  
  207.      /* list open nfs shares */
  208. -    result = EnumMounts(NULL);
  209. +    result = EnumMounts(NULL, bShellSafeURLEncoding);
  210.      if (result)
  211.          PrintErrorMessage(GetLastError());
  212.  
  213. +out:
  214.      return result;
  215.  }
  216.  
  217. @@ -595,7 +636,10 @@ int __cdecl wmain(int argc, wchar_t *argv[])
  218.      (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  219.      (void)_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  220.  
  221. -    if (argc == 1) {
  222. +    if ((argc == 1) ||
  223. +        (((argc >= 2) && (argc <= 3)) &&
  224. +            ((!wcscmp(argv[1], L"-U")) ||
  225. +            (!wcscmp(argv[1], L"--urlencoding"))))) {
  226.          result = list_nfs_mounts_main(argc, argv);
  227.          goto out;
  228.      }
  229. --
  230. 2.45.1
  231.  
  232. From 1bd6fd6e5a3fbaabd6ac021f15448433a5da1375 Mon Sep 17 00:00:00 2001
  233. From: Roland Mainz <roland.mainz@nrubsig.org>
  234. Date: Thu, 5 Dec 2024 01:52:16 +0100
  235. Subject: [PATCH 2/4] mount: nfs_mount.exe -t nfs ... should not result in an
  236.  error
  237.  
  238. nfs_mount.exe -t nfs ... should not result in an error.
  239.  
  240. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  241. ---
  242. mount/mount.c | 6 ++++++
  243.  1 file changed, 6 insertions(+)
  244.  
  245. diff --git a/mount/mount.c b/mount/mount.c
  246. index 2bc1ebb..1cf71f8 100644
  247. --- a/mount/mount.c
  248. +++ b/mount/mount.c
  249. @@ -373,6 +373,12 @@ opt_o_argv_i_again:
  250.                  }
  251.  
  252.                  if (!wcscmp(argv[i], L"nfs")) {
  253. +                    /*
  254. +                     * "nfs" is the only supported filesystem type
  255. +                     * in nfs_mount.exe
  256. +                     */
  257. +                }
  258. +                else {
  259.                      result = ERROR_BAD_ARGUMENTS;
  260.                      (void)fwprintf(stderr, L"Filesystem type '%ls' "
  261.                          L"not supported.\n\n.", argv[i]);
  262. --
  263. 2.45.1
  264.  
  265. From e78ee7653e3c693cc76080ba19d44220f09817b5 Mon Sep 17 00:00:00 2001
  266. From: Roland Mainz <roland.mainz@nrubsig.org>
  267. Date: Thu, 5 Dec 2024 02:01:37 +0100
  268. Subject: [PATCH 3/4] mount: nfs_mount.exe should be less noisy in case of
  269.  wrong arguments
  270.  
  271. nfs_mount.exe should be less noisy in case of wrong arguments,
  272. printing always the whole usage message is not what the UNIX/Linux
  273. tools would do.
  274.  
  275. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  276. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  277. ---
  278. mount/mount.c | 26 ++++++++++----------------
  279.  1 file changed, 10 insertions(+), 16 deletions(-)
  280.  
  281. diff --git a/mount/mount.c b/mount/mount.c
  282. index 1cf71f8..1b7d7ca 100644
  283. --- a/mount/mount.c
  284. +++ b/mount/mount.c
  285. @@ -250,15 +250,14 @@ int mount_main(int argc, wchar_t *argv[])
  286.                  {
  287.                      result = ERROR_BAD_ARGUMENTS;
  288.                      (void)fwprintf(stderr,
  289. -                        L"Mount options missing after '-o'.\n\n");
  290. -                    PrintMountUsage(argv[0]);
  291. +                        L"Mount options missing after '-o'.\n");
  292.                      goto out_free;
  293.                  }
  294.  
  295.                  if (num_mntopts >= (MAX_MNTOPTS-1)) {
  296.                      result = ERROR_BAD_ARGUMENTS;
  297.                      (void)fwprintf(stderr,
  298. -                        L"Too many -o options.\n\n");
  299. +                        L"Too many -o options.\n");
  300.                      goto out_free;
  301.                  }
  302.  
  303. @@ -336,7 +335,7 @@ opt_o_argv_i_again:
  304.                      (!wcscmp(argv[i], L"--read-only"))) {
  305.                  if (num_mntopts >= (MAX_MNTOPTS-1)) {
  306.                      result = ERROR_BAD_ARGUMENTS;
  307. -                    (void)fwprintf(stderr, L"Too many options.\n\n");
  308. +                    (void)fwprintf(stderr, L"Too many options.\n");
  309.                      goto out_free;
  310.                  }
  311.  
  312. @@ -348,7 +347,7 @@ opt_o_argv_i_again:
  313.                      (!wcscmp(argv[i], L"--read-write"))) {
  314.                  if (num_mntopts >= (MAX_MNTOPTS-1)) {
  315.                      result = ERROR_BAD_ARGUMENTS;
  316. -                    (void)fwprintf(stderr, L"Too many options.\n\n");
  317. +                    (void)fwprintf(stderr, L"Too many options.\n");
  318.                      goto out_free;
  319.                  }
  320.  
  321. @@ -367,8 +366,7 @@ opt_o_argv_i_again:
  322.                  {
  323.                      result = ERROR_BAD_ARGUMENTS;
  324.                      (void)fwprintf(stderr, L"Filesystem type missing "
  325. -                        L"after '-t'/'-F'.\n\n");
  326. -                    PrintMountUsage(argv[0]);
  327. +                        L"after '-t'/'-F'.\n");
  328.                      goto out_free;
  329.                  }
  330.  
  331. @@ -381,8 +379,7 @@ opt_o_argv_i_again:
  332.                  else {
  333.                      result = ERROR_BAD_ARGUMENTS;
  334.                      (void)fwprintf(stderr, L"Filesystem type '%ls' "
  335. -                        L"not supported.\n\n.", argv[i]);
  336. -                    PrintMountUsage(argv[0]);
  337. +                        L"not supported.\n", argv[i]);
  338.                      goto out_free;
  339.                  }
  340.              }
  341. @@ -423,9 +420,8 @@ opt_o_argv_i_again:
  342.          if (!ParseDriveLetter(pLocalName, szLocalName)) {
  343.              result = ERROR_BAD_ARGUMENTS;
  344.              (void)fwprintf(stderr, L"Invalid drive letter '%ls'. "
  345. -                L"Expected 'C' or 'C:'.\n\n",
  346. +                L"Expected 'C' or 'C:'.\n",
  347.                  pLocalName);
  348. -            PrintMountUsage(argv[0]);
  349.              goto out_free;
  350.          }
  351.      }
  352. @@ -447,8 +443,7 @@ opt_o_argv_i_again:
  353.          if (pRemoteName == NULL)
  354.          {
  355.              result = ERROR_BAD_NET_NAME;
  356. -            (void)fwprintf(stderr, L"Missing argument for remote path.\n\n");
  357. -            PrintMountUsage(argv[0]);
  358. +            (void)fwprintf(stderr, L"Missing argument for remote path.\n");
  359.              goto out_free;
  360.          }
  361.  
  362. @@ -548,9 +543,8 @@ int umount_main(int argc, wchar_t *argv[])
  363.      if (!ParseDriveLetter(pLocalName, szLocalName)) {
  364.          result = ERROR_BAD_ARGUMENTS;
  365.          (void)fwprintf(stderr, L"Invalid drive letter '%ls'. "
  366. -            L"Expected 'C' or 'C:'.\n\n",
  367. +            L"Expected 'C' or 'C:'.\n",
  368.              pLocalName);
  369. -        PrintUmountUsage(argv[0]);
  370.          goto out;
  371.      }
  372.  
  373. @@ -778,7 +772,7 @@ static DWORD ParseRemoteName(
  374.          if (!premotename_utf8) {
  375.              result = GetLastError();
  376.              (void)fwprintf(stderr,
  377. -                L"wcs2utf8str() failed, lasterr=%d\n.",
  378. +                L"wcs2utf8str() failed, lasterr=%d\n",
  379.                  (int)result);
  380.              goto out;
  381.          }
  382. --
  383. 2.45.1
  384.  
  385. From 40b85aa2367eb9d1039543ccb0e2000753a8476b Mon Sep 17 00:00:00 2001
  386. From: Roland Mainz <roland.mainz@nrubsig.org>
  387. Date: Thu, 5 Dec 2024 02:09:05 +0100
  388. Subject: [PATCH 4/4] mount: Usage message for remote path should include
  389.  nfs://-URL
  390.  
  391. Usage message for remote path should include nfs://-URL
  392.  
  393. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  394. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  395. ---
  396. mount/mount.c | 2 +-
  397.  1 file changed, 1 insertion(+), 1 deletion(-)
  398.  
  399. diff --git a/mount/mount.c b/mount/mount.c
  400. index 1b7d7ca..b0a39bb 100644
  401. --- a/mount/mount.c
  402. +++ b/mount/mount.c
  403. @@ -914,7 +914,7 @@ static DWORD ParseRemoteName(
  404.          pEnd = wcsrchr(premotename, L':');
  405.          if (pEnd == NULL || pEnd[1] != L'\\') {
  406.              (void)fwprintf(stderr, L"Failed to parse the remote path. "
  407. -                L"Expected 'hostname:\\path'.\n");
  408. +                L"Expected 'hostname:\\path' or nfs://-URL.\n");
  409.              result = ERROR_BAD_ARGUMENTS;
  410.              goto out;
  411.          }
  412. --
  413. 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