pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: hostname address lookup, installer, stability and misc fixes, 2023-11-07
Posted by Anonymous on Wed 8th Nov 2023 10:53
raw | new post

  1. From 07c872bfd7b43ad19c9dc211996b38df55fd986e Mon Sep 17 00:00:00 2001
  2. From: Cedric Blancher <cedric.blancher@gmail.com>
  3. Date: Tue, 7 Nov 2023 14:50:11 +0100
  4. Subject: [PATCH 1/4] daemon: Fix random hostname failures + debug output for
  5.  hostname lookup
  6.  
  7. Fix random getaddrinfo() failures by replacing it with
  8. GetAddrInfoExA() and add dprintf() output to see what hostname
  9. address lookup is doing.
  10.  
  11. Also print all returned addresses and not only the first one,
  12. per Rolands review suggestion.
  13.  
  14. Signed-off-by: Roland Mainz <roland.mainz@nrubsig.org>
  15. ---
  16. daemon/nfs41_server.c | 81 ++++++++++++++++++++++++++++++++++---------
  17.  1 file changed, 65 insertions(+), 16 deletions(-)
  18.  
  19. diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
  20. index ef8f0ac..db2d2b6 100644
  21. --- a/daemon/nfs41_server.c
  22. +++ b/daemon/nfs41_server.c
  23. @@ -279,37 +279,70 @@ int nfs41_server_resolve(
  24.  {
  25.      int status = ERROR_BAD_NET_NAME;
  26.      char service[16];
  27. -    struct addrinfo hints = { 0 }, *res, *info;
  28. +    struct addrinfoexA hints = { 0 }, *res, *info;
  29.      struct netconfig *nconf;
  30.      struct netbuf addr;
  31.      char *netid, *uaddr;
  32. +    int wse; /* Windows Socket Error */
  33. +    int retry_getaddrinfoex_counter = 0;
  34.  
  35. -    dprintf(SRVLVL, "--> nfs41_server_resolve(%s:%u)\n",
  36. +    dprintf(SRVLVL, "--> nfs41_server_resolve('%s':%u)\n",
  37.          hostname, port);
  38.  
  39.      addrs->count = 0;
  40.  
  41. -    StringCchPrintfA(service, 16, "%u", port);
  42. +    /*
  43. +     * Windows (10) /cygdrive/c/Windows/System32/drivers/etc/services
  44. +     * only has an UDP entry for NFS ("2049/udp") but none for TCP,
  45. +     * so we have to pass the numeric value here.
  46. +     */
  47. +    StringCchPrintfA(service, sizeof(service), "%u", (int)port);
  48.  
  49.      /* request a list of tcp addrs for the given hostname,port */
  50.      hints.ai_family = AF_UNSPEC;
  51.      hints.ai_socktype = SOCK_STREAM;
  52.      hints.ai_protocol = IPPROTO_TCP;
  53. +    /* AI_NUMERICSERV - no service name resolution, we pass a number */
  54. +    hints.ai_flags    |= AI_NUMERICSERV;
  55. +#if 1 /* experimental */
  56. +    hints.ai_flags    |= AI_FILESERVER;
  57. +#endif
  58. +
  59. +retry_getaddrinfoex:
  60. +    wse = GetAddrInfoExA(hostname, service, 0, NULL, &hints, &res,
  61. +        NULL, NULL, NULL, NULL);
  62. +    if (wse != 0) {
  63. +        dprintf(SRVLVL, "GetAddrInfoExA() failed with wse=%d/'%s'\n",
  64. +            wse, gai_strerrorA(wse));
  65. +        if ((wse == WSATRY_AGAIN) && (retry_getaddrinfoex_counter < 4)) {
  66. +            dprintf(SRVLVL, "GetAddrInfoExA() returned WSATRY_AGAIN, "
  67. +                "retry %d with delay...\n",
  68. +                retry_getaddrinfoex_counter);
  69. +
  70. +            retry_getaddrinfoex_counter++;
  71. +            Sleep(500*retry_getaddrinfoex_counter);
  72. +            goto retry_getaddrinfoex;
  73. +        }
  74.  
  75. -    if (getaddrinfo(hostname, service, &hints, &res) != 0)
  76.          goto out;
  77. +    }
  78.  
  79.      for (info = res; info != NULL; info = info->ai_next) {
  80. +        dprintf(SRVLVL, "GetAddrInfoExA() returned: info.{ai_family=%d}\n",
  81. +            info->ai_family);
  82. +
  83.          /* find the appropriate entry in /etc/netconfig */
  84.          switch (info->ai_family) {
  85. -        case AF_INET:  netid = "tcp";  break;
  86. -        case AF_INET6: netid = "tcp6"; break;
  87. -        default: continue;
  88. +            case AF_INET:  netid = "tcp";  break;
  89. +            case AF_INET6: netid = "tcp6"; break;
  90. +            default: continue;
  91.          }
  92.  
  93.          nconf = getnetconfigent(netid);
  94. -        if (nconf == NULL)
  95. +        if (nconf == NULL) {
  96. +            dprintf(SRVLVL, "getnetconfigent(netid='%s') failed.\n", netid);
  97.              continue;
  98. +        }
  99.  
  100.          /* convert to a transport-independent universal address */
  101.          addr.buf = info->ai_addr;
  102. @@ -318,8 +351,10 @@ int nfs41_server_resolve(
  103.          uaddr = taddr2uaddr(nconf, &addr);
  104.          freenetconfigent(nconf);
  105.  
  106. -        if (uaddr == NULL)
  107. +        if (uaddr == NULL) {
  108. +            dprintf(SRVLVL, "taddr2uaddr() failed.\n");
  109.              continue;
  110. +        }
  111.  
  112.          StringCchCopyA(addrs->arr[addrs->count].netid,
  113.              NFS41_NETWORK_ID_LEN+1, netid);
  114. @@ -328,16 +363,30 @@ int nfs41_server_resolve(
  115.          freeuaddr(uaddr);
  116.  
  117.          status = NO_ERROR;
  118. -        if (++addrs->count >= NFS41_ADDRS_PER_SERVER)
  119. +        if (++addrs->count >= NFS41_ADDRS_PER_SERVER) {
  120. +            dprintf(SRVLVL, "error: too many NFS41_ADDRS_PER_SERVER.\n");
  121.              break;
  122. +        }
  123.      }
  124. -    freeaddrinfo(res);
  125. +    FreeAddrInfoEx(res);
  126.  out:
  127. -    if (status)
  128. -        dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
  129. +    if (status) {
  130. +        dprintf(SRVLVL, "<-- nfs41_server_resolve('%s':%u) returning "
  131.              "error %d\n", hostname, port, status);
  132. -    else
  133. -        dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
  134. -            "OK %s\n", hostname, port, addrs->arr[0].uaddr);
  135. +    }
  136. +    else {
  137. +        unsigned int i;
  138. +        char buff[256];
  139. +        char *b = buff;
  140. +
  141. +        for (i=0 ; i < addrs->count ; i++) {
  142. +            b+=snprintf(b,
  143. +                ((sizeof(buff)-1) - (b-buff)),
  144. +                "'%s', ", addrs->arr[i].uaddr);
  145. +        }
  146. +
  147. +        dprintf(SRVLVL, "<-- nfs41_server_resolve('%s':%u) returning "
  148. +            "OK { %s }\n", hostname, port, buff);
  149. +    }
  150.      return status;
  151.  }
  152. --
  153. 2.42.1
  154.  
  155. From 26bf04263fb89bf6540ce21ce83357bf9a31ba1f Mon Sep 17 00:00:00 2001
  156. From: Martin Wege <martin.l.wege@gmail.com>
  157. Date: Tue, 7 Nov 2023 15:14:55 +0100
  158. Subject: [PATCH 2/4] install: Fix crashes in nfs_install
  159.  
  160. - Fix crashes in nfs_install (which is used to add "nfs41_driver"
  161. to /HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/NetworkProvider/Order/ProviderOrder)
  162. - Add debug output for nfs_install to cygwin/devel/msnfs41client.bash
  163.  
  164. Signed-off-by: Roland Mainz <roland.mainz@nrubsig.org>
  165. ---
  166. cygwin/devel/msnfs41client.bash |  6 ++++++
  167.  install/nfs_install.c           |  2 +-
  168.  install/nfsreginst.c            | 14 +++++++++-----
  169.  install/nfsreginst.h            |  1 +
  170.  4 files changed, 17 insertions(+), 6 deletions(-)
  171.  
  172. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  173. index 23ca032..c953ebc 100644
  174. --- a/cygwin/devel/msnfs41client.bash
  175. +++ b/cygwin/devel/msnfs41client.bash
  176. @@ -64,7 +64,13 @@ function nfsclient_install
  177.                 # install.bat needs PATH to include $PWD
  178.                 PATH="$PWD:$PATH" cmd /c install.bat
  179.         else
  180. +               # devel: set default in case "nfs_install" ruined it:
  181. +               #regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/NetworkProvider/Order/ProviderOrder' 'RDPNP,LanmanWorkstation,webclient'
  182. +
  183. +               printf 'before nfs_install: ProviderOrder="%s"\n' "$( strings -a '/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/NetworkProvider/Order/ProviderOrder')"
  184.                 nfs_install
  185. +               printf 'after nfs_install:  ProviderOrder="%s"\n' "$( strings -a '/proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/NetworkProvider/Order/ProviderOrder')"
  186. +
  187.                 rundll32 setupapi.dll,InstallHinfSection DefaultInstall 132 ./nfs41rdr.inf
  188.         fi
  189.  
  190. diff --git a/install/nfs_install.c b/install/nfs_install.c
  191. index d1e6b74..50b1ce2 100644
  192. --- a/install/nfs_install.c
  193. +++ b/install/nfs_install.c
  194. @@ -33,7 +33,7 @@
  195.  
  196.  void __cdecl _tmain(int argc, TCHAR *argv[])
  197.  {
  198. -       if(argc == 1 || atoi(argv[1]) == 1)
  199. +       if(argc == 1 || _tstoi(argv[1]) == 1)
  200.         {
  201.                 RdrSetupProviderOrder();
  202.         }
  203. diff --git a/install/nfsreginst.c b/install/nfsreginst.c
  204. index f4bb3e4..e7ad7b4 100644
  205. --- a/install/nfsreginst.c
  206. +++ b/install/nfsreginst.c
  207. @@ -46,7 +46,7 @@ BOOL RdrSetupProviderOrder( void )
  208.      while( RdrRemoveProviderFromOrder() ) {};
  209.  
  210.      len = RdrGetProviderOrderString( &pOrderString ) * sizeof(TCHAR);
  211. -    if ( len > 0 && pOrderString )
  212. +    if ( (len > 0) && pOrderString )
  213.      {
  214.          len += sizeof( PROVIDER_NAME ) + (2 * sizeof(TCHAR)); // add 2 for comma delimeter and null
  215.          pNewOrderString = malloc( len );
  216. @@ -74,11 +74,14 @@ BOOL RdrSetupProviderOrder( void )
  217.  
  218.  ULONG_PTR RdrGetProviderOrderString( __out LPTSTR *OrderString )
  219.  {
  220. -    HKEY hOrderKey;
  221. +    HKEY hOrderKey = NULL;
  222.      ULONG_PTR len = 0;
  223.  
  224.      if ( OpenKey( PROVIDER_ORDER_KEY, &hOrderKey ) )
  225.      {
  226. +        if (hOrderKey == NULL)
  227. +            return 0;
  228. +
  229.          ReadRegistryKeyValues( hOrderKey,
  230.                                 sizeof(ProviderOrderKeyValues) / sizeof(REGENTRY),
  231.                                 ProviderOrderKeyValues);
  232. @@ -99,7 +102,7 @@ BOOL RdrSetProviderOrderString( __in LPTSTR OrderString )
  233.  
  234.      if ( CreateKey( PROVIDER_ORDER_KEY, &hOrderKey ) )
  235.      {
  236. -        ProviderOrderKeyValues[0].dwLength = ( lstrlen( OrderString ) + 1 ) * sizeof( TCHAR );
  237. +        ProviderOrderKeyValues[0].dwLength = ( _tcsclen( OrderString ) + 1 ) * sizeof( TCHAR );
  238.          ProviderOrderKeyValues[0].pvValue = OrderString;
  239.          WriteRegistryKeyValues( hOrderKey,
  240.                                  sizeof(ProviderOrderKeyValues) / sizeof(REGENTRY),
  241. @@ -115,7 +118,7 @@ BOOL RdrSetProviderOrderString( __in LPTSTR OrderString )
  242.  
  243.  BOOL RdrRemoveProviderFromOrder( void )
  244.  {
  245. -    LPTSTR pCompare, OrderString, pOrig, Provider = PROVIDER_NAME;
  246. +    LPTSTR pCompare = NULL, OrderString = NULL, pOrig = NULL, Provider = PROVIDER_NAME;
  247.      BOOL match = FALSE;
  248.      ULONG_PTR len = 0;
  249.  
  250. @@ -127,7 +130,7 @@ BOOL RdrRemoveProviderFromOrder( void )
  251.  
  252.          while ( *OrderString )
  253.          {
  254. -            if ( toupper(*OrderString) != toupper(*pCompare++) )
  255. +            if ( _toupper(*OrderString) != _toupper(*pCompare++) )
  256.              {
  257.                  pCompare = Provider;
  258.                  while ( ( *OrderString != TEXT(',') ) && ( *OrderString != TEXT('\0') ) )
  259. @@ -141,6 +144,7 @@ BOOL RdrRemoveProviderFromOrder( void )
  260.                  if ( ( *OrderString == TEXT(',') ) || ( *OrderString == TEXT('\0') ) )
  261.                  {
  262.                      LPTSTR pNewString;
  263. +                    len += 4096;
  264.                      pNewString = malloc( len ); //Yes, this is a little larger than necessary
  265.                      //No, I don't care that much
  266.                      StringCchCopy(pNewString, len, pOrig);
  267. diff --git a/install/nfsreginst.h b/install/nfsreginst.h
  268. index 93bf954..c328b11 100644
  269. --- a/install/nfsreginst.h
  270. +++ b/install/nfsreginst.h
  271. @@ -33,6 +33,7 @@ Abstract:
  272.  
  273.  #include <windows.h>
  274.  #include <stdlib.h>
  275. +#include <tchar.h>
  276.  #include <strsafe.h>
  277.  
  278.  #include "nfs41_driver.h"
  279. --
  280. 2.42.1
  281.  
  282. From 2f25d58571c5989391fb596693b42a5c9050d075 Mon Sep 17 00:00:00 2001
  283. From: Roland Mainz <roland.mainz@nrubsig.org>
  284. Date: Tue, 7 Nov 2023 18:29:15 +0100
  285. Subject: [PATCH 3/4] daemon: |handle_mount()| should reject mount requests
  286.  without paths
  287.  
  288. |handle_mount()| should reject mount requests without |args->path|.
  289.  
  290. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  291. ---
  292. daemon/mount.c | 8 ++++++++
  293.  1 file changed, 8 insertions(+)
  294.  
  295. diff --git a/daemon/mount.c b/daemon/mount.c
  296. index 4870e09..9625387 100644
  297. --- a/daemon/mount.c
  298. +++ b/daemon/mount.c
  299. @@ -69,6 +69,14 @@ static int handle_mount(void *daemon_context, nfs41_upcall *upcall)
  300.      nfs41_client *client;
  301.      nfs41_path_fh file;
  302.  
  303. +    EASSERT(args->hostport != NULL);
  304. +
  305. +    if ((args->path == NULL) || (strlen(args->path) == 0)) {
  306. +        eprintf("handle_mount: empty mount root\n");
  307. +        status = ERROR_BAD_NETPATH;
  308. +        goto out;
  309. +    }
  310. +
  311.      (void)strcpy_s(hostname, sizeof(hostname), args->hostport);
  312.      if (s = strchr(hostname, '@')) {
  313.          *s++ = '\0';
  314. --
  315. 2.42.1
  316.  
  317. From 7815c2f0c27bcef2242a2320c74581ba7f50d261 Mon Sep 17 00:00:00 2001
  318. From: Roland Mainz <roland.mainz@nrubsig.org>
  319. Date: Tue, 7 Nov 2023 18:33:04 +0100
  320. Subject: [PATCH 4/4] msnfs41client.bash: Consolidate server args in a shell
  321.  array
  322.  
  323. cygwin/devel/msnfs41client.bash: Consolidate server args in a
  324. shell array, which is much easier to maintain.
  325.  
  326. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  327. ---
  328. cygwin/devel/msnfs41client.bash | 35 +++++++++++++++++++++++++--------
  329.  1 file changed, 27 insertions(+), 8 deletions(-)
  330.  
  331. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  332. index c953ebc..8f9bf14 100644
  333. --- a/cygwin/devel/msnfs41client.bash
  334. +++ b/cygwin/devel/msnfs41client.bash
  335. @@ -114,6 +114,13 @@ function nfsclient_rundeamon
  336.         set -o xtrace
  337.         set -o nounset
  338.  
  339. +       typeset -a nfsd_args=(
  340. +               'nfsd_debug.exe'
  341. +               '-d' '0'
  342. +               '--noldap'
  343. +               #'--gid' '1616' '--uid' '1616'
  344. +       )
  345. +
  346.         #
  347.         # cdb cheat sheet:
  348.         #
  349. @@ -123,12 +130,14 @@ function nfsclient_rundeamon
  350.         #
  351.  
  352.         if false ; then
  353. -               gdb -ex=run --args nfsd_debug -d 0 --noldap #--gid 1616 --uid 1616
  354. -       else
  355. +               gdb -ex=run --args "${nfsd_args[@]}"
  356. +       elif false ; then
  357.                 export _NT_ALT_SYMBOL_PATH="$(cygpath -w "$PWD");srv*https://msdl.microsoft.com/download/symbols"
  358.                 # use '!gflag +full;g' for heap tests, eats lots of memory
  359. -               cdb -c '!gflag +soe;sxe -c "kp;gn" *;g' "$(cygpath -w "$PWD/nfsd_debug.exe")" -d 0 --noldap #--gid 1616 --uid 1616
  360. -       fi
  361. +               cdb -c '!gflag +soe;sxe -c "kp;gn" *;g' "$(cygpath -w "$PWD/${nfsd_args[0]}")" "${nfsd_args[@]:1}"
  362. +       else
  363. +               "${nfsd_args[@]}"
  364. +        fi
  365.         return $?
  366.  }
  367.  
  368. @@ -137,13 +146,23 @@ function nfsclient_system_rundeamon
  369.         set -o xtrace
  370.         set -o nounset
  371.  
  372. +       typeset -a nfsd_args=(
  373. +               'nfsd_debug.exe'
  374. +               '-d' '0'
  375. +               '--noldap'
  376. +               #'--gid' '1616' '--uid' '1616'
  377. +       )
  378. +
  379. +
  380.         if false ; then
  381. -               su_system gdb -ex=run --args nfsd_debug -d 0 --noldap #--gid 1616 --uid 1616
  382. -       else
  383. +               su_system gdb -ex=run --args "${nfsd_args[@]}"
  384. +       elif false ; then
  385.                 export _NT_ALT_SYMBOL_PATH="$(cygpath -w "$PWD");srv*https://msdl.microsoft.com/download/symbols"
  386.                 # use '!gflag +full;g' for heap tests, eats lots of memory
  387. -               su_system cdb -c '!gflag +soe;sxe -c "kp;gn" *;g' "$(cygpath -w "$PWD/nfsd_debug.exe")" -d 0 --noldap #--gid 1616 --uid 1616
  388. -       fi
  389. +               su_system cdb -c '!gflag +soe;sxe -c "kp;gn" *;g' "$(cygpath -w "$PWD/${nfsd_args[0]}")" "${nfsd_args[@]:1}"
  390. +       else
  391. +               "${nfsd_args[@]}"
  392. +        fi
  393.         return $?
  394.  }
  395.  
  396. --
  397. 2.42.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