Making sesman running as a daemon in the background and placing session starting code in a separate util (sesrun)

ulab-original
ilsimo 19 years ago
parent c2fda67a1c
commit 2fa674469f

@ -5,11 +5,17 @@ SESMANOBJ = sesman.o config.o tcp.o sig.o session.o env.o \
../common/list.o \ ../common/list.o \
../common/file.o ../common/file.o
SESRUNOBJ = sesrun.o config.o tcp.o \
../common/os_calls.o \
../common/d3des.o \
../common/list.o \
../common/file.o
CFLAGS = -Wall -O2 -I../common CFLAGS = -Wall -O2 -I../common
LDFLAGS = -L /usr/gnu/lib LDFLAGS = -L /usr/gnu/lib
CC = gcc CC = gcc
all: nopam all: nopam tools
nopam: $(SESMANOBJ) verify_user.o nopam: $(SESMANOBJ) verify_user.o
$(CC) $(LDFLAGS) -o sesman $(SESMANOBJ) verify_user.o -ldl -lcrypt $(CC) $(LDFLAGS) -o sesman $(SESMANOBJ) verify_user.o -ldl -lcrypt
@ -20,5 +26,8 @@ pam: $(SESMANOBJ) verify_user_pam.o
pam_userpass: $(SESMANOBJ) verify_user_pam_userpass.o pam_userpass: $(SESMANOBJ) verify_user_pam_userpass.o
$(CC) $(LDFLAGS) -o sesman $(SESMANOBJ) verify_user_pam_userpass.o -ldl -lpam -lpam_userpass $(CC) $(LDFLAGS) -o sesman $(SESMANOBJ) verify_user_pam_userpass.o -ldl -lpam -lpam_userpass
tools:
$(CC) $(LDFLAGS) -o sesrun $(SESRUNOBJ) -ldl
clean: clean:
rm -f $(SESMANOBJ) verify_user.o verify_user_pam.o verify_user_pam_userpass.o sesman rm -f $(SESMANOBJ) verify_user.o verify_user_pam.o verify_user_pam_userpass.o sesman sesrun.o sesrun

@ -22,6 +22,7 @@
*/ */
#include "sesman.h" #include "sesman.h"
#include <stdio.h>
int g_sck; int g_sck;
int g_pid; int g_pid;
@ -57,7 +58,6 @@ cterm(int s)
int DEFAULT_CC int DEFAULT_CC
main(int argc, char** argv) main(int argc, char** argv)
{ {
int sck;
int in_sck; int in_sck;
int code; int code;
int i; int i;
@ -70,18 +70,37 @@ main(int argc, char** argv)
int error; int error;
struct stream* in_s; struct stream* in_s;
struct stream* out_s; struct stream* out_s;
char* username;
char* password;
char user[256]; char user[256];
char pass[256]; char pass[256];
struct session_item* s_item; struct session_item* s_item;
long data; long data;
/* start of daemonizing code */
g_pid = g_fork();
g_printf("forkando: %d\n",g_pid);
if (0!=g_pid)
{
g_printf("il processo %d esce...\n",g_pid);
g_exit(0);
}
g_file_close(0);
g_file_close(1);
g_file_close(2);
g_file_open("/dev/null");
g_file_open("/dev/null");
g_file_open("/dev/null");
/* end of daemonizing code */
if (0 != config_read(&g_cfg)) if (0 != config_read(&g_cfg))
{ {
g_printf("sesman: error reading config. quitting.\n\r"); g_printf("sesman: error reading config. quitting.\n\r");
return 1; return 1;
} }
g_memset(&g_session_items, 0, sizeof(g_session_items)); g_memset(&g_session_items, 0, sizeof(g_session_items));
g_pid = g_getpid(); g_pid = g_getpid();
g_signal(1, sig_sesman_reload_cfg); /* SIGHUP */ g_signal(1, sig_sesman_reload_cfg); /* SIGHUP */
@ -89,16 +108,8 @@ main(int argc, char** argv)
g_signal(9, sig_sesman_shutdown); /* SIGKILL */ g_signal(9, sig_sesman_shutdown); /* SIGKILL */
g_signal(15, sig_sesman_shutdown); /* SIGTERM */ g_signal(15, sig_sesman_shutdown); /* SIGTERM */
g_signal_child_stop(cterm); /* SIGCHLD */ g_signal_child_stop(cterm); /* SIGCHLD */
if (argc == 1)
{ /*main program loop*/
g_printf("xrdp session manager v0.1\n");
g_printf("usage\n");
g_printf("sesman wait - wait for connection\n");
g_printf("sesman server username password width height bpp - \
start session\n");
}
else if (argc == 2 && g_strncmp(argv[1], "wait", 255) == 0)
{
make_stream(in_s); make_stream(in_s);
init_stream(in_s, 8192); init_stream(in_s, 8192);
make_stream(out_s); make_stream(out_s);
@ -194,68 +205,11 @@ start session\n");
else else
{ {
g_printf("bind error\n"); g_printf("bind error\n");
perror("ilbind ");
} }
g_tcp_close(g_sck); g_tcp_close(g_sck);
free_stream(in_s); free_stream(in_s);
free_stream(out_s); free_stream(out_s);
}
else if (argc == 7)
{
username = argv[2];
password = argv[3];
width = g_atoi(argv[4]);
height = g_atoi(argv[5]);
bpp = g_atoi(argv[6]);
make_stream(in_s);
init_stream(in_s, 8192);
make_stream(out_s);
init_stream(out_s, 8192);
sck = g_tcp_socket();
if (g_tcp_connect(sck, argv[1], "3350") == 0)
{
s_push_layer(out_s, channel_hdr, 8);
out_uint16_be(out_s, 0); /* code */
i = g_strlen(username);
out_uint16_be(out_s, i);
out_uint8a(out_s, username, i);
i = g_strlen(password);
out_uint16_be(out_s, i);
out_uint8a(out_s, password, i);
out_uint16_be(out_s, width);
out_uint16_be(out_s, height);
out_uint16_be(out_s, bpp);
s_mark_end(out_s);
s_pop_layer(out_s, channel_hdr);
out_uint32_be(out_s, 0); /* version */
out_uint32_be(out_s, out_s->end - out_s->data); /* size */
tcp_force_send(sck, out_s->data, out_s->end - out_s->data);
if (tcp_force_recv(sck, in_s->data, 8) == 0)
{
in_uint32_be(in_s, version);
in_uint32_be(in_s, size);
init_stream(in_s, 8192);
if (tcp_force_recv(sck, in_s->data, size - 8) == 0)
{
if (version == 0)
{
in_uint16_be(in_s, code);
if (code == 3)
{
in_uint16_be(in_s, data);
in_uint16_be(in_s, display);
g_printf("ok %d display %d\n", data, display);
}
}
}
}
}
else
{
g_printf("connect error\n");
}
g_tcp_close(sck);
free_stream(in_s);
free_stream(out_s);
}
return 0; return 0;
} }

