Commit Graph

583 Commits

Author SHA1 Message Date
Liyi Meng 38c8db8293 chansrv: Reconnect ibus when the cached connection has gone stale
Fixes #3230. The static `bus` global was only ever checked for
non-NULL, not for whether the underlying connection was still alive.
If ibus disconnected (daemon restart, stale socket) or the initial
connect attempt failed, `bus` was left set to a dead/freed connection,
so every later call to xrdp_input_unicode_init() took the "already
initialized" fast path and operated on it.

- Null out bus/g_engine in the "disconnected" signal handler instead
  of leaving them dangling after g_object_unref().
- Check ibus_bus_is_connected() before trusting a cached bus, and
  tear down + reconnect if it's stale.
- Unref and clear bus on a failed connect attempt instead of leaving
  it set.
- Guard the unrefs in xrdp_input_unicode_destroy() now that bus/
  g_engine can legitimately already be NULL.
2026-08-17 08:59:18 +00:00
matt335672 a6d80e17ab Code quality: Address Copilot review comments
All accesses to g_drdynvcs[] in chansrv.c have been checked for
unbounded access.
2026-08-14 12:07:48 +01:00
matt335672 f4249b3ca6 chansrv: Use common dynamic dechunker
Addresses CVE-2026-69169

The dynamic channel processing in chansrv is updated to allow
the dechunker to be invoked automatically if the 'data_first' proc
is set to NULL. This mirrors a change made to the xrdp_channel.c.

The processor for the AUDIO_IN channel is updated to take advantage of
this, significantly simplifing the code.
2026-08-14 12:06:20 +01:00
matt335672 77d9b49432 chansrv: Use streams for dynamic channel processing
Change the dynamic channel processing to use streams rather than
a data pointer and a length. This mirrors an earlier commit for
xrdp.

The reason for the change is to make it easier to check for buffer
overflows using standard stream features.
2026-08-12 11:31:47 +01:00
matt335672 7d618945b1 regression: Fix client issues with no smartcard
57609d4aa7 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.
2026-03-18 19:56:29 +00:00
matt335672 57609d4aa7 smartcard: Update redirector smartcard capability
Only announce a smartcard capability in the redirector if we can
support it.
2026-03-17 15:22:11 +00:00
matt335672 7a2ac0c177 security: Disable smartcard code by default
The smartcard code contains a number of security vulnerabilities and
does not work at the moment.

The code has been left in the source tree, but moved behind an
'--enable-smartcard' configure flag which is clearly marked as not
for production use.
2026-03-17 15:22:11 +00:00
matt335672 90275daf6d Merge pull request #3747 from firewave/cppcheck-cv
enabled and fixed `constVariable` Cppcheck warnings
2026-03-06 11:01:56 +00:00
firewave 64154ea66d enabled and fixed constVariable Cppcheck warnings 2026-03-04 15:49:29 +01:00
matt335672 c4727ad8f3 Replace X11 display number with a display string
As far as possible, use of the X11 display number is kept to
X11-specific routines. This is to make it easier to restructure
the code to add non-X11 display support.
2026-03-04 14:34:31 +00:00
firewave 214cf50df5 fixed some unreadVariable Cppcheck warnings 2026-03-03 16:33:51 +01:00
matt335672 6a5d858dce xrdpapi: Add a way to get client connect status
Functions are added to xrdpapi to allows the connection status
to be determimed. These functions are modelled on the Windows API
functions, but are not compatible with them. In particular, the error
handling is different.

A way for an application to receive events is also provided. At present,
only connect/disconnected events are implemented.
2025-12-15 11:26:21 +00:00
matt335672 4b87cfc08f Merge pull request #2831 from firewave/wdoc
mitigated `-Wdocumentation` and `-Wdocumentation-unknown-command` Clang compiler warnings
2025-11-06 11:21:40 +00:00
matt335672 5abd51b675 Code quality: Fix expansion-to-defined warning
Fixes a gcc compiler warning regarding a potentially unportable
use of 'defined()' in a macro
2025-11-05 13:51:49 +01:00
firewave 67c11f0443 mitigated -Wdocumentation and -Wdocumentation-unknown-command Clang compiler warnings 2025-11-04 13:40:33 +01:00
matt335672 4d2c4ae8a5 Add FuseRootReportMaxFree option
Add an option to allow effectively disable file system space checks for
some file managers before copying files to remote drives.

