2012-09-20 07:51:34 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2015-12-12 07:41:17 +03:00
|
|
|
* Copyright (C) Jay Sorg 2004-2015
|
2012-09-20 07:51:34 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2005-01-30 07:34:19 +03:00
|
|
|
|
2006-05-26 00:34:32 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @file sesman.c
|
|
|
|
* @brief Main program file
|
|
|
|
* @author Jay Sorg
|
2008-07-30 14:58:30 +04:00
|
|
|
*
|
2006-05-26 00:34:32 +04:00
|
|
|
*/
|
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-09-25 07:30:09 +04:00
|
|
|
#include "sesman.h"
|
2020-06-22 12:27:54 +03:00
|
|
|
#include "xrdp_configure_options.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2022-02-14 12:16:42 +03:00
|
|
|
#include "trans.h"
|
|
|
|
|
|
|
|
#include "scp_process.h"
|
2022-03-19 14:29:28 +03:00
|
|
|
#include "lock_uds.h"
|
2020-06-22 12:27:54 +03:00
|
|
|
|
2021-07-19 12:21:20 +03:00
|
|
|
/**
|
|
|
|
* Maximum number of short-lived connections to sesman
|
|
|
|
*
|
|
|
|
* At the moment, all connections to sesman are short-lived. This may change
|
|
|
|
* in the future
|
|
|
|
*/
|
|
|
|
#define MAX_SHORT_LIVED_CONNECTIONS 16
|
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
struct sesman_startup_params
|
|
|
|
{
|
|
|
|
const char *sesman_ini;
|
|
|
|
int kill;
|
|
|
|
int no_daemon;
|
|
|
|
int help;
|
|
|
|
int version;
|
2020-12-28 14:03:36 +03:00
|
|
|
int dump_config;
|
2020-06-22 12:27:54 +03:00
|
|
|
};
|
2005-11-14 01:06:49 +03:00
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
struct config_sesman *g_cfg;
|
2005-10-06 23:21:18 +04:00
|
|
|
unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 };
|
2015-12-12 07:41:17 +03:00
|
|
|
tintptr g_term_event = 0;
|
2022-03-03 18:37:46 +03:00
|
|
|
tintptr g_sigchld_event = 0;
|
|
|
|
tintptr g_reload_event = 0;
|
2005-01-30 07:34:19 +03:00
|
|
|
|
2021-06-22 15:38:46 +03:00
|
|
|
/**
|
|
|
|
* Items stored on the g_con_list
|
|
|
|
*/
|
|
|
|
struct sesman_con
|
|
|
|
{
|
|
|
|
struct trans *t;
|
|
|
|
};
|
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
static struct trans *g_list_trans;
|
2022-03-19 14:29:28 +03:00
|
|
|
|
|
|
|
/* Variables used to lock g_list_trans */
|
|
|
|
static struct lock_uds *g_list_trans_lock;
|
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
static struct list *g_con_list = NULL;
|
2022-03-03 18:37:46 +03:00
|
|
|
static int g_pid;
|
2020-06-10 11:20:27 +03:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/**
|
|
|
|
* @brief looks for a case-insensitive match of a string in a list
|
|
|
|
* @param candidate String to match
|
|
|
|
* @param ... NULL-terminated list of strings to compare the candidate with
|
|
|
|
* @return !=0 if the candidate is found in the list
|
|
|
|
*/
|
|
|
|
static int nocase_matches(const char *candidate, ...)
|
|
|
|
{
|
|
|
|
va_list vl;
|
|
|
|
const char *member;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
va_start(vl, candidate);
|
|
|
|
while ((member = va_arg(vl, const char *)) != NULL)
|
|
|
|
{
|
|
|
|
if (g_strcasecmp(candidate, member) == 0)
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end(vl);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-06-22 15:38:46 +03:00
|
|
|
/**
|
|
|
|
* Allocates a sesman_con struct
|
|
|
|
*
|
|
|
|
* @param trans Pointer to newly-allocated transport
|
|
|
|
* @return struct sesman_con pointer
|
|
|
|
*/
|
|
|
|
static struct sesman_con *
|
|
|
|
alloc_connection(struct trans *t)
|
|
|
|
{
|
|
|
|
struct sesman_con *result;
|
|
|
|
|
|
|
|
if ((result = g_new(struct sesman_con, 1)) != NULL)
|
|
|
|
{
|
2022-02-14 12:16:42 +03:00
|
|
|
result->t = t;
|
2021-06-22 15:38:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a sesman_con struct, freeing resources
|
|
|
|
*
|
|
|
|
* After this call, the passed-in pointer is invalid and must not be
|
|
|
|
* referenced.
|
|
|
|
*
|
|
|
|
* @param sc struct to de-allocate
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
delete_connection(struct sesman_con *sc)
|
|
|
|
{
|
|
|
|
trans_delete(sc->t);
|
|
|
|
g_free(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Command line argument parser
|
|
|
|
* @param[in] argc number of command line arguments
|
|
|
|
* @param[in] argv pointer array of commandline arguments
|
|
|
|
* @param[out] sesman_startup_params Returned startup parameters
|
|
|
|
* @return 0 on success, n on nth argument is unknown
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
sesman_process_params(int argc, char **argv,
|
|
|
|
struct sesman_startup_params *startup_params)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
const char *option;
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
index = 1;
|
|
|
|
|
|
|
|
while (index < argc)
|
|
|
|
{
|
|
|
|
option = argv[index];
|
|
|
|
|
|
|
|
if (index + 1 < argc)
|
|
|
|
{
|
|
|
|
value = argv[index + 1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nocase_matches(option, "-help", "--help", "-h", NULL))
|
|
|
|
{
|
|
|
|
startup_params->help = 1;
|
|
|
|
}
|
|
|
|
else if (nocase_matches(option, "-kill", "--kill", "-k", NULL))
|
|
|
|
{
|
|
|
|
startup_params->kill = 1;
|
|
|
|
}
|
|
|
|
else if (nocase_matches(option, "-nodaemon", "--nodaemon", "-n",
|
|
|
|
"-nd", "--nd", "-ns", "--ns", NULL))
|
|
|
|
{
|
|
|
|
startup_params->no_daemon = 1;
|
|
|
|
}
|
|
|
|
else if (nocase_matches(option, "-v", "--version", NULL))
|
|
|
|
{
|
|
|
|
startup_params->version = 1;
|
|
|
|
}
|
2020-12-28 14:03:36 +03:00
|
|
|
else if (nocase_matches(option, "--dump-config", NULL))
|
|
|
|
{
|
|
|
|
startup_params->dump_config = 1;
|
|
|
|
}
|
2020-06-22 12:27:54 +03:00
|
|
|
else if (nocase_matches(option, "-c", "--config", NULL))
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
startup_params->sesman_ini = value;
|
|
|
|
}
|
|
|
|
else /* unknown option */
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-17 10:23:30 +03:00
|
|
|
/******************************************************************************/
|
2022-03-19 14:29:28 +03:00
|
|
|
static int
|
|
|
|
create_sesman_runtime_dir(void)
|
2017-05-17 10:23:30 +03:00
|
|
|
{
|
2022-03-19 14:29:28 +03:00
|
|
|
int rv = -1;
|
|
|
|
/* Make sure if we create the directory, there's no gap where it
|
|
|
|
* may have the wrong permissions */
|
|
|
|
int entry_umask = g_umask_hex(0x755);
|
2017-05-17 10:23:30 +03:00
|
|
|
|
2022-03-19 14:29:28 +03:00
|
|
|
if (!g_directory_exist(SESMAN_RUNTIME_PATH) &&
|
|
|
|
!g_create_dir(SESMAN_RUNTIME_PATH))
|
2017-05-17 10:23:30 +03:00
|
|
|
{
|
2022-03-19 14:29:28 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Can't create runtime directory '"
|
|
|
|
SESMAN_RUNTIME_PATH "' [%s]", g_get_strerror());
|
2017-05-17 10:23:30 +03:00
|
|
|
}
|
2022-03-19 14:29:28 +03:00
|
|
|
else if (g_chown(SESMAN_RUNTIME_PATH, g_getuid(), g_getuid()) != 0)
|
2017-05-17 10:23:30 +03:00
|
|
|
{
|
2022-03-19 14:29:28 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Can't set ownership of sesman runtime directory [%s]",
|
|
|
|
g_get_strerror());
|
|
|
|
}
|
|
|
|
else if (g_chmod_hex(SESMAN_RUNTIME_PATH, 0x755) != 0)
|
|
|
|
{
|
|
|
|
/* This might seem redundant, but there's a chance the
|
|
|
|
* directory already exists */
|
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Can't set permissions of sesman runtime directory [%s]",
|
|
|
|
g_get_strerror());
|
2017-05-17 10:23:30 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-19 14:29:28 +03:00
|
|
|
rv = 0;
|
2017-05-17 10:23:30 +03:00
|
|
|
}
|
2022-03-19 14:29:28 +03:00
|
|
|
g_umask_hex(entry_umask);
|
2017-05-17 10:23:30 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
|
2022-03-19 14:29:28 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
static int sesman_listen_test(struct config_sesman *cfg)
|
|
|
|
{
|
|
|
|
int status = sesman_create_listening_transport(cfg);
|
|
|
|
sesman_delete_listening_transport();
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
int
|
|
|
|
sesman_close_all(void)
|
|
|
|
{
|
|
|
|
int index;
|
2021-06-22 15:38:46 +03:00
|
|
|
struct sesman_con *sc;
|
2020-06-10 11:20:27 +03:00
|
|
|
|
2020-08-07 23:56:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "sesman_close_all:");
|
2022-03-03 18:37:46 +03:00
|
|
|
sesman_delete_listening_transport();
|
2020-06-10 11:20:27 +03:00
|
|
|
for (index = 0; index < g_con_list->count; index++)
|
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
sc = (struct sesman_con *) list_get_item(g_con_list, index);
|
|
|
|
delete_connection(sc);
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
static int
|
|
|
|
sesman_data_in(struct trans *self)
|
|
|
|
{
|
2022-02-14 12:16:42 +03:00
|
|
|
int rv;
|
|
|
|
int available;
|
2020-06-10 11:20:27 +03:00
|
|
|
|
2022-02-14 12:16:42 +03:00
|
|
|
rv = scp_msg_in_check_available(self, &available);
|
|
|
|
|
|
|
|
if (rv == 0 && available)
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
2022-02-14 12:16:42 +03:00
|
|
|
if ((rv = scp_process(self)) != 0)
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
2020-08-07 23:56:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_data_in: scp_process_msg failed");
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
2022-02-14 12:16:42 +03:00
|
|
|
scp_msg_in_reset(self);
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
2022-02-14 12:16:42 +03:00
|
|
|
|
|
|
|
return rv;
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
static int
|
|
|
|
sesman_listen_conn_in(struct trans *self, struct trans *new_self)
|
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
struct sesman_con *sc;
|
2021-07-19 12:21:20 +03:00
|
|
|
if (g_con_list->count >= MAX_SHORT_LIVED_CONNECTIONS)
|
2021-06-22 15:38:46 +03:00
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_data_in: error, too many "
|
|
|
|
"connections, rejecting");
|
|
|
|
trans_delete(new_self);
|
|
|
|
}
|
2022-02-14 12:16:42 +03:00
|
|
|
else if ((sc = alloc_connection(new_self)) == NULL ||
|
|
|
|
scp_init_trans(new_self) != 0)
|
2021-06-22 15:38:46 +03:00
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_data_in: No memory to allocate "
|
|
|
|
"new connection");
|
|
|
|
trans_delete(new_self);
|
|
|
|
}
|
|
|
|
else
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
2022-02-14 12:16:42 +03:00
|
|
|
new_self->callback_data = (void *)sc;
|
2020-06-10 11:20:27 +03:00
|
|
|
new_self->trans_data_in = sesman_data_in;
|
2021-06-22 15:38:46 +03:00
|
|
|
list_add_item(g_con_list, (intptr_t) sc);
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
2021-06-22 15:38:46 +03:00
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
/******************************************************************************/
|
|
|
|
/**
|
|
|
|
* Informs the main loop a termination signal has been received
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_term_event(int sig)
|
|
|
|
{
|
|
|
|
/* Don't try to use a wait obj in a child process */
|
|
|
|
if (g_getpid() == g_pid)
|
|
|
|
{
|
|
|
|
g_set_wait_obj(g_term_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/**
|
|
|
|
* Informs the main loop a SIGCHLD has been received
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_sigchld_event(int sig)
|
|
|
|
{
|
|
|
|
/* Don't try to use a wait obj in a child process */
|
|
|
|
if (g_getpid() == g_pid)
|
|
|
|
{
|
|
|
|
g_set_wait_obj(g_sigchld_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/**
|
|
|
|
* Informs the main loop a SIGHUP has been received
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_reload_event(int sig)
|
|
|
|
{
|
|
|
|
/* Don't try to use a wait obj in a child process */
|
|
|
|
if (g_getpid() == g_pid)
|
|
|
|
{
|
|
|
|
g_set_wait_obj(g_reload_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
void
|
|
|
|
sesman_delete_listening_transport(void)
|
|
|
|
{
|
2022-03-19 14:29:28 +03:00
|
|
|
if (g_getpid() == g_pid)
|
|
|
|
{
|
|
|
|
trans_delete(g_list_trans);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trans_delete_from_child(g_list_trans);
|
|
|
|
}
|
2022-03-03 18:37:46 +03:00
|
|
|
g_list_trans = NULL;
|
2022-03-19 14:29:28 +03:00
|
|
|
|
|
|
|
unlock_uds(g_list_trans_lock);
|
|
|
|
g_list_trans_lock = NULL;
|
2022-03-03 18:37:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
int
|
|
|
|
sesman_create_listening_transport(const struct config_sesman *cfg)
|
|
|
|
{
|
|
|
|
int rv = 1;
|
2022-03-19 14:29:28 +03:00
|
|
|
g_list_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
|
2022-03-03 18:37:46 +03:00
|
|
|
if (g_list_trans == NULL)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "%s: trans_create failed", __func__);
|
|
|
|
}
|
2022-03-19 14:29:28 +03:00
|
|
|
else if ((g_list_trans_lock = lock_uds(cfg->listen_port)) != NULL)
|
2022-03-03 18:37:46 +03:00
|
|
|
{
|
2022-03-19 14:29:28 +03:00
|
|
|
/* Make sure the file is always created with the correct
|
|
|
|
* permissions, if it's not there */
|
|
|
|
int entry_umask = g_umask_hex(0x666);
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "%s: port %s", __func__, cfg->listen_port);
|
|
|
|
rv = trans_listen_address(g_list_trans, cfg->listen_port, NULL);
|
2022-03-03 18:37:46 +03:00
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "%s: trans_listen_address failed", __func__);
|
2022-03-19 14:29:28 +03:00
|
|
|
}
|
|
|
|
else if (g_chown(cfg->listen_port, g_getuid(), g_getuid()) != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Can't set ownership of '%s' [%s]",
|
|
|
|
cfg->listen_port, g_get_strerror());
|
|
|
|
}
|
|
|
|
else if ((rv = g_chmod_hex(cfg->listen_port, 0x666)) != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "%s: Can't set permissions on '%s' [%s]",
|
|
|
|
__func__, cfg->listen_port, g_get_strerror());
|
2022-03-03 18:37:46 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_list_trans->trans_conn_in = sesman_listen_conn_in;
|
|
|
|
}
|
2022-03-19 14:29:28 +03:00
|
|
|
g_umask_hex(entry_umask);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
sesman_delete_listening_transport();
|
2022-03-03 18:37:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-05-26 00:34:32 +04:00
|
|
|
/******************************************************************************/
|
2005-11-14 01:06:49 +03:00
|
|
|
/**
|
|
|
|
*
|
2006-05-26 00:34:32 +04:00
|
|
|
* @brief Starts sesman main loop
|
2005-11-14 01:06:49 +03:00
|
|
|
*
|
|
|
|
*/
|
2020-06-22 12:27:54 +03:00
|
|
|
static int
|
2006-08-24 09:58:10 +04:00
|
|
|
sesman_main_loop(void)
|
2005-01-30 07:34:19 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int error;
|
|
|
|
int robjs_count;
|
2020-06-10 11:20:27 +03:00
|
|
|
int wobjs_count;
|
|
|
|
int timeout;
|
|
|
|
int index;
|
|
|
|
intptr_t robjs[32];
|
|
|
|
intptr_t wobjs[32];
|
2021-06-22 15:38:46 +03:00
|
|
|
struct sesman_con *scon;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
g_con_list = list_create();
|
|
|
|
if (g_con_list == NULL)
|
2014-07-27 00:33:23 +04:00
|
|
|
{
|
2020-08-07 23:56:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: list_create failed");
|
2017-05-17 10:23:30 +03:00
|
|
|
return 1;
|
2014-07-27 00:33:23 +04:00
|
|
|
}
|
2022-03-03 18:37:46 +03:00
|
|
|
if (sesman_create_listening_transport(g_cfg) != 0)
|
2005-01-30 07:34:19 +03:00
|
|
|
{
|
2022-03-03 18:37:46 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"sesman_main_loop: sesman_create_listening_transport failed");
|
2020-06-10 11:20:27 +03:00
|
|
|
list_delete(g_con_list);
|
|
|
|
return 1;
|
|
|
|
}
|
2022-03-19 14:29:28 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Sesman now listening on %s", g_cfg->listen_port);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
error = 0;
|
|
|
|
while (!error)
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
|
|
|
timeout = -1;
|
|
|
|
robjs_count = 0;
|
|
|
|
robjs[robjs_count++] = g_term_event;
|
2022-03-03 18:37:46 +03:00
|
|
|
robjs[robjs_count++] = g_sigchld_event;
|
|
|
|
robjs[robjs_count++] = g_reload_event;
|
2020-06-10 11:20:27 +03:00
|
|
|
wobjs_count = 0;
|
|
|
|
for (index = 0; index < g_con_list->count; index++)
|
2009-01-12 09:43:58 +03:00
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
scon = (struct sesman_con *)list_get_item(g_con_list, index);
|
|
|
|
if (scon != NULL)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
error = trans_get_wait_objs_rw(scon->t,
|
|
|
|
robjs, &robjs_count,
|
2020-06-10 11:20:27 +03:00
|
|
|
wobjs, &wobjs_count, &timeout);
|
|
|
|
if (error != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-08-07 23:56:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
|
|
|
|
"trans_get_wait_objs_rw failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-03-03 18:37:46 +03:00
|
|
|
if (g_list_trans != NULL)
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
2022-03-03 18:37:46 +03:00
|
|
|
/* g_list_trans might be NULL on a reconfigure if sesman
|
|
|
|
* is unable to listen again */
|
|
|
|
error = trans_get_wait_objs_rw(g_list_trans, robjs, &robjs_count,
|
|
|
|
wobjs, &wobjs_count, &timeout);
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
|
|
|
|
"trans_get_wait_objs_rw failed");
|
|
|
|
break;
|
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
}
|
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0)
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
2022-03-03 18:37:46 +03:00
|
|
|
/* should not get here */
|
|
|
|
LOG(LOG_LEVEL_WARNING, "sesman_main_loop: "
|
|
|
|
"Unexpected error from g_obj_wait()");
|
2020-06-10 11:20:27 +03:00
|
|
|
g_sleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_is_wait_obj_set(g_term_event)) /* term */
|
|
|
|
{
|
2022-03-03 18:37:46 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "sesman_main_loop: "
|
|
|
|
"sesman asked to terminate");
|
2020-06-10 11:20:27 +03:00
|
|
|
break;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
if (g_is_wait_obj_set(g_sigchld_event)) /* A child has exited */
|
|
|
|
{
|
|
|
|
g_reset_wait_obj(g_sigchld_event);
|
|
|
|
sig_sesman_session_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_is_wait_obj_set(g_reload_event)) /* We're asked to reload */
|
|
|
|
{
|
|
|
|
g_reset_wait_obj(g_reload_event);
|
|
|
|
sig_sesman_reload_cfg();
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:20:27 +03:00
|
|
|
for (index = 0; index < g_con_list->count; index++)
|
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
scon = (struct sesman_con *)list_get_item(g_con_list, index);
|
|
|
|
if (scon != NULL)
|
2020-06-10 11:20:27 +03:00
|
|
|
{
|
2022-03-03 18:37:46 +03:00
|
|
|
if (trans_check_wait_objs(scon->t) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-08-07 23:56:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
|
|
|
|
"trans_check_wait_objs failed, removing trans");
|
2021-06-22 15:38:46 +03:00
|
|
|
delete_connection(scon);
|
2020-06-10 11:20:27 +03:00
|
|
|
list_remove_item(g_con_list, index);
|
|
|
|
index--;
|
|
|
|
continue;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
2009-01-12 09:43:58 +03:00
|
|
|
}
|
2022-03-03 18:37:46 +03:00
|
|
|
|
|
|
|
if (g_list_trans != NULL)
|
2005-10-09 23:53:51 +04:00
|
|
|
{
|
2022-03-03 18:37:46 +03:00
|
|
|
error = trans_check_wait_objs(g_list_trans);
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "sesman_main_loop: "
|
|
|
|
"trans_check_wait_objs failed");
|
|
|
|
break;
|
|
|
|
}
|
2005-01-30 07:34:19 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
for (index = 0; index < g_con_list->count; index++)
|
2005-01-30 07:34:19 +03:00
|
|
|
{
|
2021-06-22 15:38:46 +03:00
|
|
|
scon = (struct sesman_con *) list_get_item(g_con_list, index);
|
|
|
|
delete_connection(scon);
|
2005-01-30 07:34:19 +03:00
|
|
|
}
|
2020-06-10 11:20:27 +03:00
|
|
|
list_delete(g_con_list);
|
2022-03-03 18:37:46 +03:00
|
|
|
sesman_delete_listening_transport();
|
2020-06-10 11:20:27 +03:00
|
|
|
return 0;
|
2005-11-14 01:06:49 +03:00
|
|
|
}
|
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
|
|
print_version(void)
|
|
|
|
{
|
|
|
|
g_writeln("xrdp-sesman %s", PACKAGE_VERSION);
|
|
|
|
g_writeln(" The xrdp session manager");
|
|
|
|
g_writeln(" Copyright (C) 2004-2020 Jay Sorg, "
|
|
|
|
"Neutrino Labs, and all contributors.");
|
|
|
|
g_writeln(" See https://github.com/neutrinolabs/xrdp for more information.");
|
|
|
|
g_writeln("%s", "");
|
|
|
|
|
|
|
|
#if defined(XRDP_CONFIGURE_OPTIONS)
|
|
|
|
g_writeln(" Configure options:");
|
|
|
|
g_writeln("%s", XRDP_CONFIGURE_OPTIONS);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-16 09:30:37 +03:00
|
|
|
/******************************************************************************/
|
2020-06-22 12:27:54 +03:00
|
|
|
static void
|
|
|
|
print_help(void)
|
2017-01-16 09:30:37 +03:00
|
|
|
{
|
|
|
|
g_printf("Usage: xrdp-sesman [options]\n");
|
2020-12-28 14:03:36 +03:00
|
|
|
g_printf(" -k, --kill shut down xrdp-sesman\n");
|
|
|
|
g_printf(" -h, --help show help\n");
|
|
|
|
g_printf(" -v, --version show version\n");
|
|
|
|
g_printf(" -n, --nodaemon don't fork into background\n");
|
|
|
|
g_printf(" -c, --config specify new path to sesman.ini\n");
|
|
|
|
g_writeln(" --dump-config display config on stdout on startup");
|
2017-01-16 09:30:37 +03:00
|
|
|
g_deinit();
|
|
|
|
}
|
|
|
|
|
2005-11-14 01:06:49 +03:00
|
|
|
/******************************************************************************/
|
2020-06-22 12:27:54 +03:00
|
|
|
static int
|
|
|
|
kill_running_sesman(const char *pid_file)
|
2005-11-14 01:06:49 +03:00
|
|
|
{
|
2016-03-17 00:32:14 +03:00
|
|
|
int error;
|
2020-06-22 12:27:54 +03:00
|
|
|
int fd;
|
2012-09-20 07:51:34 +04:00
|
|
|
int pid;
|
2020-06-22 12:27:54 +03:00
|
|
|
char pid_s[32] = {0};
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
/* check if sesman is running */
|
|
|
|
if (!g_file_exist(pid_file))
|
|
|
|
{
|
|
|
|
g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
|
|
|
|
g_deinit();
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
fd = g_file_open(pid_file);
|
|
|
|
|
|
|
|
if (-1 == fd)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-06-22 12:27:54 +03:00
|
|
|
g_printf("error opening pid file[%s]: %s\n", pid_file, g_get_strerror());
|
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2020-06-22 12:27:54 +03:00
|
|
|
|
|
|
|
error = g_file_read(fd, pid_s, sizeof(pid_s) - 1);
|
|
|
|
|
|
|
|
if (-1 == error)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-06-22 12:27:54 +03:00
|
|
|
g_printf("error reading pid file: %s\n", g_get_strerror());
|
|
|
|
g_file_close(fd);
|
|
|
|
g_deinit();
|
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2020-06-22 12:27:54 +03:00
|
|
|
|
|
|
|
g_file_close(fd);
|
|
|
|
pid = g_atoi(pid_s);
|
|
|
|
|
|
|
|
error = g_sigterm(pid);
|
|
|
|
|
|
|
|
if (0 != error)
|
2005-11-16 15:27:08 +03:00
|
|
|
{
|
2020-06-22 12:27:54 +03:00
|
|
|
g_printf("error killing sesman: %s\n", g_get_strerror());
|
2005-11-16 15:27:08 +03:00
|
|
|
}
|
2020-06-22 12:27:54 +03:00
|
|
|
else
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-06-22 12:27:54 +03:00
|
|
|
g_file_delete(pid_file);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
g_deinit();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
/******************************************************************************/
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
enum logReturns log_error;
|
|
|
|
char text[256];
|
|
|
|
char pid_file[256];
|
|
|
|
char default_sesman_ini[256];
|
|
|
|
struct sesman_startup_params startup_params = {0};
|
|
|
|
int errored_argc;
|
|
|
|
int daemon;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
g_init("xrdp-sesman");
|
|
|
|
g_snprintf(pid_file, 255, "%s/xrdp-sesman.pid", XRDP_PID_PATH);
|
|
|
|
g_snprintf(default_sesman_ini, 255, "%s/sesman.ini", XRDP_CFG_PATH);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
startup_params.sesman_ini = default_sesman_ini;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
errored_argc = sesman_process_params(argc, argv, &startup_params);
|
|
|
|
if (errored_argc > 0)
|
|
|
|
{
|
|
|
|
print_version();
|
|
|
|
g_writeln("%s", "");
|
|
|
|
print_help();
|
|
|
|
g_writeln("%s", "");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
g_writeln("Unknown option: %s", argv[errored_argc]);
|
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
if (startup_params.help)
|
|
|
|
{
|
|
|
|
print_help();
|
|
|
|
g_exit(0);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
if (startup_params.version)
|
|
|
|
{
|
|
|
|
print_version();
|
|
|
|
g_exit(0);
|
|
|
|
}
|
2005-11-14 01:06:49 +03:00
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
|
|
|
|
if (startup_params.kill)
|
|
|
|
{
|
|
|
|
g_exit(kill_running_sesman(pid_file));
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2020-06-22 12:27:54 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_file_exist(pid_file))
|
2006-09-18 08:40:43 +04:00
|
|
|
{
|
2017-01-16 09:30:37 +03:00
|
|
|
g_printf("xrdp-sesman is already running.\n");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_printf("if it's not running, try removing ");
|
2016-03-28 20:55:20 +03:00
|
|
|
g_printf("%s", pid_file);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_printf("\n");
|
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
2006-09-18 08:40:43 +04:00
|
|
|
}
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2022-03-25 16:29:44 +03:00
|
|
|
/* starting logging subsystem */
|
|
|
|
if (!g_file_exist(startup_params.sesman_ini))
|
2005-12-15 23:41:03 +03:00
|
|
|
{
|
2022-03-25 16:29:44 +03:00
|
|
|
g_printf("Config file %s does not exist\n", startup_params.sesman_ini);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
2005-12-15 23:41:03 +03:00
|
|
|
}
|
2022-03-03 18:37:09 +03:00
|
|
|
log_error = log_start(
|
|
|
|
startup_params.sesman_ini, "xrdp-sesman",
|
|
|
|
(startup_params.dump_config) ? LOG_START_DUMP_CONFIG : 0);
|
2006-04-24 01:54:12 +04:00
|
|
|
|
2016-03-17 00:32:14 +03:00
|
|
|
if (log_error != LOG_STARTUP_OK)
|
2005-11-14 01:06:49 +03:00
|
|
|
{
|
2016-03-17 00:32:14 +03:00
|
|
|
switch (log_error)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
case LOG_ERROR_MALLOC:
|
|
|
|
g_writeln("error on malloc. cannot start logging. quitting.");
|
|
|
|
break;
|
|
|
|
case LOG_ERROR_FILE_OPEN:
|
|
|
|
g_writeln("error opening log file [%s]. quitting.",
|
|
|
|
getLogFile(text, 255));
|
|
|
|
break;
|
2015-12-12 07:41:17 +03:00
|
|
|
default:
|
2022-03-25 16:29:44 +03:00
|
|
|
// Assume sufficient messages have already been generated
|
2015-12-12 07:41:17 +03:00
|
|
|
break;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2006-08-24 09:58:10 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
|
|
|
}
|
2007-05-07 01:02:25 +04:00
|
|
|
|
2022-03-25 16:29:44 +03:00
|
|
|
/* reading config */
|
|
|
|
if ((g_cfg = config_read(startup_params.sesman_ini)) == NULL)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ALWAYS, "error reading config %s: %s",
|
|
|
|
startup_params.sesman_ini, g_get_strerror());
|
|
|
|
log_end();
|
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startup_params.dump_config)
|
|
|
|
{
|
|
|
|
config_dump(g_cfg);
|
|
|
|
}
|
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_TRACE, "config loaded in %s at %s:%d", __func__, __FILE__, __LINE__);
|
2020-06-22 12:27:54 +03:00
|
|
|
LOG(LOG_LEVEL_TRACE, " sesman_ini = %s", g_cfg->sesman_ini);
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_TRACE, " listen_port = %s", g_cfg->listen_port);
|
|
|
|
LOG(LOG_LEVEL_TRACE, " enable_user_wm = %d", g_cfg->enable_user_wm);
|
|
|
|
LOG(LOG_LEVEL_TRACE, " default_wm = %s", g_cfg->default_wm);
|
|
|
|
LOG(LOG_LEVEL_TRACE, " user_wm = %s", g_cfg->user_wm);
|
|
|
|
LOG(LOG_LEVEL_TRACE, " reconnect_sh = %s", g_cfg->reconnect_sh);
|
|
|
|
LOG(LOG_LEVEL_TRACE, " auth_file_path = %s", g_cfg->auth_file_path);
|
2019-10-16 23:53:22 +03:00
|
|
|
|
2020-12-28 14:03:36 +03:00
|
|
|
daemon = !startup_params.no_daemon;
|
2018-06-01 16:44:51 +03:00
|
|
|
if (daemon)
|
|
|
|
{
|
|
|
|
/* not to spit on the console, shut up stdout/stderr before anything's logged */
|
|
|
|
g_file_close(0);
|
|
|
|
g_file_close(1);
|
|
|
|
g_file_close(2);
|
2019-10-16 23:53:22 +03:00
|
|
|
|
|
|
|
if (g_file_open("/dev/null") < 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_file_open("/dev/null") < 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_file_open("/dev/null") < 0)
|
|
|
|
{
|
|
|
|
}
|
2018-06-01 16:44:51 +03:00
|
|
|
}
|
|
|
|
|
2022-03-19 14:29:28 +03:00
|
|
|
/* Create the runtime directory before we try to listen (or
|
|
|
|
* test-listen), so there's somewhere for the default socket to live */
|
|
|
|
if (create_sesman_runtime_dir() != 0)
|
|
|
|
{
|
|
|
|
config_free(g_cfg);
|
|
|
|
log_end();
|
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (daemon)
|
2005-11-14 01:06:49 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
/* start of daemonizing code */
|
2017-12-27 18:00:18 +03:00
|
|
|
if (sesman_listen_test(g_cfg) != 0)
|
2018-01-09 08:09:13 +03:00
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Failed to start xrdp-sesman daemon, "
|
|
|
|
"possibly address already in use.");
|
2020-06-22 12:27:54 +03:00
|
|
|
config_free(g_cfg);
|
2022-03-19 14:29:28 +03:00
|
|
|
log_end();
|
2017-12-27 18:00:18 +03:00
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
|
|
|
}
|
2017-05-17 10:23:30 +03:00
|
|
|
|
2017-12-27 18:00:18 +03:00
|
|
|
if (0 != g_fork())
|
|
|
|
{
|
2020-06-22 12:27:54 +03:00
|
|
|
config_free(g_cfg);
|
2022-03-19 14:29:28 +03:00
|
|
|
log_end();
|
2012-09-20 07:51:34 +04:00
|
|
|
g_deinit();
|
|
|
|
g_exit(0);
|
|
|
|
}
|
|
|
|
|
2005-11-14 01:06:49 +03:00
|
|
|
}
|
2006-08-24 09:58:10 +04:00
|
|
|
|
2022-03-19 14:29:28 +03:00
|
|
|
/* Now we've forked (if necessary), we can get the prgram PID */
|
2012-09-20 07:51:34 +04:00
|
|
|
g_pid = g_getpid();
|
2022-03-19 14:29:28 +03:00
|
|
|
|
|
|
|
/* signal handling */
|
2022-03-03 18:37:46 +03:00
|
|
|
g_snprintf(text, 255, "xrdp_sesman_%8.8x_main_term", g_pid);
|
|
|
|
g_term_event = g_create_wait_obj(text);
|
|
|
|
g_snprintf(text, 255, "xrdp_sesman_%8.8x_sigchld", g_pid);
|
|
|
|
g_sigchld_event = g_create_wait_obj(text);
|
|
|
|
g_snprintf(text, 255, "xrdp_sesman_%8.8x_reload", g_pid);
|
|
|
|
g_reload_event = g_create_wait_obj(text);
|
|
|
|
|
|
|
|
g_signal_hang_up(set_reload_event); /* SIGHUP */
|
|
|
|
g_signal_user_interrupt(set_term_event); /* SIGINT */
|
|
|
|
g_signal_terminate(set_term_event); /* SIGTERM */
|
|
|
|
g_signal_child_stop(set_sigchld_event); /* SIGCHLD */
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (daemon)
|
2008-12-26 05:20:03 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
/* writing pid file */
|
2020-06-22 12:27:54 +03:00
|
|
|
char pid_s[32];
|
|
|
|
int fd = g_file_open(pid_file);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (-1 == fd)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"error opening pid file[%s]: %s",
|
|
|
|
pid_file, g_get_strerror());
|
2012-09-20 07:51:34 +04:00
|
|
|
log_end();
|
2020-06-22 12:27:54 +03:00
|
|
|
config_free(g_cfg);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_deinit();
|
|
|
|
g_exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_sprintf(pid_s, "%d", g_pid);
|
|
|
|
g_file_write(fd, pid_s, g_strlen(pid_s));
|
|
|
|
g_file_close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start program main loop */
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_INFO,
|
|
|
|
"starting xrdp-sesman with pid %d", g_pid);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2017-07-12 09:48:28 +03:00
|
|
|
/* make sure the socket directory exists */
|
2017-07-13 19:01:07 +03:00
|
|
|
g_mk_socket_path("xrdp-sesman");
|
2017-07-12 09:48:28 +03:00
|
|
|
|
2017-07-12 09:56:40 +03:00
|
|
|
/* make sure the /tmp/.X11-unix directory exists */
|
2012-09-20 07:51:34 +04:00
|
|
|
if (!g_directory_exist("/tmp/.X11-unix"))
|
|
|
|
{
|
2014-07-20 00:06:25 +04:00
|
|
|
if (!g_create_dir("/tmp/.X11-unix"))
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
2014-07-20 00:06:25 +04:00
|
|
|
"sesman.c: error creating dir /tmp/.X11-unix");
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
g_chmod_hex("/tmp/.X11-unix", 0x1777);
|
2008-12-26 05:20:03 +03:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2017-05-17 10:23:30 +03:00
|
|
|
error = sesman_main_loop();
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* clean up PID file on exit */
|
|
|
|
if (daemon)
|
|
|
|
{
|
|
|
|
g_file_delete(pid_file);
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:37:46 +03:00
|
|
|
g_delete_wait_obj(g_reload_event);
|
|
|
|
g_delete_wait_obj(g_sigchld_event);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_delete_wait_obj(g_term_event);
|
|
|
|
|
|
|
|
if (!daemon)
|
|
|
|
{
|
|
|
|
log_end();
|
|
|
|
}
|
|
|
|
|
2020-06-22 12:27:54 +03:00
|
|
|
config_free(g_cfg);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_deinit();
|
2017-05-17 10:23:30 +03:00
|
|
|
g_exit(error);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-01-30 07:34:19 +03:00
|
|
|
}
|