Adding logging functions and adding log options in config files

ulab-original
ilsimo 19 years ago
parent 4e8b16669e
commit e7dbdea767

@ -3,13 +3,15 @@ SESMANOBJ = sesman.o config.o tcp.o sig.o session.o env.o \
../common/os_calls.o \ ../common/os_calls.o \
../common/d3des.o \ ../common/d3des.o \
../common/list.o \ ../common/list.o \
../common/file.o ../common/file.o \
../common/log.o
SESRUNOBJ = sesrun.o config.o tcp.o \ SESRUNOBJ = sesrun.o config.o tcp.o \
../common/os_calls.o \ ../common/os_calls.o \
../common/d3des.o \ ../common/d3des.o \
../common/list.o \ ../common/list.o \
../common/file.o ../common/file.o \
../common/log.o
CFLAGS = -Wall -O2 -I../common CFLAGS = -Wall -O2 -I../common
LDFLAGS = -L /usr/gnu/lib LDFLAGS = -L /usr/gnu/lib

@ -23,17 +23,27 @@
#include "file.h" #include "file.h"
#include "sesman.h" #include "sesman.h"
/******************************************************************************/
static int text2bool(char* s)
{
if (0 == g_strncasecmp(s, "1", 1) ||
0 == g_strncasecmp(s, "true", 4) ||
0 == g_strncasecmp(s, "yes", 3))
{
return 1;
}
return 0;
}
/******************************************************************************/ /******************************************************************************/
/* returns error */ /* returns error */
int DEFAULT_CC int DEFAULT_CC
config_read(struct sesman_config* cfg) config_read(struct config_sesman* cfg)
{ {
int i;
int fd; int fd;
struct list* sec; struct list* sec;
struct list* param_n; struct list* param_n;
struct list* param_v; struct list* param_v;
char* buf;
fd = g_file_open(SESMAN_CFG_FILE); fd = g_file_open(SESMAN_CFG_FILE);
if (-1 == fd) if (-1 == fd)
@ -41,7 +51,7 @@ config_read(struct sesman_config* cfg)
g_printf("sesman: error reading config: %s\n\r", SESMAN_CFG_FILE); g_printf("sesman: error reading config: %s\n\r", SESMAN_CFG_FILE);
return 1; return 1;
} }
g_memset(cfg, 0, sizeof(struct sesman_config)); g_memset(cfg, 0, sizeof(struct config_sesman));
sec = list_create(); sec = list_create();
sec->auto_free = 1; sec->auto_free = 1;
file_read_sections(fd, sec); file_read_sections(fd, sec);
@ -49,41 +59,105 @@ config_read(struct sesman_config* cfg)
param_n->auto_free = 1; param_n->auto_free = 1;
param_v = list_create(); param_v = list_create();
param_v->auto_free = 1; param_v->auto_free = 1;
file_read_section(fd, SESMAN_CFG_GLOBALS, param_n, param_v);
/* read global config */
config_read_globals(fd, cfg, param_n, param_v);
/* read logging config */
config_read_logging(fd, &(cfg->log), param_n, param_v);
/* cleanup */
list_delete(sec);
list_delete(param_v);
list_delete(param_n);
return 0;
}
int DEFAULT_CC
config_read_globals(int file, struct config_sesman* cf, struct list* param_n, struct list* param_v)
{
int i;
char* buf;
list_clear(param_v);
list_clear(param_n);
file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);
for (i = 0; i < param_n->count; i++) for (i = 0; i < param_n->count; i++)
{ {
buf = (char*)list_get_item(param_n, i); buf = (char*)list_get_item(param_n, i);
if (0 == g_strncasecmp(buf, SESMAN_CFG_DEFWM, 20)) if (0 == g_strncasecmp(buf, SESMAN_CFG_DEFWM, 20))
{ {
g_strncpy(cfg->default_wm, (char*)list_get_item(param_v, i), 31); g_strncpy(cf->default_wm, (char*)list_get_item(param_v, i), 31);
} }
else if (0 == g_strncasecmp(buf, SESMAN_CFG_USERWM, 20)) else if (0 == g_strncasecmp(buf, SESMAN_CFG_USERWM, 20))
{ {
g_strncpy(cfg->user_wm, (char*)list_get_item(param_v, i), 31); g_strncpy(cf->user_wm, (char*)list_get_item(param_v, i), 31);
} }
else if (0 == g_strncasecmp(buf, SESMAN_CFG_ENABLE_USERWM, 20)) else if (0 == g_strncasecmp(buf, SESMAN_CFG_ENABLE_USERWM, 20))
{ {
buf = (char*)list_get_item(param_v, i); cf->enable_user_wm = text2bool((char*) list_get_item(param_v, i));
if (0 == g_strncasecmp(buf, "1", 1) ||
0 == g_strncasecmp(buf, "true", 4) ||
0 == g_strncasecmp(buf, "yes", 3))
{
cfg->enable_user_wm = 1;
}
} }
else if (0 == g_strncasecmp(buf, SESMAN_CFG_PORT, 20)) else if (0 == g_strncasecmp(buf, SESMAN_CFG_PORT, 20))
{ {
g_strncpy(cfg->listen_port, (char*)list_get_item(param_v, i), 15); g_strncpy(cf->listen_port, (char*)list_get_item(param_v, i), 15);
} }
} }
g_printf("sesman config:\n\r"); g_printf("sesman config:\n\r");
g_printf("\tListenPort: %s\n\r", cfg->listen_port); g_printf("\tListenPort: %s\n\r", cf->listen_port);
g_printf("\tEnableUserWindowManager: %i\n\r", cfg->enable_user_wm); g_printf("\tEnableUserWindowManager: %i\n\r", cf->enable_user_wm);
g_printf("\tUserWindowManager: %s\n\r", cfg->user_wm); g_printf("\tUserWindowManager: %s\n\r", cf->user_wm);
g_printf("\tDefaultWindowManager: %s\n\r", cfg->default_wm); g_printf("\tDefaultWindowManager: %s\n\r", cf->default_wm);
/* cleanup */
list_delete(sec); return 0;
list_delete(param_v); }
list_delete(param_n);
int DEFAULT_CC
config_read_logging(int file, struct log_config* lc, struct list* param_n, struct list* param_v)
{
int i;
char* buf;
list_clear(param_v);
list_clear(param_n);
/* setting defaults */
lc->program_name = g_strdup("sesman");
lc->log_file = 0;
lc->fd = 0;
lc->log_level = LOG_LEVEL_DEBUG;
lc->enable_syslog = 0;
lc->syslog_level = LOG_LEVEL_DEBUG;
file_read_section(file, SESMAN_CFG_LOGGING, param_n, param_v);
for (i = 0; i < param_n->count; i++)
{
buf = (char*)list_get_item(param_n, i);
if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_FILE, 20))
{
lc->log_file = g_strdup((char*)list_get_item(param_v, i));
}
if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_LEVEL, 20))
{
lc->log_level = log_text2level((char*)list_get_item(param_v, i));
}
if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG, 20))
{
lc->enable_syslog = text2bool((char*)list_get_item(param_v, i));
}
if (0 == g_strncasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL, 20))
{
lc->syslog_level = log_text2level((char*)list_get_item(param_v, i));
}
}
g_printf("logging configuration:\n\r");
g_printf("\tLogFile: %s\n\r",lc->log_file);
g_printf("\tLogLevel: %i\n\r", lc->log_level);
g_printf("\tEnableSyslog: %i\n\r", lc->enable_syslog);
g_printf("\tSyslogLevel: %i\n\r", lc->syslog_level);
return 0; return 0;
} }

