Commit Graph

794 Commits

Author SHA1 Message Date
matt335672 36ea4a3f86 Remove mbstowcs/wcstombs from g_strtrim()
Because of the way UTF-8 encoding works, there is no need to
use mbstowcs/wcstombs in the implementation of this function.
2023-10-23 14:15:46 +01:00
matt335672 0758fe03a6 Add UTF-16 LE I/O routines
These are intended to replace UTF-16 uses of mbstowcs() / wcstombs()
2023-10-18 10:07:49 +01:00
matt335672 0463e552dc Add UTF-8 / UTF-32 conversion routines
These are intended to replace non-UTF-16 uses of mbstowcs() / wcstombs()
2023-10-18 10:07:49 +01:00
matt335672 d11617adbe Remove dependency on signal() function
Replaces uses of signal() with sigaction() which should be far
more portable.
2023-10-09 14:05:29 +01:00
matt335672 cf677da22c Add getgrouplist() support to os_calls
On enterprise systems, using getgrouplist() (if available)
is more efficient than iterating over the members of the group,
and is also more likely to work
2023-10-04 11:02:07 +01:00
Keith Gable 9305008ba8 Tolerate XRDP_ENABLE_VSOCK being defined but the platform is neither FreeBSD nor Linux 2023-09-24 12:32:10 -07:00
Keith Gable 5ffca14b2f Change indent style to allman 2023-09-24 12:27:00 -07:00
Keith Gable 572ee7686d On FreeBSD, use AF_HYPERV in place of vsock 2023-09-23 21:28:24 -07:00
matt335672 ce42e3e12d Replace g_strsignal() with g_sig2text()
This call provides a textual representation of a signal number, i.e.
SIGHUP is mapped to "SIGHUP"

Unit tests are also added.
2023-06-12 16:19:17 +01:00
matt335672 0f32661056 Add g_strsignal() to string_calls module 2023-06-08 16:32:24 +01:00
matt335672 ac65538a48 Re-implement fifo code
Following informal option testing, a more performant fifo
implementation has been chosen which makes fewer, larger
allocations, but which does not have bad edge-case performance

Clearing the contents of a fifo is a common operation which generally
involves freeing memory. Support has been added to the fifo interface
for doing this.
2023-05-22 14:43:22 +01:00
Jay Sorg c250529e8e add large cursor support, posix shm 2023-05-16 10:20:24 -07:00
Daniel Richard G b191d87e33 Move Linux's no_new_privs call into os_calls
This helps keep the application code free of platform-specific cruft.
Also remove a needless #include<sys/prctl.h> from sesman/session_list.c.
2023-05-15 17:40:46 -04:00
Daniel Richard G 1c0c923ad1 Split g_file_open() into _ro() and _rw() variants
Rename g_file_open() to g_file_open_rw(), and add a new g_file_open_ro()
call that wraps the common g_file_open_ex(file, 1, 0, 0, 0) idiom. This
will make the file access mode more explicit in the code.

Change all calls to g_file_open() to the _ro() or _rw() variant as
appropriate, and replace g_file_open_ex(file, 1, 0, 0, 0) with the _ro()
call.

Lastly, add tests for the two new calls to test_os_calls.c (code
courteously provided by matt335672).
2023-05-15 17:38:31 -04:00
Daniel Richard G 42d32e7496 Use config_ac.h consistently and correctly 2023-05-12 13:49:53 -04:00
matt335672 e96d77bac1 Remove g_mk_socket_path() from codepaths
The socket dir is only used if we are starting a session
with sesman. Consequently, it only makes sense to create
this directory within sesman itself.
2023-05-02 11:55:22 +01:00
matt335672 cf5e1961d3 os_calls: Add g_setpgid() 2023-05-02 11:55:22 +01:00
matt335672 65ff618479 os_calls: Add g_executable_exist() 2023-05-02 11:55:22 +01:00
matt335672 ff24984cf3 os_calls: Add g_file_is_open() 2023-05-02 11:55:22 +01:00
matt335672 f08355a325 Ensure commonly used file descriptors are close-on-exec 2023-04-24 14:20:14 +01:00
matt335672 1c798cee47 Logging: Add LOG_DEVEL_LOG_LEAKING_FDS 2023-04-24 14:20:14 +01:00
matt335672 d712f3527a os_calls: Add g_get_open_fds() 2023-04-24 11:57:38 +01:00
matt335672 b811fdb36b os_calls: Add g_file_{get,set}_cloexec() functions
Allows us to avoid file descriptor leaks when running a new executable
2023-04-24 11:11:04 +01:00
matt335672 3ee8eb9c9e
Merge pull request #2592 from matt335672/restructure_session_start
Restructure session start
2023-03-27 10:38:37 +01:00
Jay Sorg 2d8b52f744 common: change g_malloc, g_free, g_memset, g_memcpy, and g_memmove to macros 2023-03-25 12:22:19 -07:00
matt335672 8b9f9b40c8 os_calls changes
- Add g_pipe()
- Add g_file_duplicate_on()
- Rework struct exit_status to make it easier to parse
- Add optional status return to g_waitchild()
2023-03-23 18:12:06 +00:00
Nexarian 5273624089 Fixing some comments 2023-03-14 02:02:09 -04:00
matt335672 3bd1820407 Fix regression caused by move to poll() 2023-03-13 20:02:05 +00:00
matt335672 621b3fc6dc Add g_execvp_list() to os_calls 2023-03-06 16:03:55 +00:00
matt335672 c3d697de16 Add list_add_strdup() etc 2023-03-06 15:58:13 +00:00
matt335672 a317c3de5d Fix regression in list module 2023-03-06 15:47:49 +00:00
Nexarian 89e178e7c9 Add function to split string into list.
- With working unit tests.
2023-03-03 18:33:33 -05:00
matt335672 86d0d0e9fd Addressed review comments 2023-02-13 14:28:29 +00:00
matt335672 78fa1c15b2 Replace select() system call with poll()
poll() is specified in POSIX.1-2001 as a simpler interface for
multiplexed file descriptors than select(). It also provides more
functionality.

This PR replaces the select() calls used in xrdp with poll()
equivalents.
2023-02-13 14:28:29 +00:00
matt335672 5aa5624551 Add memory allocation checking to the list module
The list module lacks memory allocation checking, and
consequently can coredump on list_create() or
list_add_item().
2023-02-13 10:37:46 +00:00
Derek Schrock 1e5b42893c Add g_set_alarm to set an alarm calling func after secs seconds 2023-02-11 18:01:12 -05:00
metalefty c463a0e865
Merge pull request #2541 from metalefty/log_time
log: fix syslog glitch after #2386
2023-02-10 09:06:12 +09:00
Koichiro IWAO ec2f165af4 log: fix syslog glitch after #2386
The tail of new datetime format was sticking out.
2023-02-09 17:09:28 +09:00
Nexarian 7542dfc4f2
Merge pull request #2533 from Nexarian/Nexarian/update-pixman-region-header
Add functions and reformat pixman-region.h
2023-02-05 19:16:53 -05:00
Nexarian 7520c69049 Add functions and reformat pixman-region.h
- Update pixman-region.h header
-- Reformat so all lines fit within 80 characters.
-- Update define guard to use convention for the rest of XRDP.

Add pixman_region_not_empty and pixman_region_extents in anticipation of
using it for EGFX in the future.
2023-02-04 15:07:13 -05:00
matt335672 a5034e3572 Implement g_sck_send_fd_set() and g_sck_recv_fd_set() 2023-01-30 14:31:16 +00:00
matt335672 1fbcdffff1 Use unsigned int for some data lengths 2023-01-30 14:31:16 +00:00
Nexarian db5ea2f214 Initial EGFX tests.
- Rearranging imports.
- Remove unnecessary check to g_is_wait_obj_set.
- Use g_get_term everywhere.
- Misc updates.
2023-01-23 23:05:24 -05:00
matt335672 48e46d183a Add g_setallusercontext() for *BSD systems 2023-01-05 10:52:08 +00:00
matt335672 47ace4acfd Fix g_sck_get_peer_cred() on FreeBSD
Socket level should be SOL_LOCAL rather than SOL_SOCKET - See
'man unix'.
2022-12-22 11:35:02 +00:00
matt335672 a16e56f711 Add function to get user information by UID
Moving to a uid_t to store the user information makes a lot
of sense. When doing this, we need a function to get information
about a user from the uid_t

