pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: nfs_globalmount util, winrunassystem improvements, sign all utils+misc, 2025-08-27
Posted by Anonymous on Wed 27th Aug 2025 14:21
raw | new post

  1. From 916917a9318f5307d7d7bf477c8232db055a3ffa Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 27 Aug 2025 13:39:08 +0200
  4. Subject: [PATCH 1/4] tests: Always sign the *.exe files in tests/ with the WDK
  5.  test signature
  6.  
  7. Always sign the *.exe files in tests/ with the WDK test signature, to
  8. allow a (Windows Defender) admin to whitelist the binaries based on
  9. that signature.
  10.  
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. tests/ea/Makefile                 | 7 +++++--
  14.  tests/filemmaptests/Makefile      | 7 +++++--
  15.  tests/lssparse/Makefile           | 7 +++++--
  16.  tests/winclonefile/Makefile       | 7 +++++--
  17.  tests/winfsinfo1/Makefile         | 7 +++++--
  18.  tests/winoffloadcopyfile/Makefile | 7 +++++--
  19.  tests/winrunassystem/Makefile     | 9 ++++++---
  20.  tests/winsg/Makefile              | 7 +++++--
  21.  8 files changed, 41 insertions(+), 17 deletions(-)
  22.  
  23. diff --git a/tests/ea/Makefile b/tests/ea/Makefile
  24. index 4e49afd..e24e0dc 100644
  25. --- a/tests/ea/Makefile
  26. +++ b/tests/ea/Makefile
  27. @@ -3,14 +3,17 @@
  28.  #
  29.  
  30.  # POSIX Makefile
  31. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  32.  
  33.  all: nfs_ea.i686.exe nfs_ea.x86_64.exe nfs_ea.exe
  34.  
  35.  nfs_ea.i686.exe: main.c
  36. -       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o nfs_ea.i686.exe
  37. +       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
  38. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  39.  
  40.  nfs_ea.x86_64.exe: main.c
  41. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o nfs_ea.x86_64.exe
  42. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -D_CRT_STDIO_ISO_WIDE_SPECIFIERS=1 -DUNICODE=1 -D_UNICODE=1 -isystem /usr/include/w32api/ddk -I../../include -g main.c -lntdll -o $@
  43. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  44.  
  45.  nfs_ea.exe: nfs_ea.x86_64.exe
  46.         rm -f nfs_ea.exe
  47. diff --git a/tests/filemmaptests/Makefile b/tests/filemmaptests/Makefile
  48. index e191725..3b2a9e53 100644
  49. --- a/tests/filemmaptests/Makefile
  50. +++ b/tests/filemmaptests/Makefile
  51. @@ -3,6 +3,7 @@
  52.  #
  53.  
  54.  # POSIX Makefile
  55. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  56.  
  57.  all: \
  58.         qsortonmmapedfile1.i686.exe \
  59. @@ -10,10 +11,12 @@ all: \
  60.         qsortonmmapedfile1.exe
  61.  
  62.  qsortonmmapedfile1.i686.exe: qsortonmmapedfile1.c
  63. -       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O qsortonmmapedfile1.c -o qsortonmmapedfile1.i686.exe
  64. +       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O qsortonmmapedfile1.c -o $@
  65. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  66.  
  67.  qsortonmmapedfile1.x86_64.exe: qsortonmmapedfile1.c
  68. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O qsortonmmapedfile1.c -o qsortonmmapedfile1.x86_64.exe
  69. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g -O qsortonmmapedfile1.c -o $@
  70. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  71.  
  72.  qsortonmmapedfile1.exe: qsortonmmapedfile1.x86_64.exe
  73.         ln -s qsortonmmapedfile1.x86_64.exe qsortonmmapedfile1.exe
  74. diff --git a/tests/lssparse/Makefile b/tests/lssparse/Makefile
  75. index 6b591ac..0f2a11d 100644
  76. --- a/tests/lssparse/Makefile
  77. +++ b/tests/lssparse/Makefile
  78. @@ -3,15 +3,18 @@
  79.  #
  80.  
  81.  # POSIX Makefile
  82. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  83.  
  84.  all: lssparse.x86_64.exe lssparse.exe
  85.  
  86.  # Cygwin 3.6 does not support 32bit builds anymore
  87.  #lssparse.i686.exe: lssparse.c
  88. -#      gcc -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g lssparse.c -lntdll -o lssparse.i686.exe
  89. +#      gcc -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g lssparse.c -lntdll -o $@
  90. +#      bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  91.  
  92.  lssparse.x86_64.exe: lssparse.c
  93. -       gcc -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g lssparse.c -lntdll -o lssparse.x86_64.exe
  94. +       gcc -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g lssparse.c -lntdll -o $@
  95. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  96.  
  97.  lssparse.exe: lssparse.x86_64.exe
  98.         ln -s lssparse.x86_64.exe lssparse.exe
  99. diff --git a/tests/winclonefile/Makefile b/tests/winclonefile/Makefile
  100. index d4d14a7..4c00b53 100644
  101. --- a/tests/winclonefile/Makefile
  102. +++ b/tests/winclonefile/Makefile
  103. @@ -3,14 +3,17 @@
  104.  #
  105.  
  106.  # POSIX Makefile
  107. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  108.  
  109.  all: winclonefile.i686.exe winclonefile.x86_64.exe winclonefile.exe
  110.  
  111.  winclonefile.i686.exe: winclonefile.c
  112. -       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winclonefile.c -lntdll -o winclonefile.i686.exe
  113. +       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winclonefile.c -lntdll -o $@
  114. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  115.  
  116.  winclonefile.x86_64.exe: winclonefile.c
  117. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winclonefile.c -lntdll -o winclonefile.x86_64.exe
  118. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winclonefile.c -lntdll -o $@
  119. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  120.  
  121.  winclonefile.exe: winclonefile.x86_64.exe
  122.         ln -s winclonefile.x86_64.exe winclonefile.exe
  123. diff --git a/tests/winfsinfo1/Makefile b/tests/winfsinfo1/Makefile
  124. index c927704..262a93f 100644
  125. --- a/tests/winfsinfo1/Makefile
  126. +++ b/tests/winfsinfo1/Makefile
  127. @@ -3,14 +3,17 @@
  128.  #
  129.  
  130.  # POSIX Makefile
  131. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  132.  
  133.  all: winfsinfo.i686.exe winfsinfo.x86_64.exe winfsinfo.exe
  134.  
  135.  winfsinfo.i686.exe: winfsinfo.c
  136. -       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winfsinfo.c -lmpr -lntdll -o winfsinfo.i686.exe
  137. +       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winfsinfo.c -lmpr -lntdll -o $@
  138. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  139.  
  140.  winfsinfo.x86_64.exe: winfsinfo.c
  141. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winfsinfo.c -lmpr -lntdll -o winfsinfo.x86_64.exe
  142. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winfsinfo.c -lmpr -lntdll -o $@
  143. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  144.  
  145.  winfsinfo.exe: winfsinfo.x86_64.exe
  146.         ln -s winfsinfo.x86_64.exe winfsinfo.exe
  147. diff --git a/tests/winoffloadcopyfile/Makefile b/tests/winoffloadcopyfile/Makefile
  148. index a429b44..5330d4f 100644
  149. --- a/tests/winoffloadcopyfile/Makefile
  150. +++ b/tests/winoffloadcopyfile/Makefile
  151. @@ -3,14 +3,17 @@
  152.  #
  153.  
  154.  # POSIX Makefile
  155. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  156.  
  157.  all: winoffloadcopyfile.i686.exe winoffloadcopyfile.x86_64.exe winoffloadcopyfile.exe
  158.  
  159.  winoffloadcopyfile.i686.exe: winoffloadcopyfile.c
  160. -       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winoffloadcopyfile.c -lntdll -o winoffloadcopyfile.i686.exe
  161. +       clang -target i686-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winoffloadcopyfile.c -lntdll -o $@
  162. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  163.  
  164.  winoffloadcopyfile.x86_64.exe: winoffloadcopyfile.c
  165. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winoffloadcopyfile.c -lntdll -o winoffloadcopyfile.x86_64.exe
  166. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -I../../include -g winoffloadcopyfile.c -lntdll -o $@
  167. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  168.  
  169.  winoffloadcopyfile.exe: winoffloadcopyfile.x86_64.exe
  170.         ln -s winoffloadcopyfile.x86_64.exe winoffloadcopyfile.exe
  171. diff --git a/tests/winrunassystem/Makefile b/tests/winrunassystem/Makefile
  172. index 9ade5ec..69ce1ab 100644
  173. --- a/tests/winrunassystem/Makefile
  174. +++ b/tests/winrunassystem/Makefile
  175. @@ -3,17 +3,20 @@
  176.  #
  177.  
  178.  # POSIX Makefile
  179. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  180.  
  181.  all: winrunassystem.i686.exe winrunassystem.x86_64.exe winrunassystem.exe
  182.  
  183.  winrunassystem.i686.exe: winrunassystem.c
  184. -       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winrunassystem.c -lWtsapi32 -o winrunassystem.i686.exe
  185. +       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winrunassystem.c -lWtsapi32 -o $@
  186. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  187.  
  188.  winrunassystem.x86_64.exe: winrunassystem.c
  189. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winrunassystem.c -lWtsapi32 -o winrunassystem.x86_64.exe
  190. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winrunassystem.c -lWtsapi32 -o $@
  191. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  192.  
  193.  winrunassystem.exe: winrunassystem.x86_64.exe
  194. -       ln -s winrunassystem.x86_64.exe winrunassystem.exe
  195. +       ln -s winrunassystem.x86_64.exe $@
  196.  
  197.  clean:
  198.         rm -fv \
  199. diff --git a/tests/winsg/Makefile b/tests/winsg/Makefile
  200. index 5006dce..345151d 100644
  201. --- a/tests/winsg/Makefile
  202. +++ b/tests/winsg/Makefile
  203. @@ -3,14 +3,17 @@
  204.  #
  205.  
  206.  # POSIX Makefile
  207. +SIGNTOOL="/cygdrive/c/Program Files (x86)/Microsoft SDKs/ClickOnce/SignTool/signtool.exe"
  208.  
  209.  all: winsg.i686.exe winsg.x86_64.exe winsg.exe
  210.  
  211.  winsg.i686.exe: winsg.c
  212. -       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.i686.exe
  213. +       clang -target i686-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o $@
  214. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  215.  
  216.  winsg.x86_64.exe: winsg.c
  217. -       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe
  218. +       clang -target x86_64-pc-windows-gnu -std=gnu17 -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o $@
  219. +       bash -x -c '$(SIGNTOOL) sign /ph /fd "sha256" /sha1 "$${CERTIFICATE_THUMBPRINT%$$(printf "\r")}" $@'
  220.  
  221.  winsg.exe: winsg.x86_64.exe
  222.         ln -s winsg.x86_64.exe winsg.exe
  223. --
  224. 2.45.1
  225.  
  226. From 987348fb38b9422cf28f7474a67140e991659767 Mon Sep 17 00:00:00 2001
  227. From: Roland Mainz <roland.mainz@nrubsig.org>
  228. Date: Wed, 27 Aug 2025 14:15:56 +0200
  229. Subject: [PATCH 2/4] daemon: CriticalSections used to protect list searches
  230.  should not use a spin count
  231.  
  232. CriticalSections used to protect list searches should not use a spin count,
  233. as this is wasted CPU time in such a case.
  234.  
  235. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  236. ---
  237. daemon/namespace.c    | 6 +++++-
  238.  daemon/nfs41_client.c | 6 +++++-
  239.  daemon/nfs41_server.c | 9 +++++++--
  240.  3 files changed, 17 insertions(+), 4 deletions(-)
  241.  
  242. diff --git a/daemon/namespace.c b/daemon/namespace.c
  243. index 4a2b157..89a0e0b 100644
  244. --- a/daemon/namespace.c
  245. +++ b/daemon/namespace.c
  246. @@ -88,7 +88,11 @@ int nfs41_root_create(
  247.      }
  248.      root->wsize = wsize;
  249.      root->rsize = rsize;
  250. -    InitializeCriticalSection(&root->lock);
  251. +    /*
  252. +     * Disable spin count as |root->lock| is typically used to
  253. +     * protect list searches, which takes a long time
  254. +     */
  255. +    (void)InitializeCriticalSectionAndSpinCount(&root->lock, 0);
  256.      root->ref_count = 1;
  257.      root->sec_flavor = sec_flavor;
  258.  
  259. diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
  260. index 375d7e9..7510f05 100644
  261. --- a/daemon/nfs41_client.c
  262. +++ b/daemon/nfs41_client.c
  263. @@ -136,7 +136,11 @@ int nfs41_client_create(
  264.  
  265.      list_init(&client->state.opens);
  266.      list_init(&client->state.delegations);
  267. -    InitializeCriticalSection(&client->state.lock);
  268. +    /*
  269. +     * Disable spin count as |client->state.lock| is typically used to
  270. +     * protect list searches, which takes a long time
  271. +     */
  272. +    (void)InitializeCriticalSectionAndSpinCount(&client->state.lock, 0);
  273.  
  274.      //initialize a lock used to protect access to client id and client id seq#
  275.      InitializeSRWLock(&client->exid_lock);
  276. diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
  277. index 04d3651..7e3295c 100644
  278. --- a/daemon/nfs41_server.c
  279. +++ b/daemon/nfs41_server.c
  280. @@ -1,5 +1,6 @@
  281.  /* NFSv4.1 client for Windows
  282. - * Copyright (C) 2012 The Regents of the University of Michigan
  283. + * Copyright (C) 2012 The Regents of the University of Michigan
  284. + * Copyright (C) 2024-2025 Roland Mainz <roland.mainz@nrubsig.org>
  285.   *
  286.   * Olga Kornievskaia <aglo@umich.edu>
  287.   * Casey Bodley <cbodley@umich.edu>
  288. @@ -49,7 +50,11 @@ static struct server_list g_server_list;
  289.  void nfs41_server_list_init()
  290.  {
  291.      list_init(&g_server_list.head);
  292. -    InitializeCriticalSection(&g_server_list.lock);
  293. +    /*
  294. +     * Disable spin count as |g_server_list.lock| is typically used to
  295. +     * protect list searches, which takes a long time
  296. +     */
  297. +    (void)InitializeCriticalSectionAndSpinCount(&g_server_list.lock, 0);
  298.  }
  299.  
  300.  /* http://tools.ietf.org/html/rfc5661#section-1.6
  301. --
  302. 2.45.1
  303.  
  304. From 14a65b31124e3385429048aa3c52bc0e5ff29d40 Mon Sep 17 00:00:00 2001
  305. From: Roland Mainz <roland.mainz@nrubsig.org>
  306. Date: Wed, 27 Aug 2025 14:37:32 +0200
  307. Subject: [PATCH 3/4] tests: winrunassystem.exe should forward the exit code of
  308.  the child process
  309.  
  310. winrunassystem.exe should forward the exit code of the child process.
  311.  
  312. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  313. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  314. ---
  315. tests/winrunassystem/winrunassystem.c | 61 ++++++++++++++++++++++++---
  316.  1 file changed, 56 insertions(+), 5 deletions(-)
  317.  
  318. diff --git a/tests/winrunassystem/winrunassystem.c b/tests/winrunassystem/winrunassystem.c
  319. index 80b9fbc..6ccae1b 100644
  320. --- a/tests/winrunassystem/winrunassystem.c
  321. +++ b/tests/winrunassystem/winrunassystem.c
  322. @@ -505,6 +505,41 @@ done:
  323.      (void)CloseServiceHandle(hSCManager);
  324.  }
  325.  
  326. +static
  327. +bool readfilecontentsintobuffer(const wchar_t *filename,
  328. +    char *buffer,
  329. +    size_t buffersize,
  330. +    size_t *numreadbytes)
  331. +{
  332. +    HANDLE hFile;
  333. +    bool retval = false;
  334. +    DWORD readfile_numbytesread = 0UL;
  335. +
  336. +    hFile = CreateFileW(filename,
  337. +        GENERIC_READ,
  338. +        FILE_SHARE_READ,
  339. +        NULL,
  340. +        OPEN_EXISTING,
  341. +        FILE_ATTRIBUTE_TEMPORARY,
  342. +        NULL);
  343. +    if (hFile == INVALID_HANDLE_VALUE) {
  344. +        D((void)wprintf(L"readfilecontentsintobuffer: "
  345. +            L"cannot open status file, lasterr=%d\n",
  346. +            (int)GetLastError()));
  347. +        return false;
  348. +    }
  349. +
  350. +    retval = ReadFile(hFile, buffer, (DWORD)buffersize,
  351. +        &readfile_numbytesread, NULL)?true:false;
  352. +    *numreadbytes = readfile_numbytesread;
  353. +
  354. +    if (hFile != INVALID_HANDLE_VALUE) {
  355. +        (void)CloseHandle(hFile);
  356. +    }
  357. +
  358. +    return retval;
  359. +}
  360. +
  361.  static
  362.  void usage(const wchar_t *av0)
  363.  {
  364. @@ -558,21 +593,37 @@ int wmain(int argc, wchar_t *argv[])
  365.          /* Stop and Uninstall */
  366.          UninstallService();
  367.  
  368. +        /* Get child stdout+stderr */
  369.          (void)system_fmt("C:\\cygwin64\\bin\\bash.exe -c "
  370.              "'cat \"/cygdrive/c/Windows/Temp/%ls_stderr\" 1>&2'",
  371.              service_name_buffer);
  372.          (void)system_fmt("C:\\cygwin64\\bin\\bash.exe -c "
  373.              "'cat \"/cygdrive/c/Windows/Temp/%ls_stdout\"'",
  374.              service_name_buffer);
  375. -        (void)system_fmt("C:\\cygwin64\\bin\\bash.exe -c "
  376. -            "'printf \"# Child status %%d.\\\\n\" "
  377. -            "\"$( <\"/cygdrive/c/Windows/Temp/%ls_status\" )\" 1>&2'",
  378. +
  379. +        /* Read child return value */
  380. +        wchar_t statusfilenamebuff[MAX_PATH+1];
  381. +        char statusvalue[256];
  382. +        size_t numbytesread = 0UL;
  383. +        (void)swprintf(statusfilenamebuff, sizeof(statusfilenamebuff),
  384. +            L"C:\\Windows\\Temp\\%ls_status",
  385.              service_name_buffer);
  386. +        if (readfilecontentsintobuffer(statusfilenamebuff,
  387. +            statusvalue, sizeof(statusvalue), &numbytesread)) {
  388. +            statusvalue[numbytesread] = '\0';
  389. +            retval = atoi(statusvalue);
  390. +        }
  391. +        else {
  392. +            (void)fwprintf(stderr,
  393. +                L"%ls: Cannot read child status from file '%ls'\n",
  394. +                argv[0], statusfilenamebuff);
  395. +            retval = EXIT_FAILURE;
  396. +        }
  397. +
  398. +        /* Delete temporary files */
  399.          (void)remove_fmt("C:\\Windows\\Temp\\%ls_stdout", service_name_buffer);
  400.          (void)remove_fmt("C:\\Windows\\Temp\\%ls_stderr", service_name_buffer);
  401.          (void)remove_fmt("C:\\Windows\\Temp\\%ls_status", service_name_buffer);
  402. -
  403. -        retval = EXIT_SUCCESS;
  404.      }
  405.  
  406.      return retval;
  407. --
  408. 2.45.1
  409.  
  410. From 5352805576ccfdde0adb8a422551f9b9587d6f41 Mon Sep 17 00:00:00 2001
  411. From: Roland Mainz <roland.mainz@nrubsig.org>
  412. Date: Wed, 27 Aug 2025 15:11:58 +0200
  413. Subject: [PATCH 4/4] README.md,cygwin,docs: Add /sbin/nfs_globalmount utility
  414.  to manage machine-wide mounts
  415.  
  416. Add /sbin/nfs_globalmount utility to manage machine-wide mounts.
  417.  
  418. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  419. ---
  420. README.md                                     |  5 +++-
  421.  cygwin/Makefile.install                       |  4 +++
  422.  .../utils/nfs_globalmount/nfs_globalmount.ksh | 30 +++++++++++++++++++
  423.  docs/README.xml                               |  3 +-
  424.  4 files changed, 40 insertions(+), 2 deletions(-)
  425.  create mode 100644 cygwin/utils/nfs_globalmount/nfs_globalmount.ksh
  426.  
  427. diff --git a/README.md b/README.md
  428. index efe279c..a9bb25c 100644
  429. --- a/README.md
  430. +++ b/README.md
  431. @@ -640,7 +640,10 @@ List mounted NFSv4.2 filesystems:
  432.  ### Global/System-wide mounts
  433.  
  434.  Mounts created by user "SYSTEM" are usable by all users in a system.
  435. -Example usage:
  436. +Such mounts can be created by the `/sbin/nfs_globalmount` command, or
  437. +adding an entry in `/etc/fstab.msnfs41client`.
  438. +
  439. +Example usage for `/etc/fstab.msnfs41client`:
  440.  
  441.      # Create a file /etc/fstab.msnfs41client, which list the mounts
  442.      # which should be mounted system-wide at boot
  443. diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
  444. index d0574a4..e9f68df 100644
  445. --- a/cygwin/Makefile.install
  446. +++ b/cygwin/Makefile.install
  447. @@ -86,6 +86,10 @@ installdest:
  448.         git diff -w     >"$(DESTDIR)/$(CYGWIN_BASEPATH)/usr/src/msnfs41client/msnfs41client_diff_w.diff"
  449.         git diff        >"$(DESTDIR)/$(CYGWIN_BASEPATH)/usr/src/msnfs41client/msnfs41client_diff.diff"
  450.         @ printf "# Package utilties\n"
  451. +       cp $(CYGWIN_MAKEFILE_DIR)/utils/nfs_globalmount/nfs_globalmount.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/nfs_globalmount
  452. +       chmod a+x $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/nfs_globalmount
  453. +       PATH+=":$(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/" \
  454. +               /usr/bin/ksh93 $(CYGWIN_MAKEFILE_DIR)/utils/nfs_globalmount/nfs_globalmount.ksh --nroff 2>"$(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/man/man1/nfs_globalmount.1" || true
  455.         cp $(CYGWIN_MAKEFILE_DIR)/utils/mountall_msnfs41client/mountall_msnfs41client.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/mountall_msnfs41client
  456.         chmod a+x $(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/mountall_msnfs41client
  457.         PATH+=":$(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/" \
  458. diff --git a/cygwin/utils/nfs_globalmount/nfs_globalmount.ksh b/cygwin/utils/nfs_globalmount/nfs_globalmount.ksh
  459. new file mode 100644
  460. index 0000000..c4edd41
  461. --- /dev/null
  462. +++ b/cygwin/utils/nfs_globalmount/nfs_globalmount.ksh
  463. @@ -0,0 +1,30 @@
  464. +#!/bin/ksh93
  465. +
  466. +# ksh93 scripts using AST getopts(1) support --nroff,
  467. +# but we do not do that yet
  468. +[[ "$1" == '--nroff' ]] && exit 1
  469. +
  470. +function is_windows_admin_account
  471. +{
  472. +       #
  473. +       # Test whether we have the Windows permissions to install DLLs
  474. +       # and the kernel module
  475. +       #
  476. +       # Usually Windows Adminstrator rights are indicated by the
  477. +       # membership in group "544(Administratoren)" (Cygwin maps
  478. +       # "SID S-1-5-32-544" to GID 544)
  479. +       #
  480. +       if [[ "$(/bin/id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then
  481. +               return 0
  482. +       fi
  483. +       return 1
  484. +}
  485. +
  486. +if ! is_windows_admin_account ; then
  487. +       printf $"%s: Requires Windows Adminstator permissions.\n" "$0"
  488. +       exit 1
  489. +fi
  490. +
  491. +/sbin/winrunassystem "$(cygpath -w '/sbin/nfs_mount.exe')" "$@"
  492. +exit $?
  493. +# EOF.
  494. diff --git a/docs/README.xml b/docs/README.xml
  495. index a69372a..e32fda4 100644
  496. --- a/docs/README.xml
  497. +++ b/docs/README.xml
  498. @@ -653,7 +653,8 @@ $ net use '\0.49.202.230@2049\nfs4\net_tmpfs2' /delete</programlisting>
  499.  
  500.        <section xml:id="global-system-wide-mounts">
  501.          <title>Global/System-wide mounts</title>
  502. -        <para>Mounts created by user "SYSTEM" are usable by all users in a system. Example usage:</para>
  503. +        <para>Mounts created by user "SYSTEM" are usable by all users in a system. Such mounts can be created by the <command>/sbin/nfs_globalmount</command> command, or adding an entry in <filename>/etc/fstab.msnfs41client</filename>.</para>
  504. +        <para>Example usage for <filename>/etc/fstab.msnfs41client</filename>:</para>
  505.          <programlisting># Create a file /etc/fstab.msnfs41client, which list the mounts
  506.  # which should be mounted system-wide at boot
  507.  $ cat /etc/fstab.msnfs41client
  508. --
  509. 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