Branch: ulab-next

91fd32e1 2019-03-04 12:12:54 Timothy Pearson
Fix merge
M sesman/scp_v0.c
M sesman/session.c

sesman/scp_v0.c

diff --git a/sesman/scp_v0.c b/sesman/scp_v0.c
index ba891f1..b0186ba 100644
--- a/sesman/scp_v0.c
+++ b/sesman/scp_v0.c
@@ -83,7 +83,7 @@
         if (serverpid < 0) {
             // Session NOT already running
             if (s_item != 0) {
-                log_message(&(g_cfg->log), LOG_LEVEL_INFO, "++ [FIXME] scp claimed there was an active session, but the authoritative RAPTOR database disagrees: username %s", s->username);
+                log_message( LOG_LEVEL_INFO, "++ [FIXME] scp claimed there was an active session, but the authoritative RAPTOR database disagrees: username %s", s->username);
             }
             s_item = 0;
         }

sesman/session.c

diff --git a/sesman/session.c b/sesman/session.c
index 027ddb8..db59276 100644
--- a/sesman/session.c
+++ b/sesman/session.c
@@ -476,7 +476,7 @@
     i++;
     if (i > 60)
     {
-      log_message(&(g_cfg->log), LOG_LEVEL_ERROR,
+      log_message( LOG_LEVEL_ERROR,
                   "X server for host %s and display %d startup timeout",
                   host, display);
       break;
@@ -502,7 +502,7 @@
     i++;
     if (i > 20)
     {
-      log_message(&(g_cfg->log), LOG_LEVEL_ERROR,
+      log_message( LOG_LEVEL_ERROR,
                   "Hostname allocation timeout");
       break;
     }
@@ -590,7 +590,7 @@
 
     if (display == 0)
     {
-        log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "Unable to allocate display for user %s", username);
+        log_message(LOG_LEVEL_ALWAYS, "Unable to allocate display for user %s", username);
         g_free(temp->item);
         g_free(temp);
         return 0;
@@ -643,7 +643,7 @@
 
                 pid_t wmpid;
                 wmpid = raptor_sm_run_remote_server(username, pp2, RAPTOR_SM_WM_PID_FIELD, display);
-                log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "new window manager pid code was %d for user %s", wmpid, username);
+                log_message(LOG_LEVEL_ALWAYS, "new window manager pid code was %d for user %s", wmpid, username);
 
                 if (wmpid >= 0) {
                     raptor_sm_wm_started(username, wmpid, RAPTOR_SM_WM_PID_FIELD);
@@ -798,7 +798,7 @@
 
                     pid_t serverpid;
                     serverpid = raptor_sm_run_remote_server(username, pp1, RAPTOR_SM_SERVER_PID_FIELD, -1);
-                    log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "new server pid code was %d during login for user %s", serverpid, username);
+                    log_message(LOG_LEVEL_ALWAYS, "new server pid code was %d during login for user %s", serverpid, username);
 
                     if (serverpid >= 0) {
                         if (!session_was_already_running) {
@@ -814,7 +814,7 @@
                     }
                     else {
                         raptor_sm_session_terminated(username);
-                        log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "max concurrent session limit "
+                        log_message(LOG_LEVEL_ALWAYS, "max concurrent session limit "
                                  "exceeded in group. login for user %s denied", username);
                         g_exit(1);
                     }
3214fd39 2019-03-04 12:12:54 Timothy Pearson
Add rudimentary sound support
M raptorsmiface/libraptorsmiface.c
M raptorsmiface/libraptorsmiface.h
M sesman/chansrv/chansrv.c
M sesman/chansrv/clipboard.c
M sesman/chansrv/sound.c

raptorsmiface/libraptorsmiface.c

diff --git a/raptorsmiface/libraptorsmiface.c b/raptorsmiface/libraptorsmiface.c
index 0c172f2..bd75168 100644
--- a/raptorsmiface/libraptorsmiface.c
+++ b/raptorsmiface/libraptorsmiface.c
@@ -23,7 +23,8 @@
 
 #include "libraptorsmiface.h"
 
-char *server = "localhost";
+//char *server = "localhost";
+char *server = "freyja.starlink.edu";
 char *user = "remotelab";
 char *password = "rlpass123"; /* set me first */
 char *database = "remotelab_sm";
@@ -349,6 +350,39 @@
 	}
 }
 
+char* raptor_sm_get_hostname_for_display(int display) {
+	MYSQL_RES *res;
+	MYSQL_ROW row;
+	char* query;
+
+	MYSQL *conn = connect_if_needed();
+	if (!conn) {
+		return strdup("SQLERR100");
+	}
+
+	asprintf(&query, "SELECT servername FROM sessions WHERE display='%d'", display);
+	if (mysql_query_internal(conn, query)) {
+		// Server error
+		free(query);
+		mysql_close(conn);
+		return strdup("SQLERR101");
+	}
+	else {
+		free(query);
+		res = mysql_store_result(conn);
+		while ((row = mysql_fetch_row(res)) != NULL) {
+			char* ret = strdup(row[0]);
+			mysql_free_result(res);
+			mysql_close(conn);
+			return ret;
+		}
+		// Nothing in the DB
+		mysql_free_result(res);
+		mysql_close(conn);
+		return strdup("");
+	}
+}
+
 char* raptor_sm_get_ip_for_username(char* username, bool create) {
 	char* hostname = raptor_sm_get_hostname_for_username(username, create);
 	char err;
@@ -523,13 +557,25 @@
 	}
 	char* origstr = command_string;
 
+#ifndef RAPTOR_SM_DISABLE_PULSEAUDIO
+	if (display >= 0) {
+		asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && pulseaudio -D --load=\\\"module-native-protocol-tcp listen=0.0.0.0 auth-ip-acl=%s port=%d\\\"\' &> /dev/null\" &", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), RAPTOR_SM_MANAGEMENT_SERVER_IP_NETRANGE, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display));
+		dprint("Running command %s...\n\r", command_string);
+		system(command_string);
+	}
+#endif
+
 	if (strcmp(dbfield, RAPTOR_SM_SERVER_PID_FIELD) == 0) {
 		asprintf(&command_string, "ssh root@%s \'%s & echo $! &\'", ipaddr, origstr);
 	}
 	else {
+#if RAPTOR_SM_DISABLE_PULSEAUDIO
 		asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && %s\' &> /dev/null & echo \\$!\"", ipaddr, username, display, origstr);
+#else
+		asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && %s\' &> /dev/null & echo \\$!\"", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), origstr);
+#endif
 	}
