pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Remove "insecure" NFS export requirement, /etc/ksh.kshrc+misc, 2024-03-27
Posted by Anonymous on Wed 27th Mar 2024 16:43
raw | new post

  1. From 9c5fb530ae6653bc0e4a8681cee237d06e8be9ff Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 27 Mar 2024 16:23:05 +0100
  4. Subject: [PATCH 1/4] libtirpc: Support for Win32 privileged port reservation
  5.  (TCP port < 1024)
  6.  
  7. Add support for Win32 (privileged) TCP port reservation via
  8. |SIO_ACQUIRE_PORT_RESERVATION|/|SIO_ASSOCIATE_PORT_RESERVATION|,
  9. so we can use a TCP port < 1024. This allows us to use NFS
  10. server export WITHOUT the "insecure" export option.
  11.  
  12. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  13. ---
  14. cygwin/README.bintarball.txt |  18 ++--
  15.  libtirpc/src/bindresvport.c  | 174 ++++++++++++++++++++++++++++++-----
  16.  2 files changed, 156 insertions(+), 36 deletions(-)
  17.  
  18. diff --git a/cygwin/README.bintarball.txt b/cygwin/README.bintarball.txt
  19. index b1b66e0..9fa5222 100644
  20. --- a/cygwin/README.bintarball.txt
  21. +++ b/cygwin/README.bintarball.txt
  22. @@ -129,10 +129,6 @@ $ (set -o xtrace ; cd / && tar -tf ~/download/${bintarball.base_filename}.tar.bz
  23.  $ /sbin/msnfs41client run_daemon
  24.  
  25.  # Mount a filesystem and use it
  26. -# - requires that NFSv4 server accepts connections from a TCP port
  27. -# number > 1024, which can be archived on Linux with the "insecure"
  28. -# export option in /etc/exports, or "resvport" on Solaris/Illumos
  29. -# (see nfs(5))
  30.  $ /sbin/nfs_mount -o rw N 10.49.20.110:/net_tmpfs2
  31.  Successfully mounted '10.49.20.110@2049' to drive 'N:'
  32.  $ cd /cygdrive/n/
  33. @@ -230,15 +226,15 @@ $ /sbin/nfs_mount
  34.    A::EVERYONE@:rtcy
  35.    ---- snip ----
  36.  
  37. -- nfs_mount only works when the NFSv4 server allows connections from
  38. -  ports >= 1024, as Windows does not allow the Windows NFSv4 client
  39. -  to use a "privileged port" (i.e. TCP port number < 1024)).
  40. +- nfs_mount.exe vs. reserved ports:
  41.    By default the NFSv4 server on Solaris, Illumos, Linux
  42.    etc. only accepts connections if the NFSv4 client uses a
  43. -  "privileged (TCP) port", i.e. a port number < 1024.
  44. -  This can be worked around by using the "insecure" export option in
  45. -  Linux /etc/exports, which allows connections from ports >= 1024,
  46. -  and for Solaris/Illumos see nfs(5), option "resvport".
  47. +  "privileged (TCP) port", i.e. using a TCP port number < 1024.
  48. +  If nfsd.exe/nfsd_debug.exe is started without the Windows priviledge
  49. +  to use reserved ports, then a mount attempt can fail.
  50. +  This can be worked around on the NFSv4 server side - on Linux using
  51. +  the "insecure" export option in  /etc/exports and on Solaris/Illumos
  52. +  using export option "resvport" (see nfs(5)).
  53.  
  54.  
  55.  #
  56. diff --git a/libtirpc/src/bindresvport.c b/libtirpc/src/bindresvport.c
  57. index 01d1921..bf92ff6 100644
  58. --- a/libtirpc/src/bindresvport.c
  59. +++ b/libtirpc/src/bindresvport.c
  60. @@ -1,5 +1,6 @@
  61.  /*
  62.   * Copyright (c) 2009, Sun Microsystems, Inc.
  63. + * Copyright (c) 2024, Roland Mainz <roland.mainz@nrubsig.org>
  64.   * All rights reserved.
  65.   *
  66.   * Redistribution and use in source and binary forms, with or without
  67. @@ -32,20 +33,30 @@
  68.   * Copyright (c) 1987 by Sun Microsystems, Inc.
  69.   *
  70.   * Portions Copyright(C) 1996, Jason Downs.  All rights reserved.
  71. + * Portions Copyright(C) 2024, Roland Mainz <roland.mainz@nrubsig.org>
  72.   */
  73.  
  74.  #include <wintirpc.h>
  75.  #include <sys/types.h>
  76. -//#include <sys/socket.h>
  77. -
  78. -//#include <netinet/in.h>
  79. +#ifndef _WIN32
  80. +#include <sys/socket.h>
  81. +#include <netinet/in.h>
  82. +#endif
  83.  
  84.  #include <errno.h>
  85.  #include <string.h>
  86. -//#include <unistd.h>
  87. +#ifndef _WIN32
  88. +#include <unistd.h>
  89. +#endif
  90.  
  91.  #include <rpc/rpc.h>
  92.  
  93. +#ifdef _WIN32
  94. +#include <winsock2.h>
  95. +#include <mstcpip.h>
  96. +#include <ws2ipdef.h>
  97. +#endif
  98. +
  99.  /*
  100.   * Bind a socket to a privileged IP port
  101.   */
  102. @@ -139,18 +150,147 @@ bindresvport_sa(sd, sa)
  103.          return (res);
  104.  }
  105.  
  106. +#elif defined(_WIN32)
  107. +
  108. +#define STARTPORT 600
  109. +#define ENDPORT (IPPORT_RESERVED - 1)
  110. +#define NPORTS  (ENDPORT - STARTPORT + 1)
  111. +
  112. +/* Debug */
  113. +#if 0
  114. +#define BRP_D(x) x
  115.  #else
  116. -/*----------------------
  117. -#if defined(_WIN32)
  118. +#define BRP_D(x)
  119. +#endif
  120. +
  121. +/* fixme: not threadsafe, we should use |portnum_lock| */
  122. +static int bindresvport_sa_last_n = 0;
  123.  
  124.  int
  125.  bindresvport_sa(int sd, struct sockaddr *sa)
  126.  {
  127. -       fprintf(stderr, "Do-nothing bindresvport_sa!\n");
  128. -       return 0;
  129. +       int res = 1;
  130. +       int ioctlres;
  131. +       int lasterr;
  132. +       SOCKET sd_sock;
  133. +       int currport;
  134. +       int n;
  135. +
  136. +       INET_PORT_RANGE portRange;
  137. +       INET_PORT_RESERVATION_INSTANCE portRes;
  138. +       DWORD bytesReturned;
  139. +
  140. +       BRP_D((void)fprintf(stdout,
  141. +               "--> bindresvport_sa(sd=%d,sa=0x%p): "
  142. +               "bindresvport_sa_last_n=%d\n",
  143. +               sd, sa, bindresvport_sa_last_n));
  144. +
  145. +       sd_sock = _get_osfhandle(sd);
  146. +
  147. +       for (n = 0 ; n < NPORTS ; n++) {
  148. +               currport = ((n+bindresvport_sa_last_n)%NPORTS)+STARTPORT;
  149. +
  150. +               portRange.StartPort = htons(currport);
  151. +               portRange.NumberOfPorts = 1;
  152. +
  153. +               (void)memset(&portRes, 0, sizeof(portRes));
  154. +               bytesReturned = 0;
  155. +
  156. +               BRP_D((void)fprintf(stdout,
  157. +                       "bindresvport_sa(sd=%d,sa=0x%p): "
  158. +                       "trying n=%d, bindresvport_sa_last_n=%d, port=%d ...\n",
  159. +                       sd, sa, n, bindresvport_sa_last_n,
  160. +                       (int)ntohs(portRange.StartPort)));
  161. +               ioctlres = WSAIoctl(sd_sock,
  162. +                       SIO_ACQUIRE_PORT_RESERVATION,
  163. +                       (LPVOID)&portRange,
  164. +                       sizeof(INET_PORT_RANGE),
  165. +                       (LPVOID)&portRes,
  166. +                       sizeof(INET_PORT_RESERVATION_INSTANCE),
  167. +                       &bytesReturned, NULL, NULL);
  168. +               lasterr = WSAGetLastError();
  169. +
  170. +               if ((ioctlres != 0) && (lasterr == WSAEADDRINUSE)) {
  171. +                       BRP_D((void)fprintf(stderr,
  172. +                               "bindresvport_sa(sd=%d,sa=0x%p): "
  173. +                               "port=%d in use, trying next port...\n",
  174. +                               sd, sa, currport));
  175. +                       continue;
  176. +               }
  177. +
  178. +               if (ioctlres != 0) {
  179. +                       warnx("bindresvport_sa(sd=%d,sa=0x%p): "
  180. +                               "SIO_ACQUIRE_PORT_RESERVATION failed "
  181. +                               "with error = %d\n",
  182. +                               sd, sa, lasterr);
  183. +                       res = 1;
  184. +                       bindresvport_sa_last_n = n+1;
  185. +                       goto out;
  186. +               }
  187. +
  188. +               /* Success */
  189. +               bindresvport_sa_last_n = n+1;
  190. +               break;
  191. +       }
  192. +
  193. +       if (n == NPORTS) {
  194. +               warnx("bindresvport_sa(sd=%d,sa=0x%p): "
  195. +                       "n(=%d) == NPORTS(=%d), "
  196. +                       "no reserved port available\n", n, NPORTS);
  197. +               res = 1;
  198. +               goto out;
  199. +       }
  200. +
  201. +       BRP_D((void)fprintf(stdout, "bindresvport_sa(sd=%d,sa=0x%p): "
  202. +               "SIO_ACQUIRE_PORT_RESERVATION succeeded, "
  203. +               "bytesReturned = %u, StartPort=%d, NumberOfPorts=%d, "
  204. +               "Token=0x%llx\n",
  205. +               sd, sa, bytesReturned, (int)ntohs(portRes.StartPort),
  206. +               portRes.NumberOfPorts, (long long)portRes.Token));
  207. +
  208. +       bytesReturned = 0;
  209. +       ioctlres = WSAIoctl(sd_sock, SIO_ASSOCIATE_PORT_RESERVATION,
  210. +               (LPVOID)&portRes.Token, sizeof(ULONG64), NULL, 0,
  211. +               &bytesReturned, NULL, NULL);
  212. +       lasterr = WSAGetLastError();
  213. +       if (ioctlres != 0) {
  214. +               warnx("bindresvport_sa(sd=%d,sa=0x%p): "
  215. +                       "WSAIoctl(SIO_ASSOCIATE_PORT_RESERVATION) "
  216. +                       "failed with error = %d\n",
  217. +                       sd, sa, lasterr);
  218. +               res = 1;
  219. +               goto out;
  220. +       }
  221. +
  222. +       BRP_D((void)fprintf(stdout, "bindresvport_sa(sd=%d,sa=0x%p): "
  223. +               "WSAIoctl(SIO_ASSOCIATE_PORT_RESERVATION) succeeded, "
  224. +               "bytesReturned = %u\n",
  225. +               sd, sa, bytesReturned));
  226. +       res = 0;
  227. +
  228. +       /*
  229. +        * FIXME: We should call |SIO_RELEASE_PORT_RESERVATION|,
  230. +        * but we cannot do that while |sd| is open and using the
  231. +        * reservation.
  232. +        * So basically we to store the token, and then use a second
  233. +        * socket, with matching protocol&co attributes, just to
  234. +        * release the reservation.
  235. +        *
  236. +        * A possible solution might be to derive a "control socket"
  237. +        * from |sd|, and do the reservation ioctl using that socket.
  238. +        *
  239. +        * For now we ignore this, and assume noone will do more
  240. +        * than |NPORTS| { mount, umount }-sequences during
  241. +        * nfsd.exe/nfsd_debug.exe lifetime
  242. +        */
  243. +out:
  244. +       BRP_D((void)fprintf(stdout,
  245. +               "<-- bindresvport_sa(sd=%d,sa=0x%p) returning res=%d\n",
  246. +               sd, sa, res));
  247. +       return res;
  248.  }
  249.  #else
  250. --------------------------*/
  251. +
  252.  #define IP_PORTRANGE 19
  253.  #define IP_PORTRANGE_LOW 2
  254.  
  255. @@ -174,29 +314,16 @@ bindresvport_sa(sd, sa)
  256.         int proto, portrange, portlow;
  257.         u_int16_t *portp;
  258.         socklen_t salen;
  259. -#ifdef _WIN32
  260. -               WSAPROTOCOL_INFO proto_info;
  261. -               int proto_info_size = sizeof(proto_info);
  262. -#endif
  263.  
  264.         if (sa == NULL) {
  265.                 salen = sizeof(myaddr);
  266.                 sa = (struct sockaddr *)&myaddr;
  267.  
  268. -#ifdef _WIN32
  269. -               memset(sa, 0, salen);
  270. -               if (error = wintirpc_getsockopt(sd, SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&proto_info, &proto_info_size) == SOCKET_ERROR) {
  271. -                       int sockerr = WSAGetLastError();
  272. -                       return -1;
  273. -               }
  274. -               af = proto_info.iAddressFamily;
  275. -#else
  276.                 if (wintirpc_getsockname(sd, sa, &salen) == -1)
  277.                         return -1;      /* errno is correctly set */
  278.  
  279.                 af = sa->sa_family;
  280.                 memset(sa, 0, salen);
  281. -#endif
  282.         } else
  283.                 af = sa->sa_family;
  284.  
  285. @@ -268,7 +395,4 @@ bindresvport_sa(sd, sa)
  286.  #endif
  287.         return (error);
  288.  }
  289. -/*
  290. -#endif
  291. -*/
  292.  #endif
  293. \ No newline at end of file
  294. --
  295. 2.43.0
  296.  
  297. From a569d097ddc20a90e9694fd14d0d1f61ca6a86ce Mon Sep 17 00:00:00 2001
  298. From: Roland Mainz <roland.mainz@nrubsig.org>
  299. Date: Wed, 27 Mar 2024 16:28:25 +0100
  300. Subject: [PATCH 2/4] cygwin: Makefile should use "sync"
  301.  
  302. use "sync" when finishing the "build", "installdest" etc targets,
  303. so fast turnarounds followed with a Windows kernel crash do
  304. not corrupt the scripts&binaries we just installed.
  305.  
  306. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  307. ---
  308. cygwin/Makefile | 3 +++
  309.  1 file changed, 3 insertions(+)
  310.  
  311. diff --git a/cygwin/Makefile b/cygwin/Makefile
  312. index 792d512..bf3c5ba 100644
  313. --- a/cygwin/Makefile
  314. +++ b/cygwin/Makefile
  315. @@ -32,6 +32,7 @@ build:
  316.         MSBuild.exe '$(shell cygpath -w "$(PROJECT_BASEDIR_DIR)/build.vc19/nfs41-client.sln")' -t:Build  -p:Configuration=Release -p:Platform=x64
  317.         MSBuild.exe '$(shell cygpath -w "$(PROJECT_BASEDIR_DIR)/build.vc19/nfs41-client.sln")' -t:Build  -p:Configuration=Debug -p:Platform=x64
  318.         (cd "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1" && make all)
  319. +       sync
  320.  
  321.  #
  322.  # clean target
  323. @@ -114,6 +115,7 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  324.         @printf '\n'
  325.         @printf "\n#\n# Now use\n# $$ cd '%s' && ./msnfs41client install #\n# to install the kernel driver as Admin\n#\n" \
  326.                 "$(DESTDIR)/cygdrive/c/cygwin64/sbin/"
  327. +       sync
  328.  
  329.  bintarball: installdest
  330.         set -o errexit ; set -o xtrace ; \
  331. @@ -133,6 +135,7 @@ bintarball: installdest
  332.         printf "\n#\n# tarball is ready now\n#\n" ; \
  333.         ls -l "$(DESTDIR)/$${base_filename}.tar.bz2" ; \
  334.         ls -l "$(DESTDIR)/$${base_filename}.readme"
  335. +       sync
  336.  
  337.  #
  338.  # clean destdir/, but only if nfsd*.exe does not use it right now
  339. --
  340. 2.43.0
  341.  
  342. From a25b4b222c0f70d2992a083cd7a0a4a05eb2eecb Mon Sep 17 00:00:00 2001
  343. From: Roland Mainz <roland.mainz@nrubsig.org>
  344. Date: Wed, 27 Mar 2024 16:53:52 +0100
  345. Subject: [PATCH 3/4] cygwin: ksh93 should have Cygwin-like /etc/ksh.kshrc
  346.  which sets PS1
  347.  
  348. ksh93 should have Cygwin-like /etc/ksh.kshrc which sets PS1
  349.  
  350. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  351. ---
  352. cygwin/Makefile                   | 2 ++
  353.  cygwin/cygwin_ksh93/ksh.kshrc     | 8 ++++++++
  354.  cygwin/cygwin_ksh93/ksh93.cygport | 2 +-
  355.  3 files changed, 11 insertions(+), 1 deletion(-)
  356.  create mode 100644 cygwin/cygwin_ksh93/ksh.kshrc
  357.  
  358. diff --git a/cygwin/Makefile b/cygwin/Makefile
  359. index bf3c5ba..a2fcd24 100644
  360. --- a/cygwin/Makefile
  361. +++ b/cygwin/Makefile
  362. @@ -63,6 +63,7 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  363.         # /usr/lib is a bind mount to C:/cygwin64/lib, so copy library data to /cygdrive/c/cygwin64/lib
  364.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib
  365.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib/msnfs41client
  366. +       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/etc
  367.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/usr/src/msnfs41client
  368.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/usr/share/man/man1
  369.         cp -r $(VS_BUILD_DIR)/nfsd.exe          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.exe
  370. @@ -99,6 +100,7 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  371.         @ printf "# Package ksh93&co (if available) since Cygwin does not ship with it yet\n"
  372.         [[ -x /usr/bin/ksh93.exe ]] && cp /usr/bin/ksh93.exe $(DESTDIR)/cygdrive/c/cygwin64/bin/ksh93.exe
  373.         [[ -x /usr/bin/shcomp.exe ]] && cp /usr/bin/shcomp.exe $(DESTDIR)/cygdrive/c/cygwin64/bin/shcomp.exe
  374. +       cp $(PROJECT_BASEDIR_DIR)/cygwin/cygwin_ksh93/ksh.kshrc $(DESTDIR)/cygdrive/c/cygwin64/etc/ksh.kshrc
  375.         @ printf '# Packaging libs\n'
  376.         ldd $$(find $(DESTDIR)/cygdrive/c/cygwin64/sbin/ -iname \*.exe -o -iname \*.dll) | \
  377.                 while read dummy1 dummy2 dllfile dummy3 ; do \
  378. diff --git a/cygwin/cygwin_ksh93/ksh.kshrc b/cygwin/cygwin_ksh93/ksh.kshrc
  379. new file mode 100644
  380. index 0000000..5e12602
  381. --- /dev/null
  382. +++ b/cygwin/cygwin_ksh93/ksh.kshrc
  383. @@ -0,0 +1,8 @@
  384. +#
  385. +# /etc/ksh.kshrc+~/.kshrc are sourced only for interactive shells
  386. +#
  387. +
  388. +# default prompt
  389. +PS1=$'\E[1;32m$(/usr/bin/logname)@$(/usr/bin/hostname) \E[1;33m${PWD/~(Sl-r)$HOME/"~"}\E[0m\n$ '
  390. +# default editor mode
  391. +set -o gmacs
  392. diff --git a/cygwin/cygwin_ksh93/ksh93.cygport b/cygwin/cygwin_ksh93/ksh93.cygport
  393. index 9913330..b8d13fe 100644
  394. --- a/cygwin/cygwin_ksh93/ksh93.cygport
  395. +++ b/cygwin/cygwin_ksh93/ksh93.cygport
  396. @@ -259,7 +259,7 @@ src_compile()
  397.         {
  398.                 printf '#\n# /etc/ksh.kshrc+~/.kshrc are sourced only for interactive shells\n#\n\n'
  399.                 printf '# default prompt\n'
  400. -               printf 'PS1=%q\n' $'\E[32m$(/usr/bin/logname)@$(/usr/bin/hostname) \E[33m${PWD/~(Sl-r)$HOME/"~"}\E[0m\n$ '
  401. +               printf 'PS1=%q\n' $'\E[1;32m$(/usr/bin/logname)@$(/usr/bin/hostname) \E[1;33m${PWD/~(Sl-r)$HOME/"~"}\E[0m\n$ '
  402.                 printf '# default editor mode\n'
  403.                 printf 'set -o gmacs\n'
  404.         } >${S}/etc_ksh_kshrc
  405. --
  406. 2.43.0
  407.  
  408. From 3b247f24697b93440e05372ba6ceac17657049f3 Mon Sep 17 00:00:00 2001
  409. From: Roland Mainz <roland.mainz@nrubsig.org>
  410. Date: Wed, 27 Mar 2024 17:34:40 +0100
  411. Subject: [PATCH 4/4] cygwin: Add comments about UNC+ACL support to bintarball
  412.  README
  413.  
  414. Add comments about UNC+ACL support to cygwin bintarball README
  415.  
  416. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  417. ---
  418. cygwin/README.bintarball.txt | 6 ++++++
  419.  1 file changed, 6 insertions(+)
  420.  
  421. diff --git a/cygwin/README.bintarball.txt b/cygwin/README.bintarball.txt
  422. index 9fa5222..cc275d1 100644
  423. --- a/cygwin/README.bintarball.txt
  424. +++ b/cygwin/README.bintarball.txt
  425. @@ -39,12 +39,18 @@ NFSv4.1 client and filesystem driver for Windows 10/11
  426.  
  427.  - UNC paths
  428.      - IPv6 support in UNC paths
  429. +    - /sbin/nfs_mount prints UNC paths in Win32+Cygwin formats
  430. +    - Cygwin bash+ksh93 support UNC paths, e.g.
  431. +      cd //derfwnb4966@2049/nfs4/bigdisk/mysqldb4/
  432.  
  433.  - IPv6 support
  434.      - IPv6 address within '[', ']'
  435.        (will be converted to *.ipv6-literal.net)
  436.  
  437.  - Windows ACLs
  438. +    - Win32 C:\Windows\system32\icacls.exe
  439. +    - Cygwin /usr/bin/setfacl+/usr/bin/getfacl
  440. +    - Windows Explorer ACL dialog
  441.  
  442.  - SFU/Cygwin support, including:
  443.      - uid/gid
  444. --
  445. 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