pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches to support non-ASCII characters in winsg.exe, 32bit fixes+misc, 2025-06-16
Posted by Anonymous on Mon 16th Jun 2025 20:19
raw | new post

  1. From 26418b98f5ddd743e98088d7d6a9e95c6f4cf160 Mon Sep 17 00:00:00 2001
  2. From: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  3. Date: Mon, 16 Jun 2025 15:57:07 +0200
  4. Subject: [PATCH 1/7] sys: VS2022 error - Remove |FileAccessInformation| case
  5.  which is wrong for QueryVolumeInformation
  6.  
  7. Fix Visual Studio 2022 build error "...\sys\nfs41sys_volinfo.c(202,10):
  8. warning C5286: implicit conversion from enum type
  9. '_FILE_INFORMATION_CLASS' to enum type '_FSINFOCLASS'; use an explicit
  10. cast to silence this warning...".
  11.  
  12. QueryVolumeInformation does not have a |FileAccessInformation| class,
  13. this |case FileAccessInformation| is just wrong and should be removed
  14. completely.
  15.  
  16. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  17. ---
  18. sys/nfs41sys_volinfo.c | 3 ---
  19.  1 file changed, 3 deletions(-)
  20.  
  21. diff --git a/sys/nfs41sys_volinfo.c b/sys/nfs41sys_volinfo.c
  22. index af1cfa3..a8435b9 100644
  23. --- a/sys/nfs41sys_volinfo.c
  24. +++ b/sys/nfs41sys_volinfo.c
  25. @@ -199,9 +199,6 @@ NTSTATUS nfs41_QueryVolumeInformation(
  26.          status = STATUS_SUCCESS;
  27.          goto out;
  28.      }
  29. -    case FileAccessInformation:
  30. -        status = STATUS_NOT_SUPPORTED;
  31. -        goto out;
  32.  
  33.      case FileFsAttributeInformation:
  34.          if (RxContext->Info.LengthRemaining < FS_ATTR_LEN) {
  35. --
  36. 2.45.1
  37.  
  38. From d7035e7eb97e851ddcfe7ccd2fe1253d1149d9d8 Mon Sep 17 00:00:00 2001
  39. From: Cedric Blancher <cedric.blancher@gmail.com>
  40. Date: Mon, 16 Jun 2025 16:05:13 +0200
  41. Subject: [PATCH 2/7] daemon: [32bit-Windows only] Fix crash in
  42.  |upcall_parse()| with nfsd.exe -d 2
  43.  
  44. Windows 32bit kernel only:
  45. Fix crash in |upcall_parse()| with nfsd.exe -d 2 (debug level 2),
  46. caused by improper types in vfprintf() varargs.
  47.  
  48. Stack trace:
  49. --- cut ---
  50. nfsd!vfprintf(struct _iobuf * _Stream = 0x56412810, char * _Format = 0x0055a4f0 "time=%ld version=%d xid=%d opcode='%s' session=0x%x open_state=0x%x.", char * _ArgList = 0x0185a90c "???")+0x1c [C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\ucrt\stdio.h @ 659]
  51. nfsd!dprintf_out(char * format = 0x0055a4f0 "time=%ld version=%d xid=%d opcode='%s' session=0x%x open_state=0x%x.")+0x21f [ms-nfs41-client\daemon\daemon_debug.c @ 157]
  52. nfsd!upcall_parse(unsigned char * buffer = 0x0185dcc4 "???", unsigned int length = 0x36, struct __nfs41_upcall * upcall = 0x0185abcc)+0x1d9 [ms-nfs41-client\daemon\upcall.c @ 133]
  53. nfsd!nfsd_worker_thread_main(void * args = 0x0055c008)+0x134 [ms-nfs41-client\daemon\nfs41_daemon.c @ 175]
  54. nfsd!nfsd_thread_main(void * args = 0x0055c008)+0x3d [ms-nfs41-client\daemon\nfs41_daemon.c @ 245]
  55. ucrtbased!invoke_thread_procedure(<function> * procedure = 0x0050e050, void * context = 0x0055c008)+0x28 [d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp @ 92]
  56. ucrtbased!thread_start<unsigned int (void * parameter = 0x00c47320)+0xab [d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp @ 115]
  57. KERNEL32!BaseThreadInitThunk+0x19
  58. ntdll!__RtlUserThreadStart+0x2b
  59. ntdll!_RtlUserThreadStart+0x1b
  60. --- cut ---
  61.  
  62. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  63. ---
  64. daemon/upcall.c | 13 ++++++++++---
  65.  1 file changed, 10 insertions(+), 3 deletions(-)
  66.  
  67. diff --git a/daemon/upcall.c b/daemon/upcall.c
  68. index 2f200a7..93fc329 100644
  69. --- a/daemon/upcall.c
  70. +++ b/daemon/upcall.c
  71. @@ -130,11 +130,18 @@ int upcall_parse(
  72.      status = safe_read(&buffer, &length, &upcall->state_ref, sizeof(HANDLE));
  73.      if (status) goto out;
  74.  
  75. -    DPRINTF(2, ("time=%ld version=%d xid=%d opcode='%s' session=0x%x open_state=0x%x\n",
  76. -        time(NULL), version, upcall->xid, opcode2string(upcall_upcode), upcall->root_ref,
  77. +    DPRINTF(2,
  78. +        ("time=%lld version=%ld xid=%lld opcode='%s' "
  79. +        "root_ref=0x%p state_ref=0x%p\n",
  80. +        (long long)time(NULL),
  81. +        (long)version,
  82. +        (long long)upcall->xid,
  83. +        opcode2string(upcall_upcode),
  84. +        upcall->root_ref,
  85.          upcall->state_ref));
  86.      if (version != NFS41D_VERSION) {
  87. -        eprintf("received version %d expecting version %d\n", version, NFS41D_VERSION);
  88. +        eprintf("received version %ld expecting version %ld\n",
  89. +            (long)version, (long)NFS41D_VERSION);
  90.          upcall->status = status = NFSD_VERSION_MISMATCH;
  91.          goto out;
  92.      }
  93. --
  94. 2.45.1
  95.  
  96. From 9898849dd3fb10a9a4eb1df1bd188e6e768f6f04 Mon Sep 17 00:00:00 2001
  97. From: Roland Mainz <roland.mainz@nrubsig.org>
  98. Date: Mon, 16 Jun 2025 17:27:13 +0200
  99. Subject: [PATCH 3/7] daemon: Fix |DPRINTF()|/|eprintf()| format type
  100.  mismatches
  101.  
  102. Fix |DPRINTF()|/|eprintf()| format type mismatches, and use
  103. Visual Sudio-specific macros to enable warnings in Analyzer
  104. mode to catch any new mismatches.
  105.  
  106. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  107. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  108. ---
  109. daemon/daemon_debug.c | 28 ++++++++++++++++++++++------
  110.  daemon/daemon_debug.h | 20 +++++++++++++++-----
  111.  daemon/delegation.c   |  6 +++---
  112.  daemon/fsctl.c        |  2 +-
  113.  daemon/idmap.c        | 33 ++++++++++++++++++++++-----------
  114.  daemon/nfs41_daemon.c | 11 +++++++----
  115.  daemon/open.c         |  4 ++--
  116.  daemon/readdir.c      |  9 +++++----
  117.  daemon/readwrite.c    |  8 +++++---
  118.  9 files changed, 82 insertions(+), 39 deletions(-)
  119.  
  120. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  121. index 6b53e94..0d83e99 100644
  122. --- a/daemon/daemon_debug.c
  123. +++ b/daemon/daemon_debug.c
  124. @@ -98,7 +98,11 @@ void open_log_files()
  125.  
  126.  #define DPRINTF_PRINT_IMPERSONATION_USER 1
  127.  
  128. -void dprintf_out(LPCSTR format, ...)
  129. +#ifdef _MSC_VER
  130. +void dprintf_out(_In_z_ _Printf_format_string_ const char *restrict format, ...)
  131. +#else
  132. +void dprintf_out(const char *restrict format, ...)
  133. +#endif /* _MSC_VER */
  134.  {
  135.      va_list args;
  136.      va_start(args, format);
  137. @@ -160,7 +164,11 @@ void dprintf_out(LPCSTR format, ...)
  138.  }
  139.  
  140.  /* log events (mount, umount, auth, ...) */
  141. -void logprintf(LPCSTR format, ...)
  142. +#ifdef _MSC_VER
  143. +void logprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...)
  144. +#else
  145. +void logprintf(const char *restrict format, ...)
  146. +#endif /* _MSC_VER */
  147.  {
  148.      SYSTEMTIME stime;
  149.      char username[UNLEN+1];
  150. @@ -214,7 +222,11 @@ void logprintf(LPCSTR format, ...)
  151.      }
  152.  }
  153.  
  154. -void eprintf_out(LPCSTR format, ...)
  155. +#ifdef _MSC_VER
  156. +void eprintf_out(_In_z_ _Printf_format_string_ const char *restrict format, ...)
  157. +#else
  158. +void eprintf_out(const char *restrict format, ...)
  159. +#endif /* _MSC_VER */
  160.  {
  161.      va_list args;
  162.      va_start(args, format);
  163. @@ -223,7 +235,11 @@ void eprintf_out(LPCSTR format, ...)
  164.      va_end(args);
  165.  }
  166.  
  167. -void eprintf(LPCSTR format, ...)
  168. +#ifdef _MSC_VER
  169. +void eprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...)
  170. +#else
  171. +void eprintf(const char *restrict format, ...)
  172. +#endif /* _MSC_VER */
  173.  {
  174.      va_list args;
  175.      va_start(args, format);
  176. @@ -1166,7 +1182,7 @@ void debug_list_sparsefile_holes(nfs41_open_state *state)
  177.          dprintf_out("initial SEEK_HOLE failed "
  178.          "OP_SEEK(sa_offset=%llu,sa_what=SEEK_HOLE) "
  179.          "failed with %d(='%s')\n",
  180. -        0,
  181. +        0ULL,
  182.          seek_status,
  183.          nfs_error_string(seek_status));
  184.          goto out;
  185. @@ -1216,7 +1232,7 @@ void debug_list_sparsefile_holes(nfs41_open_state *state)
  186.          dprintf_out("initial SEEL_DATA failed "
  187.          "OP_SEEK(sa_offset=%llu,sa_what=SEEK_DATA) "
  188.          "failed with %d(='%s')\n",
  189. -        0,
  190. +        0ULL,
  191.          seek_status,
  192.          nfs_error_string(seek_status));
  193.          goto out;
  194. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  195. index f3af022..6bc1119 100644
  196. --- a/daemon/daemon_debug.h
  197. +++ b/daemon/daemon_debug.h
  198. @@ -1,5 +1,6 @@
  199.  /* NFSv4.1 client for Windows
  200. - * Copyright (C) 2012 The Regents of the University of Michigan
  201. + * Copyright (C) 2012 The Regents of the University of Michigan
  202. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  203.   *
  204.   * Olga Kornievskaia <aglo@umich.edu>
  205.   * Casey Bodley <cbodley@umich.edu>
  206. @@ -120,10 +121,19 @@ extern int g_debug_level;
  207.  
  208.  /* daemon_debug.h */
  209.  void set_debug_level(int level);
  210. -void logprintf(LPCSTR format, ...);
  211. -void dprintf_out(LPCSTR format, ...);
  212. -void eprintf_out(LPCSTR format, ...);
  213. -void eprintf(LPCSTR format, ...);
  214. +#ifdef _MSC_VER
  215. +void logprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...);
  216. +void dprintf_out(_In_z_ _Printf_format_string_ const char *restrict format,
  217. +    ...);
  218. +void eprintf_out(_In_z_ _Printf_format_string_ const char *restrict format,
  219. +    ...);
  220. +void eprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...);
  221. +#else
  222. +void logprintf(const char *restrict format, ...);
  223. +void dprintf_out(const char *restrict format, ...);
  224. +void eprintf_out(const char *restrict format, ...);
  225. +void eprintf(const char *restrict format, ...);
  226. +#endif /* _MSC_VER */
  227.  
  228.  const char *map_nfs_ftype2str(int ftype);
  229.  const char *map_nfs_acetype2str(uint32_t ace_type);
  230. diff --git a/daemon/delegation.c b/daemon/delegation.c
  231. index fdd3533..efd2b20 100644
  232. --- a/daemon/delegation.c
  233. +++ b/daemon/delegation.c
  234. @@ -281,7 +281,7 @@ static int delegation_return(
  235.          DWORD inbuf_len = sizeof(HANDLE), outbuf_len, dstatus;
  236.          uint32_t length;
  237.          DPRINTF(1,
  238. -            ("delegation_return: making a downcall for srv_open=0x%x\n",
  239. +            ("delegation_return: making a downcall for srv_open=0x%p\n",
  240.              deleg->srv_open));
  241.          pipe = CreateFileA(NFS41_USER_DEVICE_NAME_A, GENERIC_READ|GENERIC_WRITE,
  242.                  FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
  243. @@ -507,7 +507,7 @@ int nfs41_delegate_open(
  244.      if (!status) {
  245.          DPRINTF(1,
  246.              ("nfs41_delegate_open: "
  247. -            "updating srv_open from 0x%x to 0x%x\n",
  248. +            "updating srv_open from 0x%p to 0x%p\n",
  249.              deleg->srv_open, state->srv_open));
  250.          deleg->srv_open = state->srv_open;
  251.      }
  252. @@ -623,7 +623,7 @@ void nfs41_delegation_remove_srvopen(
  253.      if (delegation_find(session->client, &file->fh, deleg_file_cmp, &deleg))
  254.          return;
  255.      DPRINTF(1, ("nfs41_delegation_remove_srvopen: removing reference to "
  256. -        "srv_open=0x%x\n", deleg->srv_open));
  257. +        "srv_open=0x%p\n", deleg->srv_open));
  258.      AcquireSRWLockExclusive(&deleg->lock);
  259.      deleg->srv_open = NULL;
  260.      ReleaseSRWLockExclusive(&deleg->lock);
  261. diff --git a/daemon/fsctl.c b/daemon/fsctl.c
  262. index b5de6b4..96f616f 100644
  263. --- a/daemon/fsctl.c
  264. +++ b/daemon/fsctl.c
  265. @@ -458,7 +458,7 @@ static int parse_duplicatedata(unsigned char *buffer,
  266.          "duplicatedata=(src_state=0x%p srcfileoffset=%lld "
  267.          "destfileoffset=%lld bytecount=%lld)\n",
  268.          opcode2string(upcall->opcode),
  269. -        (long long)args->src_state,
  270. +        args->src_state,
  271.          (long long)args->srcfileoffset,
  272.          (long long)args->destfileoffset,
  273.          (long long)args->bytecount));
  274. diff --git a/daemon/idmap.c b/daemon/idmap.c
  275. index 053796f..5917c64 100644
  276. --- a/daemon/idmap.c
  277. +++ b/daemon/idmap.c
  278. @@ -1,5 +1,6 @@
  279.  /* NFSv4.1 client for Windows
  280. - * Copyright (C) 2012 The Regents of the University of Michigan
  281. + * Copyright (C) 2012 The Regents of the University of Michigan
  282. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  283.   *
  284.   * Olga Kornievskaia <aglo@umich.edu>
  285.   * Casey Bodley <cbodley@umich.edu>
  286. @@ -266,8 +267,8 @@ static int config_defaults(
  287.              if (FAILED(StringCchCopyA(dst, option->max_len, option->def))) {
  288.                  status = ERROR_BUFFER_OVERFLOW;
  289.                  eprintf("failed to parse default value of '%s'=\"%s\": "
  290. -                    "buffer overflow > %u\n", option->key, option->def,
  291. -                    option->max_len);
  292. +                    "buffer overflow > %lu\n", option->key, option->def,
  293. +                    (unsigned long)option->max_len);
  294.                  break;
  295.              }
  296.          }
  297. @@ -584,7 +585,7 @@ static int idmap_filter(
  298.                  config->attributes[lookup->attr], (const char *)lookup->value))) {
  299.              status = ERROR_BUFFER_OVERFLOW;
  300.              eprintf("ldap filter buffer overflow: '%s=%s'\n",
  301. -                config->attributes[lookup->attr], lookup->value);
  302. +                config->attributes[lookup->attr], (const char *)lookup->value);
  303.          }
  304.          break;
  305.  
  306. @@ -727,8 +728,11 @@ static int idmap_lookup_user(
  307.  
  308.          if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) {
  309.              DPRINTF(CYGWINIDLVL,
  310. -                ("# ATTR_USER_NAME: cygwin_getent_passwd: returned '%s', uid=%u, gid=%u\n",
  311. -                lookup->value, (unsigned int)cy_uid, (unsigned int)cy_gid));
  312. +                ("# ATTR_USER_NAME: cygwin_getent_passwd: "
  313. +                "returned '%s', uid=%u, gid=%u\n",
  314. +                (const char *)lookup->value,
  315. +                (unsigned int)cy_uid,
  316. +                (unsigned int)cy_gid));
  317.              (void)snprintf(principal_name, sizeof(principal_name),
  318.                  "%s@%s", (const char *)lookup->value,
  319.                  context->config.localdomain_name);
  320. @@ -758,8 +762,11 @@ static int idmap_lookup_user(
  321.  
  322.          if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) {
  323.              DPRINTF(CYGWINIDLVL,
  324. -                ("# ATTR_PRINCIPAL: cygwin_getent_passwd: returned '%s', uid=%u, gid=%u\n",
  325. -                lookup->value, (unsigned int)cy_uid, (unsigned int)cy_gid));
  326. +                ("# ATTR_PRINCIPAL: cygwin_getent_passwd: "
  327. +                "returned '%s', uid=%u, gid=%u\n",
  328. +                (const char *)lookup->value,
  329. +                (unsigned int)cy_uid,
  330. +                (unsigned int)cy_gid));
  331.              (void)snprintf(principal_name, sizeof(principal_name),
  332.                  "%s@%s", (const char *)lookup->value,
  333.                  context->config.localdomain_name);
  334. @@ -787,8 +794,11 @@ static int idmap_lookup_user(
  335.  
  336.          if (!cygwin_getent_passwd(search_name, res_username, &cy_uid, &cy_gid)) {
  337.              DPRINTF(CYGWINIDLVL,
  338. -                ("# ATTR_UID: cygwin_getent_passwd: returned '%s', uid=%u, gid=%u\n",
  339. -                res_username, (unsigned int)cy_uid, (unsigned int)cy_gid));
  340. +                ("# ATTR_UID: cygwin_getent_passwd: "
  341. +                "returned '%s', uid=%u, gid=%u\n",
  342. +                res_username,
  343. +                (unsigned int)cy_uid,
  344. +                (unsigned int)cy_gid));
  345.              (void)snprintf(principal_name, sizeof(principal_name),
  346.                  "%s@%s", res_username, context->config.localdomain_name);
  347.  
  348. @@ -881,7 +891,8 @@ static int idmap_lookup_group(
  349.              DPRINTF(CYGWINIDLVL,
  350.                  ("# ATTR_GROUP_NAME: cygwin_getent_group: "
  351.                  "returned '%s', gid=%u\n",
  352. -                lookup->value, (unsigned int)cy_gid));
  353. +                (const char *)lookup->value,
  354. +                (unsigned int)cy_gid));
  355.              StringCchCopyA(group->name, VAL_LEN, lookup->value);
  356.              group->gid = cy_gid;
  357.              status = 0;
  358. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  359. index 0fd2255..70c6875 100644
  360. --- a/daemon/nfs41_daemon.c
  361. +++ b/daemon/nfs41_daemon.c
  362. @@ -1,5 +1,6 @@
  363.  /* NFSv4.1 client for Windows
  364. - * Copyright (C) 2012 The Regents of the University of Michigan
  365. + * Copyright (C) 2012 The Regents of the University of Michigan
  366. + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
  367.   *
  368.   * Olga Kornievskaia <aglo@umich.edu>
  369.   * Casey Bodley <cbodley@umich.edu>
  370. @@ -534,7 +535,8 @@ static int getdomainname()
  371.                  else {
  372.                      size_t i, len = strlen(hostname);
  373.                      char *p = hostname;
  374. -                    DPRINTF(1, ("getdomainname: hostname '%s' %d\n", hostname, len));
  375. +                    DPRINTF(1, ("getdomainname: hostname '%s' %ld\n",
  376. +                        hostname, (long)len));
  377.                      for (i = 0; i < len; i++)
  378.                          if (p[i] == '.')
  379.                              break;
  380. @@ -542,8 +544,9 @@ static int getdomainname()
  381.                          break;
  382.                      flag = TRUE;
  383.                      memcpy(nfs41_dg.localdomain_name, &hostname[i+1], len-i);
  384. -                    DPRINTF(1, ("getdomainname: domainname '%s' %d\n",
  385. -                            nfs41_dg.localdomain_name, strlen(nfs41_dg.localdomain_name)));
  386. +                    DPRINTF(1, ("getdomainname: domainname '%s' %ld\n",
  387. +                            nfs41_dg.localdomain_name,
  388. +                            (long)strlen(nfs41_dg.localdomain_name)));
  389.                      goto out_loop;
  390.                  }
  391.                  break;
  392. diff --git a/daemon/open.c b/daemon/open.c
  393. index c3c471f..aeaae11 100644
  394. --- a/daemon/open.c
  395. +++ b/daemon/open.c
  396. @@ -251,7 +251,7 @@ static int do_open(
  397.      if (deleg_state) {
  398.          deleg_state->srv_open = state->srv_open;
  399.          DPRINTF(1, ("do_open: "
  400. -            "received delegation: saving srv_open = 0x%x\n",
  401. +            "received delegation: saving srv_open = 0x%p\n",
  402.              state->srv_open));
  403.      }
  404.  
  405. @@ -1310,7 +1310,7 @@ static int parse_close(unsigned char *buffer, uint32_t length, nfs41_upcall *upc
  406.  
  407.      DPRINTF(1,
  408.          ("parsing NFS41_SYSOP_CLOSE: "
  409. -        "remove=%d srv_open=0x%x renamed=%d "
  410. +        "remove=%d srv_open=0x%p renamed=%d "
  411.          "filename='%s'\n",
  412.          args->remove, args->srv_open, args->renamed,
  413.          args->remove ? args->path : ""));
  414. diff --git a/daemon/readdir.c b/daemon/readdir.c
  415. index 82510df..f3564bf 100644
  416. --- a/daemon/readdir.c
  417. +++ b/daemon/readdir.c
  418. @@ -871,13 +871,14 @@ fetch_entries:
  419.              entry = (nfs41_readdir_entry*)entry_pos;
  420.              offset = (PULONG)dst_pos; /* ULONG NextEntryOffset */
  421.  
  422. -            DPRINTF(2, ("filter '%s' looking at '%s' with cookie %d\n",
  423. -                args->filter, entry->name, entry->cookie));
  424. +            DPRINTF(2, ("filter '%s' looking at '%s' with cookie %lld\n",
  425. +                args->filter, entry->name, (long long)entry->cookie));
  426.              if (readdir_filter((const char*)args->filter, entry->name)) {
  427.                  if (readdir_copy_entry(args, entry, &dst_pos, &dst_len)) {
  428.                      eof = 0;
  429. -                    DPRINTF(2, ("not enough space to copy entry '%s' (cookie %d)\n",
  430. -                        entry->name, entry->cookie));
  431. +                    DPRINTF(2,
  432. +                        ("not enough space to copy entry '%s' (cookie %lld)\n",
  433. +                        entry->name, (long long)entry->cookie));
  434.                      break;
  435.                  }
  436.                  last_offset = offset;
  437. diff --git a/daemon/readwrite.c b/daemon/readwrite.c
  438. index f9ac3ee..ae9a08f 100644
  439. --- a/daemon/readwrite.c
  440. +++ b/daemon/readwrite.c
  441. @@ -268,8 +268,8 @@ retry_write:
  442.      committed = FILE_SYNC4;
  443.  
  444.      if (to_send > maxwritesize) {
  445. -        DPRINTF(1, ("handle_nfs41_write: writing %d in chunks of %d\n",
  446. -            to_send, maxwritesize));
  447. +        DPRINTF(1, ("handle_nfs41_write: writing %lu in chunks of %lu\n",
  448. +            (unsigned long)to_send, (unsigned long)maxwritesize));
  449.      }
  450.  
  451.      while(to_send > 0) {
  452. @@ -293,7 +293,9 @@ retry_write:
  453.          }
  454.      }
  455.      if (committed != FILE_SYNC4) {
  456. -        DPRINTF(1, ("sending COMMIT for offset=%d and len=%d\n", args->offset, len));
  457. +        DPRINTF(1, ("sending COMMIT for offset=%llu and len=%d\n",
  458. +            (unsigned long long)args->offset,
  459. +            (unsigned long)len));
  460.          status = nfs41_commit(session, file, args->offset, len, 1, &verf, &info);
  461.          if (status)
  462.              goto out;
  463. --
  464. 2.45.1
  465.  
  466. From 9035f554d452e4e7d219217efaf4a0897ccaba62 Mon Sep 17 00:00:00 2001
  467. From: Roland Mainz <roland.mainz@nrubsig.org>
  468. Date: Mon, 16 Jun 2025 19:10:00 +0200
  469. Subject: [PATCH 4/7] cygwin_idmapper.ksh: Workaround for double quotation
  470.  marks ('"') issue for Cygwin 3.3 compatibility
  471.  
  472. Cygwin 3.3 somehow can generate extra double quotation marks ('"')
  473. in some cases when called from |CreateProcessW()| in our case.
  474.  
  475. Since '"' is an illegal character in group names we just filter them
  476. all out.
  477.  
  478. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  479. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  480. ---
  481. cygwin_idmapper.ksh | 12 ++++++++----
  482.  1 file changed, 8 insertions(+), 4 deletions(-)
  483.  
  484. diff --git a/cygwin_idmapper.ksh b/cygwin_idmapper.ksh
  485. index e55fe96..056bfa9 100644
  486. --- a/cygwin_idmapper.ksh
  487. +++ b/cygwin_idmapper.ksh
  488. @@ -12,10 +12,14 @@ export LC_ALL='en_US.UTF-8'
  489.  # (stored in compound variable so we
  490.  # can do a $ print -u2 -v c # for debugging)
  491.  #
  492. -compound c=(
  493. -       mode="$1"
  494. -       name="${2-}"
  495. -)
  496. +compound c
  497. +
  498. +c.mode="$1"
  499. +if (( $# > 1 )) ; then
  500. +       # strip '"' characters (for Cygwin 3.3 compatibility)
  501. +       # note that "${2-//..." does NOT work!
  502. +       c.name="${2//\"/}"
  503. +fi
  504.  
  505.  #
  506.  # Windows uses localised user and group names,
  507. --
  508. 2.45.1
  509.  
  510. From ce392a38b1fbb30a8275082a87b0613a266686e9 Mon Sep 17 00:00:00 2001
  511. From: Roland Mainz <roland.mainz@nrubsig.org>
  512. Date: Mon, 16 Jun 2025 19:21:11 +0200
  513. Subject: [PATCH 5/7] tests: Typo in winsg usage
  514.  
  515. Typo in winsg usage, plain Cygwin shell should be started
  516. with $ winsg -g abc2 -c #
  517.  
  518. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  519. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  520. ---
  521. tests/winsg/winsg.c | 4 ++--
  522.  1 file changed, 2 insertions(+), 2 deletions(-)
  523.  
  524. diff --git a/tests/winsg/winsg.c b/tests/winsg/winsg.c
  525. index b6d332c..5ab0ffd 100644
  526. --- a/tests/winsg/winsg.c
  527. +++ b/tests/winsg/winsg.c
  528. @@ -2,7 +2,7 @@
  529.  /*
  530.   * MIT License
  531.   *
  532. - * Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org>
  533. + * Copyright (c) 2024-2025 Roland Mainz <roland.mainz@nrubsig.org>
  534.   *
  535.   * Permission is hereby granted, free of charge, to any person obtaining a copy
  536.   * of this software and associated documentation files (the "Software"), to deal
  537. @@ -289,7 +289,7 @@ int usage(void)
  538.          "\t\twinsg /g abc1 /C\n"
  539.          "\n"
  540.          "\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
  541. -        "\t\twinsg -g abc2 -g\n"
  542. +        "\t\twinsg -g abc2 -c\n"
  543.          "\n"
  544.          "\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
  545.          "\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
  546. --
  547. 2.45.1
  548.  
  549. From 49484dc195ecf0a4469eeeaa2b126e92cfa135dd Mon Sep 17 00:00:00 2001
  550. From: Roland Mainz <roland.mainz@nrubsig.org>
  551. Date: Mon, 16 Jun 2025 20:58:42 +0200
  552. Subject: [PATCH 6/7] tests: winsg.exe should support group names with
  553.  non-ASCII characters
  554.  
  555. winsg.exe should support group names with non-ASCII characters.
  556.  
  557. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  558. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  559. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  560. ---
  561. tests/winsg/Makefile |   4 +-
  562.  tests/winsg/winsg.c  | 262 ++++++++++++++++++++++---------------------
  563.  2 files changed, 138 insertions(+), 128 deletions(-)
  564.  
  565. diff --git a/tests/winsg/Makefile b/tests/winsg/Makefile
  566. index 6c548ca..7a1ef4c 100644
  567. --- a/tests/winsg/Makefile
  568. +++ b/tests/winsg/Makefile
  569. @@ -7,10 +7,10 @@
  570.  all: winsg.i686.exe winsg.x86_64.exe winsg.exe
  571.  
  572.  winsg.i686.exe: winsg.c
  573. -       clang -target i686-pc-windows-gnu -Wall -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.i686.exe
  574. +       clang -target i686-pc-windows-gnu -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.i686.exe
  575.  
  576.  winsg.x86_64.exe: winsg.c
  577. -       clang -target x86_64-pc-windows-gnu -Wall -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe
  578. +       clang -target x86_64-pc-windows-gnu -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe
  579.  
  580.  winsg.exe: winsg.x86_64.exe
  581.         ln -s winsg.x86_64.exe winsg.exe
  582. diff --git a/tests/winsg/winsg.c b/tests/winsg/winsg.c
  583. index 5ab0ffd..77600f3 100644
  584. --- a/tests/winsg/winsg.c
  585. +++ b/tests/winsg/winsg.c
  586. @@ -31,7 +31,8 @@
  587.  
  588.  /*
  589.   * Compile with:
  590. - * $ clang -target x86_64-pc-windows-gnu -Wall -g winsg.c -o winsg.exe #
  591. + * $ clang -target x86_64-pc-windows-gnu -municode -Wall -Wextra \
  592. + *      -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe #
  593.   */
  594.  
  595.  #define UNICODE 1
  596. @@ -40,6 +41,8 @@
  597.  #include <windows.h>
  598.  #include <stdio.h>
  599.  #include <stdbool.h>
  600. +#include <locale.h>
  601. +#include <fcntl.h>
  602.  #include <assert.h>
  603.  #include <Lmcons.h>
  604.  #include <process.h>
  605. @@ -51,11 +54,11 @@
  606.  #endif
  607.  
  608.  #ifdef _WIN64
  609. -#define CYGWIN_BASH_PATH "C:\\cygwin64\\bin\\bash.exe"
  610. +#define CYGWIN_BASH_PATH L"C:\\cygwin64\\bin\\bash.exe"
  611.  #else
  612. -#define CYGWIN_BASH_PATH "C:\\cygwin\\bin\\bash.exe"
  613. +#define CYGWIN_BASH_PATH L"C:\\cygwin\\bin\\bash.exe"
  614.  #endif /* _WIN64 */
  615. -#define WIN32_CMDEXE_PATH "C:\\Windows\\system32\\cmd.exe"
  616. +#define WIN32_CMDEXE_PATH L"C:\\Windows\\system32\\cmd.exe"
  617.  
  618.  /*
  619.   * DECLARE_SID_BUFFER - declare a buffer for a SID value
  620. @@ -87,13 +90,13 @@
  621.  
  622.  D(
  623.  static
  624. -bool get_token_primarygroup_name(HANDLE tok, char *out_buffer)
  625. +bool get_token_primarygroup_name(HANDLE tok, wchar_t *out_buffer)
  626.  {
  627.      DWORD tokdatalen;
  628.      PTOKEN_PRIMARY_GROUP ptpgroup;
  629.      PSID pgsid;
  630.      DWORD namesize = GNLEN+1;
  631. -    char domainbuffer[UNLEN+1];
  632. +    wchar_t domainbuffer[UNLEN+1];
  633.      DWORD domainbuffer_size = sizeof(domainbuffer);
  634.      SID_NAME_USE name_use;
  635.  
  636. @@ -101,19 +104,19 @@ bool get_token_primarygroup_name(HANDLE tok, char *out_buffer)
  637.      ptpgroup = _alloca(tokdatalen);
  638.      if (!GetTokenInformation(tok, TokenPrimaryGroup, ptpgroup,
  639.          tokdatalen, &tokdatalen)) {
  640. -        D((void)fprintf(stderr, "get_token_primarygroup_name: "
  641. -            "GetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
  642. -            "status=%d.\n",
  643. +        D((void)fwprintf(stderr, L"get_token_primarygroup_name: "
  644. +            L"GetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
  645. +            L"status=%d.\n",
  646.              (void *)tok, (int)GetLastError()));
  647.          return false;
  648.      }
  649.  
  650.      pgsid = ptpgroup->PrimaryGroup;
  651.  
  652. -    if (!LookupAccountSidA(NULL, pgsid, out_buffer, &namesize,
  653. +    if (!LookupAccountSidW(NULL, pgsid, out_buffer, &namesize,
  654.          domainbuffer, &domainbuffer_size, &name_use)) {
  655. -        D((void)fprintf(stderr, "get_token_primarygroup_name: "
  656. -            "LookupAccountSidA() failed, status=%d.\n",
  657. +        D((void)fwprintf(stderr, L"get_token_primarygroup_name: "
  658. +            L"LookupAccountSidW() failed, status=%d.\n",
  659.              (int)GetLastError()));
  660.          return false;
  661.      }
  662. @@ -132,16 +135,16 @@ bool is_group_in_token(HANDLE tok, PSID qsid)
  663.      ptgroups = _alloca(tokdatalen);
  664.      if (!GetTokenInformation(tok, TokenGroups, ptgroups,
  665.          tokdatalen, &tokdatalen)) {
  666. -        D((void)fprintf(stderr, "is_group_in_token: "
  667. -            "GetTokenInformation(tok=0x%p, TokenGroups) failed, "
  668. -            "status=%d.\n",
  669. +        D((void)fwprintf(stderr, L"is_group_in_token: "
  670. +            L"GetTokenInformation(tok=0x%p, TokenGroups) failed, "
  671. +            L"status=%d.\n",
  672.              (void *)tok, (int)GetLastError()));
  673.          return false;
  674.      }
  675.  
  676. -    int i;
  677. +    DWORD i;
  678.      D(
  679. -        (void)fprintf(stderr, "is_group_in_token: got %d groups\n",
  680. +        (void)fwprintf(stderr, L"is_group_in_token: got %d groups\n",
  681.              (int)ptgroups->GroupCount)
  682.      );
  683.      for (i = 0 ; i < ptgroups->GroupCount ; i++) {
  684. @@ -162,9 +165,9 @@ int print_groups_in_token(HANDLE tok)
  685.  {
  686.      DWORD tokdatalen;
  687.      PTOKEN_GROUPS ptgroups;
  688. -    char namebuffer[GNLEN+1];
  689. +    wchar_t namebuffer[GNLEN+1];
  690.      DWORD namesize;
  691. -    char domainbuffer[UNLEN+1];
  692. +    wchar_t domainbuffer[UNLEN+1];
  693.      DWORD domainbuffer_size;
  694.      SID_NAME_USE name_use;
  695.  
  696. @@ -172,16 +175,16 @@ int print_groups_in_token(HANDLE tok)
  697.      ptgroups = _alloca(tokdatalen);
  698.      if (!GetTokenInformation(tok, TokenGroups, ptgroups,
  699.          tokdatalen, &tokdatalen)) {
  700. -        D((void)fprintf(stderr, "print_groups_in_token: "
  701. -            "GetTokenInformation(tok=0x%p, TokenGroups) failed, "
  702. -            "status=%d.\n",
  703. +        D((void)fwprintf(stderr, L"print_groups_in_token: "
  704. +            L"GetTokenInformation(tok=0x%p, TokenGroups) failed, "
  705. +            L"status=%d.\n",
  706.              (void *)tok, (int)GetLastError()));
  707.          return 1;
  708.      }
  709.  
  710. -    int i;
  711. +    DWORD i;
  712.      D(
  713. -        (void)fprintf(stderr, "print_groups_in_token: got %d groups\n",
  714. +        (void)fwprintf(stderr, L"print_groups_in_token: got %d groups\n",
  715.              (int)ptgroups->GroupCount)
  716.      );
  717.      for (i = 0 ; i < ptgroups->GroupCount ; i++) {
  718. @@ -192,33 +195,33 @@ int print_groups_in_token(HANDLE tok)
  719.          namesize = sizeof(namebuffer)-1;
  720.          domainbuffer_size = sizeof(domainbuffer)-1;
  721.  
  722. -        if (!LookupAccountSidA(NULL, ptgroups->Groups[i].Sid,
  723. +        if (!LookupAccountSidW(NULL, ptgroups->Groups[i].Sid,
  724.              namebuffer, &namesize, domainbuffer, &domainbuffer_size, &name_use)) {
  725. -            D((void)fprintf(stderr, "print_groups_in_token: "
  726. -                "LookupAccountSidA() failed, status=%d.\n",
  727. +            D((void)fwprintf(stderr, L"print_groups_in_token: "
  728. +                "LookupAccountSidW() failed, status=%d.\n",
  729.                  (int)GetLastError()));
  730.              continue;
  731.          }
  732.  
  733. -        (void)printf("group='%s'\n", namebuffer);
  734. +        (void)fwprintf(stdout, L"group='%ls'\n", namebuffer);
  735.      }
  736.  
  737. -    D((void)puts("is_group_in_token: #no match"));
  738. +    D((void)fwprintf(stdout, L"is_group_in_token: #no match\n"));
  739.  
  740.      return 0;
  741.  }
  742.  
  743.  static
  744. -bool get_group_sid(const char *groupname, PSID pgsid, PDWORD pgsid_size)
  745. +bool get_group_sid(const wchar_t *groupname, PSID pgsid, PDWORD pgsid_size)
  746.  {
  747. -    char domainbuffer[UNLEN+1];
  748. +    wchar_t domainbuffer[UNLEN+1];
  749.      DWORD domainbuffer_size = sizeof(domainbuffer);
  750.      SID_NAME_USE name_use;
  751.  
  752. -    if (!LookupAccountNameA(NULL, groupname,
  753. +    if (!LookupAccountNameW(NULL, groupname,
  754.          pgsid, pgsid_size, domainbuffer, &domainbuffer_size, &name_use)) {
  755. -        D((void)fprintf(stderr, "get_group_sid: "
  756. -            "LookupAccountNameA() failed.\n"));
  757. +        D((void)fwprintf(stderr, L"get_group_sid: "
  758. +            L"LookupAccountNameW() failed.\n"));
  759.          return false;
  760.      }
  761.  
  762. @@ -235,9 +238,9 @@ bool set_token_primarygroup_sid(HANDLE tok, PSID pgsid)
  763.      tpgroup.PrimaryGroup = pgsid;
  764.      if (!SetTokenInformation(tok, TokenPrimaryGroup,
  765.          &tpgroup, tokdatalen)) {
  766. -        D((void)fprintf(stderr, "set_token_primarygroup_sid: "
  767. -            "SetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
  768. -            "status=%d\n",
  769. +        D((void)fwprintf(stderr, L"set_token_primarygroup_sid: "
  770. +            L"SetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
  771. +            L"status=%d\n",
  772.              (void *)tok, (int)GetLastError()));
  773.          return false;
  774.      }
  775. @@ -246,21 +249,22 @@ bool set_token_primarygroup_sid(HANDLE tok, PSID pgsid)
  776.  }
  777.  
  778.  static
  779. -char *stpcpy (char *restrict s1, const char *restrict s2)
  780. +wchar_t *wcpcpy(wchar_t *restrict s1, const wchar_t *restrict s2)
  781.  {
  782. -    size_t l = strlen(s2);
  783. -    return memcpy(s1, s2, l+1) + l;
  784. +    size_t l = wcslen(s2);
  785. +    return memcpy(s1, s2, (l+1)*sizeof(wchar_t)) + l*sizeof(wchar_t);
  786.  }
  787.  
  788.  static
  789. -void win32cmd_quotearg(char *s1, const char *s2)
  790. +void win32cmd_quotearg(wchar_t *s1, const wchar_t *s2)
  791.  {
  792. -    int c;
  793. -    *s1++ = '"';
  794. -    while ((c = *s2) != '\0') {
  795. +    wchar_t c;
  796. +
  797. +    *s1++ = L'"';
  798. +    while ((c = *s2) != L'\0') {
  799.          switch(c) {
  800. -            case '"':
  801. -                *s1++='\\';
  802. +            case L'"':
  803. +                *s1++=L'\\';
  804.                  *s1 = c;
  805.                  break;
  806.              default:
  807. @@ -270,38 +274,38 @@ void win32cmd_quotearg(char *s1, const char *s2)
  808.          s1++;
  809.          s2++;
  810.      }
  811. -    *s1++ = '"';
  812. -    *s1 = '\0';
  813. +    *s1++ = L'"';
  814. +    *s1 = L'\0';
  815.  }
  816.  
  817.  static
  818.  int usage(void)
  819.  {
  820. -    (void)fprintf(stderr,
  821. -        "Usage: winsg [-] -g group [-c command]\n"
  822. -        "Usage: winsg [-] /g group [/C command]\n"
  823. -        "Usage: winsg -L\n"
  824. -        "Usage: winsg /? | -h | --help\n"
  825. -        "Execute command as different primary group ID\n"
  826. -        "\n"
  827. -        "Examples:\n"
  828. -        "\t1. Run new cmd.exe with primary group 'abc1':\n"
  829. -        "\t\twinsg /g abc1 /C\n"
  830. -        "\n"
  831. -        "\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
  832. -        "\t\twinsg -g abc2 -c\n"
  833. -        "\n"
  834. -        "\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
  835. -        "\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
  836. -        "\n"
  837. -        "\t4. Start /bin/id from Cygwin shell (bash) with primary "
  838. -            "group 'abc4':\n"
  839. -        "\t\twinsg -g abc4 -c '/bin/id.exe -a'\n"
  840. -        "\n"
  841. -        "\t5. List currently available groups which can be passed to "
  842. -            "winsg -g ...\n"
  843. -        "\t\twinsg -L\n"
  844. -        "\n"
  845. +    (void)fwprintf(stderr,
  846. +        L"Usage: winsg [-] -g group [-c command]\n"
  847. +        L"Usage: winsg [-] /g group [/C command]\n"
  848. +        L"Usage: winsg -L\n"
  849. +        L"Usage: winsg /? | -h | --help\n"
  850. +        L"Execute command as different primary group ID\n"
  851. +        L"\n"
  852. +        L"Examples:\n"
  853. +        L"\t1. Run new cmd.exe with primary group 'abc1':\n"
  854. +        L"\t\twinsg /g abc1 /C\n"
  855. +        L"\n"
  856. +        L"\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
  857. +        L"\t\twinsg -g abc2 -c\n"
  858. +        L"\n"
  859. +        L"\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
  860. +        L"\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
  861. +        L"\n"
  862. +        L"\t4. Start /bin/id from Cygwin shell (bash) with primary "
  863. +            L"group 'abc4':\n"
  864. +        L"\t\twinsg -g abc4 -c '/bin/id.exe -a'\n"
  865. +        L"\n"
  866. +        L"\t5. List currently available groups which can be passed to "
  867. +            L"winsg -g ...\n"
  868. +        L"\t\twinsg -L\n"
  869. +        L"\n"
  870.          "Please report bugs to "
  871.          "Roland Mainz <roland.mainz@nrubsig.org>.\n");
  872.  
  873. @@ -316,11 +320,11 @@ enum shelltype {
  874.      SHELLTYPE_SYSTEM
  875.  };
  876.  
  877. -int main(int ac, char *av[])
  878. +int wmain(int ac, wchar_t *av[])
  879.  {
  880.      enum shelltype st = SHELLTYPE_NOT_SET;
  881.      int cmd_arg_index = -1;
  882. -    const char *newgrpname = NULL;
  883. +    const wchar_t *newgrpname = NULL;
  884.      HANDLE tok = INVALID_HANDLE_VALUE;
  885.      int subcmdret = EXIT_FAILURE;
  886.      int retval = 1;
  887. @@ -328,20 +332,26 @@ int main(int ac, char *av[])
  888.      bool cmd_runasgroup = false;
  889.      bool cmd_list_token = false;
  890.  
  891. +    (void)setlocale(LC_CTYPE, ".UTF-8");
  892. +
  893. +    (void)_setmode(fileno(stdin), _O_U8TEXT);
  894. +    (void)_setmode(fileno(stdout), _O_U8TEXT);
  895. +    (void)_setmode(fileno(stderr), _O_U8TEXT);
  896. +
  897.      for (i=1 ; i < ac ; i++) {
  898. -        D((void)fprintf(stderr, "# i=%d, av[i]='%s'\n", i, av[i]));
  899. +        D((void)fwprintf(stderr, L"# i=%d, av[i]='%ls'\n", i, av[i]));
  900.  
  901. -        if (!strcmp(av[i], "-")) {
  902. -            (void)fprintf(stderr, "%s: "
  903. -                "Run in new login not supported yet.\n", av[0]);
  904. +        if (!wcscmp(av[i], L"-")) {
  905. +            (void)fwprintf(stderr,
  906. +                L"%ls: Run in new login not supported yet.\n", av[0]);
  907.              retval = 1;
  908.              goto done;
  909.          }
  910. -        else if (!strcmp(av[i], "-c")) {
  911. +        else if (!wcscmp(av[i], L"-c")) {
  912.              /* -c can take zero or one argument */
  913.              if ((ac-i) > 2) {
  914. -                (void)fprintf(stderr, "%s: "
  915. -                    "Too many arguments for -c.\n", av[0]);
  916. +                (void)fwprintf(stderr,
  917. +                    L"%ls: Too many arguments for -c.\n", av[0]);
  918.                  retval = 1;
  919.                  goto done;
  920.              }
  921. @@ -351,11 +361,11 @@ int main(int ac, char *av[])
  922.              cmd_arg_index = i+1;
  923.              break;
  924.          }
  925. -        else if (!strcmp(av[i], "/C")) {
  926. +        else if (!wcscmp(av[i], L"/C")) {
  927.              /* /C can take zero or one argument */
  928.              if ((ac-i) > 2) {
  929. -                (void)fprintf(stderr, "%s: "
  930. -                    "Too many arguments for /C.\n", av[0]);
  931. +                (void)fwprintf(stderr,
  932. +                    L"%ls: Too many arguments for /C.\n", av[0]);
  933.                  retval = 1;
  934.                  goto done;
  935.              }
  936. @@ -365,30 +375,30 @@ int main(int ac, char *av[])
  937.              cmd_arg_index = i+1;
  938.              break;
  939.          }
  940. -        else if ((!strcmp(av[i], "-g")) ||
  941. -            (!strcmp(av[i], "/g"))) {
  942. +        else if ((!wcscmp(av[i], L"-g")) ||
  943. +            (!wcscmp(av[i], L"/g"))) {
  944.              newgrpname = av[i+1];
  945.              i++;
  946.              cmd_runasgroup = true;
  947.          }
  948. -        else if ((!strcmp(av[i], "/?")) ||
  949. -                (!strcmp(av[i], "-h")) ||
  950. -                (!strcmp(av[i], "--help")) ||
  951. -                (!strcmp(av[i], "--usage"))) {
  952. +        else if ((!wcscmp(av[i], L"/?")) ||
  953. +                (!wcscmp(av[i], L"-h")) ||
  954. +                (!wcscmp(av[i], L"--help")) ||
  955. +                (!wcscmp(av[i], L"--usage"))) {
  956.              retval = usage();
  957.              goto done;
  958.          }
  959. -        else if (!strcmp(av[i], "-L")) {
  960. +        else if (!wcscmp(av[i], L"-L")) {
  961.              cmd_list_token = true;
  962.          }
  963. -        else if ((av[i][0] == '-') || (av[i][0] == '/')) {
  964. -            (void)fprintf(stderr, "%s: "
  965. -                "Unsupported option '%s'.\n", av[0], av[i]);
  966. +        else if ((av[i][0] == L'-') || (av[i][0] == L'/')) {
  967. +            (void)fwprintf(stderr,
  968. +                L"%ls: Unsupported option '%ls'.\n", av[0], av[i]);
  969.              retval = usage();
  970.              goto done;
  971.          }
  972.          else {
  973. -            if ((i == 1) && (*av[i] != '-')) {
  974. +            if ((i == 1) && (*av[i] != L'-')) {
  975.                  cmd_runasgroup = true;
  976.                  newgrpname = av[i];
  977.                  continue;
  978. @@ -402,7 +412,7 @@ int main(int ac, char *av[])
  979.      }
  980.  
  981.      if (((int)cmd_runasgroup+(int)cmd_list_token) > 1) {
  982. -        (void)fprintf(stderr, "%s: Incompatible option combination\n",
  983. +        (void)fwprintf(stderr, L"%ls: Incompatible option combination\n",
  984.              av[0]);
  985.          retval = 1;
  986.          goto done;
  987. @@ -422,24 +432,24 @@ int main(int ac, char *av[])
  988.      }
  989.  
  990.      if ((!cmd_list_token) && (!newgrpname)) {
  991. -        (void)fprintf(stderr, "%s: No group name given.\n", av[0]);
  992. +        (void)fwprintf(stderr, L"%ls: No group name given.\n", av[0]);
  993.          retval = 1;
  994.          goto done;
  995.      }
  996.  
  997. -    D((void)fprintf(stderr,
  998. -        "# shelltype=%d, cmd_arg_index=%d, "
  999. -        "av[cmd_arg_index]='%s', "
  1000. -        "new group name '%s'\n",
  1001. +    D((void)fwprintf(stderr,
  1002. +        L"# shelltype=%d, cmd_arg_index=%d, "
  1003. +        L"av[cmd_arg_index]='%ls', "
  1004. +        L"new group name '%ls'\n",
  1005.          (int)st,
  1006.          cmd_arg_index,
  1007. -        ((cmd_arg_index >= 0)?av[cmd_arg_index]:"<negative-av-idx>"),
  1008. +        ((cmd_arg_index >= 0)?av[cmd_arg_index]:L"<negative-av-idx>"),
  1009.          newgrpname));
  1010.  
  1011.      if (!OpenProcessToken(GetCurrentProcess(),
  1012.          TOKEN_QUERY|TOKEN_ADJUST_DEFAULT|TOKEN_DUPLICATE,
  1013.          &tok)) {
  1014. -        (void)fprintf(stderr, "%s: Cannot open token.\n", av[0]);
  1015. +        (void)fwprintf(stderr, L"%ls: Cannot open token.\n", av[0]);
  1016.          retval = 1;
  1017.          goto done;
  1018.      }
  1019. @@ -450,10 +460,10 @@ int main(int ac, char *av[])
  1020.      }
  1021.  
  1022.      D(
  1023. -        char pgroupname[GNLEN+1];
  1024. +        wchar_t pgroupname[GNLEN+1];
  1025.  
  1026.          get_token_primarygroup_name(tok, pgroupname);
  1027. -        (void)printf("primary group name '%s'\n", pgroupname);
  1028. +        (void)printf("primary group name '%ls'\n", pgroupname);
  1029.      )
  1030.  
  1031.      DECLARE_SID_BUFFER(sidbuff);
  1032. @@ -461,23 +471,23 @@ int main(int ac, char *av[])
  1033.      DWORD pgsid_size = SECURITY_MAX_SID_SIZE;
  1034.  
  1035.      if (!get_group_sid(newgrpname, pgsid, &pgsid_size)) {
  1036. -        (void)fprintf(stderr, "%s: Could not find group '%s'.\n",
  1037. +        (void)fwprintf(stderr, L"%ls: Could not find group '%ls'.\n",
  1038.              av[0], newgrpname);
  1039.          retval = 1;
  1040.          goto done;
  1041.      }
  1042.  
  1043.      if (!is_group_in_token(tok, pgsid)) {
  1044. -        (void)fprintf(stderr, "%s: "
  1045. -            "Current user is not a member of group '%s'.\n",
  1046. +        (void)fwprintf(stderr,
  1047. +            L"%ls: Current user is not a member of group '%ls'.\n",
  1048.              av[0], newgrpname);
  1049.          retval = 1;
  1050.          goto done;
  1051.      }
  1052.  
  1053.      if (!set_token_primarygroup_sid(tok, pgsid)) {
  1054. -        (void)fprintf(stderr,
  1055. -            "%s: Could not switch to new primary group '%s'.\n",
  1056. +        (void)fwprintf(stderr,
  1057. +            L"%ls: Could not switch to new primary group '%ls'.\n",
  1058.              av[0], newgrpname);
  1059.          retval = 1;
  1060.          goto done;
  1061. @@ -485,7 +495,7 @@ int main(int ac, char *av[])
  1062.  
  1063.      D(
  1064.          get_token_primarygroup_name(tok, pgroupname);
  1065. -        (void)printf("primary group name '%s'\n", pgroupname);
  1066. +        (void)printf("primary group name '%ls'\n", pgroupname);
  1067.      )
  1068.  
  1069.      (void)_flushall();
  1070. @@ -495,35 +505,35 @@ int main(int ac, char *av[])
  1071.      switch(st) {
  1072.          case SHELLTYPE_SYSTEM:
  1073.              if (av[cmd_arg_index] != NULL) {
  1074. -                size_t cmdbuff_size = strlen(CYGWIN_BASH_PATH)+
  1075. -                    16+
  1076. -                    strlen(av[cmd_arg_index])*2;
  1077. -                char *cmdbuff = alloca(cmdbuff_size);
  1078. -                char *s = cmdbuff;
  1079. -                s = stpcpy(s, CYGWIN_BASH_PATH);
  1080. -                s = stpcpy(s, " -c ");
  1081. +                size_t cmdbuff_size = wcslen(CYGWIN_BASH_PATH)*sizeof(wchar_t)+
  1082. +                    16*sizeof(wchar_t)+
  1083. +                    wcslen(av[cmd_arg_index])*sizeof(wchar_t)*2;
  1084. +                wchar_t *cmdbuff = alloca(cmdbuff_size);
  1085. +                wchar_t *s = cmdbuff;
  1086. +                s = wcpcpy(s, CYGWIN_BASH_PATH);
  1087. +                s = wcpcpy(s, L" -c ");
  1088.  
  1089.                  win32cmd_quotearg(s, av[cmd_arg_index]);
  1090. -                D((void)fprintf(stderr, "# executing '%s'\n", cmdbuff));
  1091. -                subcmdret = system(cmdbuff);
  1092. +                D((void)fwprintf(stderr, L"# executing '%ls'\n", cmdbuff));
  1093. +                subcmdret = _wsystem(cmdbuff);
  1094.              }
  1095.              else {
  1096. -                subcmdret = system(CYGWIN_BASH_PATH);
  1097. +                subcmdret = _wsystem(CYGWIN_BASH_PATH);
  1098.              }
  1099.              break;
  1100.          case SHELLTYPE_CMD:
  1101.              if (av[cmd_arg_index] != NULL) {
  1102. -                subcmdret = _spawnl(_P_WAIT,
  1103. +                subcmdret = _wspawnl(_P_WAIT,
  1104.                      WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH,
  1105.                      "/C", av[cmd_arg_index], NULL);
  1106.              }
  1107.              else {
  1108. -                subcmdret = _spawnl(_P_WAIT,
  1109. +                subcmdret = _wspawnl(_P_WAIT,
  1110.                      WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH, NULL);
  1111.              }
  1112.              break;
  1113.          case SHELLTYPE_NONE:
  1114. -            subcmdret = _spawnl(_P_WAIT,
  1115. +            subcmdret = _wspawnl(_P_WAIT,
  1116.                  WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH, NULL);
  1117.              break;
  1118.          default:
  1119. @@ -531,7 +541,7 @@ int main(int ac, char *av[])
  1120.              break;
  1121.      }
  1122.  
  1123. -    D((void)fprintf(stdout, "#mark winsg done, subcmdret=%d\n",
  1124. +    D((void)fwprintf(stdout, L"#mark winsg done, subcmdret=%d\n",
  1125.          (int)subcmdret));
  1126.  
  1127.  done:
  1128. --
  1129. 2.45.1
  1130.  
  1131. From d6cb6d726286a7c385584b5fd94b54c960d10304 Mon Sep 17 00:00:00 2001
  1132. From: Roland Mainz <roland.mainz@nrubsig.org>
  1133. Date: Mon, 16 Jun 2025 21:10:22 +0200
  1134. Subject: [PATCH 7/7] daemon: Make |stpcpy()| a bit more portable
  1135.  
  1136. Make |stpcpy() a bit more portable, based on the wide-char
  1137. version in winsg.c
  1138.  
  1139. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  1140. ---
  1141. daemon/util.c | 2 +-
  1142.  1 file changed, 1 insertion(+), 1 deletion(-)
  1143.  
  1144. diff --git a/daemon/util.c b/daemon/util.c
  1145. index 1317fbe..765fb27 100644
  1146. --- a/daemon/util.c
  1147. +++ b/daemon/util.c
  1148. @@ -36,7 +36,7 @@
  1149.  char *stpcpy(char *restrict s1, const char *restrict s2)
  1150.  {
  1151.      size_t l = strlen(s2);
  1152. -    return ((char *)memcpy(s1, s2, l+1)) + l;
  1153. +    return ((char *)memcpy(s1, s2, (l+1)*sizeof(char))) + l*sizeof(char);
  1154.  }
  1155.  
  1156.  int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
  1157. --
  1158. 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