From 7d618945b12cbfe24f197e3ce3fe06f9dc8f4dc3 Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Wed, 18 Mar 2026 19:56:29 +0000 Subject: [PATCH] regression: Fix client issues with no smartcard 57609d4aa7eeba7c446d10b2aee1fc670a3e954d introduced an issue where the numCapabilities field in the DR_CORE_CAPABILITY_REQ PDU was incorrect unless --enable-smartcard was specified. This commit also improves the logic around handling clients who advertise a smartcard even if we do not support it. --- sesman/chansrv/devredir.c | 13 +++++++++---- sesman/chansrv/smartcard.c | 32 +++++++++++++++++++------------- sesman/chansrv/smartcard.h | 10 +++++----- sesman/chansrv/smartcard_dummy.c | 5 +++-- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/sesman/chansrv/devredir.c b/sesman/chansrv/devredir.c index 2a091fe2..ed612f4f 100644 --- a/sesman/chansrv/devredir.c +++ b/sesman/chansrv/devredir.c @@ -484,14 +484,18 @@ devredir_send_server_core_cap_req(void) { struct stream *s; int bytes; + int caps_count = 4; +#ifdef XRDP_SMARTCARD + ++caps_count; +#endif xstream_new(s, 1024); /* setup header */ xstream_wr_u16_le(s, RDPDR_CTYP_CORE); xstream_wr_u16_le(s, PAKID_CORE_SERVER_CAPABILITY); - xstream_wr_u16_le(s, 5); /* num of caps we are sending */ + xstream_wr_u16_le(s, caps_count); /* num of caps we are sending */ xstream_wr_u16_le(s, 0x0000); /* padding */ /* setup general capability */ @@ -976,9 +980,10 @@ devredir_proc_client_devlist_announce_req(struct stream *s) "device_type=SMARTCARD device_id=0x%x dosname=%s", g_device_id, preferred_dos_name); - response_status = STATUS_SUCCESS; - - scard_device_announce(g_device_id); + if (scard_device_announce(g_device_id) == 0) + { + response_status = STATUS_SUCCESS; + } break; default: diff --git a/sesman/chansrv/smartcard.c b/sesman/chansrv/smartcard.c index ed6dfb7b..0801e747 100644 --- a/sesman/chansrv/smartcard.c +++ b/sesman/chansrv/smartcard.c @@ -273,30 +273,36 @@ static void scard_handle_GetAttrib_Return(struct stream *s, IRP *irp, /** *****************************************************************************/ -void +int scard_device_announce(tui32 device_id) { LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: device_id=%d", device_id); + int rv; if (g_smartcards_inited) { LOG_DEVEL(LOG_LEVEL_ERROR, "already init"); - return; - } - - g_memset(&smartcards, 0, sizeof(smartcards)); - g_smartcards_inited = 1; - g_device_id = device_id; - g_scard_index = scard_add_new_device(device_id); - - if (g_scard_index < 0) - { - LOG_DEVEL(LOG_LEVEL_DEBUG, "scard_add_new_device failed with DeviceId=%d", g_device_id); + rv = (device_id == g_device_id) ? 0 : 1; } else { - LOG_DEVEL(LOG_LEVEL_DEBUG, "added smartcard with DeviceId=%d to list", g_device_id); + g_memset(&smartcards, 0, sizeof(smartcards)); + g_smartcards_inited = 1; + g_scard_index = scard_add_new_device(device_id); + + if (g_scard_index < 0) + { + LOG_DEVEL(LOG_LEVEL_DEBUG, "scard_add_new_device failed with DeviceId=%d", g_device_id); + rv = 1; + } + else + { + LOG_DEVEL(LOG_LEVEL_DEBUG, "added smartcard with DeviceId=%d to list", g_device_id); + g_device_id = device_id; + rv = 0; + } } + return rv; } /** diff --git a/sesman/chansrv/smartcard.h b/sesman/chansrv/smartcard.h index 39a03c7f..509990b5 100644 --- a/sesman/chansrv/smartcard.h +++ b/sesman/chansrv/smartcard.h @@ -28,10 +28,10 @@ #include "arch.h" -void scard_device_announce(tui32 device_id); -int scard_get_wait_objs(tbus *objs, int *count, int *timeout); -int scard_check_wait_objs(void); -int scard_init(void); -int scard_deinit(void); +int scard_device_announce(tui32 device_id); +int scard_get_wait_objs(tbus *objs, int *count, int *timeout); +int scard_check_wait_objs(void); +int scard_init(void); +int scard_deinit(void); #endif /* end #ifndef SMARTCARD_H */ diff --git a/sesman/chansrv/smartcard_dummy.c b/sesman/chansrv/smartcard_dummy.c index 11c20c48..d14623ff 100644 --- a/sesman/chansrv/smartcard_dummy.c +++ b/sesman/chansrv/smartcard_dummy.c @@ -33,9 +33,10 @@ #include "smartcard.h" /*****************************************************************************/ -void +int scard_device_announce(tui32 device_id) { + return 1; // Not supported } /*****************************************************************************/ @@ -56,7 +57,7 @@ scard_check_wait_objs(void) int scard_init(void) { - return 0; + return 1; } /*****************************************************************************/