Skip to content

Commit

Permalink
Add sesman restart module
Browse files Browse the repository at this point in the history
Adds a module which can be used when sesman is restarting. This is
initially used to rediscover sessions from a previous run.
  • Loading branch information
matt335672 committed Dec 2, 2024
1 parent b4cb591 commit 5f9ea93
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sesman/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ xrdp_sesman_SOURCES = \
sesexec_control.h \
session_list.c \
session_list.h \
sesman_restart.c \
sesman_restart.h \
sig.c \
sig.h

Expand Down
4 changes: 3 additions & 1 deletion sesman/sesman.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "scp.h"
#include "scp_process.h"
#include "sesexec_control.h"
#include "sesman_restart.h"
#include "sig.h"
#include "string_calls.h"
#include "trans.h"
Expand Down Expand Up @@ -940,7 +941,8 @@ main(int argc, char **argv)
}

if ((error = pre_session_list_init(MAX_PRE_SESSION_ITEMS)) == 0 &&
(error = session_list_init()) == 0)
(error = session_list_init()) == 0 &&
(error = sesman_restart_discover_sessions()) == 0)
{
error = sesman_main_loop();
}
Expand Down
91 changes: 91 additions & 0 deletions sesman/sesman_restart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Matt Burt 2024
*
* 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.
*/

/**
*
* @file sesman_restart.c
* @brief Sesman restart definitions
* @author Matt Burt
*
*/

#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif

#include <stdio.h>

#include "os_calls.h"
#include "sesman.h"
#include "sesman_config.h"

#include "sesman_restart.h"
#include "xrdp_sockets.h"

/******************************************************************************/
static int
create_restart_directory(const char *listen_port)
{
int rv = 1;
// The restart directory contains Unix Domain sockets, so can't
// exceed XRDP_SOCKETS_MAXPATH in length
char restart_dir[XRDP_SOCKETS_MAXPATH];
// Allow some overhead for the names of the directory entries
#define MAX_LISTEN_PORT_LEN (XRDP_SOCKETS_MAXPATH - 10)

if (strlen(listen_port) > MAX_LISTEN_PORT_LEN)
{
LOG(LOG_LEVEL_ERROR, "Listen port string length must be <= %d",
MAX_LISTEN_PORT_LEN);
}
else
{
snprintf(restart_dir, sizeof(restart_dir), "%s.r", listen_port);
(void)g_mkdir(restart_dir); // Directory may already exist
if (!g_directory_exist(restart_dir))
{
LOG(LOG_LEVEL_ERROR, "Can't create restart directory %s",
restart_dir);
}
else if (g_chown(restart_dir, g_getuid(), g_getuid()) != 0)
{
LOG(LOG_LEVEL_ERROR, "Can't set ownership of '%s' [%s]",
restart_dir, g_get_strerror());
}
else if ((rv = g_chmod_hex(restart_dir, 0x700)) != 0)
{
LOG(LOG_LEVEL_ERROR, "%s: Can't set permissions on '%s' [%s]",
__func__, restart_dir, g_get_strerror());
}
else
{
rv = 0;
}
}

return rv;
#undef MAX_LISTEN_PORT_LEN
}

/******************************************************************************/
int
sesman_restart_discover_sessions(void)
{
// Needs lots of work!
return create_restart_directory(g_cfg->listen_port);
}
40 changes: 40 additions & 0 deletions sesman/sesman_restart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Matt Burt 2024
*
* 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.
*/

/**
*
* @file sesman_restart.h
* @brief Sesman restart declarations
* @author Matt Burt
*
*/


#ifndef SESMAN_RESTART_H
#define SESMAN_RESTART_H

/**
* Discover sessions from a previous sesman run
* @return 0 for success
*
* Errors are logged
*/
int
sesman_restart_discover_sessions(void);

#endif // SESMAN_RESTART_H

0 comments on commit 5f9ea93

Please sign in to comment.