-dprint("Running command %s...\n\r", command_string);
+	dprint("Running command %s...\n\r", command_string);
 	free(origstr);
 	
 	FILE *fp;
@@ -807,7 +853,11 @@
 void raptor_sm_run_remote_desktop(char* username, int display, char* executable) {
 	char* ipaddr = raptor_sm_get_ip_for_username(username, true);
 	char* command_string;
+#if RAPTOR_SM_DISABLE_PULSEAUDIO
 	asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && %s && exit\' &> /dev/null\"", ipaddr, username, display, executable);
+#else
+	asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && %s && exit\' &> /dev/null\"", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), executable);
+#endif
 	system(command_string);
 	free(command_string);
 }

raptorsmiface/libraptorsmiface.h

diff --git a/raptorsmiface/libraptorsmiface.h b/raptorsmiface/libraptorsmiface.h
index 232dfe3..d0a12a2 100644
--- a/raptorsmiface/libraptorsmiface.h
+++ b/raptorsmiface/libraptorsmiface.h
@@ -23,6 +23,9 @@
 #define RAPTOR_SM_SERVER_PID_FIELD "server_pid"
 #define RAPTOR_SM_WM_PID_FIELD "wm_pid"
 
+#define RAPTOR_SM_BASE_PULSEAUDIO_PORT 2000
+#define RAPTOR_SM_MANAGEMENT_SERVER_IP_NETRANGE "10.0.0.0/8"
+
 char* raptor_sm_get_ip_for_hostname(char* hostname, char* err);
 char* raptor_sm_get_hostname_for_username(char* username, bool create);
 
@@ -39,4 +42,5 @@
 bool  raptor_sm_sesslimit_reached(char* username);
 char  raptor_sm_set_session_state(int display, int state);
 void  raptor_sm_run_remote_desktop(char* username, int display, char* executable);
-void  raptor_sm_terminate_server(char* username);
\ No newline at end of file
+void  raptor_sm_terminate_server(char* username);
+char* raptor_sm_get_hostname_for_display(int display);
\ No newline at end of file

sesman/chansrv/chansrv.c

diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c
index 5db8f56..ebdaf3f 100644
--- a/sesman/chansrv/chansrv.c
+++ b/sesman/chansrv/chansrv.c
@@ -76,12 +76,15 @@
 /* this variable gets bumped up once per DVC we create       */
 tui32 g_dvc_chan_id = 100;
 
+// #define ENABLE_CHANSERV_DEBUG_LOGGING
+
 #if 0
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 void dprint(const char *fmt, ...)
 {
+#ifdef ENABLE_CHANSERV_DEBUG_LOGGING
 	va_list argp;
 	va_start(argp, fmt);
 	char debug[1024];
@@ -93,6 +96,7 @@
 		fclose(fp);
 	}
 	va_end(argp);
+#endif
 }
 #undef LOG
 #define LOG(_a, _params) \

sesman/chansrv/clipboard.c

diff --git a/sesman/chansrv/clipboard.c b/sesman/chansrv/clipboard.c
index 27c45ff..ff8b7de 100644
--- a/sesman/chansrv/clipboard.c
+++ b/sesman/chansrv/clipboard.c
@@ -319,6 +319,11 @@
     {
         return 0;
     }
+    if (!g_display)
+    {
+        // prevent crash in XInternAtom
+        return 3;
+    }
 
     xfuse_init();
     xcommon_init();

