Skip to content

Commit 2d541d0

Browse files
committed
Add CCP support to sesexec
sesexec can now tell the xrdp process to exit, and is aware when the xrdp process exits.
1 parent 15899ce commit 2d541d0

File tree

6 files changed

+406
-12
lines changed

6 files changed

+406
-12
lines changed

sesman/sesexec/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ xrdp_sesexec_SOURCES = \
2121
sesexec.h \
2222
session.c \
2323
session.h \
24+
ccp_server.c \
25+
ccp_server.h \
2426
eicp_server.c \
2527
eicp_server.h \
2628
ercp_server.c \

sesman/sesexec/ccp_server.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* xrdp: A Remote Desktop Protocol server.
3+
*
4+
* Copyright (C) Jay Sorg 2004-2023
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
*
21+
* @file eicp_server.c
22+
* @brief eicp (executive initialisation control protocol) server function
23+
* @author Matt Burt
24+
*
25+
*/
26+
27+
#if defined(HAVE_CONFIG_H)
28+
#include <config_ac.h>
29+
#endif
30+
31+
#include "trans.h"
32+
33+
#include "ccp.h"
34+
#include "ccp_server.h"
35+
36+
/******************************************************************************/
37+
int
38+
ccp_server(struct trans *self)
39+
{
40+
int rv = 0;
41+
enum ccp_msg_code msgno;
42+
43+
switch ((msgno = ccp_msg_in_get_msgno(self)))
44+
{
45+
default:
46+
{
47+
char buff[64];
48+
ccp_msgno_to_str(msgno, buff, sizeof(buff));
49+
LOG(LOG_LEVEL_ERROR, "Ignored CCP message %s", buff);
50+
}
51+
}
52+
return rv;
53+
}

sesman/sesexec/ccp_server.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* xrdp: A Remote Desktop Protocol server.
3+
*
4+
* Copyright (C) Jay Sorg 2004-2023
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
*
21+
* @file ccp_server.h
22+
* @brief ccp (connection control protocol) server function
23+
* @author Matt Burt
24+
*
25+
*/
26+
27+
#ifndef CCP_SERVER_H
28+
#define CCP_SERVER_H
29+
30+
/**
31+
*
32+
* @brief Processes an CCP message
33+
* @param self The CCP transport the message is coming in on
34+
*
35+
*/
36+
int
37+
ccp_server(struct trans *self);
38+
39+
#endif // CCP_SERVER_H

sesman/sesexec/ercp_server.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,33 @@ handle_connect_session_request(struct trans *self)
8787
}
8888
else
8989
{
90-
scp_fd = -1; // Don't close this twice!
90+
// Ownership of the file descriptor is passed to scp_trans;
91+
// don't delete it separately.
92+
scp_fd = -1;
9193

9294
// Now we've got a transport we can send data back to
9395
// the SCP client
9496
enum scp_sconnect_status scp_status;
9597
int display_fd = -1;
9698
int chan_fd = -1;
99+
100+
// Terminate any existing xrdp process to sesexec
101+
if (g_ccp_trans != NULL)
102+
{
103+
sesexec_terminate_connected_xrdp_process(
104+
CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION);
105+
g_sleep(500);
106+
}
97107
scp_status = get_session_fds(g_session_data, scp_flags,
98108
&display_fd, &chan_fd);
109+
110+
// Tell sesman about the new client connection
111+
if (g_ecp_trans != NULL)
112+
{
113+
/// TODO: client connect event
114+
}
115+
116+
// Pass the session file descriptors to the client
99117
rv = scp_send_connect_session_response(scp_trans, scp_status,
100118
display_fd, chan_fd);
101119

@@ -120,10 +138,17 @@ handle_connect_session_request(struct trans *self)
120138
session_run_reconnect_script(g_login_info,
121139
g_session_data);
122140
}
141+
142+
// Convert the SCP transport to a CCP transport, and
143+
// record it
144+
if (sesexec_set_ccp_trans(scp_trans) == 0)
145+
{
146+
scp_trans = NULL; // Prevent transport being deleted.
147+
}
123148
}
124149

125-
// Regardless of the result of the send, we must close all
126-
// our copies of file descriptors.
150+
// Close all our copies of file descriptors, including the
151+
// SCP transport if we failed to convert it to a CCP transport
127152
if (display_fd >= 0)
128153
{
129154
g_file_close(display_fd);
@@ -132,7 +157,10 @@ handle_connect_session_request(struct trans *self)
132157
{
133158
g_file_close(chan_fd);
134159
}
135-
trans_delete(scp_trans);
160+
if (scp_trans != NULL)
161+
{
162+
trans_delete(scp_trans);
163+
}
136164
}
137165
}
138166

0 commit comments

Comments
 (0)