From 23158bcca17c60f4a1749614d76564681c4b8f25 Mon Sep 17 00:00:00 2001 From: mstone2001 <80594939+mstone2001@users.noreply.github.com> Date: Tue, 26 Sep 2023 17:36:07 -0400 Subject: [PATCH 1/2] Support Additional OS. Update xrdp to support netbsd, openindiana, macos, gentoo linux. --- configure.ac | 7 +++++++ instfiles/Makefile.am | 6 ++++++ instfiles/openrc/Makefile.am | 3 +++ instfiles/openrc/xrdp | 4 ++++ instfiles/openrc/xrdp-sesman | 4 ++++ 5 files changed, 24 insertions(+) create mode 100644 instfiles/openrc/Makefile.am create mode 100755 instfiles/openrc/xrdp create mode 100755 instfiles/openrc/xrdp-sesman diff --git a/configure.ac b/configure.ac index 3e3557dbb4..e313bc26d1 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,11 @@ AC_ARG_ENABLE(rdpsndaudin, AS_HELP_STRING([--enable-rdpsndaudin], [], [enable_rdpsndaudin=no]) AM_CONDITIONAL(XRDP_RDPSNDAUDIN, [test x$enable_rdpsndaudin = xyes]) +AC_ARG_ENABLE(openrc, AS_HELP_STRING([--enable-openrc], + [Use openrc in (default: no)]), + [], [enable_openrc=no]) +AM_CONDITIONAL(XRDP_OPENRC, [test x$enable_openrc = xyes]) + AC_ARG_WITH(imlib2, AS_HELP_STRING([--with-imlib2=ARG], [imlib2 library to use for non-BMP backgrounds (ARG=yes/no/)]),,) AC_ARG_WITH(freetype2, AS_HELP_STRING([--with-freetype2=ARG], [freetype2 library to use for rendering fonts (ARG=yes/no/)]),,) @@ -574,6 +579,7 @@ AC_CONFIG_FILES([ instfiles/pam.d/Makefile instfiles/pulse/Makefile instfiles/rc.d/Makefile + instfiles/openrc/Makefile keygen/Makefile waitforx/Makefile libipm/Makefile @@ -628,6 +634,7 @@ echo " ipv6only $enable_ipv6only" echo " vsock $enable_vsock" echo " auth mechanism $auth_mech" echo " rdpsndaudin $enable_rdpsndaudin" +echo " openrc $enable_openrc" echo echo " with imlib2 $use_imlib2" echo " with freetype2 $use_freetype2" diff --git a/instfiles/Makefile.am b/instfiles/Makefile.am index a318ed8f92..47ccbabde1 100644 --- a/instfiles/Makefile.am +++ b/instfiles/Makefile.am @@ -66,9 +66,15 @@ systemdsystemunit_DATA = \ xrdp-sesman.service \ xrdp.service else +if XRDP_OPENRC + SUBDIRS += \ + default \ + openrc +else SUBDIRS += \ default \ init.d +endif # XRDP_OPENRC endif # HAVE_SYSTEMD endif # LINUX diff --git a/instfiles/openrc/Makefile.am b/instfiles/openrc/Makefile.am new file mode 100644 index 0000000000..576a9a70c1 --- /dev/null +++ b/instfiles/openrc/Makefile.am @@ -0,0 +1,3 @@ +startscriptdir = $(sysconfdir)/init.d + +dist_startscript_SCRIPTS = xrdp xrdp-sesman diff --git a/instfiles/openrc/xrdp b/instfiles/openrc/xrdp new file mode 100755 index 0000000000..6e59f651b5 --- /dev/null +++ b/instfiles/openrc/xrdp @@ -0,0 +1,4 @@ +#!/sbin/openrc-run + +command="/usr/local/sbin/xrdp" +pidfile="/run/${RC_SVCNAME}.pid" diff --git a/instfiles/openrc/xrdp-sesman b/instfiles/openrc/xrdp-sesman new file mode 100755 index 0000000000..c5a8827983 --- /dev/null +++ b/instfiles/openrc/xrdp-sesman @@ -0,0 +1,4 @@ +#!/sbin/openrc-run + +command="/usr/local/sbin/xrdp-sesman" +pidfile="/run/${RC_SVCNAME}.pid" From f5ceaa07cb6f2e6e7e13ee92b6ae329b660f6d3b Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Tue, 26 Sep 2023 18:30:38 -0400 Subject: [PATCH 2/2] Cleanup. Replace sbin path in openrc files with path actual path. Revert "Merge branch 'gentoo' of https://github.com/mstone2001/xrdp into gentoo" This reverts commit caf7daf3e2501d72b11685a5de92b3b05577a56a, reversing changes made to 23158bcca17c60f4a1749614d76564681c4b8f25. --- instfiles/Makefile.am | 7 ++ instfiles/openrc/xrdp | 2 +- instfiles/openrc/xrdp-sesman | 2 +- sesman/chansrv/smartcard.c | 211 ++------------------------------ sesman/chansrv/smartcard_pcsc.c | 76 +----------- xrdp/xrdp_font.c | 2 +- 6 files changed, 24 insertions(+), 276 deletions(-) diff --git a/instfiles/Makefile.am b/instfiles/Makefile.am index 47ccbabde1..d8af0d9969 100644 --- a/instfiles/Makefile.am +++ b/instfiles/Makefile.am @@ -107,3 +107,10 @@ install-data-hook: sed -i '' 's|%%PREFIX%%|$(prefix)|g' $(DESTDIR)$(sysconfdir)/rc.d/xrdp \ $(DESTDIR)$(sysconfdir)/rc.d/xrdp-sesman endif + +if XRDP_OPENRC +# must be tab below +install-data-hook: + sed -i 's|__BASE__|$(prefix)|' $(DESTDIR)$(sysconfdir)/init.d/xrdp \ + $(DESTDIR)$(sysconfdir)/init.d/xrdp-sesman +endif diff --git a/instfiles/openrc/xrdp b/instfiles/openrc/xrdp index 6e59f651b5..5c2e71ba2a 100755 --- a/instfiles/openrc/xrdp +++ b/instfiles/openrc/xrdp @@ -1,4 +1,4 @@ #!/sbin/openrc-run -command="/usr/local/sbin/xrdp" +command="__BASE__/sbin/xrdp" pidfile="/run/${RC_SVCNAME}.pid" diff --git a/instfiles/openrc/xrdp-sesman b/instfiles/openrc/xrdp-sesman index c5a8827983..a668aec4ea 100755 --- a/instfiles/openrc/xrdp-sesman +++ b/instfiles/openrc/xrdp-sesman @@ -1,4 +1,4 @@ #!/sbin/openrc-run -command="/usr/local/sbin/xrdp-sesman" +command="__BASE__/sbin/xrdp-sesman" pidfile="/run/${RC_SVCNAME}.pid" diff --git a/sesman/chansrv/smartcard.c b/sesman/chansrv/smartcard.c index 6e28bb34ff..9bc657b61f 100644 --- a/sesman/chansrv/smartcard.c +++ b/sesman/chansrv/smartcard.c @@ -18,22 +18,6 @@ * */ -/** - * @file sesman/chansrv/smartcard.c - * - * smartcard redirection support - * - * This file implements some of the PDUs detailed in [MS-RDPESC]. - * - * The PDUs use DCE IDL structs. These are required to be re-interpreted - * in DCE NDR (Netword Data Representation) - * - * For more information on this subject see DCE publication C706 - * "DCE 1.1: Remote Procedure Call" 1997. In particular:- - * Section 4.2 : Describes the IDL - * Section 14 : Describes the NDR - */ - /* * smartcard redirection support */ @@ -1101,51 +1085,13 @@ static void scard_send_ListReaders(IRP *irp, char *context, int context_bytes, char *groups, int cchReaders, int wide) { - /* see [MS-RDPESC] 2.2.2.4 - * - * IDL:- - * - * typedef struct _REDIR_SCARDCONTEXT { - * [range(0,16)] unsigned long cbContext; - * [unique] [size_is(cbContext)] byte *pbContext; - * } REDIR_SCARDCONTEXT; - * - * struct _ListReaders_Call { - * REDIR_SCARDCONTEXT Context; - * [range(0, 65536)] unsigned long cBytes; - * [unique] [size_is(cBytes)] const byte *mszGroups; - * long fmszReadersIsNULL; - * unsigned long cchReaders; - * } ListReaders_Call; - * - * Type summary:- - * - * Context.cbContext Unsigned 32-bit word - * Context.pbContext Embedded full pointer to conformant array of bytes - * cBytes Unsigned 32-bit word - * mszGroups Embedded full pointer to conformant array of bytes - * fmszReaders 32-bit word - * cchReaders Unsigned 32-bit word - * - * NDL:- - * - * Offset Decription - * 0 Context.cbContext - * 4 Referent Identifier for pbContext - * 8 cBytes - * 12 Referent Identifier for mszGroups (or NULL) - * 16 fmszReadersIsNULL - * 20 cchReaders - * 24 Conformant Array pointed to by pbContext - * ?? Conformant Array pointed to by mszGroups - * - */ + /* see [MS-RDPESC] 2.2.2.4 */ SMARTCARD *sc; struct stream *s; int bytes; - int bytes_groups; // Length of NDR for groups + 2 terminators - int val; // Referent Id for mszGroups (assume NULL) + int bytes_groups; + int val; int index; int num_chars; tui32 ioctl; @@ -1183,25 +1129,17 @@ scard_send_ListReaders(IRP *irp, char *context, int context_bytes, s_push_layer(s, mcs_hdr, 4); /* bytes, set later */ out_uint32_le(s, 0x00000000); - // REDIR_SCARDCONTEXT Context; out_uint32_le(s, context_bytes); out_uint32_le(s, 0x00020000); - // [range(0, 65536)] unsigned long cBytes; out_uint32_le(s, bytes_groups); - // [unique] [size_is(cBytes)] const byte *mszGroups; (pointer) out_uint32_le(s, val); - // long fmszReadersIsNULL; out_uint32_le(s, 0x00000000); - // unsigned long cchReaders; out_uint32_le(s, cchReaders); - // At the end of the struct come the pointed-to structures - - // Context field pbContext is a Uni-dimensional conformant array + /* insert context */ out_uint32_le(s, context_bytes); out_uint8a(s, context, context_bytes); - // mszGroups is also a Uni-dimensional conformant array of bytes if (bytes_groups > 0) { if (wide) @@ -1277,69 +1215,8 @@ scard_send_GetStatusChange(IRP *irp, char *context, int context_bytes, int wide, tui32 timeout, tui32 num_readers, READER_STATE *rsa) { - /* see [MS-RDPESC] 2.2.2.11 for ASCII - * see [MS-RDPESC] 2.2.2.12 for Wide char - * - * Here is a breakdown of the Wide-char variant - * - * IDL:- - * - * typedef struct _REDIR_SCARDCONTEXT { - * [range(0,16)] unsigned long cbContext; - * [unique] [size_is(cbContext)] byte *pbContext; - * } REDIR_SCARDCONTEXT; - * - * typedef struct _ReaderState_Common_Call { - * unsigned long dwCurrentState; - * unsigned long dwEventState; - * [range(0,36)] unsigned long cbAtr; - * byte rgbAtr[36]; - * } ReaderState_Common_Call; - * - * typedef struct _ReaderStateW { - * [string] const wchar_t* szReader; - * ReaderState_Common_Call Common; - * } ReaderStateW; - * - * struct _GetStatusChangeW_Call { - * REDIR_SCARDCONTEXT Context; - * unsigned long dwTimeOut; - * [range(0,11)] unsigned long cReaders; - * [size_is(cReaders)] ReaderStateW* rgReaderStates; - * } GetStatusChangeW_Call; - * - * Type summary:- - * - * Context.cbContext Unsigned 32-bit word - * Context.pbContext Embedded full pointer to conformant array of bytes - * dwTimeOut Unsigned 32-bit word - * cReaders Unsigned 32-bit word - * rgReaderStates - * Embedded full pointer to array of rgReaderStates - * rgReaderStates.szReader - * Embedded full pointer to conformant and varying - * string of [Windows] wchar_t - * rgReaderStates.Common.dwCurrentState - * Unsigned 32-bit word - * rgReaderStates.Common.dwEventState - * Unsigned 32-bit word - * rgReaderStates.Common.cbAtr - * Unsigned 32-bit word - * rgReaderStates.Common.rgbAtr[36] - * Uni-dimensional fixed array - * - * NDL:- - * Offset Decription - * 0 Context.cbContext - * 4 Referent Identifier for pbContext - * 8 dwTimeOut; - * 12 cReaders; - * 16 Referent Identifier for rgReaderStates - * 20 Conformant Array pointed to by pbContext - * ?? Conformant Array pointed to by rgReaderStates. Each element - * of this array has a pointer to a string for the name - * ?? String names pointed to in the above array. - */ + /* see [MS-RDPESC] 2.2.2.11 for ASCII */ + /* see [MS-RDPESC] 2.2.2.12 for Wide char */ SMARTCARD *sc; READER_STATE *rs; @@ -1368,40 +1245,27 @@ scard_send_GetStatusChange(IRP *irp, char *context, int context_bytes, s_push_layer(s, mcs_hdr, 4); /* bytes, set later */ out_uint32_le(s, 0x00000000); - // REDIR_SCARDCONTEXT Context; out_uint32_le(s, context_bytes); out_uint32_le(s, 0x00020000); - // unsigned long dwTimeOut; out_uint32_le(s, timeout); - // [range(0,11)] unsigned long cReaders; out_uint32_le(s, num_readers); - // [size_is(cReaders)] ReaderStateW* rgReaderStates; - out_uint32_le(s, 0x00020004); - - // At the end of the struct come the pointed-to structures + out_uint32_le(s, 0x00020004); /* ? */ - // Context field pbContext is a Uni-dimensional conformant array + /* insert context */ out_uint32_le(s, context_bytes); out_uint8a(s, context, context_bytes); - // rgReaderState is a Uni-dimensional conformant array out_uint32_le(s, num_readers); /* insert card reader state */ for (i = 0; i < num_readers; i++) { rs = &rsa[i]; - // [string] const wchar_t* szReader (wide) - // [string] const char_t* szReader (ASCII) - out_uint32_le(s, 0x00020008 + (i * 4)); - // unsigned long dwCurrentState; + out_uint32_le(s, 0x00020008); /* ? */ out_uint32_le(s, rs->current_state); - // unsigned long dwEventState; out_uint32_le(s, rs->event_state); - // [range(0,36)] unsigned long cbAtr; out_uint32_le(s, rs->atr_len); - // byte rgbAtr[36]; out_uint8p(s, rs->atr, 33); out_uint8s(s, 3); } @@ -1478,53 +1342,8 @@ static void scard_send_Connect(IRP *irp, char *context, int context_bytes, int wide, READER_STATE *rs) { - /* see [MS-RDPESC] 2.2.2.13 for ASCII - * see [MS-RDPESC] 2.2.2.14 for Wide char - * - * Here is a breakdown of the Wide-char variant - * - * IDL:- - * - * typedef struct _REDIR_SCARDCONTEXT { - * [range(0,16)] unsigned long cbContext; - * [unique] [size_is(cbContext)] byte *pbContext; - * } REDIR_SCARDCONTEXT; - * - * typedef struct _Connect_Common { - * REDIR_SCARDCONTEXT Context; - * unsigned long dwShareMode; - * unsigned long dwPreferredProtocols; - * } Connect_Common; - * - * typedef struct _ConnectW_Call { - * [string] const wchar_t* szReader; - * Connect_Common Common; - * } ConnectW_Call; - * - * Type summary:- - * - * szReader Embedded full pointer to conformant and varying - * string of [Windows] wchar_t - * Common.Context.cbContext - * Unsigned 32-bit word - * Common.Context.pbContext - * Embedded full pointer to conformant array of bytes - * Common.dwShareMode Unsigned 32-bit word - * Common.dwPreferredProtocols - * Unsigned 32-bit word - * - * NDL:- - * - * Offset Decription - * 0 Referent Identifier for szReader - * 4 Context.cbContext - * 8 Referent Identifier for pbContext - * 12 dwShareMode - * 16 dwPreferredProtocols - * 20 Conformant Array pointed to by szReader - * ?? Conformant Array pointed to by pbContext - * - */ + /* see [MS-RDPESC] 2.2.2.13 for ASCII */ + /* see [MS-RDPESC] 2.2.2.14 for Wide char */ SMARTCARD *sc; struct stream *s; @@ -1551,19 +1370,11 @@ scard_send_Connect(IRP *irp, char *context, int context_bytes, s_push_layer(s, mcs_hdr, 4); /* bytes, set later */ out_uint32_le(s, 0x00000000); - // [string] const wchar_t* szReader; out_uint32_le(s, 0x00020000); - - // REDIR_SCARDCONTEXT Context; out_uint32_le(s, context_bytes); out_uint32_le(s, 0x00020004); - - // unsigned long dwShareMode; out_uint32_le(s, rs->dwShareMode); - // unsigned long dwPreferredProtocols; out_uint32_le(s, rs->dwPreferredProtocols); - - /* insert card reader name */ num_chars = g_mbstowcs(w_reader_name, rs->reader_name, 99); out_uint32_le(s, num_chars + 2); out_uint32_le(s, 0x00000000); diff --git a/sesman/chansrv/smartcard_pcsc.c b/sesman/chansrv/smartcard_pcsc.c index e6f950db33..042e3de5bd 100644 --- a/sesman/chansrv/smartcard_pcsc.c +++ b/sesman/chansrv/smartcard_pcsc.c @@ -18,21 +18,9 @@ */ /* - * @file sesman/chansrv/smartcard_pcsc.c - * * smartcard redirection support, PCSC daemon standin * this will act like pcsc daemon * pcsc lib and daemon write struct on unix domain socket for communication - * - * Currently this file implements some of the PDUs detailed in [MS-RDPESC]. - * - * The PDUs use DCE IDL structs. These are required to be re-interpreted - * in DCE NDR (Netword Data Representation) - * - * For more information on this subject see DCE publication C706 - * "DCE 1.1: Remote Procedure Call" 1997. In particular:- - * Section 4.2 : Describes the IDL - * Section 14 : Describes the NDR */ #if defined(HAVE_CONFIG_H) @@ -659,31 +647,6 @@ scard_function_list_readers_return(void *user_data, struct stream *in_s, int len, int status) { - /* see [MS-RDPESC] 2.2.3.4 - * - * IDL:- - * - * typedef struct _longAndMultiString_Return { - * long ReturnCode; - * [range(0,65536)] unsigned long cBytes; - * [unique] [size_is(cBytes)] byte *msz; - * } ListReaderGroups_Return, ListReaders_Return; - * - * Type summary:- - * - * ReturnCode 32-bit word - * CBytes Unsigned 32-bit word - * msz Embedded full pointer to conformant array of bytes - * - * NDR:- - * - * Offset Decription - * 0 ReturnCode - * 4 cBytes - * 8 msz pointer Referent Identifier - * 12 length of multistring in bytes - * 16 Multistring data - */ struct stream *out_s; int chr; int readers; @@ -728,11 +691,7 @@ scard_function_list_readers_return(void *user_data, llen = 0; if (status == 0) { - // Skip [C706] PDU Header - in_uint8s(in_s, 16); - // Move to length of multistring in bytes - in_uint8s(in_s, 12); - + in_uint8s(in_s, 28); in_uint32_le(in_s, len); llen = len; if (cchReaders > 0) @@ -1438,33 +1397,6 @@ scard_function_status_return(void *user_data, struct stream *in_s, int len, int status) { - /* see [MS-RDPESC] 2.2.3.10 - * - * IDL:- - * - * typedef struct _Status_Return { - * long ReturnCode; - * unsigned long cBytes; - * [unique] [size_is(cBytes)] byte *mszReaderNames; - * unsigned long dwState; - * unsigned long dwProtocol; - * byte pbAtr[32]; - * [range(0,32)] unsigned long cbAtrLen; - * } Status_Return; - * - * NDR:- - * - * Offset Decription - * 0 ReturnCode - * 4 cBytes - * 8 Referent Identifier for mszReaderNames; - * 12 dwState - * 16 dwProtocol - * 20 pbAtr - * 52 cbAtrLen - * 56 length of multistring in bytes (same as cBytes) - * 60 Multistring data - */ struct stream *out_s; int index; int bytes; @@ -1510,10 +1442,9 @@ scard_function_status_return(void *user_data, lreader_name[0] = 0; if (status == 0) { - in_uint8s(in_s, 16); // Skip [C706] PDU Header - in_uint8s(in_s, 4); // ReturnCode + in_uint8s(in_s, 20); in_uint32_le(in_s, dwReaderLen); - in_uint8s(in_s, 4); // Referent Identifier + in_uint8s(in_s, 4); in_uint32_le(in_s, dwState); dwState = g_ms2pc[dwState % 6]; in_uint32_le(in_s, dwProtocol); @@ -1816,7 +1747,6 @@ scard_process_msg(struct trans *con, struct stream *in_s, int command) break; case 0x03: /* SCARD_LIST_READERS */ - /* This is only called from xrdp_pcsc.c */ LOG_DEVEL(LOG_LEVEL_INFO, "scard_process_msg: SCARD_LIST_READERS"); rv = scard_process_list_readers(con, in_s); break; diff --git a/xrdp/xrdp_font.c b/xrdp/xrdp_font.c index ceaadfd77f..1224338ec5 100644 --- a/xrdp/xrdp_font.c +++ b/xrdp/xrdp_font.c @@ -261,7 +261,7 @@ xrdp_font_create(struct xrdp_wm *wm, unsigned int dpi) * that it can be added to the glyph cache if required */ f->width = 1; f->height = 1; - f->data = (char *)g_malloc(FONT_DATASIZE(f), 1); + f->data = (char *)g_malloc(1, 1); } else if (s_check_rem(s, datasize)) {