sesman/chansrv/sound.c

diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c
index e8b801c..2086699 100644
--- a/sesman/chansrv/sound.c
+++ b/sesman/chansrv/sound.c
@@ -19,6 +19,8 @@
 #include "sound.h"
 #include "thread_calls.h"
 
+#include "libraptorsmiface.h"
+
 extern int g_rdpsnd_chan_id;    /* in chansrv.c */
 extern int g_display_num;       /* in chansrv.c */
 
@@ -31,6 +33,16 @@
 static void *DEFAULT_CC
 read_raw_audio_data(void *arg);
 #endif
+
+//#if 0
** Diff limit reached (max: 250 lines) **
7b891ec6 2019-03-04 12:12:54 Timothy Pearson
Add statistics reporting
M raptorsmiface/libraptorsmiface.c
M raptorsmiface/libraptorsmiface.h
M xrdp/xrdp_types.h
** Diff limit reached (max: 250 lines) **
8cdbfaa4 2019-03-04 12:12:54 Timothy Pearson
Add additional statistics reporting
M raptorsmiface/libraptorsmiface.c
M raptorsmiface/libraptorsmiface.h
M xrdp/xrdp.c
** Diff limit reached (max: 250 lines) **
b19c016a 2019-03-04 12:12:54 Timothy Pearson
Add MySQL database skeleton file
A database/mysql/remotelab_sm_database.sql
** Diff limit reached (max: 250 lines) **
a357a3f2 2019-03-04 12:12:54 Timothy Pearson
Add database configuration options to main config file
M raptorsmiface/libraptorsmiface.c
M raptorsmiface/libraptorsmiface.h
** Diff limit reached (max: 250 lines) **
d3c9396d 2019-03-04 12:12:54 Timothy Pearson
Fix non-root-user display server startup failure
Transfer and clean up Kerberos ticket on login and logout
Remove spurious debugging messages
M instfiles/pam.d/xrdp-sesman
M raptorsmiface/libraptorsmiface.c
M sesman/chansrv/sound.c
M sesman/env.c
M xrdp/xrdp_login_wnd.c
** Diff limit reached (max: 250 lines) **
36ed5920 2019-03-04 12:12:54 Timothy Pearson
Fix sporadic xrdp-sesman crash on session initiation
Fix a number of memory leaks
Fix access to freed memory
Fix invalid function return values
M raptorsmiface/libraptorsmiface.c
M raptorsmiface/libraptorsmiface.h
** Diff limit reached (max: 250 lines) **
00be702e 2019-03-04 12:12:54 Timothy Pearson
Download installation files from correct locations
Keep track of arbiter(s) in use per connection
M raptorsmiface/libraptorsmiface.c
M raptorsmiface/libraptorsmiface.h
M xorg/X11R7.6/buildx.sh
** Diff limit reached (max: 250 lines) **
6e018353 2019-03-04 12:12:54 Timothy Pearson
Second part of prior commit
M database/mysql/remotelab_sm_database.sql
** Diff limit reached (max: 250 lines) **
ab70887b 2019-03-04 12:12:54 Timothy Pearson
Update for OpenSSL 1.1
M common/ssl_calls.c
** Diff limit reached (max: 250 lines) **
8b31c81e 2019-03-04 12:12:54 Timothy Pearson
Update sources to build on ppc64el
A xorg/X11R7.6/libdrm-2.4.26.patch
M xorg/X11R7.6/buildx.sh
** Diff limit reached (max: 250 lines) **
66ad803c 2019-03-04 12:12:54 Timothy Pearson
Fix endianness checks on ppc64
M common/arch.h
** Diff limit reached (max: 250 lines) **
db2f6b32 2019-03-04 12:12:54 Timothy Pearson
Don't try connecting to remote node if preliminary node allocation has failed for any reason
M sesman/session.c
** Diff limit reached (max: 250 lines) **
cb464e3b 2019-03-04 12:12:54 Timothy Pearson
Add debug warning when maximum session limit is hit for a specified user group
M raptorsmiface/libraptorsmiface.c
** Diff limit reached (max: 250 lines) **
4aecb33c 2019-03-04 12:12:54 Timothy Pearson
Fix a few situations where process output was corrupted with existing uncleard buffer data
This fixes session termination not being marked in the database
M raptorsmiface/libraptorsmiface.c
** Diff limit reached (max: 250 lines) **
cadd2e97 2019-03-04 12:12:54 Timothy Pearson
Fix a couple of additional ppc64 endianness / alignment issues
A xorg/X11R7.6/xorg-server-1.9.3.patch
M common/arch.h
M xorg/X11R7.6/rdp/rdp.h
** Diff limit reached (max: 250 lines) **
c8ea453e 2019-03-04 12:12:54 Timothy Pearson
Work around GTK pixmaps (e.g. GIMP icons, etc) showing up as black squares
M xorg/X11R7.6/rdp/rdpmain.c
** Diff limit reached (max: 250 lines) **