@ -22,19 +22,31 @@
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#define SESMAN_CFG_FILE "./sesman.ini" #include "arch.h"
#define SESMAN_CFG_GLOBALS "Globals" #include "list.h"
#define SESMAN_CFG_DEFWM "DefaultWindowManager" #include "log.h"
#define SESMAN_CFG_PORT "ListenPort"
#define SESMAN_CFG_ENABLE_USERWM "EnableUserWindowManager" #define SESMAN_CFG_FILE "./sesman.ini"
#define SESMAN_CFG_USERWM "UserWindowManager"
#define SESMAN_CFG_GLOBALS "Globals"
struct sesman_config #define SESMAN_CFG_DEFWM "DefaultWindowManager"
#define SESMAN_CFG_PORT "ListenPort"
#define SESMAN_CFG_ENABLE_USERWM "EnableUserWindowManager"
#define SESMAN_CFG_USERWM "UserWindowManager"
#define SESMAN_CFG_LOGGING "Logging"
#define SESMAN_CFG_LOG_FILE "LogFile"
#define SESMAN_CFG_LOG_LEVEL "LogLevel"
#define SESMAN_CFG_LOG_ENABLE_SYSLOG "EnableSyslog"
#define SESMAN_CFG_LOG_SYSLOG_LEVEL "SyslogLevel"
struct config_sesman
{ {
char listen_port[16]; char listen_port[16];
int enable_user_wm; int enable_user_wm;
char default_wm[32]; char default_wm[32];
char user_wm[32]; char user_wm[32];
struct log_config log;
}; };
/** /**
@ -47,6 +59,30 @@ struct sesman_config
* *
*/ */
int DEFAULT_CC int DEFAULT_CC
config_read(struct sesman_config* cfg); config_read(struct config_sesman* cfg);
/**
*
* Reads sesman configuration
*
* @param cfg pointer to configuration object to be replaced
*
* @return 0 on success, 1 on failure
*
*/
int DEFAULT_CC
config_read_globals(int file, struct config_sesman* cf, struct list* param_n, struct list* param_v);
/**
*
* Reads sesman configuration
*
* @param cfg pointer to configuration object to be replaced
*
* @return 0 on success, 1 on failure
*
*/
int DEFAULT_CC
config_read_logging(int file, struct log_config* lc, struct list* param_n, struct list* param_v);
#endif #endif

