pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for winsgfromcmd.exe, clangfixes+misc, 2025-06-18
Posted by Anonymous on Wed 18th Jun 2025 17:24
raw | new post

  1. From 8299f6df0331998f366d35d503b44b52cb9f00c4 Mon Sep 17 00:00:00 2001
  2. From: Dan Shelton <dan.f.shelton@gmail.com>
  3. Date: Wed, 18 Jun 2025 11:51:03 +0200
  4. Subject: [PATCH 1/5] daemon: |duplicate_sparsefile()| should clear all of
  5.  |info|
  6.  
  7. |duplicate_sparsefile()| should clear all of struct |info|.
  8. Found via ReactOS clang compiler warning.
  9.  
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. daemon/fsctl.c | 2 +-
  13.  1 file changed, 1 insertion(+), 1 deletion(-)
  14.  
  15. diff --git a/daemon/fsctl.c b/daemon/fsctl.c
  16. index 96f616f..5fa19c8 100644
  17. --- a/daemon/fsctl.c
  18. +++ b/daemon/fsctl.c
  19. @@ -492,7 +492,7 @@ int duplicate_sparsefile(nfs41_open_state *src_state,
  20.      stateid_arg src_stateid;
  21.      stateid_arg dst_stateid;
  22.  
  23. -    (void)memset(info, 0, sizeof(info));
  24. +    (void)memset(info, 0, sizeof(*info));
  25.  
  26.      DPRINTF(DDLVL,
  27.          ("--> duplicate_sparsefile(src_state->path.path='%s')\n",
  28. --
  29. 2.45.1
  30.  
  31. From 2568995b4b7e010d8290526490b3a1f485d84371 Mon Sep 17 00:00:00 2001
  32. From: Dan Shelton <dan.f.shelton@gmail.com>
  33. Date: Wed, 18 Jun 2025 11:52:48 +0200
  34. Subject: [PATCH 2/5] daemon: Fix clang compiler warning in
  35.  |recover_delegation_open()|
  36.  
  37. Fix clang compiler warning in |recover_delegation_open()|:
  38. 'memcpy' call operates on objects of type 'nfs41_delegation_state'
  39. (aka 'struct __nfs41_delegation_state') while the size is based on
  40. a different type 'nfs41_delegation_state *' (aka
  41. 'struct __nfs41_delegation_state *')
  42.  
  43. The warning is wrong in this specific case, as a pointer stunt is
  44. used to create a token value.
  45.  
  46. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  47. ---
  48. daemon/recovery.c | 7 ++++---
  49.  1 file changed, 4 insertions(+), 3 deletions(-)
  50.  
  51. diff --git a/daemon/recovery.c b/daemon/recovery.c
  52. index c3dd695..99a2795 100644
  53. --- a/daemon/recovery.c
  54. +++ b/daemon/recovery.c
  55. @@ -418,9 +418,10 @@ static int recover_delegation_open(
  56.  
  57.      /* construct a temporary open owner by concatenating the time
  58.       * in seconds with the delegation pointer */
  59. -    time((time_t*)owner.owner);
  60. -    memcpy(owner.owner + sizeof(time_t), deleg, sizeof(deleg));
  61. -    owner.owner_len = sizeof(time_t) + sizeof(deleg);
  62. +    void *dp = deleg;
  63. +    (void)time((time_t*)owner.owner);
  64. +    (void)memcpy(owner.owner + sizeof(time_t), dp, sizeof(dp));
  65. +    owner.owner_len = sizeof(time_t) + sizeof(dp);
  66.  
  67.      if (*grace) {
  68.          status = recover_open_grace(session, &deleg->parent, &deleg->file,
  69. --
  70. 2.45.1
  71.  
  72. From deaf5ac3f0ec4ccbe78ce10ba203e2af77906775 Mon Sep 17 00:00:00 2001
  73. From: Roland Mainz <roland.mainz@nrubsig.org>
  74. Date: Wed, 18 Jun 2025 11:56:36 +0200
  75. Subject: [PATCH 3/5] cygwin: winsg.exe should be usable from
  76.  cmd.exe+powershell.exe
  77.  
  78. winsg.exe should be usable from cmd.exe+powershell.exe.
  79.  
  80. This didn't work because winsg.exe was created via Cygwin ln -s
  81. to map it to the correct 32bit/64bit version - but on NTFS Cygwin
  82. uses <JUNCTION> for POIX symlinks, because <SYMLINK> requires the
  83. SeCreateSymbolicLinkPrivilege (which by default not even Adminstrators
  84. have).
  85.  
  86. Unfortunately cmd.exe and powershell.exe only follow <SYMLINK> for
  87. looking up *.exe files, but NOT <JUNCTION>, and therefore winsg.exe
  88. could not be used from cmd.exe even if C:\cygwin64\bin is in %PATH%.
  89.  
  90. As fix/workaround we now use hardlinks to map winsg.exe to map
  91. it to the correct 32bit+64bit version.
  92.  
  93. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  94. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  95. ---
  96. cygwin/Makefile.install | 27 +++++++++++++++++----------
  97.  1 file changed, 17 insertions(+), 10 deletions(-)
  98.  
  99. diff --git a/cygwin/Makefile.install b/cygwin/Makefile.install
  100. index e3d8e5a..ba7d0ed 100644
  101. --- a/cygwin/Makefile.install
  102. +++ b/cygwin/Makefile.install
  103. @@ -13,6 +13,12 @@ PROJECT_BASEDIR_DIR := $(shell dirname $(realpath $(CYGWIN_MAKEFILE_DIR)/))
  104.  
  105.  DESTDIR := $(PROJECT_BASEDIR_DIR)/destdir
  106.  
  107. +# link *.exe
  108. +# We have to use hardlinks here, because cygwin defaults to use <JUNCTION>s,
  109. +# which neither cmd.exe nor powershell can follow. <SYMLINK>s are not an option,
  110. +# because it woulld required the "SeCreateSymbolicLinkPrivilege", which by default
  111. +# not even the Adminstrator has
  112. +LINKEXE = ln -f
  113.  
  114.  # install in DESTDIR
  115.  installdest:
  116. @@ -70,7 +76,8 @@ installdest:
  117.         cp $(PROJECT_BASEDIR_DIR)/ms-nfs41-idmap.conf           $(DESTDIR)/$(CYGWIN_BASEPATH)/lib/msnfs41client/.
  118.         cp $(CYGWIN_MAKEFILE_DIR)/devel/msnfs41client.bash      $(DESTDIR)/$(CYGWIN_BASEPATH)/lib/msnfs41client/msnfs41client
  119.         chmod a+x "$(DESTDIR)/$(CYGWIN_BASEPATH)/lib/msnfs41client/msnfs41client"
  120. -       (cd "$(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/" && ln -sf ../lib/msnfs41client/msnfs41client .)
  121. +       # this must be a symlink, so msnfs41client can find it's real location
  122. +       (cd "$(DESTDIR)/$(CYGWIN_BASEPATH)/sbin/" && ln -s -f ../lib/msnfs41client/msnfs41client .)
  123.         cp $(PROJECT_BASEDIR_DIR)/cygwin_idmapper.ksh           $(DESTDIR)/$(CYGWIN_BASEPATH)/lib/msnfs41client/.
  124.         @ printf "# Package sources and diffs\n"
  125.         git config --global --add safe.directory "$(PROJECT_BASEDIR_DIR)"
  126. @@ -100,34 +107,34 @@ installdest:
  127.         cp "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winfsinfo.x86_64.exe
  128.         cp "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.i686.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winfsinfo.i686.exe
  129.         if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  130. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winfsinfo.x86_64.exe winfsinfo.exe) \
  131. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) winfsinfo.x86_64.exe winfsinfo.exe) \
  132.         else \
  133. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winfsinfo.i686.exe winfsinfo.exe) \
  134. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) winfsinfo.i686.exe winfsinfo.exe) \
  135.         fi
  136.         cp "$(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winclonefile.x86_64.exe
  137.         cp "$(PROJECT_BASEDIR_DIR)/tests/winclonefile/winclonefile.i686.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winclonefile.i686.exe
  138.         if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  139. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winclonefile.x86_64.exe winclonefile.exe) \
  140. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) winclonefile.x86_64.exe winclonefile.exe) \
  141.         else \
  142. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winclonefile.i686.exe winclonefile.exe) \
  143. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) winclonefile.i686.exe winclonefile.exe) \
  144.         fi
  145.         cp "$(PROJECT_BASEDIR_DIR)/tests/lssparse/lssparse.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/lssparse.x86_64.exe
  146.         if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  147. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf lssparse.x86_64.exe lssparse.exe) \
  148. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) lssparse.x86_64.exe lssparse.exe) \
  149.         fi
  150.         cp "$(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winsg.x86_64.exe
  151.         cp "$(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.i686.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/winsg.i686.exe
  152.         if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  153. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winsg.x86_64.exe winsg.exe) \
  154. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) winsg.x86_64.exe winsg.exe) \
  155.         else \
  156. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf winsg.i686.exe winsg.exe) \
  157. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) winsg.i686.exe winsg.exe) \
  158.         fi
  159.         cp "$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.x86_64.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/nfs_ea.x86_64.exe
  160.         cp "$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.i686.exe" $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/nfs_ea.i686.exe
  161.         if [[ "$(CYGWIN_BASEPATH)" == *64* ]] ; then \
  162. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf nfs_ea.x86_64.exe nfs_ea.exe) \
  163. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) nfs_ea.x86_64.exe nfs_ea.exe) \
  164.         else \
  165. -               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && ln -sf nfs_ea.i686.exe nfs_ea.exe) \
  166. +               (cd $(DESTDIR)/$(CYGWIN_BASEPATH)/bin/ && $(LINKEXE) nfs_ea.i686.exe nfs_ea.exe) \
  167.         fi
  168.         cp $(PROJECT_BASEDIR_DIR)/tests/nfsbuildtest/nfsbuildtest.ksh93 $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/misc/nfsbuildtest.ksh93
  169.         cp $(PROJECT_BASEDIR_DIR)/tests/sparsefiles/testsparsefile1.ksh $(DESTDIR)/$(CYGWIN_BASEPATH)/usr/share/msnfs41client/tests/sparsefiles/testsparsefile1.ksh
  170. --
  171. 2.45.1
  172.  
  173. From b009ffed0eb2746d061dca99e3490179ff0072ec Mon Sep 17 00:00:00 2001
  174. From: Roland Mainz <roland.mainz@nrubsig.org>
  175. Date: Wed, 18 Jun 2025 16:13:11 +0200
  176. Subject: [PATCH 4/5] daemon: Add UTF-8 versions of |UNLEN| and |GNLEN|
  177.  
  178. Add UTF-8 versions of |UNLEN| and |GNLEN|.
  179.  
  180. User and group name buffer length constants |UNLEN| and |GNLEN|
  181. count in codepage characters. Since our code stores these values
  182. as codepage-independent UTF-8 bytes sequences we need to provide
  183. constants for such buffers.
  184.  
  185. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  186. ---
  187. daemon/accesstoken.c  | 17 ++++++++---------
  188.  daemon/acl.c          | 11 +++++------
  189.  daemon/daemon_debug.c | 10 +++++-----
  190.  daemon/nfs41_client.c |  6 ++++--
  191.  daemon/nfs41_daemon.c |  5 ++---
  192.  daemon/sid.c          | 10 +++-------
  193.  daemon/sid.h          | 13 +++++++++++++
  194.  7 files changed, 40 insertions(+), 32 deletions(-)
  195.  
  196. diff --git a/daemon/accesstoken.c b/daemon/accesstoken.c
  197. index eae34c6..c082a58 100644
  198. --- a/daemon/accesstoken.c
  199. +++ b/daemon/accesstoken.c
  200. @@ -24,7 +24,6 @@
  201.  #include "sid.h"
  202.  #include "daemon_debug.h"
  203.  #include "nfs41_daemon.h"
  204. -#include <Lmcons.h>
  205.  
  206.  #ifndef _NFS41_DRIVER_BUILDFEATURES_
  207.  #error NFS41 build config not included
  208. @@ -48,8 +47,8 @@ bool get_token_user_name(HANDLE tok, char *out_buffer)
  209.      DWORD tokdatalen;
  210.      PTOKEN_USER ptuser;
  211.      PSID pusid;
  212. -    DWORD namesize = UNLEN+1;
  213. -    char domainbuffer[UNLEN+1];
  214. +    DWORD namesize = UTF8_UNLEN+1;
  215. +    char domainbuffer[UTF8_UNLEN+1];
  216.      DWORD domainbuffer_size = sizeof(domainbuffer);
  217.      SID_NAME_USE name_use;
  218.  
  219. @@ -92,8 +91,8 @@ bool get_token_primarygroup_name(HANDLE tok, char *out_buffer)
  220.      DWORD tokdatalen;
  221.      PTOKEN_PRIMARY_GROUP ptpgroup;
  222.      PSID pgsid;
  223. -    DWORD namesize = GNLEN+1;
  224. -    char domainbuffer[UNLEN+1];
  225. +    DWORD namesize = UTF8_GNLEN+1;
  226. +    char domainbuffer[UTF8_UNLEN+1];
  227.      DWORD domainbuffer_size = sizeof(domainbuffer);
  228.      SID_NAME_USE name_use;
  229.  
  230. @@ -134,7 +133,7 @@ bool get_token_primarygroup_name(HANDLE tok, char *out_buffer)
  231.  bool fill_auth_unix_aup_gids(HANDLE tok,
  232.      gid_t *aup_gids, int *num_aup_gids)
  233.  {
  234. -    char group_names_buff[RPC_AUTHUNIX_AUP_MAX_NUM_GIDS*(GNLEN+1)];
  235. +    char group_names_buff[RPC_AUTHUNIX_AUP_MAX_NUM_GIDS*(UTF8_GNLEN+1)];
  236.      char *group_names[RPC_AUTHUNIX_AUP_MAX_NUM_GIDS];
  237.      char *s;
  238.      int i;
  239. @@ -149,7 +148,7 @@ bool fill_auth_unix_aup_gids(HANDLE tok,
  240.       */
  241.      for (s=group_names_buff,i=0 ; i < RPC_AUTHUNIX_AUP_MAX_NUM_GIDS ; i++) {
  242.          group_names[i] = s;
  243. -        s += GNLEN+1;
  244. +        s += UTF8_GNLEN+1;
  245.      }
  246.  
  247.      if (!get_token_groups_names(tok,
  248. @@ -186,9 +185,9 @@ bool get_token_groups_names(HANDLE tok,
  249.  {
  250.      DWORD tokdatalen;
  251.      PTOKEN_GROUPS ptgroups;
  252. -    char namebuffer[GNLEN+1];
  253. +    char namebuffer[UTF8_GNLEN+1];
  254.      DWORD namesize;
  255. -    char domainbuffer[UNLEN+1];
  256. +    char domainbuffer[UTF8_UNLEN+1];
  257.      DWORD domainbuffer_size;
  258.      SID_NAME_USE name_use;
  259.      bool retval = false;
  260. diff --git a/daemon/acl.c b/daemon/acl.c
  261. index 5861f1e..370f2d3 100644
  262. --- a/daemon/acl.c
  263. +++ b/daemon/acl.c
  264. @@ -25,7 +25,6 @@
  265.  #include <stdio.h>
  266.  #include <strsafe.h>
  267.  #include <sddl.h>
  268. -#include <Lmcons.h>
  269.  
  270.  #include "nfs41_ops.h"
  271.  #include "nfs41_build_features.h"
  272. @@ -930,9 +929,9 @@ int map_sid2nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid,
  273.  {
  274.      int status, lasterr;
  275.      SID_NAME_USE sid_type = 0;
  276. -    /* |(UNLEN+sizeof('\0'))*2| so we have space for user+domain */
  277. -    char who_buf[(UNLEN+1)*2];
  278. -    char domain_buf[UNLEN+1];
  279. +    /* |(UTF8_UNLEN+sizeof('\0'))*2| so we have space for user+domain */
  280. +    char who_buf[(UTF8_UNLEN+1)*2];
  281. +    char domain_buf[UTF8_UNLEN+1];
  282.      DWORD who_size = sizeof(who_buf), domain_size = sizeof(domain_buf);
  283.      LPSTR sidstr = NULL;
  284.  
  285. @@ -1035,7 +1034,7 @@ int map_sid2nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid,
  286.  
  287.                  if (unixuser_sid2uid(sid, &unixuser_uid)) {
  288.                      if (!nfs41_idmap_uid_to_name(nfs41_dg.idmapper,
  289. -                        unixuser_uid, who_out, UNLEN)) {
  290. +                        unixuser_uid, who_out, UTF8_UNLEN)) {
  291.                          who_size = (DWORD)strlen(who_out);
  292.                          sid_type = SidTypeUser;
  293.                          status = ERROR_SUCCESS;
  294. @@ -1056,7 +1055,7 @@ int map_sid2nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid,
  295.  
  296.                  if (unixgroup_sid2gid(sid, &unixgroup_gid)) {
  297.                      if (!nfs41_idmap_gid_to_group(nfs41_dg.idmapper,
  298. -                        unixgroup_gid, who_out, GNLEN)) {
  299. +                        unixgroup_gid, who_out, UTF8_GNLEN)) {
  300.                          who_size = (DWORD)strlen(who_out);
  301.                          sid_type = SidTypeGroup;
  302.                          status = ERROR_SUCCESS;
  303. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  304. index 0d83e99..20fd420 100644
  305. --- a/daemon/daemon_debug.c
  306. +++ b/daemon/daemon_debug.c
  307. @@ -24,7 +24,6 @@
  308.  #include <windows.h>
  309.  #include <stdio.h>
  310.  #include <sddl.h>
  311. -#include <lmcons.h>
  312.  #include <direct.h> /* for |_getcwd()| */
  313.  
  314.  #include "daemon_debug.h"
  315. @@ -35,6 +34,7 @@
  316.  #include "rpc/rpc.h"
  317.  #include "rpc/auth_sspi.h"
  318.  #include "accesstoken.h"
  319. +#include "sid.h"
  320.  
  321.  int g_debug_level = DEFAULT_DEBUG_LEVEL;
  322.  
  323. @@ -107,8 +107,8 @@ void dprintf_out(const char *restrict format, ...)
  324.      va_list args;
  325.      va_start(args, format);
  326.  #ifdef DPRINTF_PRINT_IMPERSONATION_USER
  327. -    char username[UNLEN+1];
  328. -    char groupname[GNLEN+1];
  329. +    char username[UTF8_UNLEN+1];
  330. +    char groupname[UTF8_GNLEN+1];
  331.      HANDLE tok;
  332.      const char *tok_src;
  333.      bool free_tok = false;
  334. @@ -171,8 +171,8 @@ void logprintf(const char *restrict format, ...)
  335.  #endif /* _MSC_VER */
  336.  {
  337.      SYSTEMTIME stime;
  338. -    char username[UNLEN+1];
  339. -    char groupname[GNLEN+1];
  340. +    char username[UTF8_UNLEN+1];
  341. +    char groupname[UTF8_GNLEN+1];
  342.      HANDLE tok;
  343.      const char *tok_src;
  344.      bool free_tok = false;
  345. diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
  346. index a31d336..92319e7 100644
  347. --- a/daemon/nfs41_client.c
  348. +++ b/daemon/nfs41_client.c
  349. @@ -1,5 +1,6 @@
  350.  /* NFSv4.1 client for Windows
  351. - * Copyright (C) 2012 The Regents of the University of Michigan
  352. + * Copyright (C) 2012 The Regents of the University of Michigan
  353. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  354.   *
  355.   * Olga Kornievskaia <aglo@umich.edu>
  356.   * Casey Bodley <cbodley@umich.edu>
  357. @@ -34,6 +35,7 @@
  358.  #include "daemon_debug.h"
  359.  #include "nfs41_ops.h"
  360.  #include "accesstoken.h"
  361. +#include "sid.h"
  362.  
  363.  
  364.  uint32_t nfs41_exchange_id_flags(
  365. @@ -374,7 +376,7 @@ int nfs41_client_owner(
  366.      DWORD length;
  367.      const ULONGLONG time_created = GetTickCount64();
  368.      int status;
  369. -    char username[UNLEN+1];
  370. +    char username[UTF8_UNLEN+1];
  371.      HANDLE thrtoken = GetCurrentThreadEffectiveToken();
  372.  #ifdef NFS41_DRIVER_USE_AUTHENTICATIONID_FOR_MOUNT_NAMESPACE
  373.      LUID authenticationid;
  374. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  375. index 8e3dcc2..8aba2f6 100644
  376. --- a/daemon/nfs41_daemon.c
  377. +++ b/daemon/nfs41_daemon.c
  378. @@ -30,7 +30,6 @@
  379.  #include <stdio.h>
  380.  
  381.  #include <devioctl.h>
  382. -#include <lmcons.h> /* UNLEN for GetUserName() */
  383.  #include <iphlpapi.h> /* for GetNetworkParam() */
  384.  #include "nfs41_build_features.h"
  385.  #include "nfs41_driver.h" /* for NFS41_USER_DEVICE_NAME_A */
  386. @@ -76,8 +75,8 @@ typedef struct _nfs41_process_thread {
  387.  static int map_current_user_to_ids(nfs41_idmapper *idmapper,
  388.      HANDLE impersonation_tok, uid_t *puid, gid_t *pgid)
  389.  {
  390. -    char username[UNLEN+1];
  391. -    char pgroupname[GNLEN+1];
  392. +    char username[UTF8_UNLEN+1];
  393. +    char pgroupname[UTF8_GNLEN+1];
  394.      int status = NO_ERROR;
  395.  
  396.      if (!get_token_user_name(impersonation_tok, username)) {
  397. diff --git a/daemon/sid.c b/daemon/sid.c
  398. index 0ce84f8..945f744 100644
  399. --- a/daemon/sid.c
  400. +++ b/daemon/sid.c
  401. @@ -27,7 +27,6 @@
  402.  #include <time.h>
  403.  #include <strsafe.h>
  404.  #include <sddl.h>
  405. -#include <Lmcons.h>
  406.  
  407.  #include "nfs41_ops.h"
  408.  #include "nfs41_build_features.h"
  409. @@ -226,7 +225,7 @@ bool unixgroup_sid2gid(PSID psid, gid_t *pgid)
  410.  
  411.  typedef struct _sidcache_entry
  412.  {
  413. -#define SIDCACHE_ENTRY_NAME_SIZE (UNLEN + 1)
  414. +#define SIDCACHE_ENTRY_NAME_SIZE (UTF8_UNLEN + 1)
  415.      char    win32name[SIDCACHE_ENTRY_NAME_SIZE]; /* must fit something like "user@domain" */
  416.      char    aliasname[SIDCACHE_ENTRY_NAME_SIZE];
  417.      PSID    sid;
  418. @@ -426,8 +425,8 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  419.  
  420.      int status = ERROR_INTERNAL_ERROR;
  421.      SID_NAME_USE sid_type = 0;
  422. -    char nfsname_buff[UNLEN+1];
  423. -    char domain_buff[UNLEN+1];
  424. +    char nfsname_buff[UTF8_UNLEN+1];
  425. +    char domain_buff[UTF8_UNLEN+1];
  426.      DWORD domain_len = 0;
  427.  #ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
  428.      signed long user_uid = -1;
  429. @@ -747,9 +746,6 @@ out_free_sid:
  430.  }
  431.  
  432.  
  433. -/* Maximum number of bytes required to store one |wchar_t| as UTF-8 */
  434. -#define MAX_UTF8_BYTES_PER_WCHAR_T (5)
  435. -
  436.  /*
  437.   * |lookupaccountnameutf8()| - UTF-8 version of |LookupAccountNameA()|
  438.   *
  439. diff --git a/daemon/sid.h b/daemon/sid.h
  440. index c19b3d9..3e12c6d 100644
  441. --- a/daemon/sid.h
  442. +++ b/daemon/sid.h
  443. @@ -28,12 +28,25 @@
  444.  #include "nfs41_build_features.h"
  445.  #include "nfs41_daemon.h"
  446.  #include <stdbool.h>
  447. +#include <Lmcons.h> /* for |UNLEN| and |GNLEN| */
  448.  
  449.  typedef struct _sidcache sidcache;
  450.  
  451.  extern sidcache user_sidcache;
  452.  extern sidcache group_sidcache;
  453.  
  454. +/* Maximum number of bytes required to store one |wchar_t| as UTF-8 */
  455. +#define MAX_UTF8_BYTES_PER_WCHAR_T (5)
  456. +
  457. +/*
  458. + * |UNLEN|+|GNLEN| count in codepage characters, but since we store
  459. + * our user and group names as UTF-8 we need buffer sizes which can
  460. + * hold the maximum length in UTF-8
  461. + */
  462. +#define UTF8_UNLEN (UNLEN*MAX_UTF8_BYTES_PER_WCHAR_T)
  463. +#define UTF8_GNLEN (GNLEN*MAX_UTF8_BYTES_PER_WCHAR_T)
  464. +
  465. +
  466.  /*
  467.   * DECLARE_SID_BUFFER - declare a buffer for a SID value
  468.   * Note that buffers with SID values must be 16byte aligned
  469. --
  470. 2.45.1
  471.  
  472. From fd75f2aafff2808f5aba7fdf73b787e3c80a9620 Mon Sep 17 00:00:00 2001
  473. From: Roland Mainz <roland.mainz@nrubsig.org>
  474. Date: Wed, 18 Jun 2025 17:45:07 +0200
  475. Subject: [PATCH 5/5] daemon,sys: |IOCTL_NFS41_READ| and |IOCTL_NFS41_WRITE|
  476.  should return error codes on failure
  477.  
  478. |IOCTL_NFS41_READ| and |IOCTL_NFS41_WRITE| should return error codes on failure.
  479.  
  480. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  481. ---
  482. daemon/nfs41_daemon.c     |  4 +++-
  483.  sys/nfs41sys_updowncall.c | 25 +++++++------------------
  484.  2 files changed, 10 insertions(+), 19 deletions(-)
  485.  
  486. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  487. index 8aba2f6..d8bf867 100644
  488. --- a/daemon/nfs41_daemon.c
  489. +++ b/daemon/nfs41_daemon.c
  490. @@ -168,7 +168,9 @@ static unsigned int nfsd_worker_thread_main(void *args)
  491.          status = DeviceIoControl(pipe, IOCTL_NFS41_READ, NULL, 0,
  492.              outbuf, UPCALL_BUF_SIZE, (LPDWORD)&outbuf_len, NULL);
  493.          if (!status) {
  494. -            eprintf("IOCTL_NFS41_READ failed %d\n", GetLastError());
  495. +            eprintf("nfsd_worker_thread_main: "
  496. +                "IOCTL_NFS41_READ failed, status=0x%x, lasterr=%d\n",
  497. +                status, (int)GetLastError());
  498.              continue;
  499.          }
  500.  
  501. diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
  502. index 29e7ac5..9ec5382 100644
  503. --- a/sys/nfs41sys_updowncall.c
  504. +++ b/sys/nfs41sys_updowncall.c
  505. @@ -590,13 +590,6 @@ process_upcall:
  506.              RxContext->InformationToReturn = len;
  507.      }
  508.      else {
  509. -/*
  510. - * gisburn: |NFSV41_UPCALL_RETRY_WAIT| disabled for now because it
  511. - * causes nfsd_debug.exe to hang on <CTRL-C>
  512. - */
  513. -#ifdef NFSV41_UPCALL_RETRY_WAIT
  514. -retry_wait:
  515. -#endif /* NFSV41_UPCALL_RETRY_WAIT */
  516.          status = KeWaitForSingleObject(&upcallEvent, Executive, UserMode, TRUE,
  517.              (PLARGE_INTEGER) NULL);
  518.          print_wait_status(0, "[upcall]", status, NULL, NULL, 0);
  519. @@ -606,17 +599,9 @@ retry_wait:
  520.              case STATUS_USER_APC:
  521.              case STATUS_ALERTED:
  522.                  DbgP("nfs41_upcall: KeWaitForSingleObject() "
  523. -                    "returned status(=0x%lx)"
  524. -#ifdef NFSV41_UPCALL_RETRY_WAIT
  525. -                    ", retry waiting"
  526. -#endif /* NFSV41_UPCALL_RETRY_WAIT */
  527. -                    "\n",
  528. +                    "returned status(=0x%lx)\n",
  529.                      (long)status);
  530. -#ifdef NFSV41_UPCALL_RETRY_WAIT
  531. -                goto retry_wait;
  532. -#else
  533. -                /* fall-through */
  534. -#endif /* NFSV41_UPCALL_RETRY_WAIT */
  535. +                goto out;
  536.              default:
  537.                  DbgP("nfs41_upcall: KeWaitForSingleObject() "
  538.                      "returned UNEXPECTED status(=0x%lx)\n",
  539. @@ -652,7 +637,10 @@ NTSTATUS nfs41_downcall(
  540.      tmp = &stacktmp;
  541.  #else
  542.      tmp = nfs41_downcall_allocate_updowncall_entry();
  543. -    if (tmp == NULL) goto out;
  544. +    if (tmp == NULL) {
  545. +        status = STATUS_INSUFFICIENT_RESOURCES;
  546. +        goto out;
  547. +    }
  548.  #endif /* USE_STACK_FOR_DOWNCALL_UPDOWNCALLENTRY_MEM */
  549.  
  550.      unmarshal_nfs41_header(tmp, &buf);
  551. @@ -675,6 +663,7 @@ NTSTATUS nfs41_downcall(
  552.      SeStopImpersonatingClient();
  553.      if (!found) {
  554.          print_error("Didn't find xid=%lld entry\n", tmp->xid);
  555. +        status = STATUS_NOT_FOUND;
  556.          goto out_free;
  557.      }
  558.  
  559. --
  560. 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