@ -0,0 +1,121 @@
/*
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 "sesman.h"
int g_sck;
int g_pid;
struct sesman_config g_cfg; /* config.h */
/******************************************************************************/
int DEFAULT_CC
main(int argc, char** argv)
{
int sck;
int code;
int i;
int size;
int version;
int width;
int height;
int bpp;
int display;
struct stream* in_s;
struct stream* out_s;
char* username;
char* password;
long data;
if (0 != config_read(&g_cfg))
{
g_printf("sesrun: error reading config. quitting.\n\r");
return 1;
}
g_pid = g_getpid();
if (argc == 1)
{
g_printf("xrdp session starter v0.1\n");
g_printf("\nusage:\n");
g_printf("sesrun <server> <username> <password> <width> <height> <bpp>\n");
}
else if (argc == 7)
{
username = argv[2];
password = argv[3];
width = g_atoi(argv[4]);
height = g_atoi(argv[5]);
bpp = g_atoi(argv[6]);
make_stream(in_s);
init_stream(in_s, 8192);
make_stream(out_s);
init_stream(out_s, 8192);
sck = g_tcp_socket();
if (g_tcp_connect(sck, argv[1], "3350") == 0)
{
s_push_layer(out_s, channel_hdr, 8);
out_uint16_be(out_s, 0); /* code */
i = g_strlen(username);
out_uint16_be(out_s, i);
out_uint8a(out_s, username, i);
i = g_strlen(password);
out_uint16_be(out_s, i);
out_uint8a(out_s, password, i);
out_uint16_be(out_s, width);
out_uint16_be(out_s, height);
out_uint16_be(out_s, bpp);
s_mark_end(out_s);
s_pop_layer(out_s, channel_hdr);
out_uint32_be(out_s, 0); /* version */
out_uint32_be(out_s, out_s->end - out_s->data); /* size */
tcp_force_send(sck, out_s->data, out_s->end - out_s->data);
if (tcp_force_recv(sck, in_s->data, 8) == 0)
{
in_uint32_be(in_s, version);
in_uint32_be(in_s, size);
init_stream(in_s, 8192);
if (tcp_force_recv(sck, in_s->data, size - 8) == 0)
{
if (version == 0)
{
in_uint16_be(in_s, code);
if (code == 3)
{
in_uint16_be(in_s, data);
in_uint16_be(in_s, display);
g_printf("ok %d display %d\n", data, display);
}
}
}
}
}
else
{
g_printf("connect error\n");
}
g_tcp_close(sck);
free_stream(in_s);
free_stream(out_s);
}
return 0;
}
Loading…
Cancel
Save