@ -23,22 +23,9 @@
*/ */
//#include "d3des.h"
//#include "arch.h"
//#include "parse.h"
//#include "os_calls.h"
#include "sesman.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]; 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 int DEFAULT_CC
@ -54,6 +41,7 @@ env_check_password_file(char* filename, char* password)
fd = g_file_open(filename); fd = g_file_open(filename);
if (fd == 0) if (fd == 0)
{ {
log_message(LOG_LEVEL_WARNING, "can't read vnc password file - %s", filename);
return 1; return 1;
} }
g_file_write(fd, encryptedPasswd, 8); g_file_write(fd, encryptedPasswd, 8);
@ -104,5 +92,9 @@ env_set_user(char* username, char* passwd_file, int display)
} }
} }
} }
else
{
log_message(LOG_LEVEL_ERROR, "error getting user info for user %s", username);
}
return error; return error;
} }

@ -28,7 +28,7 @@ int g_sck;
int g_pid; int g_pid;
unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 };
struct session_item g_session_items[100]; /* sesman.h */ struct session_item g_session_items[100]; /* sesman.h */
struct sesman_config g_cfg; /* config.h */ struct config_sesman g_cfg; /* config.h */
/******************************************************************************/ /******************************************************************************/
static void DEFAULT_CC static void DEFAULT_CC
@ -75,6 +75,27 @@ main(int argc, char** argv)
struct session_item* s_item; struct session_item* s_item;
long data; long data;
if (0 != config_read(&g_cfg))
{
g_printf("error reading config. quitting.\n\r");
return 1;
}
error = log_start(g_cfg.log.program_name, g_cfg.log.log_file, g_cfg.log.log_level,
g_cfg.log.enable_syslog, g_cfg.log.syslog_level);
if (error != LOG_STARTUP_OK)
{
switch (error)
{
case LOG_ERROR_MALLOC:
g_printf("error on malloc. cannot start logging. quitting.\n\r");
case LOG_ERROR_FILE_OPEN:
g_printf("error opening log file. quitting.\n\r");
}
return 1;
}
/* start of daemonizing code */ /* start of daemonizing code */
g_pid = g_fork(); g_pid = g_fork();
@ -92,12 +113,6 @@ main(int argc, char** argv)
g_file_open("/dev/null"); g_file_open("/dev/null");
/* end of daemonizing code */ /* end of daemonizing code */
if (0 != config_read(&g_cfg))
{
g_printf("sesman: error reading config. quitting.\n\r");
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 */
@ -111,7 +126,8 @@ main(int argc, char** argv)
init_stream(in_s, 8192); init_stream(in_s, 8192);
make_stream(out_s); make_stream(out_s);
init_stream(out_s, 8192); init_stream(out_s, 8192);
g_printf("listening\n");
log_message(LOG_LEVEL_INFO, "listening...");
g_sck = g_tcp_socket(); g_sck = g_tcp_socket();
g_tcp_set_non_blocking(g_sck); g_tcp_set_non_blocking(g_sck);
error = g_tcp_bind(g_sck, g_cfg.listen_port); error = g_tcp_bind(g_sck, g_cfg.listen_port);
@ -196,13 +212,12 @@ main(int argc, char** argv)
} }
else else
{ {
g_printf("listen error\n"); log_message(LOG_LEVEL_ERROR, "listen error");
} }
} }
else else
{ {
g_printf("bind error\n"); log_message(LOG_LEVEL_ERROR, "bind error");
perror("ilbind ");
} }
g_tcp_close(g_sck); g_tcp_close(g_sck);
free_stream(in_s); free_stream(in_s);

@ -26,6 +26,7 @@
#include "arch.h" #include "arch.h"
#include "parse.h" #include "parse.h"
#include "os_calls.h" #include "os_calls.h"
#include "log.h"
#include "env.h" #include "env.h"
#include "auth.h" #include "auth.h"
#include "config.h" #include "config.h"

@ -3,3 +3,9 @@ ListenPort=3350
EnableUserWindowManager=1 EnableUserWindowManager=1
UserWindowManager=startwm.sh UserWindowManager=startwm.sh
DefaultWindowManager=startwm.sh DefaultWindowManager=startwm.sh
[Logging]
LogFile=/usr/local/xrdp/sesman.log
LogLevel=DEBUG
EnableSyslog=0
SyslogLevel=DEBUG

