2005-09-25 07:30:09 +04:00
|
|
|
/*
|
|
|
|
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.
|
2006-04-24 01:54:12 +04:00
|
|
|
Copyright (C) Jay Sorg 2005-2006
|
2005-09-25 07:30:09 +04:00
|
|
|
*/
|
|
|
|
|
2006-05-26 00:34:32 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @file config.c
|
|
|
|
* @brief User authentication code
|
|
|
|
* @author Simone Fedele @< simo [at] esseemme [dot] org @>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-19 04:37:49 +03:00
|
|
|
#include "arch.h"
|
2005-09-25 07:30:09 +04:00
|
|
|
#include "list.h"
|
|
|
|
#include "file.h"
|
2005-10-06 23:21:18 +04:00
|
|
|
#include "sesman.h"
|
2005-09-25 07:30:09 +04:00
|
|
|
|
2005-10-24 01:47:17 +04:00
|
|
|
/******************************************************************************/
|
2006-05-26 00:34:32 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Reads sesman configuration
|
|
|
|
* @param s translates the strings "1", "true" and "yes" in 1 (true) and other strings in 0
|
|
|
|
* @return 0 on success, 1 on failure
|
|
|
|
*
|
|
|
|
*/
|
2005-11-19 04:37:49 +03:00
|
|
|
static int APP_CC
|
|
|
|
text2bool(char* s)
|
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(s, "1") ||
|
|
|
|
0 == g_strcasecmp(s, "true") ||
|
|
|
|
0 == g_strcasecmp(s, "yes"))
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-25 07:30:09 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
int DEFAULT_CC
|
2005-10-24 01:47:17 +04:00
|
|
|
config_read(struct config_sesman* cfg)
|
2005-09-25 07:30:09 +04:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct list* sec;
|
|
|
|
struct list* param_n;
|
|
|
|
struct list* param_v;
|
|
|
|
|
|
|
|
fd = g_file_open(SESMAN_CFG_FILE);
|
|
|
|
if (-1 == fd)
|
|
|
|
{
|
2006-09-18 08:40:43 +04:00
|
|
|
log_message(LOG_LEVEL_ALWAYS, "error opening %s in \
|
|
|
|
config_read", SESMAN_CFG_FILE);
|
2005-09-25 07:30:09 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2005-10-24 01:47:17 +04:00
|
|
|
g_memset(cfg, 0, sizeof(struct config_sesman));
|
2005-09-25 07:30:09 +04:00
|
|
|
sec = list_create();
|
|
|
|
sec->auto_free = 1;
|
|
|
|
file_read_sections(fd, sec);
|
|
|
|
param_n = list_create();
|
|
|
|
param_n->auto_free = 1;
|
|
|
|
param_v = list_create();
|
|
|
|
param_v->auto_free = 1;
|
2005-10-24 01:47:17 +04:00
|
|
|
|
|
|
|
/* read global config */
|
|
|
|
config_read_globals(fd, cfg, param_n, param_v);
|
2005-11-19 04:37:49 +03:00
|
|
|
|
2005-10-24 01:47:17 +04:00
|
|
|
/* read logging config */
|
|
|
|
config_read_logging(fd, &(cfg->log), param_n, param_v);
|
2005-11-19 04:37:49 +03:00
|
|
|
|
2005-12-15 23:41:03 +03:00
|
|
|
/* read security config */
|
|
|
|
config_read_security(fd, &(cfg->sec), param_n, param_v);
|
|
|
|
|
2006-01-13 18:51:23 +03:00
|
|
|
/* read session config */
|
|
|
|
config_read_sessions(fd, &(cfg->sess), param_n, param_v);
|
|
|
|
|
2005-10-24 01:47:17 +04:00
|
|
|
/* cleanup */
|
|
|
|
list_delete(sec);
|
|
|
|
list_delete(param_v);
|
|
|
|
list_delete(param_n);
|
2006-09-18 08:40:43 +04:00
|
|
|
g_file_close(fd);
|
2005-10-24 01:47:17 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-19 04:37:49 +03:00
|
|
|
/******************************************************************************/
|
2005-10-24 01:47:17 +04:00
|
|
|
int DEFAULT_CC
|
2005-11-19 04:37:49 +03:00
|
|
|
config_read_globals(int file, struct config_sesman* cf, struct list* param_n,
|
|
|
|
struct list* param_v)
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char* buf;
|
|
|
|
|
|
|
|
list_clear(param_v);
|
|
|
|
list_clear(param_n);
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2005-12-15 23:41:03 +03:00
|
|
|
/* resetting the struct */
|
2006-04-24 01:54:12 +04:00
|
|
|
cf->listen_port[0] = '\0';
|
|
|
|
cf->enable_user_wm = 0;
|
|
|
|
cf->user_wm[0] = '\0';
|
|
|
|
cf->default_wm[0] = '\0';
|
2005-11-19 04:37:49 +03:00
|
|
|
|
2005-10-24 01:47:17 +04:00
|
|
|
file_read_section(file, SESMAN_CFG_GLOBALS, param_n, param_v);
|
2005-09-25 07:30:09 +04:00
|
|
|
for (i = 0; i < param_n->count; i++)
|
|
|
|
{
|
|
|
|
buf = (char*)list_get_item(param_n, i);
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_DEFWM))
|
2005-09-25 07:30:09 +04:00
|
|
|
{
|
2005-10-24 01:47:17 +04:00
|
|
|
g_strncpy(cf->default_wm, (char*)list_get_item(param_v, i), 31);
|
2005-09-25 07:30:09 +04:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_USERWM))
|
2005-09-25 07:30:09 +04:00
|
|
|
{
|
2005-10-24 01:47:17 +04:00
|
|
|
g_strncpy(cf->user_wm, (char*)list_get_item(param_v, i), 31);
|
2005-09-25 07:30:09 +04:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_ENABLE_USERWM))
|
2005-09-25 07:30:09 +04:00
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
cf->enable_user_wm = text2bool((char*)list_get_item(param_v, i));
|
2005-09-25 07:30:09 +04:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
else if (0 == g_strcasecmp(buf, SESMAN_CFG_PORT))
|
2005-09-25 07:30:09 +04:00
|
|
|
{
|
2005-10-24 01:47:17 +04:00
|
|
|
g_strncpy(cf->listen_port, (char*)list_get_item(param_v, i), 15);
|
2005-09-25 07:30:09 +04:00
|
|
|
}
|
|
|
|
}
|
2005-11-19 04:37:49 +03:00
|
|
|
|
2005-12-15 23:41:03 +03:00
|
|
|
/* checking for missing required parameters */
|
2006-04-24 01:54:12 +04:00
|
|
|
if ('\0' == cf->listen_port[0])
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
|
|
|
g_strncpy(cf->listen_port, "3350", 5);
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if ('\0' == cf->user_wm[0])
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
cf->enable_user_wm = 0;
|
2005-12-15 23:41:03 +03:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if ('\0' == cf->default_wm[0])
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
|
|
|
g_strncpy(cf->default_wm, "startwm.sh", 11);
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2005-12-15 23:41:03 +03:00
|
|
|
/* showing read config */
|
2005-11-19 04:37:49 +03:00
|
|
|
g_printf("sesman config:\r\n");
|
|
|
|
g_printf("\tListenPort: %s\r\n", cf->listen_port);
|
|
|
|
g_printf("\tEnableUserWindowManager: %i\r\n", cf->enable_user_wm);
|
|
|
|
g_printf("\tUserWindowManager: %s\r\n", cf->user_wm);
|
|
|
|
g_printf("\tDefaultWindowManager: %s\r\n", cf->default_wm);
|
|
|
|
|
2005-10-24 01:47:17 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-19 04:37:49 +03:00
|
|
|
/******************************************************************************/
|
2005-10-24 01:47:17 +04:00
|
|
|
int DEFAULT_CC
|
2005-11-19 04:37:49 +03:00
|
|
|
config_read_logging(int file, struct log_config* lc, struct list* param_n,
|
|
|
|
struct list* param_v)
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
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;
|
2005-11-19 04:37:49 +03:00
|
|
|
|
2005-10-24 01:47:17 +04:00
|
|
|
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);
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_FILE))
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
lc->log_file = g_strdup((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_LEVEL))
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
lc->log_level = log_text2level((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_ENABLE_SYSLOG))
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
lc->enable_syslog = text2bool((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_LOG_SYSLOG_LEVEL))
|
2005-10-24 01:47:17 +04:00
|
|
|
{
|
|
|
|
lc->syslog_level = log_text2level((char*)list_get_item(param_v, i));
|
|
|
|
}
|
|
|
|
}
|
2005-11-19 04:37:49 +03:00
|
|
|
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == lc->log_file)
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
|
|
|
lc->log_file=g_strdup("./sesman.log");
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2005-11-19 04:37:49 +03:00
|
|
|
g_printf("logging configuration:\r\n");
|
|
|
|
g_printf("\tLogFile: %s\r\n",lc->log_file);
|
|
|
|
g_printf("\tLogLevel: %i\r\n", lc->log_level);
|
|
|
|
g_printf("\tEnableSyslog: %i\r\n", lc->enable_syslog);
|
|
|
|
g_printf("\tSyslogLevel: %i\r\n", lc->syslog_level);
|
|
|
|
|
2005-09-25 07:30:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2005-10-24 01:47:17 +04:00
|
|
|
|
2005-12-15 23:41:03 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
int DEFAULT_CC
|
2006-04-24 01:54:12 +04:00
|
|
|
config_read_security(int file, struct config_security* sc,
|
|
|
|
struct list* param_n,
|
|
|
|
struct list* param_v)
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-04-24 01:54:12 +04:00
|
|
|
int gid;
|
2005-12-15 23:41:03 +03:00
|
|
|
char* buf;
|
|
|
|
|
|
|
|
list_clear(param_v);
|
|
|
|
list_clear(param_n);
|
|
|
|
|
|
|
|
/* setting defaults */
|
2006-04-24 01:54:12 +04:00
|
|
|
sc->allow_root = 0;
|
|
|
|
sc->ts_users_enable = 0;
|
|
|
|
sc->ts_admins_enable = 0;
|
2005-12-15 23:41:03 +03:00
|
|
|
|
|
|
|
file_read_section(file, SESMAN_CFG_SECURITY, param_n, param_v);
|
|
|
|
for (i = 0; i < param_n->count; i++)
|
|
|
|
{
|
|
|
|
buf = (char*)list_get_item(param_n, i);
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ALLOW_ROOT))
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
|
|
|
sc->allow_root = text2bool((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_USR_GROUP))
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
if (g_getgroup_info((char*)list_get_item(param_v, i), &gid) == 0)
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
sc->ts_users_enable = 1;
|
|
|
|
sc->ts_users = gid;
|
2006-01-13 18:51:23 +03:00
|
|
|
}
|
2005-12-15 23:41:03 +03:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SEC_ADM_GROUP))
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
if (g_getgroup_info((char*)list_get_item(param_v, i), &gid) == 0)
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
2006-04-24 01:54:12 +04:00
|
|
|
sc->ts_admins_enable = 1;
|
|
|
|
sc->ts_admins = gid;
|
2006-01-13 18:51:23 +03:00
|
|
|
}
|
2005-12-15 23:41:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* printing security config */
|
|
|
|
g_printf("security configuration:\r\n");
|
|
|
|
g_printf("\tAllowRootLogin: %i\r\n",sc->allow_root);
|
|
|
|
if (sc->ts_users_enable)
|
|
|
|
{
|
|
|
|
g_printf("\tTSUsersGroup: %i\r\n", sc->ts_users);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_printf("\tNo TSUsersGroup defined\r\n");
|
|
|
|
}
|
|
|
|
if (sc->ts_admins_enable)
|
|
|
|
{
|
|
|
|
g_printf("\tTSAdminsGroup: %i\r\n", sc->ts_admins);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_printf("\tNo TSAdminsGroup defined\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-13 18:51:23 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
int DEFAULT_CC
|
|
|
|
config_read_sessions(int file, struct config_sessions* se, struct list* param_n,
|
|
|
|
struct list* param_v)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char* buf;
|
|
|
|
|
|
|
|
list_clear(param_v);
|
|
|
|
list_clear(param_n);
|
|
|
|
|
|
|
|
/* setting defaults */
|
|
|
|
se->max_sessions=0;
|
|
|
|
se->max_idle_time=0;
|
|
|
|
se->max_disc_time=0;
|
|
|
|
se->kill_disconnected=0;
|
|
|
|
|
|
|
|
file_read_section(file, SESMAN_CFG_SESSIONS, param_n, param_v);
|
|
|
|
for (i = 0; i < param_n->count; i++)
|
|
|
|
{
|
|
|
|
buf = (char*)list_get_item(param_n, i);
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_MAX))
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
|
|
|
se->max_sessions = g_atoi((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_KILL_DISC))
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
|
|
|
se->kill_disconnected = text2bool((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_IDLE_LIMIT))
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
|
|
|
se->max_idle_time=g_atoi((char*)list_get_item(param_v, i));
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
if (0 == g_strcasecmp(buf, SESMAN_CFG_SESS_DISC_LIMIT))
|
2006-01-13 18:51:23 +03:00
|
|
|
{
|
|
|
|
se->max_disc_time=g_atoi((char*)list_get_item(param_v, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* printing security config */
|
|
|
|
g_printf("session configuration:\r\n");
|
|
|
|
g_printf("\tMaxSessions: %i\r\n", se->max_sessions);
|
|
|
|
g_printf("\tKillDisconnected: %i\r\n", se->kill_disconnected);
|
|
|
|
g_printf("\tIdleTimeLimit: %i\r\n", se->max_idle_time);
|
|
|
|
g_printf("\tDisconnectedTimeLimit: %i\r\n", se->max_idle_time);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-18 08:40:43 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
/* returns in params a list of parameters that need to be freed */
|
|
|
|
/* returns error */
|
|
|
|
int DEFAULT_CC
|
|
|
|
config_read_xserver_params(int server_type, struct list* param_array)
|
|
|
|
{
|
|
|
|
struct list* names;
|
|
|
|
struct list* params;
|
|
|
|
int fd;
|
|
|
|
char section_name[16];
|
|
|
|
|
|
|
|
if (server_type == SESMAN_SESSION_TYPE_XRDP)
|
|
|
|
{
|
|
|
|
g_strncpy(section_name, "X11rdp", 15);
|
|
|
|
}
|
|
|
|
else if (server_type == SESMAN_SESSION_TYPE_XVNC)
|
|
|
|
{
|
|
|
|
g_strncpy(section_name, "Xvnc", 15);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "error unknown type in \
|
|
|
|
config_read_xserver_params");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
fd = g_file_open(SESMAN_CFG_FILE);
|
|
|
|
if (-1 == fd)
|
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
log_message(LOG_LEVEL_ALWAYS, "error opening %s in \
|
|
|
|
config_read_xserver_params %s", SESMAN_CFG_FILE, g_get_strerror());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
names = list_create();
|
|
|
|
names->auto_free = 1;
|
|
|
|
params = list_create();
|
|
|
|
params->auto_free = 1;
|
|
|
|
if (file_read_section(fd, section_name, names, params) == 0)
|
|
|
|
{
|
|
|
|
list_append_list_strdup(params, param_array, 0);
|
|
|
|
}
|
|
|
|
g_file_close(fd);
|
|
|
|
list_delete(names);
|
|
|
|
list_delete(params);
|
|
|
|
return 0;
|
|
|
|
}
|