This is a temporary solution. A better solution is to provide each
remote drive with its own mountpoint, so that the xrdp FUSE filesystem
becomes POSIX compliant.
2025-10-06 11:45:43 +01:00
matt335672 8099299ab0 Allow for empty UTF8_STRING to be pasted
The current code doesn't allow for an empty string to be pasted to the
clipboard on the X11 side.  This is done by some lock screen programs
to prevent information leakage.
2025-08-04 11:25:54 +01:00
matt335672 539eb33795 Prevent possible double-free on chansrv exit 2025-06-21 14:38:06 +01:00
matt335672 554515e39c Refactor static channel name handling
1) Remove 'magic numbers' related to static channel name lengths, and
   replace with CHANNEL_NAME_LEN, or CHANNEL_NAME_LEN+1, as appropriate.
2) Always add static channel definitions, even if they are malformed.
3) Log channels which the client sends, which aren't named in
   the [Channels] section of xrdp.ini.

(cherry picked from commit 9092d898b7dceda713bd05b296ea8e8213ee614b)
2025-04-26 17:06:10 +01:00
matt335672 343e84a76a Remove SIGTERM race in chansrv
The signal handlers for SIGTERM are put in place before the
sigterm object is created. If a SIGTERM is received between the
two, it is ignored and chansrv will not exit.
2025-03-29 17:15:45 +00:00
matt335672 8b449868fe Coverity CID 468108
Repeated constant WAVE_FORMAT_MULAW in conditional
2025-02-28 14:34:26 +00:00
matt335672 2f46ef27a2 Add support for cppcheck 2.17.0
cppcheck 2.17.0 adds checks that a NULL pointer returned from malloc() and
calloc() is not used.

We do this quite a lot.

I've addressed this by adding functions g_malloc_nofail() and
g_calloc_nofail() which either allocate memory or abort.
functions are now called in places where we are not making these
checks.

Many of these checks are in test programs or example programs.

I've modified the list16 module to handle out-of-memory conditions.
2025-02-27 15:04:11 +00:00
matt335672 cb90458609 Coverity CID 468116 2025-02-10 15:31:19 +00:00
matt335672 6088ba3f3b Address offline Coverity issue
This Coverity issue was encountered in a private build, but does not
appear to be in the Github CI build. Coverity is suspecting a copy-paste
betweem these lines in sound.c:-

1838: xstream_copyin(s, &g_stream_inp->data[g_stream_inp->size - g_bytes_in_stream], i);
1844: xstream_copyin(s, &g_stream_inp->data[g_stream_inp->size - g_bytes_in_stream], g_bytes_in_stream);

An inspection of the code shows this to bre a false positive
2025-02-10 15:26:55 +00:00
matt335672 eff8ba75ee Coverity CID 468140 2025-02-03 15:32:55 +00:00
matt335672 db32f9c6a3 Coverity CID 468119
Add additional check to prevent Coverity assuming the worst
2025-02-03 15:32:55 +00:00
matt335672 201cdc1aea Fix coverity warning over mem leak in smartcard code 2025-01-24 11:36:40 +00:00
matt335672 b04743066d Fix coverity-reported issues
The errors in sesman/chansrv/chansrv_fuse.c appear to be false positives
caused by allocating xhandle->dir_handle, and then
casting xhandle to an integer in xfuse_handle_to_fuse_handle(), thus
hiding xhandle->dir_handle

For both occurrences, the logic has been simplified and made the same,
and a comment has been added to suppress the error.
2025-01-13 10:27:29 +00:00
Constantin Kulikov 151c555fc0 Add sesman.ini FuseMountNameColonCharReplacement option 2025-01-08 16:23:14 +03:00
matt335672 e3d502ca06 Merge pull request #3328 from matt335672/fix_time_calls
Remove/replace time calls
2025-01-06 10:22:40 +00:00
Koichiro Iwao 75736f4853 Allow to change config file (sub)directory
This allows the `xrdp` part of the path `/etc/xrdp` where config files
are placed to be customizable. This change is useful when trying the
stable version and the devel version alternately.
2024-12-27 10:53:31 +09:00
matt335672 1f79eb1c01 Replace g_time3() with g_get_elapsed_ms()
The function as specified used gettimeofday() which is susceptible
to manual time changes, and is obsoleted in POSIX.1-2008. The
replacement uses clock_gettime(CLOCK_MONOTONIC, ) which is not
susceptible to manual time changes (at least on Linux) and cannot run
backwards.

Also, on systems with 32-bit integers, the value returned by this
function wraps around every 49.7 days. To cope with a wraparound in
a way compliant with the C standard, this value needs to return an
unsigned integer type rather than a signed integer type.
2024-12-16 16:13:15 +00:00
matt335672 90798cdeaa Remove g_time2() call
This is currently unused in xrdp
2024-12-16 16:13:15 +00:00
matt335672 b02689ab44 Remove g_time1() call
This is not year 2038 compliant on systems with 32-bit integers.

