forked from neutrinolabs/xrdp
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
b4cb591
commit 5f9ea93
Showing
4 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |