From 58c9cb43e9e83a6f5cc8a13cd84aa67cce8cacd5 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 14 Mar 2017 21:45:50 -0700 Subject: [PATCH] Make socket directory configurable, don't hardcode /tmp/.xrdp Use XRDP_SOCKET_PATH in file_loc.h Don't define any non-socket paths in file_loc.h, they should come from the makefiles. Define all paths unconditionally, they should not be defined elsewhere. Pass XRDP_SOCKET_PATH as environment variable to the backends. --- common/Makefile.am | 3 +- common/file_loc.h | 49 +++-------------------- common/os_calls.c | 11 ++--- configure.ac | 6 +++ docs/man/Makefile.am | 3 +- docs/man/xrdp-chansrv.8.in | 4 +- docs/man/xrdp-dis.1.in | 2 +- sesman/Makefile.am | 1 + sesman/chansrv/Makefile.am | 1 + sesman/chansrv/pulse/module-xrdp-sink.c | 2 +- sesman/chansrv/pulse/module-xrdp-source.c | 2 +- sesman/session.c | 1 + sesman/tools/Makefile.am | 1 + sesman/tools/dis.c | 4 +- xrdp/Makefile.am | 1 + xrdpapi/Makefile.am | 4 ++ xrdpapi/xrdpapi.c | 3 +- 17 files changed, 41 insertions(+), 57 deletions(-) diff --git a/common/Makefile.am b/common/Makefile.am index 0af033a3..dab9d524 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -16,7 +16,8 @@ AM_CPPFLAGS = \ -DXRDP_SBIN_PATH=\"${sbindir}\" \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ - -DXRDP_LOG_PATH=\"${localstatedir}/log\" + -DXRDP_LOG_PATH=\"${localstatedir}/log\" \ + -DXRDP_SOCKET_PATH=\"${socketdir}\" if XRDP_DEBUG AM_CPPFLAGS += -DXRDP_DEBUG diff --git a/common/file_loc.h b/common/file_loc.h index 8f5146cb..45178964 100644 --- a/common/file_loc.h +++ b/common/file_loc.h @@ -21,48 +21,11 @@ #if !defined(FILE_LOC_H) #define FILE_LOC_H -#if !defined(XRDP_CFG_PATH) -#define XRDP_CFG_PATH "/etc/xrdp" -#endif - -#if !defined(XRDP_PID_PATH) -#define XRDP_PID_PATH "/var/run" -#endif - -#if !defined(XRDP_SBIN_PATH) -#define XRDP_SBIN_PATH "/usr/local/sbin" -#endif - -#if !defined(XRDP_SHARE_PATH) -#define XRDP_SHARE_PATH "/usr/local/share/xrdp" -#endif - -#if !defined(XRDP_MODULE_PATH) -#define XRDP_MODULE_PATH "/usr/local/lib/xrdp" -#endif - -#if !defined(XRDP_LOG_PATH) -#define XRDP_LOG_PATH "/var/log" -#endif - -#if !defined(XRDP_CHANSRV_STR) -#define XRDP_CHANSRV_STR "/tmp/.xrdp/xrdp_chansrv_socket_%d" -#endif - -#if !defined(CHANSRV_PORT_OUT_STR) -#define CHANSRV_PORT_OUT_STR "/tmp/.xrdp/xrdp_chansrv_audio_out_socket_%d" -#endif - -#if !defined(CHANSRV_PORT_IN_STR) -#define CHANSRV_PORT_IN_STR "/tmp/.xrdp/xrdp_chansrv_audio_in_socket_%d" -#endif - -#if !defined(CHANSRV_API_STR) -#define CHANSRV_API_STR "/tmp/.xrdp/xrdpapi_%d" -#endif - -#if !defined(XRDP_X11RDP_STR) -#define XRDP_X11RDP_STR "/tmp/.xrdp/xrdp_display_%d" -#endif +#define XRDP_CHANSRV_STR XRDP_SOCKET_PATH "/xrdp_chansrv_socket_%d" +#define CHANSRV_PORT_OUT_STR XRDP_SOCKET_PATH "/xrdp_chansrv_audio_out_socket_%d" +#define CHANSRV_PORT_IN_STR XRDP_SOCKET_PATH "/xrdp_chansrv_audio_in_socket_%d" +#define CHANSRV_API_STR XRDP_SOCKET_PATH "/xrdpapi_%d" +#define XRDP_X11RDP_STR XRDP_SOCKET_PATH "/xrdp_display_%d" +#define XRDP_DISCONNECT_STR XRDP_SOCKET_PATH "/xrdp_disconnect_display_%d" #endif diff --git a/common/os_calls.c b/common/os_calls.c index f85e5d2e..a0d8ce1a 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -111,18 +111,19 @@ g_rm_temp_dir(void) int g_mk_temp_dir(const char *app_name) { - if (!g_directory_exist("/tmp/.xrdp")) + if (!g_directory_exist(XRDP_SOCKET_PATH)) { - if (!g_create_dir("/tmp/.xrdp")) + if (!g_create_dir(XRDP_SOCKET_PATH)) { /* if failed, still check if it got created by someone else */ - if (!g_directory_exist("/tmp/.xrdp")) + if (!g_directory_exist(XRDP_SOCKET_PATH)) { - printf("g_mk_temp_dir: g_create_dir failed\n"); + printf("g_mk_temp_dir: g_create_dir(%s) failed\n", + XRDP_SOCKET_PATH); return 1; } } - g_chmod_hex("/tmp/.xrdp", 0x1777); + g_chmod_hex(XRDP_SOCKET_PATH, 0x1777); } return 0; } diff --git a/configure.ac b/configure.ac index 68620e13..577777bc 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,12 @@ AM_CONDITIONAL(FREEBSD, [test "x$freebsd" = xyes]) AM_CONDITIONAL(OPENBSD, [test "x$openbsd" = xyes]) AM_CONDITIONAL(NETBSD, [test "x$netbsd" = xyes]) +AC_ARG_WITH([socketdir], + [AS_HELP_STRING([--with-socketdir=DIR], + [Use directory for UNIX sockets (default: /tmp/.xrdp)])], + [], [with_socketdir="/tmp/.xrdp"]) +AC_SUBST([socketdir], [$with_socketdir]) + AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]), [], [ diff --git a/docs/man/Makefile.am b/docs/man/Makefile.am index 705def0c..f6e0bd5a 100644 --- a/docs/man/Makefile.am +++ b/docs/man/Makefile.am @@ -17,7 +17,8 @@ SUBST_VARS = sed \ -e 's|@PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \ -e 's|@bindir[@]|$(bindir)|g' \ -e 's|@localstatedir[@]|$(localstatedir)|g' \ - -e 's|@sysconfdir[@]|$(sysconfdir)|g' + -e 's|@sysconfdir[@]|$(sysconfdir)|g' \ + -e 's|@socketdir[@]|$(socketdir)|g' subst_verbose = $(subst_verbose_@AM_V@) subst_verbose_ = $(subst_verbose_@AM_DEFAULT_V@) diff --git a/docs/man/xrdp-chansrv.8.in b/docs/man/xrdp-chansrv.8.in index 332a1907..62edd3b2 100644 --- a/docs/man/xrdp-chansrv.8.in +++ b/docs/man/xrdp-chansrv.8.in @@ -30,10 +30,10 @@ Dynamic Virtual Channel .SH FILES .TP -.I /tmp/.xrdp/xrdp_chansrv_socket_* +.I @socketdir@/xrdp_chansrv_socket_* UNIX socket used by external programs to implement channels. .TP -.I /tmp/.xrdp/xrdp_api_* +.I @socketdir@/xrdp_api_* UNIX socket used by \fBxrdp\-chansrv\fP to communicate with \fBxrdp\-sesman\fP. .TP .I $XDG_DATA_HOME/xrdp/xrdp-chansrv.log diff --git a/docs/man/xrdp-dis.1.in b/docs/man/xrdp-dis.1.in index 54ba5db2..2015389f 100644 --- a/docs/man/xrdp-dis.1.in +++ b/docs/man/xrdp-dis.1.in @@ -16,7 +16,7 @@ to get the default host and display number. .SH FILES .TP -.I /tmp/.xrdp/xrdp_disconnect_display_* +.I @socketdir@/xrdp_disconnect_display_* UNIX socket used to communicate with the \fBxrdp\fP(8) session manager. .SH KNOWN ISSUES diff --git a/sesman/Makefile.am b/sesman/Makefile.am index d965f46c..bef787a3 100644 --- a/sesman/Makefile.am +++ b/sesman/Makefile.am @@ -6,6 +6,7 @@ AM_CPPFLAGS = \ -DXRDP_SBIN_PATH=\"${sbindir}\" \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ + -DXRDP_SOCKET_PATH=\"${socketdir}\" \ -I$(top_srcdir)/common \ -I$(top_srcdir)/sesman/libscp diff --git a/sesman/chansrv/Makefile.am b/sesman/chansrv/Makefile.am index 05ca50f5..1df6c762 100644 --- a/sesman/chansrv/Makefile.am +++ b/sesman/chansrv/Makefile.am @@ -9,6 +9,7 @@ AM_CPPFLAGS = \ -DXRDP_SBIN_PATH=\"${sbindir}\" \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ + -DXRDP_SOCKET_PATH=\"${socketdir}\" \ -I$(top_srcdir)/common if XRDP_DEBUG diff --git a/sesman/chansrv/pulse/module-xrdp-sink.c b/sesman/chansrv/pulse/module-xrdp-sink.c index 3e4756eb..f7f98b05 100644 --- a/sesman/chansrv/pulse/module-xrdp-sink.c +++ b/sesman/chansrv/pulse/module-xrdp-sink.c @@ -68,6 +68,7 @@ typedef bool pa_bool_t; #endif #include "module-xrdp-sink-symdef.h" +#include "../common/file_loc.h" PA_MODULE_AUTHOR("Jay Sorg"); PA_MODULE_DESCRIPTION("xrdp sink"); @@ -84,7 +85,6 @@ PA_MODULE_USAGE( #define DEFAULT_SINK_NAME "xrdp-sink" #define BLOCK_USEC 30000 //#define BLOCK_USEC (PA_USEC_PER_SEC * 2) -#define CHANSRV_PORT_STR "/tmp/.xrdp/xrdp_chansrv_audio_out_socket_%d" struct userdata { pa_core *core; diff --git a/sesman/chansrv/pulse/module-xrdp-source.c b/sesman/chansrv/pulse/module-xrdp-source.c index 78124f9d..25cc8e4d 100644 --- a/sesman/chansrv/pulse/module-xrdp-source.c +++ b/sesman/chansrv/pulse/module-xrdp-source.c @@ -55,6 +55,7 @@ typedef bool pa_bool_t; #endif #include "module-xrdp-source-symdef.h" +#include "../common/file_loc.h" PA_MODULE_AUTHOR("Laxmikant Rashinkar"); PA_MODULE_DESCRIPTION("xrdp source"); @@ -72,7 +73,6 @@ PA_MODULE_USAGE( #define DEFAULT_SOURCE_NAME "xrdp-source" #define DEFAULT_LATENCY_TIME 10 #define MAX_LATENCY_USEC 1000 -#define CHANSRV_PORT_STR "/tmp/.xrdp/xrdp_chansrv_audio_in_socket_%d" struct userdata { pa_core *core; diff --git a/sesman/session.c b/sesman/session.c index 06e44cf0..1d06b802 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -668,6 +668,7 @@ session_start_fork(tbus data, tui8 type, struct SCP_SESSION *s) g_setenv("XRDP_SESMAN_MAX_DISC_TIME", text, 1); g_snprintf(text, 255, "%d", g_cfg->sess.kill_disconnected); g_setenv("XRDP_SESMAN_KILL_DISCONNECTED", text, 1); + g_setenv("XRDP_SOCKET_PATH", XRDP_SOCKET_PATH, 1); /* prepare the Xauthority stuff */ if (g_getenv("XAUTHORITY") != NULL) diff --git a/sesman/tools/Makefile.am b/sesman/tools/Makefile.am index 9d6d6f9e..2f8be440 100644 --- a/sesman/tools/Makefile.am +++ b/sesman/tools/Makefile.am @@ -3,6 +3,7 @@ AM_CPPFLAGS = \ -DXRDP_SBIN_PATH=\"${sbindir}\" \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ + -DXRDP_SOCKET_PATH=\"${socketdir}\" \ -I$(top_srcdir)/common \ -I$(top_srcdir)/sesman/libscp \ -I$(top_srcdir)/sesman diff --git a/sesman/tools/dis.c b/sesman/tools/dis.c index 086dc1b9..61f2bea2 100644 --- a/sesman/tools/dis.c +++ b/sesman/tools/dis.c @@ -27,6 +27,8 @@ #include #include +#include "file_loc.h" + int main(int argc, char **argv) { int sck; @@ -54,7 +56,7 @@ int main(int argc, char **argv) dis = strtol(display + 1, &p, 10); memset(&sa, 0, sizeof(sa)); sa.sun_family = AF_UNIX; - sprintf(sa.sun_path, "/tmp/.xrdp/xrdp_disconnect_display_%d", dis); + sprintf(sa.sun_path, XRDP_DISCONNECT_STR, dis); if (access(sa.sun_path, F_OK) != 0) { diff --git a/xrdp/Makefile.am b/xrdp/Makefile.am index 3765f203..a259ef32 100644 --- a/xrdp/Makefile.am +++ b/xrdp/Makefile.am @@ -9,6 +9,7 @@ AM_CPPFLAGS = \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ -DXRDP_MODULE_PATH=\"${moduledir}\" \ + -DXRDP_SOCKET_PATH=\"${socketdir}\" \ -I$(top_builddir) \ -I$(top_srcdir)/common \ -I$(top_srcdir)/libxrdp diff --git a/xrdpapi/Makefile.am b/xrdpapi/Makefile.am index fefa03fc..d40109a9 100644 --- a/xrdpapi/Makefile.am +++ b/xrdpapi/Makefile.am @@ -3,6 +3,10 @@ EXTRA_DIST = \ vrplayer.c \ vrplayer.mk +AM_CPPFLAGS = \ + -DXRDP_SOCKET_PATH=\"${socketdir}\" \ + -I$(top_srcdir)/common + module_LTLIBRARIES = \ libxrdpapi.la diff --git a/xrdpapi/xrdpapi.c b/xrdpapi/xrdpapi.c index 07af7091..d5666aa0 100644 --- a/xrdpapi/xrdpapi.c +++ b/xrdpapi/xrdpapi.c @@ -39,6 +39,7 @@ #include #include +#include "file_loc.h" #include "xrdpapi.h" struct wts_obj @@ -148,7 +149,7 @@ WTSVirtualChannelOpenEx(unsigned int SessionId, const char *pVirtualName, memset(&s, 0, sizeof(struct sockaddr_un)); s.sun_family = AF_UNIX; bytes = sizeof(s.sun_path); - snprintf(s.sun_path, bytes - 1, "/tmp/.xrdp/xrdpapi_%d", wts->display_num); + snprintf(s.sun_path, bytes - 1, CHANSRV_API_STR, wts->display_num); s.sun_path[bytes - 1] = 0; bytes = sizeof(struct sockaddr_un);