As well as creating the function g_getuser_info_by_uid() we also
rename g_getuser_info() to g_getuser_info_by_name() and make the
parameter ordering more usual.
2022-12-22 11:35:02 +00:00
matt335672 a4fb635a5d
Merge pull request #2453 from matt335672/update_kerberos
Fix the kerberos module
2022-12-14 10:44:31 +00:00
matt335672 cce78b0698
Merge pull request #2407 from alexpevzner/devel
LogFile=- redirects log to stdout, which is useful for debugging
2022-12-12 20:33:04 +00:00
matt335672 df83fbf9bf Fix const-correctness for g_system() 2022-12-12 19:52:27 +00:00
matt335672 b1147f5faa CVE-2022-23479
Detect attempts to overflow input buffer

If application code hasn't properly sanitised the header_size
for a transport, it is possible for read requests to be issued
which overflow the input buffer. This change detects this
at a low level and bounces the read request.
2022-12-09 17:34:25 +00:00
matt335672 c3bb7dc294 guid_new() returns GUIDs compatible with RFC4122 2022-11-10 14:19:19 +00:00
matt335672 3a0a932472 Add --reload option to sesman
Adds a --reload switch to sesman and plumbs this in
to systemctl reload xrdp-sesman.service
2022-11-09 09:46:36 +00:00
Alexander Pevzner 79d6219d9d Code formatting fixed 2022-11-04 22:18:02 +03:00
metalefty cc43061ed4
Merge pull request #2401 from metalefty/codec_guid
Record codec GUID to identify unknown codec
2022-11-04 16:13:30 +09:00
Koichiro IWAO 9120dc9a66 Update header comments 2022-11-04 16:06:50 +09:00
Alexander Pevzner d6e888cf38 Use LogFile=<stdiut> instead of LogFile=- to redirect log to stdout 2022-11-03 14:44:58 +03:00
Alexander Pevzner 59ca0e1c58 LogFile=- redirects log to stdout, which is useful for debugging 2022-11-02 17:00:44 +03:00
Koichiro IWAO 32da5a7ed6 Replace guid_to_str() with ms_guid_to_str() 2022-11-02 00:20:31 +09:00
Koichiro IWAO 44c977a7c2 Use 8-4-4-4-12 rather than 8-4-4-16 for GUID textual representation 2022-11-01 22:57:07 +09:00
Koichiro IWAO 791f055e18 common: add function to convert from Microsoft's GUID to string 2022-11-01 19:24:02 +09:00
Koichiro IWAO ece8fd2946 Add CODEC_GUID_IGNORE
ref. https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/86507fed-a0ee-4242-b802-237534a8f65e
2022-11-01 19:24:02 +09:00
matt335672 18c5538781 Add casts required for C++ CI and OpenSSL 3.x 2022-10-20 09:56:23 +01:00
Koichiro IWAO 662011a757 log: add some more comments 2022-10-11 09:56:40 +09:00
Koichiro IWAO db96239982 log: quit using lrint and -lm 2022-10-11 09:56:36 +09:00
Koichiro IWAO aca05c4f2e log: change date format to ISO8601-like
Former format:  "[20221007-16:36:02] "
New format:     "[2022-10-07T16:36:04.357+0900] "
2022-10-11 09:55:33 +09:00
sefler cb2b32e6c5 fix code review issues 2022-09-15 23:55:23 +08:00
sefler c4d6714979 touchpad scrolling works now 2022-09-15 23:53:26 +08:00
matt335672 9875f0c0d8 Add g_memmove() to os_calls 2022-09-06 09:31:47 +01:00
matt335672 888c2a0434 Font macro updates for adding font utilities 2022-09-06 09:31:47 +01:00
a1346054 7fe18cc1c0
fix typos 2022-09-03 02:01:48 +00:00
matt335672 d5445e9dc1 Parse more physical monitor size information
To implement a scalable login screen, we need to be able to ascertain
the DPI of the connected primary monitor.

