- From 26418b98f5ddd743e98088d7d6a9e95c6f4cf160 Mon Sep 17 00:00:00 2001
- From: Aurelien Couderc <aurelien.couderc2002@gmail.com>
- Date: Mon, 16 Jun 2025 15:57:07 +0200
- Subject: [PATCH 1/7] sys: VS2022 error - Remove |FileAccessInformation| case
- which is wrong for QueryVolumeInformation
- Fix Visual Studio 2022 build error "...\sys\nfs41sys_volinfo.c(202,10):
- warning C5286: implicit conversion from enum type
- '_FILE_INFORMATION_CLASS' to enum type '_FSINFOCLASS'; use an explicit
- cast to silence this warning...".
- QueryVolumeInformation does not have a |FileAccessInformation| class,
- this |case FileAccessInformation| is just wrong and should be removed
- completely.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- sys/nfs41sys_volinfo.c | 3 ---
- 1 file changed, 3 deletions(-)
- diff --git a/sys/nfs41sys_volinfo.c b/sys/nfs41sys_volinfo.c
- index af1cfa3..a8435b9 100644
- --- a/sys/nfs41sys_volinfo.c
- +++ b/sys/nfs41sys_volinfo.c
- @@ -199,9 +199,6 @@ NTSTATUS nfs41_QueryVolumeInformation(
- status = STATUS_SUCCESS;
- goto out;
- }
- - case FileAccessInformation:
- - status = STATUS_NOT_SUPPORTED;
- - goto out;
- case FileFsAttributeInformation:
- if (RxContext->Info.LengthRemaining < FS_ATTR_LEN) {
- --
- 2.45.1
- From d7035e7eb97e851ddcfe7ccd2fe1253d1149d9d8 Mon Sep 17 00:00:00 2001
- From: Cedric Blancher <cedric.blancher@gmail.com>
- Date: Mon, 16 Jun 2025 16:05:13 +0200
- Subject: [PATCH 2/7] daemon: [32bit-Windows only] Fix crash in
- |upcall_parse()| with nfsd.exe -d 2
- Windows 32bit kernel only:
- Fix crash in |upcall_parse()| with nfsd.exe -d 2 (debug level 2),
- caused by improper types in vfprintf() varargs.
- Stack trace:
- --- cut ---
- 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]
- 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]
- nfsd!upcall_parse(unsigned char * buffer = 0x0185dcc4 "???", unsigned int length = 0x36, struct __nfs41_upcall * upcall = 0x0185abcc)+0x1d9 [ms-nfs41-client\daemon\upcall.c @ 133]
- nfsd!nfsd_worker_thread_main(void * args = 0x0055c008)+0x134 [ms-nfs41-client\daemon\nfs41_daemon.c @ 175]
- nfsd!nfsd_thread_main(void * args = 0x0055c008)+0x3d [ms-nfs41-client\daemon\nfs41_daemon.c @ 245]
- ucrtbased!invoke_thread_procedure(<function> * procedure = 0x0050e050, void * context = 0x0055c008)+0x28 [d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp @ 92]
- ucrtbased!thread_start<unsigned int (void * parameter = 0x00c47320)+0xab [d:\th\minkernel\crts\ucrt\src\appcrt\startup\thread.cpp @ 115]
- KERNEL32!BaseThreadInitThunk+0x19
- ntdll!__RtlUserThreadStart+0x2b
- ntdll!_RtlUserThreadStart+0x1b
- --- cut ---
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/upcall.c | 13 ++++++++++---
- 1 file changed, 10 insertions(+), 3 deletions(-)
- diff --git a/daemon/upcall.c b/daemon/upcall.c
- index 2f200a7..93fc329 100644
- --- a/daemon/upcall.c
- +++ b/daemon/upcall.c
- @@ -130,11 +130,18 @@ int upcall_parse(
- status = safe_read(&buffer, &length, &upcall->state_ref, sizeof(HANDLE));
- if (status) goto out;
- - DPRINTF(2, ("time=%ld version=%d xid=%d opcode='%s' session=0x%x open_state=0x%x\n",
- - time(NULL), version, upcall->xid, opcode2string(upcall_upcode), upcall->root_ref,
- + DPRINTF(2,
- + ("time=%lld version=%ld xid=%lld opcode='%s' "
- + "root_ref=0x%p state_ref=0x%p\n",
- + (long long)time(NULL),
- + (long)version,
- + (long long)upcall->xid,
- + opcode2string(upcall_upcode),
- + upcall->root_ref,
- upcall->state_ref));
- if (version != NFS41D_VERSION) {
- - eprintf("received version %d expecting version %d\n", version, NFS41D_VERSION);
- + eprintf("received version %ld expecting version %ld\n",
- + (long)version, (long)NFS41D_VERSION);
- upcall->status = status = NFSD_VERSION_MISMATCH;
- goto out;
- }
- --
- 2.45.1
- From 9898849dd3fb10a9a4eb1df1bd188e6e768f6f04 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 16 Jun 2025 17:27:13 +0200
- Subject: [PATCH 3/7] daemon: Fix |DPRINTF()|/|eprintf()| format type
- mismatches
- Fix |DPRINTF()|/|eprintf()| format type mismatches, and use
- Visual Sudio-specific macros to enable warnings in Analyzer
- mode to catch any new mismatches.
- Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/daemon_debug.c | 28 ++++++++++++++++++++++------
- daemon/daemon_debug.h | 20 +++++++++++++++-----
- daemon/delegation.c | 6 +++---
- daemon/fsctl.c | 2 +-
- daemon/idmap.c | 33 ++++++++++++++++++++++-----------
- daemon/nfs41_daemon.c | 11 +++++++----
- daemon/open.c | 4 ++--
- daemon/readdir.c | 9 +++++----
- daemon/readwrite.c | 8 +++++---
- 9 files changed, 82 insertions(+), 39 deletions(-)
- diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
- index 6b53e94..0d83e99 100644
- --- a/daemon/daemon_debug.c
- +++ b/daemon/daemon_debug.c
- @@ -98,7 +98,11 @@ void open_log_files()
- #define DPRINTF_PRINT_IMPERSONATION_USER 1
- -void dprintf_out(LPCSTR format, ...)
- +#ifdef _MSC_VER
- +void dprintf_out(_In_z_ _Printf_format_string_ const char *restrict format, ...)
- +#else
- +void dprintf_out(const char *restrict format, ...)
- +#endif /* _MSC_VER */
- {
- va_list args;
- va_start(args, format);
- @@ -160,7 +164,11 @@ void dprintf_out(LPCSTR format, ...)
- }
- /* log events (mount, umount, auth, ...) */
- -void logprintf(LPCSTR format, ...)
- +#ifdef _MSC_VER
- +void logprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...)
- +#else
- +void logprintf(const char *restrict format, ...)
- +#endif /* _MSC_VER */
- {
- SYSTEMTIME stime;
- char username[UNLEN+1];
- @@ -214,7 +222,11 @@ void logprintf(LPCSTR format, ...)
- }
- }
- -void eprintf_out(LPCSTR format, ...)
- +#ifdef _MSC_VER
- +void eprintf_out(_In_z_ _Printf_format_string_ const char *restrict format, ...)
- +#else
- +void eprintf_out(const char *restrict format, ...)
- +#endif /* _MSC_VER */
- {
- va_list args;
- va_start(args, format);
- @@ -223,7 +235,11 @@ void eprintf_out(LPCSTR format, ...)
- va_end(args);
- }
- -void eprintf(LPCSTR format, ...)
- +#ifdef _MSC_VER
- +void eprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...)
- +#else
- +void eprintf(const char *restrict format, ...)
- +#endif /* _MSC_VER */
- {
- va_list args;
- va_start(args, format);
- @@ -1166,7 +1182,7 @@ void debug_list_sparsefile_holes(nfs41_open_state *state)
- dprintf_out("initial SEEK_HOLE failed "
- "OP_SEEK(sa_offset=%llu,sa_what=SEEK_HOLE) "
- "failed with %d(='%s')\n",
- - 0,
- + 0ULL,
- seek_status,
- nfs_error_string(seek_status));
- goto out;
- @@ -1216,7 +1232,7 @@ void debug_list_sparsefile_holes(nfs41_open_state *state)
- dprintf_out("initial SEEL_DATA failed "
- "OP_SEEK(sa_offset=%llu,sa_what=SEEK_DATA) "
- "failed with %d(='%s')\n",
- - 0,
- + 0ULL,
- seek_status,
- nfs_error_string(seek_status));
- goto out;
- diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
- index f3af022..6bc1119 100644
- --- a/daemon/daemon_debug.h
- +++ b/daemon/daemon_debug.h
- @@ -1,5 +1,6 @@
- /* NFSv4.1 client for Windows
- - * Copyright (C) 2012 The Regents of the University of Michigan
- + * Copyright (C) 2012 The Regents of the University of Michigan
- + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- @@ -120,10 +121,19 @@ extern int g_debug_level;
- /* daemon_debug.h */
- void set_debug_level(int level);
- -void logprintf(LPCSTR format, ...);
- -void dprintf_out(LPCSTR format, ...);
- -void eprintf_out(LPCSTR format, ...);
- -void eprintf(LPCSTR format, ...);
- +#ifdef _MSC_VER
- +void logprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...);
- +void dprintf_out(_In_z_ _Printf_format_string_ const char *restrict format,
- + ...);
- +void eprintf_out(_In_z_ _Printf_format_string_ const char *restrict format,
- + ...);
- +void eprintf(_In_z_ _Printf_format_string_ const char *restrict format, ...);
- +#else
- +void logprintf(const char *restrict format, ...);
- +void dprintf_out(const char *restrict format, ...);
- +void eprintf_out(const char *restrict format, ...);
- +void eprintf(const char *restrict format, ...);
- +#endif /* _MSC_VER */
- const char *map_nfs_ftype2str(int ftype);
- const char *map_nfs_acetype2str(uint32_t ace_type);
- diff --git a/daemon/delegation.c b/daemon/delegation.c
- index fdd3533..efd2b20 100644
- --- a/daemon/delegation.c
- +++ b/daemon/delegation.c
- @@ -281,7 +281,7 @@ static int delegation_return(
- DWORD inbuf_len = sizeof(HANDLE), outbuf_len, dstatus;
- uint32_t length;
- DPRINTF(1,
- - ("delegation_return: making a downcall for srv_open=0x%x\n",
- + ("delegation_return: making a downcall for srv_open=0x%p\n",
- deleg->srv_open));
- pipe = CreateFileA(NFS41_USER_DEVICE_NAME_A, GENERIC_READ|GENERIC_WRITE,
- FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
- @@ -507,7 +507,7 @@ int nfs41_delegate_open(
- if (!status) {
- DPRINTF(1,
- ("nfs41_delegate_open: "
- - "updating srv_open from 0x%x to 0x%x\n",
- + "updating srv_open from 0x%p to 0x%p\n",
- deleg->srv_open, state->srv_open));
- deleg->srv_open = state->srv_open;
- }
- @@ -623,7 +623,7 @@ void nfs41_delegation_remove_srvopen(
- if (delegation_find(session->client, &file->fh, deleg_file_cmp, &deleg))
- return;
- DPRINTF(1, ("nfs41_delegation_remove_srvopen: removing reference to "
- - "srv_open=0x%x\n", deleg->srv_open));
- + "srv_open=0x%p\n", deleg->srv_open));
- AcquireSRWLockExclusive(&deleg->lock);
- deleg->srv_open = NULL;
- ReleaseSRWLockExclusive(&deleg->lock);
- diff --git a/daemon/fsctl.c b/daemon/fsctl.c
- index b5de6b4..96f616f 100644
- --- a/daemon/fsctl.c
- +++ b/daemon/fsctl.c
- @@ -458,7 +458,7 @@ static int parse_duplicatedata(unsigned char *buffer,
- "duplicatedata=(src_state=0x%p srcfileoffset=%lld "
- "destfileoffset=%lld bytecount=%lld)\n",
- opcode2string(upcall->opcode),
- - (long long)args->src_state,
- + args->src_state,
- (long long)args->srcfileoffset,
- (long long)args->destfileoffset,
- (long long)args->bytecount));
- diff --git a/daemon/idmap.c b/daemon/idmap.c
- index 053796f..5917c64 100644
- --- a/daemon/idmap.c
- +++ b/daemon/idmap.c
- @@ -1,5 +1,6 @@
- /* NFSv4.1 client for Windows
- - * Copyright (C) 2012 The Regents of the University of Michigan
- + * Copyright (C) 2012 The Regents of the University of Michigan
- + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- @@ -266,8 +267,8 @@ static int config_defaults(
- if (FAILED(StringCchCopyA(dst, option->max_len, option->def))) {
- status = ERROR_BUFFER_OVERFLOW;
- eprintf("failed to parse default value of '%s'=\"%s\": "
- - "buffer overflow > %u\n", option->key, option->def,
- - option->max_len);
- + "buffer overflow > %lu\n", option->key, option->def,
- + (unsigned long)option->max_len);
- break;
- }
- }
- @@ -584,7 +585,7 @@ static int idmap_filter(
- config->attributes[lookup->attr], (const char *)lookup->value))) {
- status = ERROR_BUFFER_OVERFLOW;
- eprintf("ldap filter buffer overflow: '%s=%s'\n",
- - config->attributes[lookup->attr], lookup->value);
- + config->attributes[lookup->attr], (const char *)lookup->value);
- }
- break;
- @@ -727,8 +728,11 @@ static int idmap_lookup_user(
- if (!cygwin_getent_passwd(lookup->value, NULL, &cy_uid, &cy_gid)) {
- DPRINTF(CYGWINIDLVL,
- - ("# ATTR_USER_NAME: cygwin_getent_passwd: returned '%s', uid=%u, gid=%u\n",
- - lookup->value, (unsigned int)cy_uid, (unsigned int)cy_gid));
- + ("# ATTR_USER_NAME: cygwin_getent_passwd: "
- + "returned '%s', uid=%u, gid=%u\n",
- + (const char *)lookup->value,
- + (unsigned int)cy_uid,
- + (unsigned int)cy_gid));
- (void)snprintf(principal_name, sizeof(principal_name),
- "%s@%s", (const char *)lookup->value,
- context->config.localdomain_name);
- @@ -758,8 +762,11 @@ static int idmap_lookup_user(
- if (!cygwin_getent_passwd(search_name, NULL, &cy_uid, &cy_gid)) {
- DPRINTF(CYGWINIDLVL,
- - ("# ATTR_PRINCIPAL: cygwin_getent_passwd: returned '%s', uid=%u, gid=%u\n",
- - lookup->value, (unsigned int)cy_uid, (unsigned int)cy_gid));
- + ("# ATTR_PRINCIPAL: cygwin_getent_passwd: "
- + "returned '%s', uid=%u, gid=%u\n",
- + (const char *)lookup->value,
- + (unsigned int)cy_uid,
- + (unsigned int)cy_gid));
- (void)snprintf(principal_name, sizeof(principal_name),
- "%s@%s", (const char *)lookup->value,
- context->config.localdomain_name);
- @@ -787,8 +794,11 @@ static int idmap_lookup_user(
- if (!cygwin_getent_passwd(search_name, res_username, &cy_uid, &cy_gid)) {
- DPRINTF(CYGWINIDLVL,
- - ("# ATTR_UID: cygwin_getent_passwd: returned '%s', uid=%u, gid=%u\n",
- - res_username, (unsigned int)cy_uid, (unsigned int)cy_gid));
- + ("# ATTR_UID: cygwin_getent_passwd: "
- + "returned '%s', uid=%u, gid=%u\n",
- + res_username,
- + (unsigned int)cy_uid,
- + (unsigned int)cy_gid));
- (void)snprintf(principal_name, sizeof(principal_name),
- "%s@%s", res_username, context->config.localdomain_name);
- @@ -881,7 +891,8 @@ static int idmap_lookup_group(
- DPRINTF(CYGWINIDLVL,
- ("# ATTR_GROUP_NAME: cygwin_getent_group: "
- "returned '%s', gid=%u\n",
- - lookup->value, (unsigned int)cy_gid));
- + (const char *)lookup->value,
- + (unsigned int)cy_gid));
- StringCchCopyA(group->name, VAL_LEN, lookup->value);
- group->gid = cy_gid;
- status = 0;
- diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
- index 0fd2255..70c6875 100644
- --- a/daemon/nfs41_daemon.c
- +++ b/daemon/nfs41_daemon.c
- @@ -1,5 +1,6 @@
- /* NFSv4.1 client for Windows
- - * Copyright (C) 2012 The Regents of the University of Michigan
- + * Copyright (C) 2012 The Regents of the University of Michigan
- + * Copyright (C) 2023-2025 Roland Mainz <roland.mainz@nrubsig.org>
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- @@ -534,7 +535,8 @@ static int getdomainname()
- else {
- size_t i, len = strlen(hostname);
- char *p = hostname;
- - DPRINTF(1, ("getdomainname: hostname '%s' %d\n", hostname, len));
- + DPRINTF(1, ("getdomainname: hostname '%s' %ld\n",
- + hostname, (long)len));
- for (i = 0; i < len; i++)
- if (p[i] == '.')
- break;
- @@ -542,8 +544,9 @@ static int getdomainname()
- break;
- flag = TRUE;
- memcpy(nfs41_dg.localdomain_name, &hostname[i+1], len-i);
- - DPRINTF(1, ("getdomainname: domainname '%s' %d\n",
- - nfs41_dg.localdomain_name, strlen(nfs41_dg.localdomain_name)));
- + DPRINTF(1, ("getdomainname: domainname '%s' %ld\n",
- + nfs41_dg.localdomain_name,
- + (long)strlen(nfs41_dg.localdomain_name)));
- goto out_loop;
- }
- break;
- diff --git a/daemon/open.c b/daemon/open.c
- index c3c471f..aeaae11 100644
- --- a/daemon/open.c
- +++ b/daemon/open.c
- @@ -251,7 +251,7 @@ static int do_open(
- if (deleg_state) {
- deleg_state->srv_open = state->srv_open;
- DPRINTF(1, ("do_open: "
- - "received delegation: saving srv_open = 0x%x\n",
- + "received delegation: saving srv_open = 0x%p\n",
- state->srv_open));
- }
- @@ -1310,7 +1310,7 @@ static int parse_close(unsigned char *buffer, uint32_t length, nfs41_upcall *upc
- DPRINTF(1,
- ("parsing NFS41_SYSOP_CLOSE: "
- - "remove=%d srv_open=0x%x renamed=%d "
- + "remove=%d srv_open=0x%p renamed=%d "
- "filename='%s'\n",
- args->remove, args->srv_open, args->renamed,
- args->remove ? args->path : ""));
- diff --git a/daemon/readdir.c b/daemon/readdir.c
- index 82510df..f3564bf 100644
- --- a/daemon/readdir.c
- +++ b/daemon/readdir.c
- @@ -871,13 +871,14 @@ fetch_entries:
- entry = (nfs41_readdir_entry*)entry_pos;
- offset = (PULONG)dst_pos; /* ULONG NextEntryOffset */
- - DPRINTF(2, ("filter '%s' looking at '%s' with cookie %d\n",
- - args->filter, entry->name, entry->cookie));
- + DPRINTF(2, ("filter '%s' looking at '%s' with cookie %lld\n",
- + args->filter, entry->name, (long long)entry->cookie));
- if (readdir_filter((const char*)args->filter, entry->name)) {
- if (readdir_copy_entry(args, entry, &dst_pos, &dst_len)) {
- eof = 0;
- - DPRINTF(2, ("not enough space to copy entry '%s' (cookie %d)\n",
- - entry->name, entry->cookie));
- + DPRINTF(2,
- + ("not enough space to copy entry '%s' (cookie %lld)\n",
- + entry->name, (long long)entry->cookie));
- break;
- }
- last_offset = offset;
- diff --git a/daemon/readwrite.c b/daemon/readwrite.c
- index f9ac3ee..ae9a08f 100644
- --- a/daemon/readwrite.c
- +++ b/daemon/readwrite.c
- @@ -268,8 +268,8 @@ retry_write:
- committed = FILE_SYNC4;
- if (to_send > maxwritesize) {
- - DPRINTF(1, ("handle_nfs41_write: writing %d in chunks of %d\n",
- - to_send, maxwritesize));
- + DPRINTF(1, ("handle_nfs41_write: writing %lu in chunks of %lu\n",
- + (unsigned long)to_send, (unsigned long)maxwritesize));
- }
- while(to_send > 0) {
- @@ -293,7 +293,9 @@ retry_write:
- }
- }
- if (committed != FILE_SYNC4) {
- - DPRINTF(1, ("sending COMMIT for offset=%d and len=%d\n", args->offset, len));
- + DPRINTF(1, ("sending COMMIT for offset=%llu and len=%d\n",
- + (unsigned long long)args->offset,
- + (unsigned long)len));
- status = nfs41_commit(session, file, args->offset, len, 1, &verf, &info);
- if (status)
- goto out;
- --
- 2.45.1
- From 9035f554d452e4e7d219217efaf4a0897ccaba62 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 16 Jun 2025 19:10:00 +0200
- Subject: [PATCH 4/7] cygwin_idmapper.ksh: Workaround for double quotation
- marks ('"') issue for Cygwin 3.3 compatibility
- Cygwin 3.3 somehow can generate extra double quotation marks ('"')
- in some cases when called from |CreateProcessW()| in our case.
- Since '"' is an illegal character in group names we just filter them
- all out.
- Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- cygwin_idmapper.ksh | 12 ++++++++----
- 1 file changed, 8 insertions(+), 4 deletions(-)
- diff --git a/cygwin_idmapper.ksh b/cygwin_idmapper.ksh
- index e55fe96..056bfa9 100644
- --- a/cygwin_idmapper.ksh
- +++ b/cygwin_idmapper.ksh
- @@ -12,10 +12,14 @@ export LC_ALL='en_US.UTF-8'
- # (stored in compound variable so we
- # can do a $ print -u2 -v c # for debugging)
- #
- -compound c=(
- - mode="$1"
- - name="${2-}"
- -)
- +compound c
- +
- +c.mode="$1"
- +if (( $# > 1 )) ; then
- + # strip '"' characters (for Cygwin 3.3 compatibility)
- + # note that "${2-//..." does NOT work!
- + c.name="${2//\"/}"
- +fi
- #
- # Windows uses localised user and group names,
- --
- 2.45.1
- From ce392a38b1fbb30a8275082a87b0613a266686e9 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 16 Jun 2025 19:21:11 +0200
- Subject: [PATCH 5/7] tests: Typo in winsg usage
- Typo in winsg usage, plain Cygwin shell should be started
- with $ winsg -g abc2 -c #
- Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- tests/winsg/winsg.c | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
- diff --git a/tests/winsg/winsg.c b/tests/winsg/winsg.c
- index b6d332c..5ab0ffd 100644
- --- a/tests/winsg/winsg.c
- +++ b/tests/winsg/winsg.c
- @@ -2,7 +2,7 @@
- /*
- * MIT License
- *
- - * Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org>
- + * Copyright (c) 2024-2025 Roland Mainz <roland.mainz@nrubsig.org>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- @@ -289,7 +289,7 @@ int usage(void)
- "\t\twinsg /g abc1 /C\n"
- "\n"
- "\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
- - "\t\twinsg -g abc2 -g\n"
- + "\t\twinsg -g abc2 -c\n"
- "\n"
- "\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
- "\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
- --
- 2.45.1
- From 49484dc195ecf0a4469eeeaa2b126e92cfa135dd Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 16 Jun 2025 20:58:42 +0200
- Subject: [PATCH 6/7] tests: winsg.exe should support group names with
- non-ASCII characters
- winsg.exe should support group names with non-ASCII characters.
- Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
- Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- tests/winsg/Makefile | 4 +-
- tests/winsg/winsg.c | 262 ++++++++++++++++++++++---------------------
- 2 files changed, 138 insertions(+), 128 deletions(-)
- diff --git a/tests/winsg/Makefile b/tests/winsg/Makefile
- index 6c548ca..7a1ef4c 100644
- --- a/tests/winsg/Makefile
- +++ b/tests/winsg/Makefile
- @@ -7,10 +7,10 @@
- all: winsg.i686.exe winsg.x86_64.exe winsg.exe
- winsg.i686.exe: winsg.c
- - clang -target i686-pc-windows-gnu -Wall -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.i686.exe
- + clang -target i686-pc-windows-gnu -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.i686.exe
- winsg.x86_64.exe: winsg.c
- - clang -target x86_64-pc-windows-gnu -Wall -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe
- + clang -target x86_64-pc-windows-gnu -municode -Wall -Wextra -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe
- winsg.exe: winsg.x86_64.exe
- ln -s winsg.x86_64.exe winsg.exe
- diff --git a/tests/winsg/winsg.c b/tests/winsg/winsg.c
- index 5ab0ffd..77600f3 100644
- --- a/tests/winsg/winsg.c
- +++ b/tests/winsg/winsg.c
- @@ -31,7 +31,8 @@
- /*
- * Compile with:
- - * $ clang -target x86_64-pc-windows-gnu -Wall -g winsg.c -o winsg.exe #
- + * $ clang -target x86_64-pc-windows-gnu -municode -Wall -Wextra \
- + * -DUNICODE=1 -D_UNICODE=1 -g winsg.c -o winsg.x86_64.exe #
- */
- #define UNICODE 1
- @@ -40,6 +41,8 @@
- #include <windows.h>
- #include <stdio.h>
- #include <stdbool.h>
- +#include <locale.h>
- +#include <fcntl.h>
- #include <assert.h>
- #include <Lmcons.h>
- #include <process.h>
- @@ -51,11 +54,11 @@
- #endif
- #ifdef _WIN64
- -#define CYGWIN_BASH_PATH "C:\\cygwin64\\bin\\bash.exe"
- +#define CYGWIN_BASH_PATH L"C:\\cygwin64\\bin\\bash.exe"
- #else
- -#define CYGWIN_BASH_PATH "C:\\cygwin\\bin\\bash.exe"
- +#define CYGWIN_BASH_PATH L"C:\\cygwin\\bin\\bash.exe"
- #endif /* _WIN64 */
- -#define WIN32_CMDEXE_PATH "C:\\Windows\\system32\\cmd.exe"
- +#define WIN32_CMDEXE_PATH L"C:\\Windows\\system32\\cmd.exe"
- /*
- * DECLARE_SID_BUFFER - declare a buffer for a SID value
- @@ -87,13 +90,13 @@
- D(
- static
- -bool get_token_primarygroup_name(HANDLE tok, char *out_buffer)
- +bool get_token_primarygroup_name(HANDLE tok, wchar_t *out_buffer)
- {
- DWORD tokdatalen;
- PTOKEN_PRIMARY_GROUP ptpgroup;
- PSID pgsid;
- DWORD namesize = GNLEN+1;
- - char domainbuffer[UNLEN+1];
- + wchar_t domainbuffer[UNLEN+1];
- DWORD domainbuffer_size = sizeof(domainbuffer);
- SID_NAME_USE name_use;
- @@ -101,19 +104,19 @@ bool get_token_primarygroup_name(HANDLE tok, char *out_buffer)
- ptpgroup = _alloca(tokdatalen);
- if (!GetTokenInformation(tok, TokenPrimaryGroup, ptpgroup,
- tokdatalen, &tokdatalen)) {
- - D((void)fprintf(stderr, "get_token_primarygroup_name: "
- - "GetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
- - "status=%d.\n",
- + D((void)fwprintf(stderr, L"get_token_primarygroup_name: "
- + L"GetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
- + L"status=%d.\n",
- (void *)tok, (int)GetLastError()));
- return false;
- }
- pgsid = ptpgroup->PrimaryGroup;
- - if (!LookupAccountSidA(NULL, pgsid, out_buffer, &namesize,
- + if (!LookupAccountSidW(NULL, pgsid, out_buffer, &namesize,
- domainbuffer, &domainbuffer_size, &name_use)) {
- - D((void)fprintf(stderr, "get_token_primarygroup_name: "
- - "LookupAccountSidA() failed, status=%d.\n",
- + D((void)fwprintf(stderr, L"get_token_primarygroup_name: "
- + L"LookupAccountSidW() failed, status=%d.\n",
- (int)GetLastError()));
- return false;
- }
- @@ -132,16 +135,16 @@ bool is_group_in_token(HANDLE tok, PSID qsid)
- ptgroups = _alloca(tokdatalen);
- if (!GetTokenInformation(tok, TokenGroups, ptgroups,
- tokdatalen, &tokdatalen)) {
- - D((void)fprintf(stderr, "is_group_in_token: "
- - "GetTokenInformation(tok=0x%p, TokenGroups) failed, "
- - "status=%d.\n",
- + D((void)fwprintf(stderr, L"is_group_in_token: "
- + L"GetTokenInformation(tok=0x%p, TokenGroups) failed, "
- + L"status=%d.\n",
- (void *)tok, (int)GetLastError()));
- return false;
- }
- - int i;
- + DWORD i;
- D(
- - (void)fprintf(stderr, "is_group_in_token: got %d groups\n",
- + (void)fwprintf(stderr, L"is_group_in_token: got %d groups\n",
- (int)ptgroups->GroupCount)
- );
- for (i = 0 ; i < ptgroups->GroupCount ; i++) {
- @@ -162,9 +165,9 @@ int print_groups_in_token(HANDLE tok)
- {
- DWORD tokdatalen;
- PTOKEN_GROUPS ptgroups;
- - char namebuffer[GNLEN+1];
- + wchar_t namebuffer[GNLEN+1];
- DWORD namesize;
- - char domainbuffer[UNLEN+1];
- + wchar_t domainbuffer[UNLEN+1];
- DWORD domainbuffer_size;
- SID_NAME_USE name_use;
- @@ -172,16 +175,16 @@ int print_groups_in_token(HANDLE tok)
- ptgroups = _alloca(tokdatalen);
- if (!GetTokenInformation(tok, TokenGroups, ptgroups,
- tokdatalen, &tokdatalen)) {
- - D((void)fprintf(stderr, "print_groups_in_token: "
- - "GetTokenInformation(tok=0x%p, TokenGroups) failed, "
- - "status=%d.\n",
- + D((void)fwprintf(stderr, L"print_groups_in_token: "
- + L"GetTokenInformation(tok=0x%p, TokenGroups) failed, "
- + L"status=%d.\n",
- (void *)tok, (int)GetLastError()));
- return 1;
- }
- - int i;
- + DWORD i;
- D(
- - (void)fprintf(stderr, "print_groups_in_token: got %d groups\n",
- + (void)fwprintf(stderr, L"print_groups_in_token: got %d groups\n",
- (int)ptgroups->GroupCount)
- );
- for (i = 0 ; i < ptgroups->GroupCount ; i++) {
- @@ -192,33 +195,33 @@ int print_groups_in_token(HANDLE tok)
- namesize = sizeof(namebuffer)-1;
- domainbuffer_size = sizeof(domainbuffer)-1;
- - if (!LookupAccountSidA(NULL, ptgroups->Groups[i].Sid,
- + if (!LookupAccountSidW(NULL, ptgroups->Groups[i].Sid,
- namebuffer, &namesize, domainbuffer, &domainbuffer_size, &name_use)) {
- - D((void)fprintf(stderr, "print_groups_in_token: "
- - "LookupAccountSidA() failed, status=%d.\n",
- + D((void)fwprintf(stderr, L"print_groups_in_token: "
- + "LookupAccountSidW() failed, status=%d.\n",
- (int)GetLastError()));
- continue;
- }
- - (void)printf("group='%s'\n", namebuffer);
- + (void)fwprintf(stdout, L"group='%ls'\n", namebuffer);
- }
- - D((void)puts("is_group_in_token: #no match"));
- + D((void)fwprintf(stdout, L"is_group_in_token: #no match\n"));
- return 0;
- }
- static
- -bool get_group_sid(const char *groupname, PSID pgsid, PDWORD pgsid_size)
- +bool get_group_sid(const wchar_t *groupname, PSID pgsid, PDWORD pgsid_size)
- {
- - char domainbuffer[UNLEN+1];
- + wchar_t domainbuffer[UNLEN+1];
- DWORD domainbuffer_size = sizeof(domainbuffer);
- SID_NAME_USE name_use;
- - if (!LookupAccountNameA(NULL, groupname,
- + if (!LookupAccountNameW(NULL, groupname,
- pgsid, pgsid_size, domainbuffer, &domainbuffer_size, &name_use)) {
- - D((void)fprintf(stderr, "get_group_sid: "
- - "LookupAccountNameA() failed.\n"));
- + D((void)fwprintf(stderr, L"get_group_sid: "
- + L"LookupAccountNameW() failed.\n"));
- return false;
- }
- @@ -235,9 +238,9 @@ bool set_token_primarygroup_sid(HANDLE tok, PSID pgsid)
- tpgroup.PrimaryGroup = pgsid;
- if (!SetTokenInformation(tok, TokenPrimaryGroup,
- &tpgroup, tokdatalen)) {
- - D((void)fprintf(stderr, "set_token_primarygroup_sid: "
- - "SetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
- - "status=%d\n",
- + D((void)fwprintf(stderr, L"set_token_primarygroup_sid: "
- + L"SetTokenInformation(tok=0x%p, TokenPrimaryGroup) failed, "
- + L"status=%d\n",
- (void *)tok, (int)GetLastError()));
- return false;
- }
- @@ -246,21 +249,22 @@ bool set_token_primarygroup_sid(HANDLE tok, PSID pgsid)
- }
- static
- -char *stpcpy (char *restrict s1, const char *restrict s2)
- +wchar_t *wcpcpy(wchar_t *restrict s1, const wchar_t *restrict s2)
- {
- - size_t l = strlen(s2);
- - return memcpy(s1, s2, l+1) + l;
- + size_t l = wcslen(s2);
- + return memcpy(s1, s2, (l+1)*sizeof(wchar_t)) + l*sizeof(wchar_t);
- }
- static
- -void win32cmd_quotearg(char *s1, const char *s2)
- +void win32cmd_quotearg(wchar_t *s1, const wchar_t *s2)
- {
- - int c;
- - *s1++ = '"';
- - while ((c = *s2) != '\0') {
- + wchar_t c;
- +
- + *s1++ = L'"';
- + while ((c = *s2) != L'\0') {
- switch(c) {
- - case '"':
- - *s1++='\\';
- + case L'"':
- + *s1++=L'\\';
- *s1 = c;
- break;
- default:
- @@ -270,38 +274,38 @@ void win32cmd_quotearg(char *s1, const char *s2)
- s1++;
- s2++;
- }
- - *s1++ = '"';
- - *s1 = '\0';
- + *s1++ = L'"';
- + *s1 = L'\0';
- }
- static
- int usage(void)
- {
- - (void)fprintf(stderr,
- - "Usage: winsg [-] -g group [-c command]\n"
- - "Usage: winsg [-] /g group [/C command]\n"
- - "Usage: winsg -L\n"
- - "Usage: winsg /? | -h | --help\n"
- - "Execute command as different primary group ID\n"
- - "\n"
- - "Examples:\n"
- - "\t1. Run new cmd.exe with primary group 'abc1':\n"
- - "\t\twinsg /g abc1 /C\n"
- - "\n"
- - "\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
- - "\t\twinsg -g abc2 -c\n"
- - "\n"
- - "\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
- - "\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
- - "\n"
- - "\t4. Start /bin/id from Cygwin shell (bash) with primary "
- - "group 'abc4':\n"
- - "\t\twinsg -g abc4 -c '/bin/id.exe -a'\n"
- - "\n"
- - "\t5. List currently available groups which can be passed to "
- - "winsg -g ...\n"
- - "\t\twinsg -L\n"
- - "\n"
- + (void)fwprintf(stderr,
- + L"Usage: winsg [-] -g group [-c command]\n"
- + L"Usage: winsg [-] /g group [/C command]\n"
- + L"Usage: winsg -L\n"
- + L"Usage: winsg /? | -h | --help\n"
- + L"Execute command as different primary group ID\n"
- + L"\n"
- + L"Examples:\n"
- + L"\t1. Run new cmd.exe with primary group 'abc1':\n"
- + L"\t\twinsg /g abc1 /C\n"
- + L"\n"
- + L"\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
- + L"\t\twinsg -g abc2 -c\n"
- + L"\n"
- + L"\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
- + L"\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
- + L"\n"
- + L"\t4. Start /bin/id from Cygwin shell (bash) with primary "
- + L"group 'abc4':\n"
- + L"\t\twinsg -g abc4 -c '/bin/id.exe -a'\n"
- + L"\n"
- + L"\t5. List currently available groups which can be passed to "
- + L"winsg -g ...\n"
- + L"\t\twinsg -L\n"
- + L"\n"
- "Please report bugs to "
- "Roland Mainz <roland.mainz@nrubsig.org>.\n");
- @@ -316,11 +320,11 @@ enum shelltype {
- SHELLTYPE_SYSTEM
- };
- -int main(int ac, char *av[])
- +int wmain(int ac, wchar_t *av[])
- {
- enum shelltype st = SHELLTYPE_NOT_SET;
- int cmd_arg_index = -1;
- - const char *newgrpname = NULL;
- + const wchar_t *newgrpname = NULL;
- HANDLE tok = INVALID_HANDLE_VALUE;
- int subcmdret = EXIT_FAILURE;
- int retval = 1;
- @@ -328,20 +332,26 @@ int main(int ac, char *av[])
- bool cmd_runasgroup = false;
- bool cmd_list_token = false;
- + (void)setlocale(LC_CTYPE, ".UTF-8");
- +
- + (void)_setmode(fileno(stdin), _O_U8TEXT);
- + (void)_setmode(fileno(stdout), _O_U8TEXT);
- + (void)_setmode(fileno(stderr), _O_U8TEXT);
- +
- for (i=1 ; i < ac ; i++) {
- - D((void)fprintf(stderr, "# i=%d, av[i]='%s'\n", i, av[i]));
- + D((void)fwprintf(stderr, L"# i=%d, av[i]='%ls'\n", i, av[i]));
- - if (!strcmp(av[i], "-")) {
- - (void)fprintf(stderr, "%s: "
- - "Run in new login not supported yet.\n", av[0]);
- + if (!wcscmp(av[i], L"-")) {
- + (void)fwprintf(stderr,
- + L"%ls: Run in new login not supported yet.\n", av[0]);
- retval = 1;
- goto done;
- }
- - else if (!strcmp(av[i], "-c")) {
- + else if (!wcscmp(av[i], L"-c")) {
- /* -c can take zero or one argument */
- if ((ac-i) > 2) {
- - (void)fprintf(stderr, "%s: "
- - "Too many arguments for -c.\n", av[0]);
- + (void)fwprintf(stderr,
- + L"%ls: Too many arguments for -c.\n", av[0]);
- retval = 1;
- goto done;
- }
- @@ -351,11 +361,11 @@ int main(int ac, char *av[])
- cmd_arg_index = i+1;
- break;
- }
- - else if (!strcmp(av[i], "/C")) {
- + else if (!wcscmp(av[i], L"/C")) {
- /* /C can take zero or one argument */
- if ((ac-i) > 2) {
- - (void)fprintf(stderr, "%s: "
- - "Too many arguments for /C.\n", av[0]);
- + (void)fwprintf(stderr,
- + L"%ls: Too many arguments for /C.\n", av[0]);
- retval = 1;
- goto done;
- }
- @@ -365,30 +375,30 @@ int main(int ac, char *av[])
- cmd_arg_index = i+1;
- break;
- }
- - else if ((!strcmp(av[i], "-g")) ||
- - (!strcmp(av[i], "/g"))) {
- + else if ((!wcscmp(av[i], L"-g")) ||
- + (!wcscmp(av[i], L"/g"))) {
- newgrpname = av[i+1];
- i++;
- cmd_runasgroup = true;
- }
- - else if ((!strcmp(av[i], "/?")) ||
- - (!strcmp(av[i], "-h")) ||
- - (!strcmp(av[i], "--help")) ||
- - (!strcmp(av[i], "--usage"))) {
- + else if ((!wcscmp(av[i], L"/?")) ||
- + (!wcscmp(av[i], L"-h")) ||
- + (!wcscmp(av[i], L"--help")) ||
- + (!wcscmp(av[i], L"--usage"))) {
- retval = usage();
- goto done;
- }
- - else if (!strcmp(av[i], "-L")) {
- + else if (!wcscmp(av[i], L"-L")) {
- cmd_list_token = true;
- }
- - else if ((av[i][0] == '-') || (av[i][0] == '/')) {
- - (void)fprintf(stderr, "%s: "
- - "Unsupported option '%s'.\n", av[0], av[i]);
- + else if ((av[i][0] == L'-') || (av[i][0] == L'/')) {
- + (void)fwprintf(stderr,
- + L"%ls: Unsupported option '%ls'.\n", av[0], av[i]);
- retval = usage();
- goto done;
- }
- else {
- - if ((i == 1) && (*av[i] != '-')) {
- + if ((i == 1) && (*av[i] != L'-')) {
- cmd_runasgroup = true;
- newgrpname = av[i];
- continue;
- @@ -402,7 +412,7 @@ int main(int ac, char *av[])
- }
- if (((int)cmd_runasgroup+(int)cmd_list_token) > 1) {
- - (void)fprintf(stderr, "%s: Incompatible option combination\n",
- + (void)fwprintf(stderr, L"%ls: Incompatible option combination\n",
- av[0]);
- retval = 1;
- goto done;
- @@ -422,24 +432,24 @@ int main(int ac, char *av[])
- }
- if ((!cmd_list_token) && (!newgrpname)) {
- - (void)fprintf(stderr, "%s: No group name given.\n", av[0]);
- + (void)fwprintf(stderr, L"%ls: No group name given.\n", av[0]);
- retval = 1;
- goto done;
- }
- - D((void)fprintf(stderr,
- - "# shelltype=%d, cmd_arg_index=%d, "
- - "av[cmd_arg_index]='%s', "
- - "new group name '%s'\n",
- + D((void)fwprintf(stderr,
- + L"# shelltype=%d, cmd_arg_index=%d, "
- + L"av[cmd_arg_index]='%ls', "
- + L"new group name '%ls'\n",
- (int)st,
- cmd_arg_index,
- - ((cmd_arg_index >= 0)?av[cmd_arg_index]:"<negative-av-idx>"),
- + ((cmd_arg_index >= 0)?av[cmd_arg_index]:L"<negative-av-idx>"),
- newgrpname));
- if (!OpenProcessToken(GetCurrentProcess(),
- TOKEN_QUERY|TOKEN_ADJUST_DEFAULT|TOKEN_DUPLICATE,
- &tok)) {
- - (void)fprintf(stderr, "%s: Cannot open token.\n", av[0]);
- + (void)fwprintf(stderr, L"%ls: Cannot open token.\n", av[0]);
- retval = 1;
- goto done;
- }
- @@ -450,10 +460,10 @@ int main(int ac, char *av[])
- }
- D(
- - char pgroupname[GNLEN+1];
- + wchar_t pgroupname[GNLEN+1];
- get_token_primarygroup_name(tok, pgroupname);
- - (void)printf("primary group name '%s'\n", pgroupname);
- + (void)printf("primary group name '%ls'\n", pgroupname);
- )
- DECLARE_SID_BUFFER(sidbuff);
- @@ -461,23 +471,23 @@ int main(int ac, char *av[])
- DWORD pgsid_size = SECURITY_MAX_SID_SIZE;
- if (!get_group_sid(newgrpname, pgsid, &pgsid_size)) {
- - (void)fprintf(stderr, "%s: Could not find group '%s'.\n",
- + (void)fwprintf(stderr, L"%ls: Could not find group '%ls'.\n",
- av[0], newgrpname);
- retval = 1;
- goto done;
- }
- if (!is_group_in_token(tok, pgsid)) {
- - (void)fprintf(stderr, "%s: "
- - "Current user is not a member of group '%s'.\n",
- + (void)fwprintf(stderr,
- + L"%ls: Current user is not a member of group '%ls'.\n",
- av[0], newgrpname);
- retval = 1;
- goto done;
- }
- if (!set_token_primarygroup_sid(tok, pgsid)) {
- - (void)fprintf(stderr,
- - "%s: Could not switch to new primary group '%s'.\n",
- + (void)fwprintf(stderr,
- + L"%ls: Could not switch to new primary group '%ls'.\n",
- av[0], newgrpname);
- retval = 1;
- goto done;
- @@ -485,7 +495,7 @@ int main(int ac, char *av[])
- D(
- get_token_primarygroup_name(tok, pgroupname);
- - (void)printf("primary group name '%s'\n", pgroupname);
- + (void)printf("primary group name '%ls'\n", pgroupname);
- )
- (void)_flushall();
- @@ -495,35 +505,35 @@ int main(int ac, char *av[])
- switch(st) {
- case SHELLTYPE_SYSTEM:
- if (av[cmd_arg_index] != NULL) {
- - size_t cmdbuff_size = strlen(CYGWIN_BASH_PATH)+
- - 16+
- - strlen(av[cmd_arg_index])*2;
- - char *cmdbuff = alloca(cmdbuff_size);
- - char *s = cmdbuff;
- - s = stpcpy(s, CYGWIN_BASH_PATH);
- - s = stpcpy(s, " -c ");
- + size_t cmdbuff_size = wcslen(CYGWIN_BASH_PATH)*sizeof(wchar_t)+
- + 16*sizeof(wchar_t)+
- + wcslen(av[cmd_arg_index])*sizeof(wchar_t)*2;
- + wchar_t *cmdbuff = alloca(cmdbuff_size);
- + wchar_t *s = cmdbuff;
- + s = wcpcpy(s, CYGWIN_BASH_PATH);
- + s = wcpcpy(s, L" -c ");
- win32cmd_quotearg(s, av[cmd_arg_index]);
- - D((void)fprintf(stderr, "# executing '%s'\n", cmdbuff));
- - subcmdret = system(cmdbuff);
- + D((void)fwprintf(stderr, L"# executing '%ls'\n", cmdbuff));
- + subcmdret = _wsystem(cmdbuff);
- }
- else {
- - subcmdret = system(CYGWIN_BASH_PATH);
- + subcmdret = _wsystem(CYGWIN_BASH_PATH);
- }
- break;
- case SHELLTYPE_CMD:
- if (av[cmd_arg_index] != NULL) {
- - subcmdret = _spawnl(_P_WAIT,
- + subcmdret = _wspawnl(_P_WAIT,
- WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH,
- "/C", av[cmd_arg_index], NULL);
- }
- else {
- - subcmdret = _spawnl(_P_WAIT,
- + subcmdret = _wspawnl(_P_WAIT,
- WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH, NULL);
- }
- break;
- case SHELLTYPE_NONE:
- - subcmdret = _spawnl(_P_WAIT,
- + subcmdret = _wspawnl(_P_WAIT,
- WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH, NULL);
- break;
- default:
- @@ -531,7 +541,7 @@ int main(int ac, char *av[])
- break;
- }
- - D((void)fprintf(stdout, "#mark winsg done, subcmdret=%d\n",
- + D((void)fwprintf(stdout, L"#mark winsg done, subcmdret=%d\n",
- (int)subcmdret));
- done:
- --
- 2.45.1
- From d6cb6d726286a7c385584b5fd94b54c960d10304 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Mon, 16 Jun 2025 21:10:22 +0200
- Subject: [PATCH 7/7] daemon: Make |stpcpy()| a bit more portable
- Make |stpcpy() a bit more portable, based on the wide-char
- version in winsg.c
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/util.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/daemon/util.c b/daemon/util.c
- index 1317fbe..765fb27 100644
- --- a/daemon/util.c
- +++ b/daemon/util.c
- @@ -36,7 +36,7 @@
- char *stpcpy(char *restrict s1, const char *restrict s2)
- {
- size_t l = strlen(s2);
- - return ((char *)memcpy(s1, s2, l+1)) + l;
- + return ((char *)memcpy(s1, s2, (l+1)*sizeof(char))) + l*sizeof(char);
- }
- int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
- --
- 2.45.1
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
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.