pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for nfs://-URLs, 2024-01-25
Posted by Anonymous on Thu 25th Jan 2024 12:49
raw | new post

  1. From d628bf9478c24de7560f317abe8a32cb2ca9b590 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Thu, 25 Jan 2024 12:09:49 +0100
  4. Subject: [PATCH 1/4] mount: Fix absolute nfs://-URLs
  5.  
  6. Fix absolute nfs://-URLs - the '/' after hostport is the separator,
  7. and NOT part of the path, so an absolute path needs another '/'.
  8.  
  9. Example:
  10. "nfs://hostbar:93/relativepath/a"
  11. "nfs://hostbar:93//absolutepath/a"
  12.  
  13. nfs://-URLs do support relative paths, usually relative to the
  14. public file handle, but we do not support that yet.
  15.  
  16. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  17. ---
  18. mount/mount.c      | 28 ++++++++++++++++++++--------
  19.  mount/urlparser1.c |  2 +-
  20.  2 files changed, 21 insertions(+), 9 deletions(-)
  21.  
  22. diff --git a/mount/mount.c b/mount/mount.c
  23. index 7edc05f..91d5292 100644
  24. --- a/mount/mount.c
  25. +++ b/mount/mount.c
  26. @@ -103,11 +103,11 @@ static VOID PrintUsage(LPTSTR pProcess)
  27.          TEXT("\tnfs_mount.exe -p -o rw 'H' derfwpc5131_ipv4:/export/home2/rmainz\n")
  28.          TEXT("\tnfs_mount.exe -o rw '*' bigramhost:/tmp\n")
  29.          TEXT("\tnfs_mount.exe -o rw,sec=sys,port=30000 T grendel:/net_tmpfs2\n")
  30. -        TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1/net_tmpfs2/test2\n")
  31. -        TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1:1234/net_tmpfs2/test2\n")
  32. -        TEXT("\tnfs_mount.exe -o sec=sys,rw,port=1234 S nfs://myhost1/net_tmpfs2/test2\n")
  33. -        TEXT("\tnfs_mount.exe -o sec=sys,rw '*' [fe80::21b:1bff:fec3:7713]:/net_tmpfs2/test2\n")
  34. -        TEXT("\tnfs_mount.exe -o sec=sys,rw '*' nfs://[fe80::21b:1bff:fec3:7713]/net_tmpfs2/test2\n"),
  35. +        TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1//net_tmpfs2/test2\n")
  36. +        TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1:1234//net_tmpfs2/test2\n")
  37. +        TEXT("\tnfs_mount.exe -o sec=sys,rw,port=1234 S nfs://myhost1//net_tmpfs2/test2\n")
  38. +        TEXT("\tnfs_mount.exe -o sec=sys,rw '*' [fe80::21b:1bff:fec3:7713]://net_tmpfs2/test2\n")
  39. +        TEXT("\tnfs_mount.exe -o sec=sys,rw '*' nfs://[fe80::21b:1bff:fec3:7713]//net_tmpfs2/test2\n"),
  40.          pProcess);
  41.  }
  42.  
  43. @@ -331,15 +331,27 @@ static DWORD ParseRemoteName(
  44.              goto out;
  45.          }
  46.  
  47. -        (void)_sntprintf(premotename, NFS41_SYS_MAX_PATH_LEN, TEXT("%s"),
  48. -            uctx->hostport.hostname);
  49. -
  50.          if (uctx->hostport.port != -1)
  51.              port = uctx->hostport.port;
  52.          else
  53.              port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
  54.  
  55. +        (void)_sntprintf(premotename, NFS41_SYS_MAX_PATH_LEN, TEXT("%s"),
  56. +            uctx->hostport.hostname);
  57.          ConvertUnixSlashes(premotename);
  58. +
  59. +        if (!uctx->path) {
  60. +            result = ERROR_BAD_ARGUMENTS;
  61. +            (void)_ftprintf(stderr, TEXT("Path missing in nfs://-URL\n"));
  62. +            goto out;
  63. +        }
  64. +
  65. +        if (uctx->path[0] != TEXT('/')) {
  66. +            result = ERROR_BAD_ARGUMENTS;
  67. +            (void)_ftprintf(stderr, TEXT("Relative nfs://-URLs are not supported\n"));
  68. +            goto out;
  69. +        }
  70. +
  71.          pEnd = uctx->path;
  72.          ConvertUnixSlashes(pEnd);
  73.      }
  74. diff --git a/mount/urlparser1.c b/mount/urlparser1.c
  75. index 66b8b56..6a4f3f9 100644
  76. --- a/mount/urlparser1.c
  77. +++ b/mount/urlparser1.c
  78. @@ -156,7 +156,7 @@ int url_parser_parse(url_parser_context *uctx)
  79.                 slen = s-urlstr;
  80.                 (void)memcpy(uctx->hostport.hostname, urlstr, slen*sizeof(TCHAR));
  81.                 uctx->hostport.hostname[slen] = TEXT('\0');
  82. -               urlstr += slen;
  83. +               urlstr += slen + 1;
  84.  
  85.                 /*
  86.                  * check for addresses within '[' and ']', like
  87. --
  88. 2.43.0
  89.  
  90. From 9be7da9cea3a69dee00545e276e03ba95e52550f Mon Sep 17 00:00:00 2001
  91. From: Roland Mainz <roland.mainz@nrubsig.org>
  92. Date: Thu, 25 Jan 2024 13:21:08 +0100
  93. Subject: [PATCH 2/4] mount: urldecoding support in nfs://-URLs for <space> and
  94.  Unicode support
  95.  
  96. Add support for urldecoding (e.g. <space>=="%20" or "+") in nfs://-URLs
  97. for space and Unicode support, so nfs_mount.exe can mount paths with
  98. spaces or Unicode symbols (e.g. German umlauts etc.)
  99.  
  100. Note that URLs do urlencoding and urldecoding in bytes
  101. (see RFC3986 ("Uniform Resource Identifier (URI): Generic Syntax"),
  102. e.g. Unicode Euro symbol U+20AC is encoded as "%E2%82%AC", but our code
  103. works with Windows |TCHAR|/|wchart_t|, so convertion from |wchar_t| to
  104. UTF-8 and back is required.
  105.  
  106. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  107. ---
  108. mount/mount.c      |  89 ++++++++++++++++++++--
  109.  mount/urlparser1.c | 180 +++++++++++++++++++++++++++++++++++----------
  110.  mount/urlparser1.h |  24 +++---
  111.  3 files changed, 235 insertions(+), 58 deletions(-)
  112.  
  113. diff --git a/mount/mount.c b/mount/mount.c
  114. index 91d5292..94d1a66 100644
  115. --- a/mount/mount.c
  116. +++ b/mount/mount.c
  117. @@ -107,7 +107,9 @@ static VOID PrintUsage(LPTSTR pProcess)
  118.          TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1:1234//net_tmpfs2/test2\n")
  119.          TEXT("\tnfs_mount.exe -o sec=sys,rw,port=1234 S nfs://myhost1//net_tmpfs2/test2\n")
  120.          TEXT("\tnfs_mount.exe -o sec=sys,rw '*' [fe80::21b:1bff:fec3:7713]://net_tmpfs2/test2\n")
  121. -        TEXT("\tnfs_mount.exe -o sec=sys,rw '*' nfs://[fe80::21b:1bff:fec3:7713]//net_tmpfs2/test2\n"),
  122. +        TEXT("\tnfs_mount.exe -o sec=sys,rw '*' nfs://[fe80::21b:1bff:fec3:7713]//net_tmpfs2/test2\n")
  123. +        TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1//dirwithspace/dir%%20space/test2\n")
  124. +        TEXT("\tnfs_mount.exe -o sec=sys,rw S nfs://myhost1//dirwithspace/dir+space/test2\n"),
  125.          pProcess);
  126.  }
  127.  
  128. @@ -289,6 +291,50 @@ static void ConvertUnixSlashes(
  129.              *pos = TEXT('\\');
  130.  }
  131.  
  132. +
  133. +#define DEBUG_MOUNT 1
  134. +
  135. +static
  136. +char *wcs2utf8str(const wchar_t *wstr)
  137. +{
  138. +    char *utf8str;
  139. +    size_t wstr_len;
  140. +    size_t utf8_len;
  141. +
  142. +    wstr_len = wcslen(wstr);
  143. +    utf8_len = WideCharToMultiByte(CP_UTF8, 0,
  144. +        wstr, (int)wstr_len, NULL, 0, NULL, NULL);
  145. +
  146. +    utf8str = malloc(utf8_len+1);
  147. +    if (!utf8str)
  148. +        return NULL;
  149. +    (void)WideCharToMultiByte(CP_UTF8, 0,
  150. +        wstr, (int)wstr_len, utf8str, (int)utf8_len, NULL, NULL);
  151. +    utf8str[utf8_len] = '\0';
  152. +    return utf8str;
  153. +}
  154. +
  155. +static
  156. +wchar_t *utf8str2wcs(const char *utf8str)
  157. +{
  158. +    wchar_t *wstr;
  159. +    size_t utf8len;
  160. +    size_t wstr_len;
  161. +
  162. +    utf8len = strlen(utf8str);
  163. +    wstr_len = MultiByteToWideChar(CP_UTF8, 0,
  164. +        utf8str, (int)utf8len, NULL, 0);
  165. +
  166. +    wstr = malloc((wstr_len+1)*sizeof(wchar_t));
  167. +    if (!wstr)
  168. +        return NULL;
  169. +
  170. +    (void)MultiByteToWideChar(CP_UTF8, 0,
  171. +        utf8str, (int)utf8len, wstr, (int)wstr_len);
  172. +    wstr[wstr_len] = L'\0';
  173. +    return wstr;
  174. +}
  175. +
  176.  static DWORD ParseRemoteName(
  177.      IN LPTSTR pRemoteName,
  178.      IN OUT PMOUNT_OPTION_LIST pOptions,
  179. @@ -298,6 +344,7 @@ static DWORD ParseRemoteName(
  180.  {
  181.      DWORD result = NO_ERROR;
  182.      LPTSTR pEnd;
  183. +    wchar_t *mountstrmem = NULL;
  184.      int port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
  185.      PFILE_FULL_EA_INFORMATION port_option_val;
  186.      wchar_t remotename[NFS41_SYS_MAX_PATH_LEN];
  187. @@ -313,7 +360,27 @@ static DWORD ParseRemoteName(
  188.       * including port support (nfs://hostname@port/path/...)
  189.       */
  190.      if (!wcsncmp(premotename, TEXT("nfs://"), 6)) {
  191. -        uctx = url_parser_create_context(premotename, 0);
  192. +        char *premotename_utf8;
  193. +        wchar_t *hostname_wstr;
  194. +
  195. +        /*
  196. +         * URLs do urlencoding and urldecoding in bytes (see
  197. +         * RFC3986 ("Uniform Resource Identifier (URI): Generic
  198. +         * Syntax"), e.g. Unicode Euro symbol U+20AC is encoded
  199. +         * as "%E2%82%AC".
  200. +         * So we have to convert from our |wchar_t| string to
  201. +         * a UTF-8 byte string, do the URL processing on byte
  202. +         * level, and convert that UTF-8 byte string back to a
  203. +         * |wchar_t| string.
  204. +         */
  205. +        premotename_utf8 = wcs2utf8str(premotename);
  206. +        if (!premotename_utf8) {
  207. +            result = ERROR_NOT_ENOUGH_MEMORY;
  208. +            goto out;
  209. +        }
  210. +
  211. +        uctx = url_parser_create_context(premotename_utf8, 0);
  212. +        free(premotename_utf8);
  213.          if (!uctx) {
  214.              result = ERROR_NOT_ENOUGH_MEMORY;
  215.              goto out;
  216. @@ -333,11 +400,14 @@ static DWORD ParseRemoteName(
  217.  
  218.          if (uctx->hostport.port != -1)
  219.              port = uctx->hostport.port;
  220. -        else
  221. -            port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
  222.  
  223. -        (void)_sntprintf(premotename, NFS41_SYS_MAX_PATH_LEN, TEXT("%s"),
  224. -            uctx->hostport.hostname);
  225. +        hostname_wstr = utf8str2wcs(uctx->hostport.hostname);
  226. +        if (!hostname_wstr) {
  227. +            result = ERROR_NOT_ENOUGH_MEMORY;
  228. +            goto out;
  229. +        }
  230. +        (void)wcscpy_s(premotename, NFS41_SYS_MAX_PATH_LEN, hostname_wstr);
  231. +        free(hostname_wstr);
  232.          ConvertUnixSlashes(premotename);
  233.  
  234.          if (!uctx->path) {
  235. @@ -346,13 +416,13 @@ static DWORD ParseRemoteName(
  236.              goto out;
  237.          }
  238.  
  239. -        if (uctx->path[0] != TEXT('/')) {
  240. +        if (uctx->path[0] != '/') {
  241.              result = ERROR_BAD_ARGUMENTS;
  242.              (void)_ftprintf(stderr, TEXT("Relative nfs://-URLs are not supported\n"));
  243.              goto out;
  244.          }
  245.  
  246. -        pEnd = uctx->path;
  247. +        pEnd = mountstrmem = utf8str2wcs(uctx->path);
  248.          ConvertUnixSlashes(pEnd);
  249.      }
  250.      else
  251. @@ -535,6 +605,9 @@ out:
  252.      if (uctx) {
  253.          url_parser_free_context(uctx);
  254.      }
  255. +    if (mountstrmem) {
  256. +        free(mountstrmem);
  257. +    }
  258.      return result;
  259.  }
  260.  
  261. diff --git a/mount/urlparser1.c b/mount/urlparser1.c
  262. index 6a4f3f9..bdba1b5 100644
  263. --- a/mount/urlparser1.c
  264. +++ b/mount/urlparser1.c
  265. @@ -1,6 +1,9 @@
  266. -/* NFSv4.1 client for Windows
  267. +/*
  268. + * NFSv4.1 client for Windows
  269.   * Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org>
  270.   *
  271. + * Roland Mainz <roland.mainz@nrubsig.org>
  272. + *
  273.   * This library is free software; you can redistribute it and/or modify it
  274.   * under the terms of the GNU Lesser General Public License as published by
  275.   * the Free Software Foundation; either version 2.1 of the License, or (at
  276. @@ -16,17 +19,16 @@
  277.   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  278.   */
  279.  
  280. -
  281.  /* urlparser1.c - simple URL parser */
  282.  
  283.  #if ((__STDC_VERSION__-0) < 201710L)
  284.  #error Code requires ISO C17
  285.  #endif
  286.  
  287. -
  288. -#include <crtdbg.h>
  289. -#include <Windows.h>
  290.  #include <stdlib.h>
  291. +#include <stdbool.h>
  292. +#include <string.h>
  293. +#include <stdio.h>
  294.  
  295.  #include "urlparser1.h"
  296.  
  297. @@ -58,34 +60,84 @@
  298.   * "$"
  299.   */
  300.  
  301. -#define DBGNULLSTR(s) (((s)!=NULL)?(s):TEXT("<NULL>"))
  302. -#if 0
  303. +#define DBGNULLSTR(s) (((s)!=NULL)?(s):"<NULL>")
  304. +#if 1
  305.  #define D(x) x
  306.  #else
  307.  #define D(x)
  308.  #endif
  309.  
  310. -url_parser_context *url_parser_create_context(const TCHAR *in_url, unsigned int flags)
  311. +static
  312. +void urldecodestr(char *dst, const char *src, size_t len)
  313. +{
  314. +       /*
  315. +        * Unicode characters with a code point > 255 are encoded
  316. +        * as UTF-8 bytes
  317. +        */
  318. +#define isurlxdigit(c) \
  319. +       (((c) >= '0' && (c) <= '9') || \
  320. +       ((c) >= 'a' && (c) <= 'f') || \
  321. +       ((c) >= 'A' && (c) <= 'F'))
  322. +       char a, b;
  323. +       while (*src && len--) {
  324. +               if (len > 2) {
  325. +                       if ((*src == '%') &&
  326. +                               (a = src[1]) && (b = src[2])) {
  327. +                               if ((isurlxdigit(a) &&
  328. +                                       isurlxdigit(b))) {
  329. +                                       if (a >= 'a')
  330. +                                               a -= 'a'-'A';
  331. +                                       if (a >= 'A')
  332. +                                               a -= ('A' - 10);
  333. +                                       else
  334. +                                               a -= '0';
  335. +
  336. +                                       if (b >= 'a')
  337. +                                               b -= 'a'-'A';
  338. +                                       if (b >= 'A')
  339. +                                               b -= ('A' - 10);
  340. +                                       else
  341. +                                               b -= '0';
  342. +
  343. +                                       *dst++ = 16*a+b;
  344. +
  345. +                                       src+=3;
  346. +                                       len-=2;
  347. +                                       continue;
  348. +                               }
  349. +                       }
  350. +                }
  351. +               if (*src == '+') {
  352. +                       *dst++ = ' ';
  353. +                       src++;
  354. +                       continue;
  355. +                }
  356. +               *dst++ = *src++;
  357. +       }
  358. +       *dst++ = '\0';
  359. +}
  360. +
  361. +url_parser_context *url_parser_create_context(const char *in_url, unsigned int flags)
  362.  {
  363.         url_parser_context *uctx;
  364. -       TCHAR *s;
  365. +       char *s;
  366.         size_t in_url_len;
  367.         size_t context_len;
  368.  
  369.         if (!in_url)
  370.                 return NULL;
  371.  
  372. -       in_url_len = _tcsclen(in_url);
  373. +       in_url_len = strlen(in_url);
  374.  
  375.         context_len = sizeof(url_parser_context) +
  376. -               (((in_url_len+1)*5L*sizeof(TCHAR)));
  377. +               ((in_url_len+1)*5);
  378.         uctx = malloc(context_len);
  379.         if (!uctx)
  380.                 return NULL;
  381.  
  382.         s = (void *)(uctx+1);
  383.         uctx->in_url = s;               s+= in_url_len+1;
  384. -       (void)_tcscpy(uctx->in_url, in_url);
  385. +       (void)strcpy(uctx->in_url, in_url);
  386.         uctx->scheme = s;               s+= in_url_len+1;
  387.         uctx->login.username = s;       s+= in_url_len+1;
  388.         uctx->hostport.hostname = s;    s+= in_url_len+1;
  389. @@ -97,38 +149,37 @@ url_parser_context *url_parser_create_context(const TCHAR *in_url, unsigned int
  390.  
  391.  int url_parser_parse(url_parser_context *uctx)
  392.  {
  393. -       D((void)_tprintf(TEXT("## parser in_url='%s'\n"), uctx->in_url));
  394. +       D((void)fprintf(stderr, "## parser in_url='%s'\n", uctx->in_url));
  395.  
  396. -       TCHAR *s;
  397. -       const TCHAR *urlstr = uctx->in_url;
  398. +       char *s;
  399. +       const char *urlstr = uctx->in_url;
  400.         size_t slen;
  401.  
  402. -       s = _tcsstr(urlstr, TEXT("://"));
  403. +       s = strstr(urlstr, "://");
  404.         if (!s) {
  405. -               D((void)_tprintf(TEXT("url_parser: Not an URL\n")));
  406. +               D((void)fprintf(stderr, "url_parser: Not an URL\n"));
  407.                 return -1;
  408.         }
  409.  
  410.         slen = s-urlstr;
  411. -       (void)memcpy(uctx->scheme, urlstr, slen*sizeof(TCHAR));
  412. -       uctx->scheme[slen] = TEXT('\0');
  413. +       (void)memcpy(uctx->scheme, urlstr, slen);
  414. +       uctx->scheme[slen] = '\0';
  415.         urlstr += slen + 3;
  416.  
  417. -       D((void)_tprintf(TEXT("scheme='%s', rest='%s'\n"), uctx->scheme, urlstr));
  418. +       D((void)fprintf(stdout, "scheme='%s', rest='%s'\n", uctx->scheme, urlstr));
  419.  
  420. -       s = _tcsstr(urlstr, TEXT("@"));
  421. +       s = strstr(urlstr, "@");
  422.         if (s) {
  423.                 /* URL has user/password */
  424.                 slen = s-urlstr;
  425. -               (void)memcpy(uctx->login.username, urlstr, slen*sizeof(TCHAR));
  426. -               uctx->login.username[slen] = TEXT('\0');
  427. +               urldecodestr(uctx->login.username, urlstr, slen);
  428.                 urlstr += slen + 1;
  429.  
  430. -               s = _tcsstr(uctx->login.username, TEXT(":"));
  431. +               s = strstr(uctx->login.username, ":");
  432.                 if (s) {
  433.                         /* found passwd */
  434.                         uctx->login.passwd = s+1;
  435. -                       *s = TEXT('\0');
  436. +                       *s = '\0';
  437.                 }
  438.                 else
  439.                 {
  440. @@ -136,7 +187,7 @@ int url_parser_parse(url_parser_context *uctx)
  441.                 }
  442.  
  443.                 /* catch password-only URLs */
  444. -               if (uctx->login.username[0] == TEXT('\0'))
  445. +               if (uctx->login.username[0] == '\0')
  446.                         uctx->login.username = NULL;
  447.         }
  448.         else
  449. @@ -145,17 +196,16 @@ int url_parser_parse(url_parser_context *uctx)
  450.                 uctx->login.passwd = NULL;
  451.         }
  452.  
  453. -       D((void)_tprintf(TEXT("login='%s', passwd='%s', rest='%s'\n"),
  454. +       D((void)fprintf(stdout, "login='%s', passwd='%s', rest='%s'\n",
  455.                 DBGNULLSTR(uctx->login.username),
  456.                 DBGNULLSTR(uctx->login.passwd),
  457.                 DBGNULLSTR(urlstr)));
  458.  
  459. -       s = _tcsstr(urlstr, TEXT("/"));
  460. +       s = strstr(urlstr, "/");
  461.         if (s) {
  462.                 /* URL has hostport */
  463.                 slen = s-urlstr;
  464. -               (void)memcpy(uctx->hostport.hostname, urlstr, slen*sizeof(TCHAR));
  465. -               uctx->hostport.hostname[slen] = TEXT('\0');
  466. +               urldecodestr(uctx->hostport.hostname, urlstr, slen);
  467.                 urlstr += slen + 1;
  468.  
  469.                 /*
  470. @@ -163,29 +213,29 @@ int url_parser_parse(url_parser_context *uctx)
  471.                  * IPv6 addresses
  472.                  */
  473.                 s = uctx->hostport.hostname;
  474. -               if (s[0] == TEXT('['))
  475. -                       s = _tcsstr(s, TEXT("]"));
  476. +               if (s[0] == '[')
  477. +                       s = strstr(s, "]");
  478.  
  479.                 if (s == NULL) {
  480. -                       D((void)_tprintf(TEXT("url_parser: Unmatched '[' in hostname\n")));
  481. +                       D((void)fprintf(stderr, "url_parser: Unmatched '[' in hostname\n"));
  482.                         return -1;
  483.                 }
  484.  
  485. -               s = _tcsstr(s, TEXT(":"));
  486. +               s = strstr(s, ":");
  487.                 if (s) {
  488.                         /* found port number */
  489. -                       uctx->hostport.port = _tstoi(s+1);
  490. -                       *s = TEXT('\0');
  491. +                       uctx->hostport.port = atoi(s+1);
  492. +                       *s = '\0';
  493.                 }
  494.         }
  495.         else
  496.         {
  497. -               (void)_tcscpy(uctx->hostport.hostname, urlstr);
  498. +               (void)strcpy(uctx->hostport.hostname, urlstr);
  499.                 uctx->path = NULL;
  500.                 urlstr = NULL;
  501.         }
  502.  
  503. -       D((void)_tprintf(TEXT("hostport='%s', port=%d, rest='%s'\n"),
  504. +       D((void)fprintf(stdout, "hostport='%s', port=%d, rest='%s'\n",
  505.                 DBGNULLSTR(uctx->hostport.hostname),
  506.                 uctx->hostport.port,
  507.                 DBGNULLSTR(urlstr)));
  508. @@ -194,8 +244,8 @@ int url_parser_parse(url_parser_context *uctx)
  509.                 return 0;
  510.         }
  511.  
  512. -       (void)_tcscpy(uctx->path, urlstr);
  513. -       D((void)_tprintf(TEXT("path='%s'\n"), uctx->path));
  514. +       urldecodestr(uctx->path, urlstr, strlen(urlstr));
  515. +       D((void)fprintf(stdout, "path='%s'\n", uctx->path));
  516.  
  517.         return 0;
  518.  }
  519. @@ -204,3 +254,53 @@ void url_parser_free_context(url_parser_context *c)
  520.  {
  521.         free(c);
  522.  }
  523. +
  524. +#ifdef TEST_URLPARSER
  525. +static
  526. +void test_url_parser(const char *instr)
  527. +{
  528. +       url_parser_context *c;
  529. +
  530. +       c = url_parser_create_context(instr, 0);
  531. +
  532. +       (void)url_parser_parse(c);
  533. +
  534. +       (void)fputc('\n', stdout);
  535. +
  536. +       url_parser_free_context(c);
  537. +}
  538. +
  539. +int main(int ac, char *av[])
  540. +{
  541. +       (void)puts("#start");
  542. +
  543. +       (void)setvbuf(stdout, NULL, _IONBF, 0);
  544. +       (void)setvbuf(stderr, NULL, _IONBF, 0);
  545. +
  546. +       (void)test_url_parser("foo://hostbar/baz");
  547. +       (void)test_url_parser("foo://myuser@hostbar/baz");
  548. +       (void)test_url_parser("foo://myuser:mypasswd@hostbar/baz");
  549. +       (void)test_url_parser("foo://Vorname+Nachname:mypasswd@hostbar/baz");
  550. +       (void)test_url_parser("foo://Vorname%20Nachname:mypasswd@hostbar/baz%");
  551. +       (void)test_url_parser("foo://myuser:mypasswd@hostbar:666/baz");
  552. +       (void)test_url_parser("foo://myuser:mypasswd@hostbar:666//baz");
  553. +       (void)test_url_parser("foo://myuser:mypasswd@[fe80::21b:1bff:fec3:7713]:666/baz");
  554. +       (void)test_url_parser("foo://:mypasswd2@hostbar2:667/baf");
  555. +       (void)test_url_parser("foo://hostbar/euro/symbol/%E2%82%AC/here");
  556. +       (void)test_url_parser("foo://hostbar");
  557. +       (void)test_url_parser("foo://hostbar:93");
  558. +       (void)test_url_parser("nfs://hostbar:93/relativepath/a");
  559. +       (void)test_url_parser("nfs://hostbar:93//absolutepath/a");
  560. +       (void)test_url_parser("nfs://hostbar:93//absolutepath/blank%20path/a");
  561. +       (void)test_url_parser("nfs://hostbar:93//absolutepath/blank+path/a");
  562. +
  563. +
  564. +       (void)test_url_parser("foo://");
  565. +       (void)test_url_parser("typo:/hostbar");
  566. +       (void)test_url_parser("wrong");
  567. +
  568. +       (void)puts("#done");
  569. +
  570. +       return EXIT_SUCCESS;
  571. +}
  572. +#endif /* !TEST_URLPARSER */
  573. diff --git a/mount/urlparser1.h b/mount/urlparser1.h
  574. index ea715d2..8ed0f91 100644
  575. --- a/mount/urlparser1.h
  576. +++ b/mount/urlparser1.h
  577. @@ -1,6 +1,9 @@
  578. -/* NFSv4.1 client for Windows
  579. +/*
  580. + * NFSv4.1 client for Windows
  581.   * Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org>
  582.   *
  583. + * Roland Mainz <roland.mainz@nrubsig.org>
  584. + *
  585.   * This library is free software; you can redistribute it and/or modify it
  586.   * under the terms of the GNU Lesser General Public License as published by
  587.   * the Free Software Foundation; either version 2.1 of the License, or (at
  588. @@ -16,30 +19,31 @@
  589.   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  590.   */
  591.  
  592. +/* urlparser1.h - header for simple URL parser */
  593. +
  594.  #ifndef __URLPARSER1_H__
  595.  #define __URLPARSER1_H__
  596.  
  597. -#include <tchar.h>
  598. +#include <stdlib.h>
  599.  
  600.  typedef
  601.  struct _url_parser_context {
  602. -       TCHAR *in_url;
  603. +       char *in_url;
  604.  
  605. -       TCHAR *scheme;
  606. +       char *scheme;
  607.         struct {
  608. -               TCHAR *username;
  609. -               TCHAR *passwd;
  610. +               char *username;
  611. +               char *passwd;
  612.         } login;
  613.         struct {
  614. -               TCHAR *hostname;
  615. +               char *hostname;
  616.                 signed int port;
  617.         } hostport;
  618. -       TCHAR *path;
  619. +       char *path;
  620.  } url_parser_context;
  621.  
  622. -
  623.  /* Prototypes */
  624. -url_parser_context *url_parser_create_context(const TCHAR *in_url, unsigned int flags);
  625. +url_parser_context *url_parser_create_context(const char *in_url, unsigned int flags);
  626.  int url_parser_parse(url_parser_context *uctx);
  627.  void url_parser_free_context(url_parser_context *c);
  628.  
  629. --
  630. 2.43.0
  631.  
  632. From bf076ef13ad325d961776e499aa4b87e0b988f34 Mon Sep 17 00:00:00 2001
  633. From: Roland Mainz <roland.mainz@nrubsig.org>
  634. Date: Thu, 25 Jan 2024 13:28:52 +0100
  635. Subject: [PATCH 3/4] mount: Disable debug output
  636.  
  637. Disable debug output in nfs_mount.exe
  638.  
  639. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  640. ---
  641. mount/mount.c | 2 --
  642.  1 file changed, 2 deletions(-)
  643.  
  644. diff --git a/mount/mount.c b/mount/mount.c
  645. index 94d1a66..1656508 100644
  646. --- a/mount/mount.c
  647. +++ b/mount/mount.c
  648. @@ -292,8 +292,6 @@ static void ConvertUnixSlashes(
  649.  }
  650.  
  651.  
  652. -#define DEBUG_MOUNT 1
  653. -
  654.  static
  655.  char *wcs2utf8str(const wchar_t *wstr)
  656.  {
  657. --
  658. 2.43.0
  659.  
  660. From 2a9d9c7719edd1213c70d1fb7a18a10f3831bc55 Mon Sep 17 00:00:00 2001
  661. From: Roland Mainz <roland.mainz@nrubsig.org>
  662. Date: Thu, 25 Jan 2024 13:36:46 +0100
  663. Subject: [PATCH 4/4] mount: Disable DEBUG mode in URL parser
  664.  
  665. Disable DEBUG mode in URL parser
  666.  
  667. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  668. ---
  669. mount/urlparser1.c | 2 +-
  670.  1 file changed, 1 insertion(+), 1 deletion(-)
  671.  
  672. diff --git a/mount/urlparser1.c b/mount/urlparser1.c
  673. index bdba1b5..3de1047 100644
  674. --- a/mount/urlparser1.c
  675. +++ b/mount/urlparser1.c
  676. @@ -61,7 +61,7 @@
  677.   */
  678.  
  679.  #define DBGNULLSTR(s) (((s)!=NULL)?(s):"<NULL>")
  680. -#if 1
  681. +#if 0
  682.  #define D(x) x
  683.  #else
  684.  #define D(x)
  685. --
  686. 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