summaryrefslogtreecommitdiffstats
path: root/sesman
diff options
context:
space:
mode:
authorilsimo <ilsimo>2005-10-06 19:27:38 +0000
committerilsimo <ilsimo>2005-10-06 19:27:38 +0000
commitc2fda67a1c245ac9963b583df5e9cc00c4eeb298 (patch)
tree46a09b2f5a1da03083a7e3c58a8f6401b7a9f3c6 /sesman
parent534b2691cdc8822d92709d16d5be21950c484fe1 (diff)
downloadxrdp-proprietary-c2fda67a1c245ac9963b583df5e9cc00c4eeb298.tar.gz
xrdp-proprietary-c2fda67a1c245ac9963b583df5e9cc00c4eeb298.zip
Adding auth.h env.c env.h session.c session.h tcp.c tcp.h
Diffstat (limited to 'sesman')
-rw-r--r--sesman/auth.h34
-rw-r--r--sesman/env.c108
-rw-r--r--sesman/env.h38
-rw-r--r--sesman/session.c176
-rw-r--r--sesman/session.h49
-rw-r--r--sesman/tcp.c93
-rw-r--r--sesman/tcp.h66
7 files changed, 564 insertions, 0 deletions
diff --git a/sesman/auth.h b/sesman/auth.h
new file mode 100644
index 00000000..a2c35765
--- /dev/null
+++ b/sesman/auth.h
@@ -0,0 +1,34 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager - main header
+*/
+
+#ifndef AUTH_H
+#define AUTH_H
+
+long DEFAULT_CC
+auth_userpass(char* user, char* pass);
+int DEFAULT_CC
+auth_start_session(long in_val, int in_display);
+int DEFAULT_CC
+auth_end(long in_val);
+int DEFAULT_CC
+auth_set_env(long in_val);
+
+#endif
diff --git a/sesman/env.c b/sesman/env.c
new file mode 100644
index 00000000..9ea5d6bd
--- /dev/null
+++ b/sesman/env.c
@@ -0,0 +1,108 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager
+ linux only
+
+ enc.c: user environment handling code
+
+*/
+
+//#include "d3des.h"
+//#include "arch.h"
+//#include "parse.h"
+//#include "os_calls.h"
+#include "sesman.h"
+//#include "config.h"
+//#include "tcp.h"
+//#include "sig.h"
+//#include "session.h"
+//#include "env.h"
+
+//int g_sck;
+//extern int g_pid;
+extern unsigned char g_fixedkey[8];
+//struct session_item g_session_items[100]; /* sesman.h */
+//struct sesman_config g_cfg; /* config.h */
+
+/******************************************************************************/
+int DEFAULT_CC
+env_check_password_file(char* filename, char* password)
+{
+ char encryptedPasswd[16];
+ int fd;
+
+ g_memset(encryptedPasswd, 0, 16);
+ g_strncpy(encryptedPasswd, password, 8);
+ rfbDesKey(g_fixedkey, 0);
+ rfbDes(encryptedPasswd, encryptedPasswd);
+ fd = g_file_open(filename);
+ if (fd == 0)
+ {
+ return 1;
+ }
+ g_file_write(fd, encryptedPasswd, 8);
+ g_file_close(fd);
+ g_set_file_rights(filename, 1, 1); /* set read and write flags */
+ return 0;
+}
+
+/******************************************************************************/
+int DEFAULT_CC
+env_set_user(char* username, char* passwd_file, int display)
+{
+ int error;
+ int pw_uid;
+ int pw_gid;
+ int uid;
+ char pw_shell[256];
+ char pw_dir[256];
+ char pw_gecos[256];
+ char text[256];
+
+ error = g_getuser_info(username, &pw_gid, &pw_uid, pw_shell, pw_dir,
+ pw_gecos);
+ if (error == 0)
+ {
+ error = g_setgid(pw_gid);
+ if (error == 0)
+ {
+ uid = pw_uid;
+ error = g_setuid(uid);
+ }
+ if (error == 0)
+ {
+ g_clearenv();
+ g_setenv("SHELL", pw_shell, 1);
+ g_setenv("PATH", "/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin", 1);
+ g_setenv("USER", username, 1);
+ g_sprintf(text, "%d", uid);
+ g_setenv("UID", text, 1);
+ g_setenv("HOME", pw_dir, 1);
+ g_set_current_dir(pw_dir);
+ g_sprintf(text, ":%d.0", display);
+ g_setenv("DISPLAY", text, 1);
+ if (passwd_file != 0)
+ {
+ g_mkdir(".vnc");
+ g_sprintf(passwd_file, "%s/.vnc/sesman_passwd", pw_dir);
+ }
+ }
+ }
+ return error;
+}
diff --git a/sesman/env.h b/sesman/env.h
new file mode 100644
index 00000000..d53045c7
--- /dev/null
+++ b/sesman/env.h
@@ -0,0 +1,38 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager
+ linux only
+
+ env.h: user environment handling code declarations
+
+*/
+
+#ifndef ENV_H
+#define ENV_H
+
+/******************************************************************************/
+int DEFAULT_CC
+env_check_password_file(char* filename, char* password);
+
+/******************************************************************************/
+int DEFAULT_CC
+env_set_user(char* username, char* passwd_file, int display);
+
+#endif
+
diff --git a/sesman/session.c b/sesman/session.c
new file mode 100644
index 00000000..572114db
--- /dev/null
+++ b/sesman/session.c
@@ -0,0 +1,176 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager
+ linux only
+
+*/
+
+//#include "d3des.h"
+//#include "arch.h"
+//#include "os_calls.h"
+#include "sesman.h"
+//#include "config.h"
+//#include "env.h"
+
+extern unsigned char g_fixedkey[8];
+extern struct session_item g_session_items[100]; /* sesman.h */
+extern struct sesman_config g_cfg; /* config.h */
+
+/******************************************************************************/
+struct session_item* DEFAULT_CC
+session_find_item(char* name, int width, int height, int bpp)
+{
+ int i;
+
+ for (i = 0; i < 100; i++)
+ {
+ if (g_strncmp(name, g_session_items[i].name, 255) == 0 &&
+ g_session_items[i].width == width &&
+ g_session_items[i].height == height &&
+ g_session_items[i].bpp == bpp)
+ {
+ return g_session_items + i;
+ }
+ }
+ return 0;
+}
+
+/******************************************************************************/
+/* returns non zero if there is an xserver running on this display */
+static int DEFAULT_CC
+x_server_running(int display)
+{
+ char text[256];
+
+ g_sprintf(text, "/tmp/.X11-unix/X%d", display);
+ return g_file_exist(text);
+}
+
+/******************************************************************************/
+/* returns 0 if error else the display number the session was started on */
+int DEFAULT_CC
+session_start(int width, int height, int bpp, char* username, char* password,
+ long data)
+{
+ int display;
+ int pid;
+ int wmpid;
+ int xpid;
+ char geometry[32];
+ char depth[32];
+ char screen[32];
+ char cur_dir[256];
+ char text[256];
+ char passwd_file[256];
+
+ g_get_current_dir(cur_dir, 255);
+ display = 10;
+ while (x_server_running(display) && display < 50)
+ {
+ display++;
+ }
+ if (display >= 50)
+ {
+ return 0;
+ }
+ wmpid = 0;
+ pid = g_fork();
+ if (pid == -1)
+ {
+ }
+ else if (pid == 0) /* child */
+ {
+ g_unset_signals();
+ auth_start_session(data, display);
+ g_sprintf(geometry, "%dx%d", width, height);
+ g_sprintf(depth, "%d", bpp);
+ g_sprintf(screen, ":%d", display);
+ wmpid = g_fork();
+ if (wmpid == -1)
+ {
+ }
+ else if (wmpid == 0) /* child */
+ {
+ /* give X a bit to start */
+ g_sleep(1000);
+ env_set_user(username, 0, display);
+ if (x_server_running(display))
+ {
+ auth_set_env(data);
+ /* try to execute user window manager if enabled */
+ if (g_cfg.enable_user_wm)
+ {
+ g_sprintf(text,"%s/%s", g_getenv("HOME"), g_cfg.user_wm);
+ if (g_file_exist(text))
+ {
+ g_execlp3(text, g_cfg.user_wm, 0);
+ }
+ }
+ /* if we're here something happened to g_execlp3
+ so we try running the default window manager */
+ g_sprintf(text, "%s/%s", cur_dir, g_cfg.default_wm);
+ g_execlp3(text, g_cfg.default_wm, 0);
+ /* still a problem starting window manager just start xterm */
+ g_execlp3("xterm", "xterm", 0);
+ /* should not get here */
+ }
+ g_printf("error starting window manager\n");
+ g_exit(0);
+ }
+ else /* parent */
+ {
+ xpid = g_fork();
+ if (xpid == -1)
+ {
+ }
+ else if (xpid == 0) /* child */
+ {
+ env_set_user(username, passwd_file, display);
+ env_check_password_file(passwd_file, password);
+ g_execlp11("Xvnc", "Xvnc", screen, "-geometry", geometry,
+ "-depth", depth, "-bs", "-rfbauth", passwd_file, 0);
+ /* should not get here */
+ g_printf("error\n");
+ g_exit(0);
+ }
+ else /* parent */
+ {
+ g_waitpid(wmpid);
+ g_sigterm(xpid);
+ g_sigterm(wmpid);
+ g_sleep(1000);
+ auth_end(data);
+ g_exit(0);
+ }
+ }
+ }
+ else /* parent */
+ {
+ g_session_items[display].pid = pid;
+ g_strcpy(g_session_items[display].name, username);
+ g_session_items[display].display = display;
+ g_session_items[display].width = width;
+ g_session_items[display].height = height;
+ g_session_items[display].bpp = bpp;
+ g_session_items[display].data = data;
+ g_sleep(5000);
+ }
+ return display;
+}
+
diff --git a/sesman/session.h b/sesman/session.h
new file mode 100644
index 00000000..c8615c05
--- /dev/null
+++ b/sesman/session.h
@@ -0,0 +1,49 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager
+ linux only
+
+*/
+
+#ifndef SESSION_H
+#define SESSION_H
+
+struct session_item
+{
+ char name[256];
+ int pid; /* pid of sesman waiting for wm to end */
+ int display;
+ int width;
+ int height;
+ int bpp;
+ long data;
+};
+
+/******************************************************************************/
+struct session_item* DEFAULT_CC
+session_find_item(char* name, int width, int height, int bpp);
+
+/******************************************************************************/
+/* returns 0 if error else the display number the session was started on */
+int DEFAULT_CC
+session_start(int width, int height, int bpp, char* username, char* password,
+ long data);
+
+#endif
+
diff --git a/sesman/tcp.c b/sesman/tcp.c
new file mode 100644
index 00000000..2bfa84c2
--- /dev/null
+++ b/sesman/tcp.c
@@ -0,0 +1,93 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager
+ linux only
+
+ tcp.c: tcp stream funcions
+
+*/
+
+#include "sesman.h"
+
+/*****************************************************************************/
+int DEFAULT_CC
+tcp_force_recv(int sck, char* data, int len)
+{
+ int rcvd;
+
+ while (len > 0)
+ {
+ rcvd = g_tcp_recv(sck, data, len, 0);
+ if (rcvd == -1)
+ {
+ if (g_tcp_last_error_would_block(sck))
+ {
+ g_sleep(1);
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else if (rcvd == 0)
+ {
+ return 1;
+ }
+ else
+ {
+ data += rcvd;
+ len -= rcvd;
+ }
+ }
+ return 0;
+}
+
+/*****************************************************************************/
+int DEFAULT_CC
+tcp_force_send(int sck, char* data, int len)
+{
+ int sent;
+
+ while (len > 0)
+ {
+ sent = g_tcp_send(sck, data, len, 0);
+ if (sent == -1)
+ {
+ if (g_tcp_last_error_would_block(sck))
+ {
+ g_sleep(1);
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ else if (sent == 0)
+ {
+ return 1;
+ }
+ else
+ {
+ data += sent;
+ len -= sent;
+ }
+ }
+ return 0;
+}
+
diff --git a/sesman/tcp.h b/sesman/tcp.h
new file mode 100644
index 00000000..130c18a7
--- /dev/null
+++ b/sesman/tcp.h
@@ -0,0 +1,66 @@
+/*
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ xrdp: A Remote Desktop Protocol server.
+ Copyright (C) Jay Sorg 2005
+
+ session manager
+ linux only
+
+ tcp.h: tcp stream functions declarations
+
+*/
+
+/**
+ *
+ * @file tcp stream functions
+ *
+ */
+
+#ifndef TCP_H
+#define TCP_H
+
+/**
+ *
+ * force receiving data from tcp stream
+ *
+ * @param sck the socket to read from
+ * @param data buffer
+ * @param len buffer size
+ *
+ * @return 0: ok, 1: error
+ *
+ */
+
+int DEFAULT_CC
+tcp_force_recv(int sck, char* data, int len);
+
+/**
+ *
+ * force sending data to tcp stream
+ *
+ * @param sck the socket to write to
+ * @param data buffer
+ * @param len buffer size
+ *
+ * @return 0: ok, 1: error
+ *
+ */
+
+int DEFAULT_CC
+tcp_force_send(int sck, char* data, int len);
+
+#endif
+