@ -25,7 +25,7 @@
int g_sck; int g_sck;
int g_pid; int g_pid;
struct sesman_config g_cfg; /* config.h */ struct config_sesman g_cfg; /* config.h */
/******************************************************************************/ /******************************************************************************/
int DEFAULT_CC int DEFAULT_CC

@ -21,16 +21,11 @@
*/ */
//#include "d3des.h"
//#include "arch.h"
//#include "os_calls.h"
#include "sesman.h" #include "sesman.h"
//#include "config.h"
//#include "env.h"
extern unsigned char g_fixedkey[8]; extern unsigned char g_fixedkey[8];
extern struct session_item g_session_items[100]; /* sesman.h */ extern struct session_item g_session_items[100]; /* sesman.h */
extern struct sesman_config g_cfg; /* config.h */ extern struct config_sesman g_cfg; /* config.h */
/******************************************************************************/ /******************************************************************************/
struct session_item* DEFAULT_CC struct session_item* DEFAULT_CC
@ -126,11 +121,12 @@ session_start(int width, int height, int bpp, char* username, char* password,
so we try running the default window manager */ so we try running the default window manager */
g_sprintf(text, "%s/%s", cur_dir, g_cfg.default_wm); g_sprintf(text, "%s/%s", cur_dir, g_cfg.default_wm);
g_execlp3(text, g_cfg.default_wm, 0); g_execlp3(text, g_cfg.default_wm, 0);
/* still a problem starting window manager just start xterm */ /* still a problem starting window manager just start xterm */
g_execlp3("xterm", "xterm", 0); g_execlp3("xterm", "xterm", 0);
/* should not get here */ /* should not get here */
} }
g_printf("error starting window manager\n"); log_message(LOG_LEVEL_ALWAYS,"error starting window manager %s - pid %d", username, g_getpid());
g_exit(0); g_exit(0);
} }
else /* parent */ else /* parent */
@ -145,8 +141,9 @@ session_start(int width, int height, int bpp, char* username, char* password,
env_check_password_file(passwd_file, password); env_check_password_file(passwd_file, password);
g_execlp11("Xvnc", "Xvnc", screen, "-geometry", geometry, g_execlp11("Xvnc", "Xvnc", screen, "-geometry", geometry,
"-depth", depth, "-bs", "-rfbauth", passwd_file, 0); "-depth", depth, "-bs", "-rfbauth", passwd_file, 0);
/* should not get here */ /* should not get here */
g_printf("error\n"); log_message(LOG_LEVEL_ALWAYS,"error doing execve for user %s - pid %d",username,g_getpid());
g_exit(0); g_exit(0);
} }
else /* parent */ else /* parent */

@ -33,7 +33,7 @@
extern int g_sck; extern int g_sck;
extern int g_pid; extern int g_pid;
extern struct sesman_config g_cfg; extern struct config_sesman g_cfg;
/** /**
* *
@ -45,12 +45,16 @@ extern struct sesman_config g_cfg;
void DEFAULT_CC void DEFAULT_CC
sig_sesman_shutdown(int sig) sig_sesman_shutdown(int sig)
{ {
log_message(LOG_LEVEL_INFO, "shutting down sesman %d",1);
if (g_getpid() != g_pid) if (g_getpid() != g_pid)
{ {
LOG_DBG("g_getpid() [%d] differs from g_pid [%d]", (g_getpid()), g_pid);
return; return;
} }
g_printf("shutting down\n\r");
g_printf("signal %d pid %d\n\r", sig, g_getpid()); LOG_DBG(" - getting signal %d pid %d", sig, g_getpid());
g_tcp_close(g_sck); g_tcp_close(g_sck);
} }
@ -64,19 +68,23 @@ sig_sesman_shutdown(int sig)
void DEFAULT_CC void DEFAULT_CC
sig_sesman_reload_cfg(int sig) sig_sesman_reload_cfg(int sig)
{ {
struct sesman_config cfg; struct config_sesman cfg;
log_message(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1);
if (g_getpid() != g_pid) if (g_getpid() != g_pid)
{ {
LOG_DBG("g_getpid() [%d] differs from g_pid [%d]", g_getpid(), g_pid);
return; return;
} }
g_printf("sesman: received SIGHUP\n\r");
if (config_read(&cfg) != 0) if (config_read(&cfg) != 0)
{ {
g_printf("sesman: error reading config. keeping old cfg.\n\r"); log_message(LOG_LEVEL_ERROR, "error reading config - keeping old cfg");
return; return;
} }
g_cfg = cfg; g_cfg = cfg;
g_printf("sesman: configuration reloaded\n\r");
log_message(LOG_LEVEL_INFO, "configuration reloaded");
} }

Loading…
Cancel
Save