At present, in a multi-monitor situation, this information is available in
the struct display_size_description, which can be searched for the primary
monitor. This is only the case however if the Display Control Channel
Extension is in use ([MS-RDPEDISP]), and a DISPLAYCONTROL_MONITOR_LAYOUT
has been received.

This PR retrieves physical monitor size information from the following
two additional places.

1) The TS_UD_CS_CORE PDU. Physical size information is optionally
   included in this PDU for single-screen configurations.
2) The TS_UD_CS_MONITOR_EX PDU. This includes physical size
   information for multiple-screen configurations.
2022-07-29 10:48:04 +01:00
matt335672 61bfb264de Add bitmask to character string conversions 2022-05-18 12:35:07 +01:00
matt335672 c1d2dcfc7f Cosmetic fixes to string_calls 2022-05-18 12:35:07 +01:00
matt335672 79bec8110c Unify connection fields for the connected client
The connected client is currently described in two places in
the xrdp_client_info structure:-

1) In the connection_description field. This was introduced as
   field client_ip by commit d797b2cf49
   for xrdp v0.6.0

2) In the client_addr and client_port fields introduced by commit
   25369460a1 for xrdp v0.8.0

This commit unifies these two sets of fields into a single
set of fields describing the connection IP and port (for
AF_INET/AF_INET6 connections only) and a connection description
for all connection types.

The code in os_calls to provide client logging has been simplified
somewhat which should make it easier to add new connection types (e.g.
AF_VSOCK).

The old connection_description field used to be passed to sesman to
inform sesman of the IP address of the client, and also to provide
a string for 'C' field session policy matching. 'C' field session policy
matching does not actually need this string (see #2239), and so now only
the IP field is passed to sesman.
2022-05-18 12:35:07 +01:00
matt335672 34fe9b60eb
Merge pull request #1983 from matt335672/pam_group_fix
Moved g_initgroups() call to before auth_start_session()
2022-05-04 09:29:15 +01:00
matt335672 0db849fc5c Move SCP to a Unix Domain Socket
The TCP socket implementation of sesman has a number of limitations,
namely that it is affected by firewalls, and also that determining the
user on the other end requires a full authentication process.

The advantage of the TCP socket is that sesman and xrdp can be run on
separate machines. This is however not supported by the xorgxrdp
backend (shared memory), and is insecure, in that passwords are sent
in-the-clear, and the connection is susceptible to MitM attacks. This
architecture has been deprecated in release notes since xrdp v0.9.17,
and although it will continue to be supported in any further releases
in the x0.9.x series, it will not be supported in the next major
version.
2022-04-18 09:12:35 +01:00
matt335672 0a54106866 Added g_umask_hex() call 2022-04-15 11:12:01 +01:00
matt335672 4183d8ddbf Moved initgroups call to before auth_start_session()
This is required for PAM systems that depend on group membership being
available during PAM processing. This is used by pam_group on FreeBSD
and pam_group on Linux-PAM, although the functionality of both is
different.
2022-04-05 16:07:26 +01:00
matt335672 1d190c6ea8 Prevent unnecessary close of sck = -1 in trans_listen_address() 2022-04-01 11:51:11 +01:00
matt335672 275eaf7683 Rework transport connect logic
There are a number of ways the existing transport connect logic in
trans_connect could be improved for POSIX compatibility, and also
slightly tidied up:-
1) The same socket is re-used for multiple connect attempts following
   failure which isn't behaviour defined by POSIX.1-2017 (although it
   works on Linux).
2) An asynchronous connect is started, and then after a short
   delay connect() is called again on the same socket. POSIX.1-2017
   is clear that in this situation EALREADY is returned before the
   connection is established, but is silent on the behaviour expected
   when the connection is established. Returning success is an option,
   but so is returning EISCONN. The current code assumes the connect()
   call will succeed.
3) The code contains two virtually identical, quite complex loops for
   TCP and UNIX sockets, differing only in the calls to create a socket
   and connect it.
4) trans_connect() contains looping and retry logic, but this isn't
   seen as sufficient by the chansrv connect code in xrdp/xrdp_mm.c and
   the Xorg connect code in xup/xup.c. Both of these implement their own
   looping and retry logic on top of the logic in trans_connect(),
   resulting in slightly unpredictable behaviour with regard to
   timeouts.
