From 08a5dc554f8dfde06de516120aa899d492dcc046 Mon Sep 17 00:00:00 2001 From: mstone2001 <80594939+mstone2001@users.noreply.github.com> Date: Sun, 1 Oct 2023 12:59:34 -0400 Subject: [PATCH 1/7] Support for NetBSD and OpenIndiana. Log an info message instead of error if waitpid returns ECHILD. Need to re-register for SIGCHLD on Solaris. Retry on EINTR. Retry SIGINT in waitpid. Fix issues with SIGINT on solaris. Add -w option to waitforx to configure wait time. Fix call to usleep for NetBSD, where value must be < 1000000 Update flags for Solaris. Support Additional OS. Update xrdp to support netbsd, openindiana. Support Additional OS. Update xrdp to support netbsd. --- common/Makefile.am | 2 +- common/os_calls.c | 158 +++++++++++++++++++++++++---- common/os_calls.h | 2 +- configure.ac | 16 ++- instfiles/Makefile.am | 22 ++++ instfiles/manifest/Makefile.am | 3 + instfiles/manifest/xrdp-sesman.xml | 55 ++++++++++ instfiles/manifest/xrdp.xml | 55 ++++++++++ instfiles/method/Makefile.am | 3 + instfiles/method/xrdp | 85 ++++++++++++++++ instfiles/method/xrdp-sesman | 87 ++++++++++++++++ sesman/Makefile.am | 7 ++ sesman/sesexec/sesexec.c | 7 ++ sesman/sesexec/session.c | 4 +- sesman/sesexec/xwait.c | 10 +- sesman/tools/Makefile.am | 8 ++ tools/devel/tcp_proxy/Makefile.am | 4 + waitforx/waitforx.c | 24 +++-- 18 files changed, 514 insertions(+), 38 deletions(-) create mode 100644 instfiles/manifest/Makefile.am create mode 100644 instfiles/manifest/xrdp-sesman.xml create mode 100644 instfiles/manifest/xrdp.xml create mode 100644 instfiles/method/Makefile.am create mode 100755 instfiles/method/xrdp create mode 100755 instfiles/method/xrdp-sesman diff --git a/common/Makefile.am b/common/Makefile.am index c929baab19..23d1997f7b 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -28,7 +28,7 @@ AM_CPPFLAGS = \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ -DXRDP_LOG_PATH=\"${localstatedir}/log\" \ - -DXRDP_SOCKET_PATH=\"${socketdir}\" + -DXRDP_SOCKET_PATH=\"${socketdir}\" # -no-suppress is an automake-specific flag which is needed # to prevent us missing compiler errors in some circumstances diff --git a/common/os_calls.c b/common/os_calls.c index a58051a5ed..acbc900400 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -32,10 +32,6 @@ #include #include #else -/* fix for solaris 10 with gcc 3.3.2 problem */ -#if defined(sun) || defined(__sun) -#define ctid_t id_t -#endif #include #include #include @@ -55,6 +51,7 @@ struct sockaddr_hvs }; #endif #endif +#include #include #include #include @@ -111,8 +108,11 @@ extern char **environ; /* sys/ucred.h needs to be included to use struct xucred * in FreeBSD and OS X. No need for other BSDs except GNU/kFreeBSD */ +/* Solaris uses __sun and needs .h */ #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) #include +#elif defined(__sun) +#include #endif /* for solaris */ @@ -164,11 +164,14 @@ g_mk_socket_path(void) LOG(LOG_LEVEL_ERROR, "g_mk_socket_path: g_create_path(%s) failed", XRDP_SOCKET_PATH); + + LOG(LOG_LEVEL_TRACE, "g_mk_socket_path() returned 1"); return 1; } } g_chmod_hex(XRDP_SOCKET_PATH, 0x1777); } + return 0; } @@ -616,6 +619,7 @@ g_sck_vsock_socket(void) int g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) { + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred(%d)", sck); #if defined(SO_PEERCRED) socklen_t ucred_length; struct myucred @@ -628,6 +632,7 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) ucred_length = sizeof(credentials); if (getsockopt(sck, SOL_SOCKET, SO_PEERCRED, &credentials, &ucred_length)) { + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; } if (pid != 0) @@ -651,6 +656,8 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) if (getsockopt(sck, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_length)) { + LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; } if (pid != 0) @@ -665,8 +672,69 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) { *gid = xucred.cr_gid; } + + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 0"); + return 0; +#elif defined(LOCAL_PEEREID) + /* Net BSD */ + #ifndef SOL_LOCAL + #define SOL_LOCAL 0 + #endif + struct unpcbid xucred; + unsigned int xucred_length; + xucred_length = sizeof(xucred); + if (getsockopt(sck, SOL_LOCAL, LOCAL_PEEREID, &xucred, &xucred_length)) + { + LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); + return 1; + } + + if (pid != 0) + { + *pid = xucred.unp_pid; + } + if (uid != 0) + { + *uid = xucred.unp_euid; + } + if (gid != 0) + { + *gid = xucred.unp_egid; + } + + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 0"); + return 0; +#elif defined(__sun) + /* Solaris, OpenIndiana */ + ucred_t* xucred = NULL; + + if(getpeerucred(sck, &xucred)) + { + LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); + return 1; + } + + if (pid != 0) + { + *pid = ucred_getpid(xucred); + } + if (uid != 0) + { + *uid = ucred_geteuid(xucred); + } + if (gid != 0) + { + *gid = ucred_getegid(xucred); + } + + ucred_free(xucred); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 0"); return 0; #else + LOG(LOG_LEVEL_ERROR, "g_sck_get_peer_cred() has no implementation."); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; #endif } @@ -1403,8 +1471,25 @@ g_sleep(int msecs) { #if defined(_WIN32) Sleep(msecs); + //On NetBSD usleep can not be > 1000000, so use sleep instead. +#elif defined(__NetBSD__) + if( msecs >= 1000 ) + { + int secs = msecs / 1000; + int remainder = msecs % 1000; + + if( secs != 0 ) + { + sleep(msecs / 1000); + } + + if( remainder != 0 ) + { + usleep(remainder * 1000); + } + } #else - usleep(msecs * 1000); + usleep(msecs * 1000); #endif } @@ -2990,6 +3075,7 @@ g_set_alarm(void (*func)(int), unsigned int secs) /* Cancel any previous alarm to prevent a race */ unsigned int rv = alarm(0); signal(SIGALRM, func); + signal(SIGINT, func); (void)alarm(secs); return rv; #endif @@ -3001,6 +3087,7 @@ void g_signal_child_stop(void (*func)(int)) { #if defined(_WIN32) + return; #else signal(SIGCHLD, func); #endif @@ -3080,6 +3167,7 @@ g_fork(void) #if defined(_WIN32) return 0; #else + LOG_DEVEL(LOG_LEVEL_TRACE, "g_fork()"); int rv; rv = fork(); @@ -3091,6 +3179,7 @@ g_fork(void) g_get_errno(), g_get_strerror()); } + LOG_DEVEL(LOG_LEVEL_TRACE, "g_fork() returned %d", rv); return rv; #endif } @@ -3103,7 +3192,10 @@ g_setgid(int pid) #if defined(_WIN32) return 0; #else - return setgid(pid); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_setgid(%d)", pid); + int retval = setgid(pid); + LOG_DEVEL(LOG_LEVEL_TRACE, "--g_setgid()"); + return retval; #endif } @@ -3116,12 +3208,15 @@ g_initgroups(const char *username) #if defined(_WIN32) return 0; #else + LOG_DEVEL(LOG_LEVEL_TRACE, "g_initgroups(%s)", username); int gid; int error = g_getuser_info_by_name(username, NULL, &gid, NULL, NULL, NULL); if (error == 0) { error = initgroups(username, gid); } + + LOG_DEVEL(LOG_LEVEL_TRACE, "g_initgroups() returned %d", error); return error; #endif } @@ -3247,7 +3342,7 @@ g_waitchild(struct exit_status *e) e->reason = E_XR_UNEXPECTED; e->val = 0; - rv = waitpid(-1, &wstat, WNOHANG); + rv = g_waitpid(-1, &wstat, WNOHANG); if (rv == -1) { @@ -3279,20 +3374,31 @@ g_waitchild(struct exit_status *e) Note that signal handlers are established with BSD-style semantics, so this call is NOT interrupted by a signal */ int -g_waitpid(int pid) +g_waitpid(int pid, int *stat_loc, int options) { #if defined(_WIN32) return 0; #else int rv = 0; - if (pid < 0) +again: + rv = waitpid(pid, stat_loc, options); + //retry EINTR. + if( rv == -1 && errno == EINTR ) { - rv = -1; + goto again; } - else + + if( rv == -1 ) { - rv = waitpid(pid, 0, 0); + if( errno == ECHILD ) + { + LOG(LOG_LEVEL_INFO, "waitpid returned %s", g_get_strerror()); + } + else + { + LOG(LOG_LEVEL_ERROR, "waitpid returned %s", g_get_strerror()); + } } return rv; @@ -3317,7 +3423,7 @@ g_waitpid_status(int pid) int status; LOG(LOG_LEVEL_DEBUG, "waiting for pid %d to exit", pid); - rv = waitpid(pid, &status, 0); + rv = g_waitpid(pid, &status, 0); if (rv != -1) { @@ -3334,7 +3440,7 @@ g_waitpid_status(int pid) } else { - LOG(LOG_LEVEL_WARNING, "wait for pid %d returned unknown result", pid); + LOG(LOG_LEVEL_WARNING, "wait for pid %d returned unknown result %s", pid, g_get_strerror()); } } @@ -3365,14 +3471,16 @@ g_setpgid(int pid, int pgid) void g_clearenv(void) { + LOG_DEVEL(LOG_LEVEL_TRACE, "g_clearenv()"); #if defined(_WIN32) #else -#if defined(BSD) +#if defined(BSD) || defined(__sun) || defined(__APPLE__) environ[0] = 0; #else environ = 0; #endif #endif + LOG_DEVEL(LOG_LEVEL_TRACE, "--g_clearenv()"); } /*****************************************************************************/ @@ -3383,7 +3491,10 @@ g_setenv(const char *name, const char *value, int rewrite) #if defined(_WIN32) return 0; #else - return setenv(name, value, rewrite); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_setenv(%s, %s, %d)", name, value, rewrite); + int retval = setenv(name, value, rewrite); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_setenv() returned %d", retval); + return retval; #endif } @@ -3487,7 +3598,10 @@ g_getuser_info_by_name(const char *username, int *uid, int *gid, if (gecos != 0) { - *gecos = g_strdup(pwd_1->pw_gecos); + if( pwd_1->pw_gecos == NULL ) + *gecos = g_strdup(""); + else + *gecos = g_strdup(pwd_1->pw_gecos); } } } @@ -3535,7 +3649,10 @@ g_getuser_info_by_uid(int uid, char **username, int *gid, if (gecos != 0) { - *gecos = g_strdup(pwd_1->pw_gecos); + if( pwd_1->pw_gecos == NULL ) + *gecos = g_strdup(""); + else + *gecos = g_strdup(pwd_1->pw_gecos); } return 0; @@ -3843,7 +3960,10 @@ g_shmdt(const void *shmaddr) int g_gethostname(char *name, int len) { - return gethostname(name, len); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_gethostname(name, %d)", len); + int retval = gethostname(name, len); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_gethostname(%s, %d) returned %d", name, len, retval); + return retval; } static unsigned char g_reverse_byte[0x100] = diff --git a/common/os_calls.h b/common/os_calls.h index 2374df3e32..097bf348fb 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -300,7 +300,7 @@ int g_setlogin(const char *name); int g_set_allusercontext(int uid); #endif int g_waitchild(struct exit_status *e); -int g_waitpid(int pid); +int g_waitpid(int pid, int *stat_loc, int options); struct exit_status g_waitpid_status(int pid); /* * Sets the process group ID of the indicated process to the specified value. diff --git a/configure.ac b/configure.ac index 414ce3b92e..1b05b0c71a 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,9 @@ case $host_os in *darwin*) macos=yes ;; + *solaris*) + solaris=yes + ;; esac AM_CONDITIONAL(LINUX, [test "x$linux" = xyes]) @@ -46,6 +49,7 @@ AM_CONDITIONAL(FREEBSD, [test "x$freebsd" = xyes]) AM_CONDITIONAL(OPENBSD, [test "x$openbsd" = xyes]) AM_CONDITIONAL(NETBSD, [test "x$netbsd" = xyes]) AM_CONDITIONAL(MACOS, [test "x$macos" = xyes]) +AM_CONDITIONAL(SOLARIS, [test "x$solaris" = xyes]) AC_CHECK_SIZEOF([int]) AC_CHECK_SIZEOF([long]) @@ -86,8 +90,8 @@ AC_ARG_ENABLE(tests, [Ensure dependencies for the tests are installed]), [ensure_tests_deps=yes], []) AC_ARG_ENABLE(pam, AS_HELP_STRING([--enable-pam], - [Build PAM support (default: yes)]), - [], [enable_pam=yes]) + [Build PAM support (default: no)]), + [], [enable_pam=no]) AM_CONDITIONAL(SESMAN_NOPAM, [test x$enable_pam != xyes]) AC_ARG_ENABLE(vsock, AS_HELP_STRING([--enable-vsock], [Build AF_VSOCK support (default: no)]), @@ -286,6 +290,11 @@ if test x$use_imlib2 = xyes; then AC_DEFINE([USE_IMLIB2],1, [Compile with imlib2 support]) fi +if test x$solaris = xyes; then + CFLAGS="${CFLAGS} -D_XOPEN_SOURCE=600" + AC_SUBST(CFLAGS) +fi + # Find freetype2 # # The modversion used by pkgcheck does not correspond to the @@ -580,6 +589,8 @@ AC_CONFIG_FILES([ instfiles/pam.d/Makefile instfiles/pulse/Makefile instfiles/rc.d/Makefile + instfiles/method/Makefile + instfiles/manifest/Makefile keygen/Makefile waitforx/Makefile libipm/Makefile @@ -658,6 +669,7 @@ echo " unit tests performable $perform_unit_tests" echo "" echo " CFLAGS = $CFLAGS" echo " LDFLAGS = $LDFLAGS" +echo " CPPFLAGS = $CPPFLAGS" # xrdp_configure_options.h will be written to the build directory, not the source directory echo '#define XRDP_CONFIGURE_OPTIONS \' > ./xrdp_configure_options.h diff --git a/instfiles/Makefile.am b/instfiles/Makefile.am index a318ed8f92..947217b986 100644 --- a/instfiles/Makefile.am +++ b/instfiles/Makefile.am @@ -79,6 +79,19 @@ SUBDIRS += \ pulse endif +if NETBSD +SUBDIRS += \ + pam.d \ + rc.d \ + pulse +endif + +if SOLARIS +SUBDIRS += \ + manifest \ + method +endif + if MACOS SUBDIRS += pam.d endif @@ -101,3 +114,12 @@ install-data-hook: sed -i '' 's|%%PREFIX%%|$(prefix)|g' $(DESTDIR)$(sysconfdir)/rc.d/xrdp \ $(DESTDIR)$(sysconfdir)/rc.d/xrdp-sesman endif + +if NETBSD +# must be tab below +install-data-hook: + sed -i 's|%%PREFIX%%/sbin|$(prefix)/sbin|g' $(DESTDIR)$(sysconfdir)/rc.d/xrdp \ + $(DESTDIR)$(sysconfdir)/rc.d/xrdp-sesman + sed -i 's|%%PREFIX%%||g' $(DESTDIR)$(sysconfdir)/rc.d/xrdp \ + $(DESTDIR)$(sysconfdir)/rc.d/xrdp-sesman +endif diff --git a/instfiles/manifest/Makefile.am b/instfiles/manifest/Makefile.am new file mode 100644 index 0000000000..e702630df4 --- /dev/null +++ b/instfiles/manifest/Makefile.am @@ -0,0 +1,3 @@ +startscriptdir = /lib/svc/manifest/site + +dist_startscript_SCRIPTS = xrdp.xml xrdp-sesman.xml diff --git a/instfiles/manifest/xrdp-sesman.xml b/instfiles/manifest/xrdp-sesman.xml new file mode 100644 index 0000000000..b8f0ae6ad5 --- /dev/null +++ b/instfiles/manifest/xrdp-sesman.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/instfiles/manifest/xrdp.xml b/instfiles/manifest/xrdp.xml new file mode 100644 index 0000000000..e687eaa825 --- /dev/null +++ b/instfiles/manifest/xrdp.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/instfiles/method/Makefile.am b/instfiles/method/Makefile.am new file mode 100644 index 0000000000..89c9d98f7a --- /dev/null +++ b/instfiles/method/Makefile.am @@ -0,0 +1,3 @@ +startscriptdir = /lib/svc/method + +dist_startscript_SCRIPTS = xrdp xrdp-sesman diff --git a/instfiles/method/xrdp b/instfiles/method/xrdp new file mode 100755 index 0000000000..4b4d0e9cba --- /dev/null +++ b/instfiles/method/xrdp @@ -0,0 +1,85 @@ +#!/bin/bash +. /lib/svc/share/smf_include.sh + +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib +export PATH=$PATH:$ORACLE_HOME/bin + +VERBOSE= +NAME=xrdp +FULLNAME=/usr/local/sbin/$NAME +TIMEOUT=15 + +log_if_verbose() +{ + if [ -n "$VERBOSE" ]; then + echo $@ + fi +} + +waitFor() { + name=$1 + timeout=$2 + + let i=0 + + # Loop until we are certain that the process has been stopped + while [ $i -lt $timeout ]; do + pgrep -xf $name > /dev/null + if [ $? -ne 0 ]; then + break; + fi + + let i=i+1 + sleep 1 + log_if_verbose "$i seconds" + done + + pgrep -xf $name > /dev/null + return $? +} + +function start +{ + $FULLNAME +} + +function stop +{ + log_if_verbose "Sending TERM to $NAME" + pkill -TERM -xf $FULLNAME + + waitFor $FULLNAME $TIMEOUT + + if [ $? -eq 0 ]; then + log_if_verbose "Sending KILL to $NAME" + pkill -KILL -xf $FULLNAME + waitFor $FULLNAME 1 + rm -f /var/run/$NAME.pid + fi + + return $? +} + +function refresh +{ + log_if_verbose "Refresh not implemented." + return 1; +} + +case $1 in + start) start ;; + stop) stop ;; + refresh) refresh;; + + *) echo "Usage: $0 { start | stop | refresh }" >&2 + exit $SMF_EXIT_ERR_FATAL + ;; +esac + +retval=$? + +if [ $? -eq 0 ]; then + retval=$SMF_EXIT_OK +fi; + +exit $SMF_EXIT_OK diff --git a/instfiles/method/xrdp-sesman b/instfiles/method/xrdp-sesman new file mode 100755 index 0000000000..07c8d7ce44 --- /dev/null +++ b/instfiles/method/xrdp-sesman @@ -0,0 +1,87 @@ +#!/bin/bash +. /lib/svc/share/smf_include.sh + +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib +export PATH=$PATH:$ORACLE_HOME/bin + +VERBOSE=true +NAME=xrdp-sesman +FULLNAME=/usr/local/sbin/$NAME +TIMEOUT=5 + +log_if_verbose() +{ + if [ -n "$VERBOSE" ]; then + echo $@ + fi +} + +waitFor() { + name=$1 + timeout=$2 + + let i=0 + + # Loop until we are certain that the process has been stopped + while [ $i -lt $timeout ]; do + pgrep -xf $name > /dev/null + if [ $? -eq 0 ]; then + break; + fi + + let i=i+1 + sleep 1 + log_if_verbose "$i seconds" + done + + pgrep -xf $name > /dev/null + return $? +} + +function start +{ + $FULLNAME +} + +function stop +{ + log_if_verbose "Sending TERM to $NAME" + pkill -TERM -xf $FULLNAME + + waitFor $FULLNAME $TIMEOUT + retval=$? + + if [ $? -ne 0 ]; then + log_if_verbose "Sending KILL to $NAME" + pkill -KILL -xf $FULLNAME + waitFor $FULLNAME 1 + retval=$? + rm -f /var/run/$NAME.pid + fi + + return $retval +} + +function refresh +{ + log_if_verbose "Refresh not implemented." + return 1; +} + +case $1 in + start) start ;; + stop) stop ;; + refresh) refresh;; + + *) echo "Usage: $0 { start | stop | refresh }" >&2 + exit $SMF_EXIT_ERR_FATAL + ;; +esac + +retval=$? + +if [ $? -eq 0 ]; then + retval=$SMF_EXIT_OK +fi; + +exit $SMF_EXIT_OK diff --git a/sesman/Makefile.am b/sesman/Makefile.am index 542186d87d..5acb834403 100644 --- a/sesman/Makefile.am +++ b/sesman/Makefile.am @@ -65,3 +65,10 @@ SUBDIRS = \ sesexec \ tools \ chansrv + +if SOLARIS +# must be tab below. SOLARIS Xorg does not allow logfile parameter. +install-data-hook: + sed -i 's|param=-logfile|;param=-logfile|g' $(DESTDIR)$(sysconfdir)/xrdp/sesman.ini + sed -i 's|param=.xorgxrdp.%s.log|;param=.xorgxrdp.%s.log|g' $(DESTDIR)$(sysconfdir)/xrdp/sesman.ini +endif diff --git a/sesman/sesexec/sesexec.c b/sesman/sesexec/sesexec.c index 563a0695dd..175202405f 100644 --- a/sesman/sesexec/sesexec.c +++ b/sesman/sesexec/sesexec.c @@ -220,6 +220,11 @@ set_sigchld_event(int sig) { g_set_wait_obj(g_sigchld_event); } + +#ifdef __sun +/* On solaris we need to re-register for the signal hander. */ + g_signal_child_stop(set_sigchld_event); +#endif } /******************************************************************************/ @@ -241,6 +246,7 @@ sesexec_terminate_main_loop(int status) static void process_sigchld_event(void) { + LOG(LOG_LEVEL_TRACE, "process_sigchld_event()"); struct exit_status e; int pid; @@ -249,6 +255,7 @@ process_sigchld_event(void) { session_process_child_exit(g_session_data, pid, &e); } + LOG(LOG_LEVEL_TRACE, "process_sigchld_event() returned"); } /******************************************************************************/ diff --git a/sesman/sesexec/session.c b/sesman/sesexec/session.c index 900b394333..0ac2cdf76c 100644 --- a/sesman/sesexec/session.c +++ b/sesman/sesexec/session.c @@ -641,7 +641,7 @@ session_start_wrapped(struct login_info *login_info, /* Kill it anyway in case it did start and we just failed to * pick up on it */ g_sigterm(display_pid); - g_waitpid(display_pid); + g_waitpid(display_pid, 0, 0); } else { @@ -654,7 +654,7 @@ session_start_wrapped(struct login_info *login_info, if (window_manager_pid < 0) { g_sigterm(display_pid); - g_waitpid(display_pid); + g_waitpid(display_pid, 0, 0); } else { diff --git a/sesman/sesexec/xwait.c b/sesman/sesexec/xwait.c index 9a7bd376f6..9732f40618 100644 --- a/sesman/sesexec/xwait.c +++ b/sesman/sesexec/xwait.c @@ -56,18 +56,20 @@ log_waitforx_messages(FILE *dp) * Contruct the command to run to check the X server */ static struct list * -make_xwait_command(int display) +make_xwait_command(int display, int wait) { const char exe[] = XRDP_LIBEXEC_PATH "/waitforx"; char displaystr[64]; + char waitstr[64]; struct list *cmd = list_create(); if (cmd != NULL) { cmd->auto_free = 1; g_snprintf(displaystr, sizeof(displaystr), ":%d", display); - - if (!list_add_strdup_multi(cmd, exe, "-d", displaystr, NULL)) + g_snprintf(waitstr, sizeof(waitstr), "%d", wait); + + if (!list_add_strdup_multi(cmd, exe, "-d", displaystr, "-w", waitstr, NULL)) { list_delete(cmd); cmd = NULL; @@ -86,7 +88,7 @@ wait_for_xserver(uid_t uid, { enum xwait_status rv = XW_STATUS_MISC_ERROR; int fd[2] = {-1, -1}; - struct list *cmd = make_xwait_command(display); + struct list *cmd = make_xwait_command(display, 10); // Construct the command to execute to check the display diff --git a/sesman/tools/Makefile.am b/sesman/tools/Makefile.am index a6803bb3f1..ce19b63067 100644 --- a/sesman/tools/Makefile.am +++ b/sesman/tools/Makefile.am @@ -32,6 +32,10 @@ xrdp_dis_SOURCES = \ xrdp_dis_LDADD = \ $(top_builddir)/common/libcommon.la +if SOLARIS + xrdp_dis_LDADD += -lsocket +endif + xrdp_xcon_SOURCES = \ xcon.c @@ -43,6 +47,10 @@ xrdp_sesrun_LDADD = \ $(top_builddir)/common/libcommon.la \ $(top_builddir)/libipm/libipm.la +if SOLARIS + xrdp_sesrun_LDADD += -lsocket +endif + xrdp_sesadmin_LDADD = \ $(top_builddir)/sesman/libsesman/libsesman.la \ $(top_builddir)/common/libcommon.la \ diff --git a/tools/devel/tcp_proxy/Makefile.am b/tools/devel/tcp_proxy/Makefile.am index 6c1e534336..85ab24e0c0 100644 --- a/tools/devel/tcp_proxy/Makefile.am +++ b/tools/devel/tcp_proxy/Makefile.am @@ -11,3 +11,7 @@ tcp_proxy_SOURCES = \ tcp_proxy_LDADD = \ $(top_builddir)/common/libcommon.la \ $(DLOPEN_LIBS) + +if SOLARIS + tcp_proxy_LDADD += -lsocket +endif diff --git a/waitforx/waitforx.c b/waitforx/waitforx.c index b9dabedfe2..13f738d024 100644 --- a/waitforx/waitforx.c +++ b/waitforx/waitforx.c @@ -21,20 +21,23 @@ alarm_handler(int signal_num) * * Prefix the message with a newline in case another message * has been partly output */ + + if( signal_num == SIGALRM ) + { const char msg[] = "\nTimed out waiting for RandR outputs\n"; g_file_write(1, msg, g_strlen(msg)); exit(XW_STATUS_TIMED_OUT); + } } /*****************************************************************************/ static Display * -open_display(const char *display) +open_display(const char *display, const int wait) { Display *dpy = NULL; - unsigned int wait = ATTEMPTS; unsigned int n; - for (n = 1; n <= ATTEMPTS; ++n) + for (n = 1; n <= wait; ++n) { printf("Opening display %s. Attempt %u of %u\n", display, n, wait); dpy = XOpenDisplay(display); @@ -57,12 +60,11 @@ open_display(const char *display) * @return 0 if/when outputs are available, 1 otherwise */ static int -wait_for_r_and_r(Display *dpy) +wait_for_r_and_r(Display *dpy, int wait) { int error_base = 0; int event_base = 0; unsigned int outputs = 0; - unsigned int wait = ATTEMPTS; unsigned int n; XRRScreenResources *res = NULL; @@ -104,7 +106,7 @@ wait_for_r_and_r(Display *dpy) static void usage(const char *argv0, int status) { - printf("Usage: %s -d display\n", argv0); + printf("Usage: %s -d display [-w waittime]\n", argv0); exit(status); } @@ -115,19 +117,23 @@ main(int argc, char **argv) const char *display_name = NULL; int opt; int status = XW_STATUS_MISC_ERROR; + unsigned int wait = ATTEMPTS; Display *dpy = NULL; /* Disable stdout buffering so any messages are passed immediately * to sesman */ setvbuf(stdout, NULL, _IONBF, 0); - while ((opt = getopt(argc, argv, "d:")) != -1) + while ((opt = getopt(argc, argv, "d:w:")) != -1) { switch (opt) { case 'd': display_name = optarg; break; + case 'w': + wait = atoi(optarg); + break; default: /* '?' */ usage(argv[0], status); } @@ -140,7 +146,7 @@ main(int argc, char **argv) g_set_alarm(alarm_handler, ALARM_WAIT); - dpy = open_display(display_name); + dpy = open_display(display_name, wait); if (!dpy) { printf("Unable to open display %s\n", display_name); @@ -148,7 +154,7 @@ main(int argc, char **argv) } else { - if (wait_for_r_and_r(dpy) == 0) + if (wait_for_r_and_r(dpy, wait) == 0) { status = XW_STATUS_OK; } From e029f62b3ac0338790bd623a3546622e9265ebc4 Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Sat, 14 Oct 2023 19:06:42 -0400 Subject: [PATCH 2/7] Remove trailing whitespace from lines where present. Run astyle to fix code formatting. Use nanosleep instead of usleep for cross platform compatibility. Remove extraneous devel logging. --- common/Makefile.am | 2 +- common/os_calls.c | 96 ++++++++++++++---------------- sesman/libsesman/verify_user_pam.c | 3 +- sesman/sesexec/sesexec.c | 2 +- sesman/sesexec/xwait.c | 2 +- waitforx/waitforx.c | 12 ++-- xrdp/Makefile.am | 1 + 7 files changed, 58 insertions(+), 60 deletions(-) diff --git a/common/Makefile.am b/common/Makefile.am index 23d1997f7b..c929baab19 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -28,7 +28,7 @@ AM_CPPFLAGS = \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ -DXRDP_LOG_PATH=\"${localstatedir}/log\" \ - -DXRDP_SOCKET_PATH=\"${socketdir}\" + -DXRDP_SOCKET_PATH=\"${socketdir}\" # -no-suppress is an automake-specific flag which is needed # to prevent us missing compiler errors in some circumstances diff --git a/common/os_calls.c b/common/os_calls.c index 9345a9dce4..dfbb98f8e6 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -165,7 +165,7 @@ g_mk_socket_path(void) "g_mk_socket_path: g_create_path(%s) failed", XRDP_SOCKET_PATH); - LOG(LOG_LEVEL_TRACE, "g_mk_socket_path() returned 1"); + LOG(LOG_LEVEL_TRACE, "g_mk_socket_path() returned 1"); return 1; } } @@ -657,7 +657,6 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) if (getsockopt(sck, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_length)) { LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; } if (pid != 0) @@ -677,16 +676,15 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) return 0; #elif defined(LOCAL_PEEREID) /* Net BSD */ - #ifndef SOL_LOCAL - #define SOL_LOCAL 0 - #endif +#ifndef SOL_LOCAL +#define SOL_LOCAL 0 +#endif struct unpcbid xucred; unsigned int xucred_length; xucred_length = sizeof(xucred); if (getsockopt(sck, SOL_LOCAL, LOCAL_PEEREID, &xucred, &xucred_length)) { LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; } @@ -707,13 +705,12 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) return 0; #elif defined(__sun) /* Solaris, OpenIndiana */ - ucred_t* xucred = NULL; + ucred_t *xucred = NULL; - if(getpeerucred(sck, &xucred)) + if (getpeerucred(sck, &xucred)) { LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); - return 1; + return 1; } if (pid != 0) @@ -734,7 +731,6 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) return 0; #else LOG(LOG_LEVEL_ERROR, "g_sck_get_peer_cred() has no implementation."); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; #endif } @@ -1471,25 +1467,15 @@ g_sleep(int msecs) { #if defined(_WIN32) Sleep(msecs); - //On NetBSD usleep can not be > 1000000, so use sleep instead. -#elif defined(__NetBSD__) - if( msecs >= 1000 ) - { - int secs = msecs / 1000; - int remainder = msecs % 1000; - - if( secs != 0 ) - { - sleep(msecs / 1000); - } - - if( remainder != 0 ) - { - usleep(remainder * 1000); - } - } #else - usleep(msecs * 1000); + struct timespec tv; + tv.tv_sec = msecs / 1000; + tv.tv_nsec = ( msecs % 1000 ) * 1000000; + if ( nanosleep(&tv, NULL) == -1 ) + { + LOG(LOG_LEVEL_ERROR, "nanosleep returned error %s", g_get_strerror()); + } + #endif } @@ -3105,7 +3091,7 @@ void g_signal_child_stop(void (*func)(int)) { #if defined(_WIN32) - return; + return; #else struct sigaction action; @@ -3333,7 +3319,7 @@ g_initgroups(const char *username) error = initgroups(username, gid); } - LOG_DEVEL(LOG_LEVEL_TRACE, "g_initgroups() returned %d", error); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_initgroups() returned %d", error); return error; #endif } @@ -3500,22 +3486,24 @@ g_waitpid(int pid, int *stat_loc, int options) again: rv = waitpid(pid, stat_loc, options); - //retry EINTR. - if( rv == -1 && errno == EINTR ) +#if defined(__NetBSD__) || defined(__sun) + //Retry EINTR for NetBSD and OpenIndiana. + if ( rv == -1 && errno == EINTR ) { goto again; } +#endif - if( rv == -1 ) + if ( rv == -1 ) { - if( errno == ECHILD ) - { - LOG(LOG_LEVEL_INFO, "waitpid returned %s", g_get_strerror()); - } - else + if ( errno == ECHILD ) + { + LOG(LOG_LEVEL_INFO, "waitpid returned %s", g_get_strerror()); + } + else { - LOG(LOG_LEVEL_ERROR, "waitpid returned %s", g_get_strerror()); - } + LOG(LOG_LEVEL_ERROR, "waitpid returned %s", g_get_strerror()); + } } return rv; @@ -3597,7 +3585,7 @@ g_clearenv(void) environ = 0; #endif #endif - LOG_DEVEL(LOG_LEVEL_TRACE, "--g_clearenv()"); + LOG_DEVEL(LOG_LEVEL_TRACE, "--g_clearenv()"); } /*****************************************************************************/ @@ -3715,10 +3703,14 @@ g_getuser_info_by_name(const char *username, int *uid, int *gid, if (gecos != 0) { - if( pwd_1->pw_gecos == NULL ) - *gecos = g_strdup(""); - else - *gecos = g_strdup(pwd_1->pw_gecos); + if ( pwd_1->pw_gecos == NULL ) + { + *gecos = g_strdup(""); + } + else + { + *gecos = g_strdup(pwd_1->pw_gecos); + } } } } @@ -3766,10 +3758,14 @@ g_getuser_info_by_uid(int uid, char **username, int *gid, if (gecos != 0) { - if( pwd_1->pw_gecos == NULL ) - *gecos = g_strdup(""); - else - *gecos = g_strdup(pwd_1->pw_gecos); + if ( pwd_1->pw_gecos == NULL ) + { + *gecos = g_strdup(""); + } + else + { + *gecos = g_strdup(pwd_1->pw_gecos); + } } return 0; diff --git a/sesman/libsesman/verify_user_pam.c b/sesman/libsesman/verify_user_pam.c index ca5136688d..34b37917a5 100644 --- a/sesman/libsesman/verify_user_pam.c +++ b/sesman/libsesman/verify_user_pam.c @@ -503,9 +503,10 @@ auth_end(struct auth_info *auth_info) pam_end(auth_info->ph, PAM_SUCCESS); auth_info->ph = 0; } + + g_free(auth_info); } - g_free(auth_info); return 0; } diff --git a/sesman/sesexec/sesexec.c b/sesman/sesexec/sesexec.c index 175202405f..95501b49f3 100644 --- a/sesman/sesexec/sesexec.c +++ b/sesman/sesexec/sesexec.c @@ -222,7 +222,7 @@ set_sigchld_event(int sig) } #ifdef __sun -/* On solaris we need to re-register for the signal hander. */ + /* On solaris we need to re-register for the signal hander. */ g_signal_child_stop(set_sigchld_event); #endif } diff --git a/sesman/sesexec/xwait.c b/sesman/sesexec/xwait.c index 9732f40618..44010561b0 100644 --- a/sesman/sesexec/xwait.c +++ b/sesman/sesexec/xwait.c @@ -68,7 +68,7 @@ make_xwait_command(int display, int wait) cmd->auto_free = 1; g_snprintf(displaystr, sizeof(displaystr), ":%d", display); g_snprintf(waitstr, sizeof(waitstr), "%d", wait); - + if (!list_add_strdup_multi(cmd, exe, "-d", displaystr, "-w", waitstr, NULL)) { list_delete(cmd); diff --git a/waitforx/waitforx.c b/waitforx/waitforx.c index 13f738d024..e7a797c0c2 100644 --- a/waitforx/waitforx.c +++ b/waitforx/waitforx.c @@ -22,11 +22,11 @@ alarm_handler(int signal_num) * Prefix the message with a newline in case another message * has been partly output */ - if( signal_num == SIGALRM ) + if ( signal_num == SIGALRM ) { - const char msg[] = "\nTimed out waiting for RandR outputs\n"; - g_file_write(1, msg, g_strlen(msg)); - exit(XW_STATUS_TIMED_OUT); + const char msg[] = "\nTimed out waiting for RandR outputs\n"; + g_file_write(1, msg, g_strlen(msg)); + exit(XW_STATUS_TIMED_OUT); } } @@ -132,8 +132,8 @@ main(int argc, char **argv) display_name = optarg; break; case 'w': - wait = atoi(optarg); - break; + wait = atoi(optarg); + break; default: /* '?' */ usage(argv[0], status); } diff --git a/xrdp/Makefile.am b/xrdp/Makefile.am index 432fdf2da0..f5e332f43a 100644 --- a/xrdp/Makefile.am +++ b/xrdp/Makefile.am @@ -110,3 +110,4 @@ dist_xrdppkgdata_DATA = \ sans-18.fv1 \ cursor0.cur \ cursor1.cur + From e656e2a118d2a83bec92458e6187766fa8e78067 Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Sun, 15 Oct 2023 11:46:53 -0400 Subject: [PATCH 3/7] Change --enable-pam to --enable-nopam. Pam is the default. --- configure.ac | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 7b14d5383b..b7d578acb2 100644 --- a/configure.ac +++ b/configure.ac @@ -89,10 +89,10 @@ AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests], [Ensure dependencies for the tests are installed]), [ensure_tests_deps=yes], []) -AC_ARG_ENABLE(pam, AS_HELP_STRING([--enable-pam], +AC_ARG_ENABLE(nopam, AS_HELP_STRING([--enable-nopam], [Build PAM support (default: no)]), - [], [enable_pam=no]) -AM_CONDITIONAL(SESMAN_NOPAM, [test x$enable_pam != xyes]) + [enable_nopam=yes], [enable_nopam=no]) +AM_CONDITIONAL(SESMAN_NOPAM, [test x$enable_nopam = xyes]) AC_ARG_ENABLE(vsock, AS_HELP_STRING([--enable-vsock], [Build AF_VSOCK support (default: no)]), [], [enable_vsock=no]) @@ -103,7 +103,7 @@ AC_ARG_ENABLE(ipv6only, AS_HELP_STRING([--enable-ipv6only], [Build IPv6-only (default: no)]), [], [enable_ipv6only=no]) AC_ARG_ENABLE(kerberos, AS_HELP_STRING([--enable-kerberos], - [Build kerberos support (prefer --enable-pam if available) (default: no)]), + [Build kerberos support (default: no)]), [], [enable_kerberos=no]) AC_ARG_ENABLE(bsd, AS_HELP_STRING([--enable-bsd], [Build BSD auth support (default: no)]), @@ -345,12 +345,12 @@ auth_cnt=0 auth_mech="Builtin" AUTHMOD_OBJ=verify_user.lo AUTHMOD_LIB=-lcrypt -if test x$enable_pam = xyes +if test x$enable_nopam = xyes then auth_cnt=`expr $auth_cnt + 1` - auth_mech="PAM" - AUTHMOD_OBJ=verify_user_pam.lo - AUTHMOD_LIB=-lpam + auth_mech="No PAM" + AUTHMOD_OBJ=verify_user.lo + AUTHMOD_LIB= fi if test x$bsd = xtrue then @@ -373,17 +373,23 @@ then AUTHMOD_OBJ=verify_user_pam_userpass.lo AUTHMOD_LIB="-lpam -lpam_userpass" fi - +if test $auth_cnt -eq 0 +then + auth_cnt=`expr $auth_cnt + 1` + auth_mech="Enable PAM" + AUTHMOD_OBJ=verify_user_pam.lo + AUTHMOD_LIB=-lpam +fi if test $auth_cnt -gt 1 then - AC_MSG_ERROR([--enable-pam, --enable-bsd, --enable-pamuserpass and --enable-kerberos are mutually exclusive]) + AC_MSG_ERROR([--enable-nopam, --enable-bsd, --enable-pamuserpass and --enable-kerberos are mutually exclusive]) fi AC_SUBST([AUTHMOD_OBJ]) AC_SUBST([AUTHMOD_LIB]) # checking if pam should be autodetected. -if test "x$enable_pam" = "xyes" +if test "x$enable_nopam" != "xyes" then if test -z "$enable_bsd" then From d979a88bf1c554f53d614996b08f2b5505161680 Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Sun, 15 Oct 2023 11:55:59 -0400 Subject: [PATCH 4/7] Check = xno instead of != xyes --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b7d578acb2..28a6f35dc3 100644 --- a/configure.ac +++ b/configure.ac @@ -389,7 +389,7 @@ AC_SUBST([AUTHMOD_OBJ]) AC_SUBST([AUTHMOD_LIB]) # checking if pam should be autodetected. -if test "x$enable_nopam" != "xyes" +if test "x$enable_nopam" = "xno" then if test -z "$enable_bsd" then From f8a69d4014b8b9a5e53dc4a12b56d0cf719b5bb4 Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Sat, 14 Oct 2023 19:06:42 -0400 Subject: [PATCH 5/7] Remove trailing whitespace from lines where present. Run astyle to fix code formatting. Use nanosleep instead of usleep for cross platform compatibility. Remove extraneous devel logging. Check = xno instead of != xyes Change --enable-pam to --enable-nopam. Pam is the default. --- common/Makefile.am | 2 +- common/os_calls.c | 96 ++++++++++++++---------------- configure.ac | 28 +++++---- sesman/libsesman/verify_user_pam.c | 3 +- sesman/sesexec/sesexec.c | 2 +- sesman/sesexec/xwait.c | 2 +- waitforx/waitforx.c | 12 ++-- xrdp/Makefile.am | 1 + 8 files changed, 75 insertions(+), 71 deletions(-) diff --git a/common/Makefile.am b/common/Makefile.am index 23d1997f7b..c929baab19 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -28,7 +28,7 @@ AM_CPPFLAGS = \ -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ -DXRDP_PID_PATH=\"${localstatedir}/run\" \ -DXRDP_LOG_PATH=\"${localstatedir}/log\" \ - -DXRDP_SOCKET_PATH=\"${socketdir}\" + -DXRDP_SOCKET_PATH=\"${socketdir}\" # -no-suppress is an automake-specific flag which is needed # to prevent us missing compiler errors in some circumstances diff --git a/common/os_calls.c b/common/os_calls.c index 9345a9dce4..dfbb98f8e6 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -165,7 +165,7 @@ g_mk_socket_path(void) "g_mk_socket_path: g_create_path(%s) failed", XRDP_SOCKET_PATH); - LOG(LOG_LEVEL_TRACE, "g_mk_socket_path() returned 1"); + LOG(LOG_LEVEL_TRACE, "g_mk_socket_path() returned 1"); return 1; } } @@ -657,7 +657,6 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) if (getsockopt(sck, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_length)) { LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; } if (pid != 0) @@ -677,16 +676,15 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) return 0; #elif defined(LOCAL_PEEREID) /* Net BSD */ - #ifndef SOL_LOCAL - #define SOL_LOCAL 0 - #endif +#ifndef SOL_LOCAL +#define SOL_LOCAL 0 +#endif struct unpcbid xucred; unsigned int xucred_length; xucred_length = sizeof(xucred); if (getsockopt(sck, SOL_LOCAL, LOCAL_PEEREID, &xucred, &xucred_length)) { LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; } @@ -707,13 +705,12 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) return 0; #elif defined(__sun) /* Solaris, OpenIndiana */ - ucred_t* xucred = NULL; + ucred_t *xucred = NULL; - if(getpeerucred(sck, &xucred)) + if (getpeerucred(sck, &xucred)) { LOG(LOG_LEVEL_ERROR, "getsockopt() failed: %s", strerror(errno)); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); - return 1; + return 1; } if (pid != 0) @@ -734,7 +731,6 @@ g_sck_get_peer_cred(int sck, int *pid, int *uid, int *gid) return 0; #else LOG(LOG_LEVEL_ERROR, "g_sck_get_peer_cred() has no implementation."); - LOG_DEVEL(LOG_LEVEL_TRACE, "g_sck_get_peer_cred() returned 1"); return 1; #endif } @@ -1471,25 +1467,15 @@ g_sleep(int msecs) { #if defined(_WIN32) Sleep(msecs); - //On NetBSD usleep can not be > 1000000, so use sleep instead. -#elif defined(__NetBSD__) - if( msecs >= 1000 ) - { - int secs = msecs / 1000; - int remainder = msecs % 1000; - - if( secs != 0 ) - { - sleep(msecs / 1000); - } - - if( remainder != 0 ) - { - usleep(remainder * 1000); - } - } #else - usleep(msecs * 1000); + struct timespec tv; + tv.tv_sec = msecs / 1000; + tv.tv_nsec = ( msecs % 1000 ) * 1000000; + if ( nanosleep(&tv, NULL) == -1 ) + { + LOG(LOG_LEVEL_ERROR, "nanosleep returned error %s", g_get_strerror()); + } + #endif } @@ -3105,7 +3091,7 @@ void g_signal_child_stop(void (*func)(int)) { #if defined(_WIN32) - return; + return; #else struct sigaction action; @@ -3333,7 +3319,7 @@ g_initgroups(const char *username) error = initgroups(username, gid); } - LOG_DEVEL(LOG_LEVEL_TRACE, "g_initgroups() returned %d", error); + LOG_DEVEL(LOG_LEVEL_TRACE, "g_initgroups() returned %d", error); return error; #endif } @@ -3500,22 +3486,24 @@ g_waitpid(int pid, int *stat_loc, int options) again: rv = waitpid(pid, stat_loc, options); - //retry EINTR. - if( rv == -1 && errno == EINTR ) +#if defined(__NetBSD__) || defined(__sun) + //Retry EINTR for NetBSD and OpenIndiana. + if ( rv == -1 && errno == EINTR ) { goto again; } +#endif - if( rv == -1 ) + if ( rv == -1 ) { - if( errno == ECHILD ) - { - LOG(LOG_LEVEL_INFO, "waitpid returned %s", g_get_strerror()); - } - else + if ( errno == ECHILD ) + { + LOG(LOG_LEVEL_INFO, "waitpid returned %s", g_get_strerror()); + } + else { - LOG(LOG_LEVEL_ERROR, "waitpid returned %s", g_get_strerror()); - } + LOG(LOG_LEVEL_ERROR, "waitpid returned %s", g_get_strerror()); + } } return rv; @@ -3597,7 +3585,7 @@ g_clearenv(void) environ = 0; #endif #endif - LOG_DEVEL(LOG_LEVEL_TRACE, "--g_clearenv()"); + LOG_DEVEL(LOG_LEVEL_TRACE, "--g_clearenv()"); } /*****************************************************************************/ @@ -3715,10 +3703,14 @@ g_getuser_info_by_name(const char *username, int *uid, int *gid, if (gecos != 0) { - if( pwd_1->pw_gecos == NULL ) - *gecos = g_strdup(""); - else - *gecos = g_strdup(pwd_1->pw_gecos); + if ( pwd_1->pw_gecos == NULL ) + { + *gecos = g_strdup(""); + } + else + { + *gecos = g_strdup(pwd_1->pw_gecos); + } } } } @@ -3766,10 +3758,14 @@ g_getuser_info_by_uid(int uid, char **username, int *gid, if (gecos != 0) { - if( pwd_1->pw_gecos == NULL ) - *gecos = g_strdup(""); - else - *gecos = g_strdup(pwd_1->pw_gecos); + if ( pwd_1->pw_gecos == NULL ) + { + *gecos = g_strdup(""); + } + else + { + *gecos = g_strdup(pwd_1->pw_gecos); + } } return 0; diff --git a/configure.ac b/configure.ac index 7b14d5383b..28a6f35dc3 100644 --- a/configure.ac +++ b/configure.ac @@ -89,10 +89,10 @@ AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests], [Ensure dependencies for the tests are installed]), [ensure_tests_deps=yes], []) -AC_ARG_ENABLE(pam, AS_HELP_STRING([--enable-pam], +AC_ARG_ENABLE(nopam, AS_HELP_STRING([--enable-nopam], [Build PAM support (default: no)]), - [], [enable_pam=no]) -AM_CONDITIONAL(SESMAN_NOPAM, [test x$enable_pam != xyes]) + [enable_nopam=yes], [enable_nopam=no]) +AM_CONDITIONAL(SESMAN_NOPAM, [test x$enable_nopam = xyes]) AC_ARG_ENABLE(vsock, AS_HELP_STRING([--enable-vsock], [Build AF_VSOCK support (default: no)]), [], [enable_vsock=no]) @@ -103,7 +103,7 @@ AC_ARG_ENABLE(ipv6only, AS_HELP_STRING([--enable-ipv6only], [Build IPv6-only (default: no)]), [], [enable_ipv6only=no]) AC_ARG_ENABLE(kerberos, AS_HELP_STRING([--enable-kerberos], - [Build kerberos support (prefer --enable-pam if available) (default: no)]), + [Build kerberos support (default: no)]), [], [enable_kerberos=no]) AC_ARG_ENABLE(bsd, AS_HELP_STRING([--enable-bsd], [Build BSD auth support (default: no)]), @@ -345,12 +345,12 @@ auth_cnt=0 auth_mech="Builtin" AUTHMOD_OBJ=verify_user.lo AUTHMOD_LIB=-lcrypt -if test x$enable_pam = xyes +if test x$enable_nopam = xyes then auth_cnt=`expr $auth_cnt + 1` - auth_mech="PAM" - AUTHMOD_OBJ=verify_user_pam.lo - AUTHMOD_LIB=-lpam + auth_mech="No PAM" + AUTHMOD_OBJ=verify_user.lo + AUTHMOD_LIB= fi if test x$bsd = xtrue then @@ -373,17 +373,23 @@ then AUTHMOD_OBJ=verify_user_pam_userpass.lo AUTHMOD_LIB="-lpam -lpam_userpass" fi - +if test $auth_cnt -eq 0 +then + auth_cnt=`expr $auth_cnt + 1` + auth_mech="Enable PAM" + AUTHMOD_OBJ=verify_user_pam.lo + AUTHMOD_LIB=-lpam +fi if test $auth_cnt -gt 1 then - AC_MSG_ERROR([--enable-pam, --enable-bsd, --enable-pamuserpass and --enable-kerberos are mutually exclusive]) + AC_MSG_ERROR([--enable-nopam, --enable-bsd, --enable-pamuserpass and --enable-kerberos are mutually exclusive]) fi AC_SUBST([AUTHMOD_OBJ]) AC_SUBST([AUTHMOD_LIB]) # checking if pam should be autodetected. -if test "x$enable_pam" = "xyes" +if test "x$enable_nopam" = "xno" then if test -z "$enable_bsd" then diff --git a/sesman/libsesman/verify_user_pam.c b/sesman/libsesman/verify_user_pam.c index ca5136688d..34b37917a5 100644 --- a/sesman/libsesman/verify_user_pam.c +++ b/sesman/libsesman/verify_user_pam.c @@ -503,9 +503,10 @@ auth_end(struct auth_info *auth_info) pam_end(auth_info->ph, PAM_SUCCESS); auth_info->ph = 0; } + + g_free(auth_info); } - g_free(auth_info); return 0; } diff --git a/sesman/sesexec/sesexec.c b/sesman/sesexec/sesexec.c index 175202405f..95501b49f3 100644 --- a/sesman/sesexec/sesexec.c +++ b/sesman/sesexec/sesexec.c @@ -222,7 +222,7 @@ set_sigchld_event(int sig) } #ifdef __sun -/* On solaris we need to re-register for the signal hander. */ + /* On solaris we need to re-register for the signal hander. */ g_signal_child_stop(set_sigchld_event); #endif } diff --git a/sesman/sesexec/xwait.c b/sesman/sesexec/xwait.c index 9732f40618..44010561b0 100644 --- a/sesman/sesexec/xwait.c +++ b/sesman/sesexec/xwait.c @@ -68,7 +68,7 @@ make_xwait_command(int display, int wait) cmd->auto_free = 1; g_snprintf(displaystr, sizeof(displaystr), ":%d", display); g_snprintf(waitstr, sizeof(waitstr), "%d", wait); - + if (!list_add_strdup_multi(cmd, exe, "-d", displaystr, "-w", waitstr, NULL)) { list_delete(cmd); diff --git a/waitforx/waitforx.c b/waitforx/waitforx.c index 13f738d024..e7a797c0c2 100644 --- a/waitforx/waitforx.c +++ b/waitforx/waitforx.c @@ -22,11 +22,11 @@ alarm_handler(int signal_num) * Prefix the message with a newline in case another message * has been partly output */ - if( signal_num == SIGALRM ) + if ( signal_num == SIGALRM ) { - const char msg[] = "\nTimed out waiting for RandR outputs\n"; - g_file_write(1, msg, g_strlen(msg)); - exit(XW_STATUS_TIMED_OUT); + const char msg[] = "\nTimed out waiting for RandR outputs\n"; + g_file_write(1, msg, g_strlen(msg)); + exit(XW_STATUS_TIMED_OUT); } } @@ -132,8 +132,8 @@ main(int argc, char **argv) display_name = optarg; break; case 'w': - wait = atoi(optarg); - break; + wait = atoi(optarg); + break; default: /* '?' */ usage(argv[0], status); } diff --git a/xrdp/Makefile.am b/xrdp/Makefile.am index 432fdf2da0..f5e332f43a 100644 --- a/xrdp/Makefile.am +++ b/xrdp/Makefile.am @@ -110,3 +110,4 @@ dist_xrdppkgdata_DATA = \ sans-18.fv1 \ cursor0.cur \ cursor1.cur + From 2e2ab0f8bf3e127e877af75e8891d175a9f852be Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Sun, 15 Oct 2023 13:15:01 -0400 Subject: [PATCH 6/7] Fix warnings from cppcheck. --- waitforx/waitforx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/waitforx/waitforx.c b/waitforx/waitforx.c index e7a797c0c2..963c113de6 100644 --- a/waitforx/waitforx.c +++ b/waitforx/waitforx.c @@ -32,7 +32,7 @@ alarm_handler(int signal_num) /*****************************************************************************/ static Display * -open_display(const char *display, const int wait) +open_display(const char *display, const unsigned int wait) { Display *dpy = NULL; unsigned int n; @@ -60,7 +60,7 @@ open_display(const char *display, const int wait) * @return 0 if/when outputs are available, 1 otherwise */ static int -wait_for_r_and_r(Display *dpy, int wait) +wait_for_r_and_r(Display *dpy, unsigned int wait) { int error_base = 0; int event_base = 0; From 5dc050c49fe5f7e80e459504c88a575be6ecf768 Mon Sep 17 00:00:00 2001 From: Michael Stone Date: Mon, 16 Oct 2023 15:08:03 -0400 Subject: [PATCH 7/7] Fix compilation error caused by unused label. --- common/os_calls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/os_calls.c b/common/os_calls.c index dfbb98f8e6..05d3aa91eb 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -3483,8 +3483,9 @@ g_waitpid(int pid, int *stat_loc, int options) return 0; #else int rv = 0; - +#if defined(__NetBSD__) || defined(__sun) again: +#endif rv = waitpid(pid, stat_loc, options); #if defined(__NetBSD__) || defined(__sun) //Retry EINTR for NetBSD and OpenIndiana.