The call can be replaced with the standard C time() call. On
POSIX systems, time_t is guaranteed to be an integer type.
2024-12-16 16:13:15 +00:00
matt335672 162153ab6f Move LogFilePath parameter to [ChansrvLogging]
This seems a better fit than having it in the [Chansrv] section.

Also fixed a minor logging error relating to the parameter in
chansrv_config.c

(cherry picked from commit 6d2fd1be8451418f01dfbb203929e2838c1a979f)
2024-12-16 10:55:30 +00:00
matt335672 2f7be3f634 Allow a path to be specified for the chansrv log
This is useful for NFS-mounted home directories, where hosts
may otherwise produce colliding chansrv log file names

(cherry picked from commit cfc2e362b47103bc2c786252f331bb26b6ddecb5)
2024-12-16 10:55:21 +00:00
matt335672 6a49ff9946 Add fix for chromium saving files to FUSE filesys
Chromium 130 won't save to our filesystem if we don't return a
max filename length.

Dummy parameters were tried for inode counts, but these do not seem to
be necessary. Not also that btrfs foes not return values for these
fields.
2024-11-11 12:15:23 +00:00
matt335672 5dc4fdbc2c Add support for statvfs() to FUSE
Some desktop environments are now checking for free space before
copying files to a destination.

To support this, the FUSE filesystem needs to convert the statvfs()
system call to the relevent PDUs from [MS-RDPEFS]
2024-11-08 15:57:40 +00:00
matt335672 514c62c7c1 Merge pull request #3275 from matt335672/move_to_fuse3
Move to fuse3
2024-10-23 10:12:35 +01:00
matt335672 c46eece00f Add support for creating sockdir to chansrv
Chansrv now checks for the user sockdir being present. If it
isn't, it connects to chansrv and requests it be created.

This also needs the sesman port to be added to the chansrv
config struct.
2024-10-22 12:21:25 +01:00
matt335672 b5772cef91 Only use fuse_set_log_func() for libfuse >= 3.7 2024-10-21 16:55:24 +01:00
matt335672 edd4276633 Migrate chansrv to FUSE3 interface 2024-10-15 11:44:16 +01:00
matt335672 b9703af7ee Pick up correct includes/libraries for FUSE3 2024-10-14 16:44:09 +01:00
Bob Carroll 89a4a1b8f7 update man page and fix code style issue 2024-09-24 18:03:40 -07:00
Bob Carroll 66e5eebb1c add option to enable FUSE direct i/o on file open 2024-09-20 20:23:47 -07:00
matt335672 0f6e731524 clipboard: Allow a file read to return 0 for EOF
When used with a FreeRDP client on Linux, a file copy operation from
the clipboard detects end-of-file by a read returning 0 bytes. This is
currently marked as an error.

It is assumed that mstsc.exe detects end-of-file in another way, which
is why this has not been found before.
2024-08-02 12:41:20 +01:00
matt335672 34b5582460 Remove unnecessary copy from clipboard_get_files()
The routine clipboard_get_files() parses a potentially long string,
and copies portions of it into a temporary buffer. This buffer is then
passed to clipboard_get_file() as pointer + length;

The buffer is inadequately sized for very long filenames which may
approach XFS_MAXFILENAMELEN in length. This can cause chansrv to fail
when the user copies such filenames.

It turns out the buffer is unnecessary, as the filenames can be
passed directly into clipboard_get_file() from the source string,
using pointer + length. This avoids the length limitation entirely.
2024-08-02 12:41:20 +01:00
matt335672 c3f7eec4f5 Allow for longer filenames from the redirector.
This commit ensures that filenames up to the maximum size supported
by our xfs can be supported.
2024-08-02 12:41:20 +01:00
matt335672 a90228241d Remove hard-coded filename limit for clipboard file lists
The limit of 256 characters for clipboard files is limiting for
many Asian locales, particularly as '%xx' notation is used to
communicate bytes with bit 7 set.
2024-08-02 12:41:20 +01:00
matt335672 d8b5435710 Dynamically allocate XFS filesystem names
Replace the 256 byte buffer used for names in the XFS filesystem with a
dynamically allocated buffer.

The define XFS_MAXFILENAMELEN which used to be 255 has been retained,
but bumped to 1023. This value is no longer used for long-lived
allocations, but is used in chansrv_fuse.c for maintaining state
information for in-fligh I/O requests.
2024-08-02 12:41:20 +01:00