5) A socket number can technically be zero, but in a couple of places
   this isn't allowed for.

This PR attempts to correct the implementation of trans_connect(),
and also to simplify the areas it is called from.

As part of the PR, the signature of the server_is_term member of the
xrdp module interface is changed to match the signature expected by the
is_term member of a struct trans. This allows for trans_connect()
in xrdp modules to directly access g_is_term() within the main xrdp
executable. At the moment this functionality is only used by the xup
module.
2022-03-31 20:48:07 +01:00
Christopher Pitstick bd9147d18f Updating to refactor xrdp_client_info
- Eliminate duplicaiton for display_size_description
- monitorCount needs to be uint32_t
- width/height -> session_width/session_height
- Update CLIENT_INFO_CURRENT_VERSION
- Also some misc unit test updates.
- Minor log updates.
2022-03-27 16:38:32 -04:00
Christopher Pitstick 4a0db63be7 Unify monitor processing logic.
There are two places where monitor descriptions are passed through the
RDP protocol:

- TS_UD_CS_MONITOR ([MS-RDPBCGR] 2.2.1.3.6 Client Monitor Data)
- DISPLAYCONTROL_PDU_TYPE_MONITOR_LAYOUT ([MS-RDPEDISP] 2.2.2.2)

The processing logic for both of them is similar enough that they should be unified.

Also update to define the constants for the maximum and minimum desktop width/height for monitors and total area.

Also a large number of clarifications for the constants and protocol
requirements.

Note that this is also the first step to making resizing work with the extension GFX channel as well as an important
foundational step to enable HiDPI compatibility.

Also some misc logging updates.
2022-03-26 23:45:16 -04:00
matt335672 6cf053c9df Add libipm test suite 2022-03-15 10:23:27 +00:00
matt335672 8f4860cb55 Add subclassing capability to struct trans 2022-03-15 10:23:27 +00:00
matt335672 2484928a5a Change 3rd parameter of log_start() to flags field 2022-03-04 11:37:45 +00:00
matt335672 a94ddce0bd logging : Remove processing for unused variables 2022-03-03 17:02:18 +00:00
zbstao 1309ea405e Fixed g_waitpid function
Fixed g_waitpid function
2022-02-15 22:32:46 +08:00
Nexarian a0f4d94cfe Fix NPEs in log.c
Multiple NPEs can happen in the internal_log_config_copy procedure,
and we need to address this before we merge in changes for egfx.
2022-02-14 14:45:43 -05:00
matt335672 e6c098e750 Remove s_check() macro 2022-02-09 10:18:15 +00:00
matt335672 4699dced14 Implement base64 without openssl 2022-01-28 12:23:40 +00:00
matt335672 8b8cfbe119 Improve wrapping of openssl module 2022-01-28 12:23:40 +00:00
matt335672 6cebade78e OpenSSL 3.x compatibility 2022-01-20 16:45:25 +00:00
matt335672 d853228c19 const fixes for SSL calls 2022-01-19 11:11:37 +00:00
Kentaro Hayashi 69ea406440 Add g_str_to_bitmask utility function
It should be used for comma separated configuration to bitmask.

e.g. RestrictOutboundClipboard = text, file, image
2022-01-14 10:17:02 +09:00
matt335672 8b9b22c773 Create shared GUID module to simplify session guid handling 2021-11-25 13:29:55 +00:00
matt335672 ce23c824ea
Merge pull request #1976 from matt335672/fail2ban_support
Fail2ban support (#1076)
2021-11-18 10:11:12 +00:00
liuxiang88 03ae4840e4 Set loongarch need-align-macro. 2021-11-18 15:19:46 +08:00
matt335672 a7b48cd1cf Added more string calls + fix prototypes
- Added g_strrchr() and g_strstr()
- Made C prototypes for g_strchr() and g_strnchr() compatible with
  expected C library functions
2021-10-25 16:13:09 +01:00
matt335672 50e37bf673 Add more file info functions
- g_file_get_device_number()
- g_file_get_inode_num()
2021-10-25 15:24:27 +01:00
matt335672 5fb621ca53 Logged IP address for fail2ban on login failure 2021-10-25 11:35:35 +01:00