564147de | 2019-03-04 11:30:48 | Timothy Pearson |
Add preliminary Raptor session management |
||
A raptorsmiface/Makefile.am A raptorsmiface/libraptorsmiface.c A raptorsmiface/libraptorsmiface.h M Makefile.am M configure.ac M sesman/Makefile.am M sesman/chansrv/Makefile.am M sesman/chansrv/chansrv.c M sesman/sesman.ini M sesman/session.c M xrdp/Makefile.am M xrdp/xrdp.ini M xrdp/xrdp_mm.c M xrdp/xrdp_types.h |
||
Makefile.amdiff --git a/Makefile.am b/Makefile.am index 5193171..dfe64df 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,6 +14,7 @@ SUBDIRS = \ common \ + raptorsmiface \ vnc \ rdp \ xup \ configure.acdiff --git a/configure.ac b/configure.ac index d431513..5a1ab65 100644 --- a/configure.ac +++ b/configure.ac @@ -112,6 +112,7 @@ fi AC_CONFIG_FILES([Makefile common/Makefile + raptorsmiface/Makefile vnc/Makefile rdp/Makefile libxrdp/Makefile raptorsmiface/Makefile.amdiff --git a/raptorsmiface/Makefile.am b/raptorsmiface/Makefile.am new file mode 100644 index 0000000..acf3e23 --- /dev/null +++ b/raptorsmiface/Makefile.am @@ -0,0 +1,34 @@ +EXTRA_DIST = libraptorsmiface.h + +EXTRA_DEFINES = +EXTRA_INCLUDES = +EXTRA_LIBS = +EXTRA_FLAGS = + +if GOT_PREFIX +EXTRA_INCLUDES += -I$(prefix)/include +EXTRA_FLAGS += -L$(prefix)/lib -Wl,-rpath -Wl,$(prefix)/lib +endif + +AM_CFLAGS = \ + -DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \ + -DXRDP_SBIN_PATH=\"${sbindir}\" \ + -DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \ + -DXRDP_PID_PATH=\"${localstatedir}/run\" \ + $(EXTRA_DEFINES) + +INCLUDES = \ + -I$(top_srcdir)/common \ + $(EXTRA_INCLUDES) + +lib_LTLIBRARIES = \ + libraptorsmiface.la + +libraptorsmiface_la_SOURCES = \ + libraptorsmiface.c + +libraptorsmiface_la_LDFLAGS = \ + $(EXTRA_FLAGS) -lmysqlclient + +libraptorsmiface_la_LIBADD = \ + $(EXTRA_LIBS) raptorsmiface/libraptorsmiface.cdiff --git a/raptorsmiface/libraptorsmiface.c b/raptorsmiface/libraptorsmiface.c new file mode 100644 index 0000000..4d3db02 --- /dev/null +++ b/raptorsmiface/libraptorsmiface.c @@ -0,0 +1,568 @@ +// (c) 2012 Timothy Pearson +// (c) 2012 Raptor Engineering +// ALL RIGHTS RESERVED + +#define _GNU_SOURCE + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> +#include <limits.h> + +#include <netdb.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include <pwd.h> +#include <grp.h> +#include <time.h> + +#include <mysql/mysql.h> + +#include "libraptorsmiface.h" + +MYSQL *conn = 0; + +char *server = "localhost"; +char *user = "remotelab"; +char *password = "rlpass123"; /* set me first */ +char *database = "remotelab_sm"; + +void dprint(const char *fmt, ...) +{ + va_list argp; + va_start(argp, fmt); + +#if 0 + vprintf(fmt, argp); +#else + char debug[1024]; + vsprintf(debug, fmt, argp); + FILE *fp = fopen("/raptorsmiface.debug", "a"); + if (fp != NULL) + { + fputs(debug, fp); + fclose(fp); + } +#endif + + va_end(argp); +} + +void connect_if_needed() { + if (!conn) { + conn = mysql_init(NULL); + if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) { + dprint("[ERROR] MySQL connection FAILED [%s]\n\r", mysql_error(conn)); + conn = 0; + } + } +} + +char* get_mysql_escaped_string(MYSQL *sqlcn, char* rawstr) { + unsigned int minlen = strlen(rawstr); + unsigned int maxlen = ((minlen*2)+1); + char* escstr = malloc(maxlen*sizeof(char)); + mysql_real_escape_string(sqlcn, escstr, rawstr, minlen); + return escstr; +} + +char* get_group_for_user(char* username) { + struct passwd* pwd; + pwd = getpwnam(username); + if (!pwd) { + return true; + } + gid_t groupid = pwd->pw_gid; + struct group* primarygroup; + primarygroup = getgrgid(groupid); + if (!primarygroup) { + return true; + } + + return strdup(primarygroup->gr_name); +} + +char raptor_sm_deallocate_session(char* username) { + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_RES *svr_res; + MYSQL_ROW svr_row; + MYSQL_RES *cnt_res; + MYSQL_ROW cnt_row; + char* query; + + connect_if_needed(); + if (!conn) { + return 1; + } + + // Remove the user from the system + char* safe_username = get_mysql_escaped_string(conn, username); + asprintf(&query, "DELETE FROM sessions WHERE username='%s'", safe_username); + free(safe_username); + if (mysql_query(conn, query)) { + // Server error + free(query); + return 2; + } + else { + free(query); + return 0; + } +} + +char* raptor_sm_allocate_session(char* username) { + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL_RES *svr_res; + MYSQL_ROW svr_row; + MYSQL_RES *cnt_res; + MYSQL_ROW cnt_row; + char* query; + + connect_if_needed(); + if (!conn) { + return strdup("SQLERR001"); + } + + // Verify that this user is not already on the system + char* safe_username = get_mysql_escaped_string(conn, username); + asprintf(&query, "SELECT servername FROM sessions WHERE username='%s'", safe_username); + free(safe_username); + if (mysql_query(conn, query)) { + // Server error + free(query); + return strdup("SQLERR002"); + } + else { + free(query); + res = mysql_store_result(conn); + if ((row = mysql_fetch_row(res)) == NULL) { + // User is not on a system + // Find the least utilized node + if (mysql_query(conn, "SELECT name FROM servers")) { + // Server error + mysql_free_result(res); + return strdup("SQLERR003"); + } + else { + svr_res = mysql_store_result(conn); + char* bestserver = strdup(""); + int bestusage = INT_MAX; + while ((svr_row = mysql_fetch_row(svr_res)) != NULL) { + char* safe_servername = get_mysql_escaped_string(conn, svr_row[0]); + asprintf(&query, "SELECT username FROM sessions WHERE servername='%s'", safe_servername); + free(safe_servername); + if (mysql_query(conn, query)) { + // Server error + free(query); + free(bestserver); + mysql_free_result(res); + mysql_free_result(svr_res); + return strdup("SQLERR004"); + } + else { + free(query); + cnt_res = mysql_store_result(conn); + int usagecount = 0; + while ((cnt_row = mysql_fetch_row(cnt_res)) != NULL) { + usagecount++; + } + mysql_free_result(cnt_res); + if (usagecount < bestusage) { + free(bestserver); + bestserver = strdup(svr_row[0]); + bestusage = usagecount; + } + }** Diff limit reached (max: 250 lines) ** |
||
70007b5c | 2019-03-04 11:30:48 | Timothy Pearson |
Fix a number of problems System is now mostly stabilized |
||
M common/defines.h M common/trans.c M raptorsmiface/libraptorsmiface.c M raptorsmiface/libraptorsmiface.h M sesman/chansrv/chansrv.c M sesman/scp_v0.c M sesman/scp_v1.c M sesman/session.c M xrdp/xrdp_mm.c M xup/xup.c |
||
** Diff limit reached (max: 250 lines) **
|
||
091eca1d | 2019-03-04 11:30:48 | Timothy Pearson |
Add server/group mapping |
||
M raptorsmiface/libraptorsmiface.c M xrdp/xrdp_mm.c |
||
** Diff limit reached (max: 250 lines) **
|
||
fa9f98c3 | 2019-03-04 11:30:48 | Timothy Pearson |
Partially fix immediate exit after login |
||
M xup/xup.c |
||
** Diff limit reached (max: 250 lines) **
|
||
0cb18974 | 2019-03-04 11:30:48 | Timothy Pearson |
Add hack to support blank cursors for now |
||
M xorg/X11R7.6/rdp/rdpinput.c M xup/xup.c |
||
** Diff limit reached (max: 250 lines) **
|
||
0a4fecca | 2019-03-04 11:30:48 | Timothy Pearson |
Update branding |
||
M xrdp/ad24b.bmp M xrdp/ad256.bmp M xrdp/xrdp.ini M xrdp/xrdp24b.bmp M xrdp/xrdp256.bmp M xrdp/xrdp_login_wnd.c |
||
** Diff limit reached (max: 250 lines) **
|
||
7a973a4d | 2019-03-04 11:30:48 | Timothy Pearson |
Use a black login background |
||
M xrdp/xrdp.ini M xrdp/xrdp24b.bmp M xrdp/xrdp256.bmp |
||
** Diff limit reached (max: 250 lines) **
|
||
208248f2 | 2019-03-04 11:30:48 | Timothy Pearson |
Add ability to recover somewhat from a dead master node |
||
M raptorsmiface/libraptorsmiface.c |
||
** Diff limit reached (max: 250 lines) **
|
||
46b7c01b | 2019-03-04 11:30:48 | Timothy Pearson |
Add master node session recovery support |
||
M raptorsmiface/libraptorsmiface.c M raptorsmiface/libraptorsmiface.h M sesman/scp_v0.c M sesman/scp_v1.c M sesman/session.c |
||
** Diff limit reached (max: 250 lines) **
|
||
ec5f249e | 2019-03-04 11:30:48 | Timothy Pearson |
Add additional debug statement |
||
M raptorsmiface/libraptorsmiface.c |
||
** Diff limit reached (max: 250 lines) **
|
||
798bf941 | 2019-03-04 11:30:48 | Timothy Pearson |
Fix merge |
||
M sesman/scp_v0.c M sesman/session.c |
||
** Diff limit reached (max: 250 lines) **
|
||
78340c11 | 2019-03-04 11:30:48 | 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 |
||
** Diff limit reached (max: 250 lines) **
|
||
8d7b77b9 | 2019-03-04 11:30:48 | Timothy Pearson |
Add statistics reporting |
||
M raptorsmiface/libraptorsmiface.c M raptorsmiface/libraptorsmiface.h M xrdp/xrdp_types.h |
||
** Diff limit reached (max: 250 lines) **
|
||
6b9f2369 | 2019-03-04 11:30:48 | Timothy Pearson |
Add additional statistics reporting |
||
M raptorsmiface/libraptorsmiface.c M raptorsmiface/libraptorsmiface.h M xrdp/xrdp.c |
||
** Diff limit reached (max: 250 lines) **
|
||
ef24343f | 2019-03-04 11:30:48 | Timothy Pearson |
Add MySQL database skeleton file |
||
A database/mysql/remotelab_sm_database.sql |
||
** Diff limit reached (max: 250 lines) **
|
||
d7ab09e9 | 2019-03-04 11:30:48 | Timothy Pearson |
Add database configuration options to main config file |
||
M raptorsmiface/libraptorsmiface.c M raptorsmiface/libraptorsmiface.h |
||
** Diff limit reached (max: 250 lines) **
|
||
d6b5e0b8 | 2019-03-04 11:30:48 | 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) **
|
||
9c9ed6d4 | 2019-03-04 11:30:48 | 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) **
|
||
678efa0e | 2019-03-04 11:30:48 | 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) **
|
||
6b2ae24e | 2019-03-04 11:30:48 | Timothy Pearson |
Second part of prior commit |
||
M database/mysql/remotelab_sm_database.sql |
||
** Diff limit reached (max: 250 lines) **
|
||
73d7dcd9 | 2019-03-04 11:30:48 | Timothy Pearson |
Update for OpenSSL 1.1 |
||
M common/ssl_calls.c |
||
** Diff limit reached (max: 250 lines) **
|
||
c6c23052 | 2019-03-04 11:30:48 | 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) **
|
||
c773c33e | 2019-03-04 11:30:48 | Timothy Pearson |
Fix endianness checks on ppc64 |
||
M common/arch.h |
||
** Diff limit reached (max: 250 lines) **
|
||
60edc7e6 | 2019-03-04 11:30:48 | 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) **
|
||
e968d508 | 2019-03-04 11:30:48 | 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) **
|
||
2de4313c | 2019-03-04 11:30:48 | 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) **
|
||
193abcfc | 2019-03-04 11:30:48 | 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) **
|
||
e31ee626 | 2019-03-04 11:30:48 | 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) **
|