2012-07-25 06:16:00 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2013-04-01 05:06:33 +04:00
|
|
|
* Copyright (C) Jay Sorg 2009-2013
|
2012-09-28 06:48:44 +04:00
|
|
|
* Copyright (C) Laxmikant Rashinkar 2009-2012
|
2012-07-25 06:16:00 +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.
|
|
|
|
*/
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2024-04-17 08:56:52 +03:00
|
|
|
#ifdef XRDP_IBUS
|
|
|
|
#include "input.h"
|
|
|
|
#endif
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
#include "arch.h"
|
|
|
|
#include "os_calls.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2009-04-19 21:16:46 +04:00
|
|
|
#include "thread_calls.h"
|
|
|
|
#include "trans.h"
|
|
|
|
#include "chansrv.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "sound.h"
|
2009-04-22 08:34:45 +04:00
|
|
|
#include "clipboard.h"
|
|
|
|
#include "devredir.h"
|
2009-09-06 09:58:26 +04:00
|
|
|
#include "list.h"
|
|
|
|
#include "file.h"
|
2012-07-27 01:38:02 +04:00
|
|
|
#include "log.h"
|
|
|
|
#include "rail.h"
|
|
|
|
#include "xcommon.h"
|
2012-10-30 07:12:24 +04:00
|
|
|
#include "chansrv_fuse.h"
|
2020-07-06 13:53:56 +03:00
|
|
|
#include "chansrv_config.h"
|
2017-03-18 20:15:50 +03:00
|
|
|
#include "xrdp_sockets.h"
|
2019-07-04 07:31:52 +03:00
|
|
|
#include "audin.h"
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2020-04-27 17:01:56 +03:00
|
|
|
#include "ms-rdpbcgr.h"
|
|
|
|
|
2020-04-18 18:56:53 +03:00
|
|
|
#define MAX_PATH 260
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
static struct trans *g_lis_trans = 0;
|
|
|
|
static struct trans *g_con_trans = 0;
|
|
|
|
static struct trans *g_api_lis_trans = 0;
|
2014-08-13 21:10:04 +04:00
|
|
|
static struct list *g_api_con_trans_list = 0; /* list of apps using api functions */
|
2009-04-19 21:16:46 +04:00
|
|
|
static struct chan_item g_chan_items[32];
|
|
|
|
static int g_num_chan_items = 0;
|
2009-04-22 08:34:45 +04:00
|
|
|
static int g_cliprdr_index = -1;
|
|
|
|
static int g_rdpsnd_index = -1;
|
|
|
|
static int g_rdpdr_index = -1;
|
2012-07-27 01:38:02 +04:00
|
|
|
static int g_rail_index = -1;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2009-09-02 06:52:30 +04:00
|
|
|
static tbus g_term_event = 0;
|
2023-05-15 16:16:29 +03:00
|
|
|
static tintptr g_sigchld_event = 0;
|
2009-09-02 06:52:30 +04:00
|
|
|
static tbus g_thread_done_event = 0;
|
|
|
|
|
2020-07-06 13:53:56 +03:00
|
|
|
struct config_chansrv *g_cfg = NULL;
|
2009-09-06 09:58:26 +04:00
|
|
|
|
2021-03-31 13:31:41 +03:00
|
|
|
int g_display_num = -1;
|
2009-04-22 08:34:45 +04:00
|
|
|
int g_cliprdr_chan_id = -1; /* cliprdr */
|
2012-09-28 06:48:44 +04:00
|
|
|
int g_rdpsnd_chan_id = -1; /* rdpsnd */
|
|
|
|
int g_rdpdr_chan_id = -1; /* rdpdr */
|
|
|
|
int g_rail_chan_id = -1; /* rail */
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
char *g_exec_name;
|
2020-07-06 13:53:56 +03:00
|
|
|
tbus g_exec_event = 0;
|
2012-08-01 03:54:54 +04:00
|
|
|
tbus g_exec_mutex;
|
|
|
|
tbus g_exec_sem;
|
2012-08-03 09:34:00 +04:00
|
|
|
int g_exec_pid = 0;
|
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
#define ARRAYSIZE(x) (sizeof(x)/sizeof(*(x)))
|
2018-10-12 08:09:20 +03:00
|
|
|
/* max total channel bytes size */
|
|
|
|
#define MAX_CHANNEL_BYTES (1 * 1024 * 1024 * 1024) /* 1 GB */
|
|
|
|
#define MAX_CHANNEL_FRAG_BYTES 1600
|
|
|
|
|
|
|
|
#define CHANSRV_DRDYNVC_STATUS_CLOSED 0
|
|
|
|
#define CHANSRV_DRDYNVC_STATUS_OPEN_SENT 1
|
|
|
|
#define CHANSRV_DRDYNVC_STATUS_OPEN 2
|
|
|
|
#define CHANSRV_DRDYNVC_STATUS_CLOSE_SENT 3
|
|
|
|
|
|
|
|
struct chansrv_drdynvc
|
|
|
|
{
|
|
|
|
int chan_id;
|
|
|
|
int status; /* see CHANSRV_DRDYNVC_STATUS_* */
|
|
|
|
int flags;
|
|
|
|
int pad0;
|
|
|
|
int (*open_response)(int chan_id, int creation_status);
|
|
|
|
int (*close_response)(int chan_id);
|
|
|
|
int (*data_first)(int chan_id, char *data, int bytes, int total_bytes);
|
|
|
|
int (*data)(int chan_id, char *data, int bytes);
|
|
|
|
struct trans *xrdp_api_trans;
|
|
|
|
};
|
2013-08-08 08:02:22 +04:00
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
static struct chansrv_drdynvc g_drdynvcs[256];
|
|
|
|
|
|
|
|
/* data in struct trans::callback_data */
|
|
|
|
struct xrdp_api_data
|
|
|
|
{
|
|
|
|
int chan_flags;
|
|
|
|
int chan_id;
|
|
|
|
};
|
2012-08-01 03:54:54 +04:00
|
|
|
|
2013-09-08 10:54:36 +04:00
|
|
|
struct timeout_obj
|
|
|
|
{
|
2013-07-06 19:42:05 +04:00
|
|
|
tui32 mstime;
|
2013-09-26 22:28:07 +04:00
|
|
|
void *data;
|
|
|
|
void (*callback)(void *data);
|
|
|
|
struct timeout_obj *next;
|
2013-09-08 10:54:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct timeout_obj *g_timeout_head = 0;
|
|
|
|
static struct timeout_obj *g_timeout_tail = 0;
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2013-09-08 10:54:36 +04:00
|
|
|
add_timeout(int msoffset, void (*callback)(void *data), void *data)
|
|
|
|
{
|
|
|
|
struct timeout_obj *tobj;
|
|
|
|
tui32 now;
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "add_timeout:");
|
2013-09-08 10:54:36 +04:00
|
|
|
now = g_time3();
|
2016-06-22 02:30:18 +03:00
|
|
|
tobj = g_new0(struct timeout_obj, 1);
|
2013-09-08 10:54:36 +04:00
|
|
|
tobj->mstime = now + msoffset;
|
|
|
|
tobj->callback = callback;
|
|
|
|
tobj->data = data;
|
|
|
|
if (g_timeout_tail == 0)
|
|
|
|
{
|
|
|
|
g_timeout_head = tobj;
|
|
|
|
g_timeout_tail = tobj;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_timeout_tail->next = tobj;
|
|
|
|
g_timeout_tail = tobj;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2013-09-08 10:54:36 +04:00
|
|
|
get_timeout(int *timeout)
|
|
|
|
{
|
|
|
|
struct timeout_obj *tobj;
|
|
|
|
tui32 now;
|
|
|
|
int ltimeout;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "get_timeout:");
|
2013-09-08 10:54:36 +04:00
|
|
|
ltimeout = *timeout;
|
|
|
|
if (ltimeout < 1)
|
|
|
|
{
|
|
|
|
ltimeout = 0;
|
|
|
|
}
|
|
|
|
tobj = g_timeout_head;
|
|
|
|
if (tobj != 0)
|
|
|
|
{
|
|
|
|
now = g_time3();
|
|
|
|
while (tobj != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " now %u tobj->mstime %u", now, tobj->mstime);
|
2013-09-08 10:54:36 +04:00
|
|
|
if (now < tobj->mstime)
|
|
|
|
{
|
|
|
|
ltimeout = tobj->mstime - now;
|
|
|
|
}
|
|
|
|
tobj = tobj->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ltimeout > 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " ltimeout %d", ltimeout);
|
2013-09-08 10:54:36 +04:00
|
|
|
if (*timeout < 1)
|
|
|
|
{
|
|
|
|
*timeout = ltimeout;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*timeout > ltimeout)
|
|
|
|
{
|
|
|
|
*timeout = ltimeout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2013-09-08 10:54:36 +04:00
|
|
|
check_timeout(void)
|
|
|
|
{
|
|
|
|
struct timeout_obj *tobj;
|
|
|
|
struct timeout_obj *last_tobj;
|
|
|
|
struct timeout_obj *temp_tobj;
|
|
|
|
int count;
|
|
|
|
tui32 now;
|
2022-09-01 06:19:32 +03:00
|
|
|
UNUSED_VAR(count);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "check_timeout:");
|
2013-09-08 10:54:36 +04:00
|
|
|
count = 0;
|
|
|
|
tobj = g_timeout_head;
|
|
|
|
if (tobj != 0)
|
|
|
|
{
|
|
|
|
last_tobj = 0;
|
|
|
|
while (tobj != 0)
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
now = g_time3();
|
|
|
|
if (now >= tobj->mstime)
|
|
|
|
{
|
|
|
|
tobj->callback(tobj->data);
|
|
|
|
if (last_tobj == 0)
|
|
|
|
{
|
|
|
|
g_timeout_head = tobj->next;
|
|
|
|
if (g_timeout_head == 0)
|
|
|
|
{
|
|
|
|
g_timeout_tail = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last_tobj->next = tobj->next;
|
|
|
|
if (g_timeout_tail == tobj)
|
|
|
|
{
|
|
|
|
g_timeout_tail = last_tobj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp_tobj = tobj;
|
|
|
|
tobj = tobj->next;
|
|
|
|
g_free(temp_tobj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last_tobj = tobj;
|
|
|
|
tobj = tobj->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " count %d", count);
|
2013-09-08 10:54:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-18 00:32:53 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2013-08-18 00:32:53 +04:00
|
|
|
g_is_term(void)
|
|
|
|
{
|
|
|
|
return g_is_wait_obj_set(g_term_event);
|
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
2018-10-12 08:09:20 +03:00
|
|
|
/* send data to a static virtual channel
|
|
|
|
size can be > MAX_CHANNEL_FRAG_BYTES, in which case, > 1 message
|
|
|
|
will be sent*/
|
2009-04-19 21:16:46 +04:00
|
|
|
/* returns error */
|
2018-10-12 08:09:20 +03:00
|
|
|
int
|
|
|
|
send_channel_data(int chan_id, const char *data, int size)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
int sending_bytes;
|
2012-09-20 07:51:34 +04:00
|
|
|
int chan_flags;
|
|
|
|
int error;
|
2018-10-12 08:09:20 +03:00
|
|
|
int total_size;
|
|
|
|
struct stream *s;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
if ((chan_id < 0) || (chan_id > 31) ||
|
2020-11-30 03:36:20 +03:00
|
|
|
(data == NULL) ||
|
|
|
|
(size < 1) || (size > MAX_CHANNEL_BYTES))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
/* bad param */
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
total_size = size;
|
|
|
|
chan_flags = 1; /* first */
|
|
|
|
while (size > 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
sending_bytes = MIN(MAX_CHANNEL_FRAG_BYTES, size);
|
|
|
|
if (sending_bytes >= size)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
chan_flags |= 2; /* last */
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
s = trans_get_out_s(g_con_trans, 26 + sending_bytes);
|
|
|
|
if (s == NULL)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
return 2;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 26 + sending_bytes);
|
|
|
|
out_uint32_le(s, 8); /* msg id */
|
|
|
|
out_uint32_le(s, 18 + sending_bytes);
|
|
|
|
out_uint16_le(s, chan_id);
|
|
|
|
out_uint16_le(s, chan_flags);
|
|
|
|
out_uint16_le(s, sending_bytes);
|
|
|
|
out_uint32_le(s, total_size);
|
|
|
|
out_uint8a(s, data, sending_bytes);
|
|
|
|
s_mark_end(s);
|
|
|
|
size -= sending_bytes;
|
|
|
|
data += sending_bytes;
|
|
|
|
error = trans_write_copy(g_con_trans);
|
|
|
|
if (error != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
return 3;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
chan_flags = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2013-06-30 23:36:01 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2020-11-30 03:36:20 +03:00
|
|
|
send_rail_drawing_orders(char *data, int size)
|
2013-06-30 23:36:01 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "chansrv::send_rail_drawing_orders: size %d", size);
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
struct stream *s;
|
2013-06-30 23:36:01 +04:00
|
|
|
int error;
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2013-06-30 23:36:01 +04:00
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
2023-03-05 08:38:43 +03:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2013-06-30 23:36:01 +04:00
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8 + size); /* size */
|
|
|
|
out_uint32_le(s, 10); /* msg id */
|
|
|
|
out_uint32_le(s, 8 + size); /* size */
|
|
|
|
out_uint8a(s, data, size);
|
|
|
|
s_mark_end(s);
|
|
|
|
error = trans_force_write(g_con_trans);
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
process_message_channel_setup(struct stream *s)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int num_chans;
|
|
|
|
int index;
|
|
|
|
int rv;
|
|
|
|
struct chan_item *ci;
|
|
|
|
|
|
|
|
g_num_chan_items = 0;
|
|
|
|
g_cliprdr_index = -1;
|
|
|
|
g_rdpsnd_index = -1;
|
|
|
|
g_rdpdr_index = -1;
|
|
|
|
g_rail_index = -1;
|
|
|
|
g_cliprdr_chan_id = -1;
|
|
|
|
g_rdpsnd_chan_id = -1;
|
|
|
|
g_rdpdr_chan_id = -1;
|
|
|
|
g_rail_chan_id = -1;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_channel_setup:");
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, num_chans);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_channel_setup: num_chans %d",
|
2020-11-30 03:36:20 +03:00
|
|
|
num_chans);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
for (index = 0; index < num_chans; index++)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
ci = &(g_chan_items[g_num_chan_items]);
|
|
|
|
g_memset(ci->name, 0, sizeof(ci->name));
|
|
|
|
in_uint8a(s, ci->name, 8);
|
|
|
|
in_uint16_le(s, ci->id);
|
|
|
|
in_uint16_le(s, ci->flags);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' "
|
2020-11-30 03:36:20 +03:00
|
|
|
"id %d flags %8.8x", ci->name, ci->id, ci->flags);
|
2012-10-05 09:55:06 +04:00
|
|
|
|
2021-06-07 19:26:56 +03:00
|
|
|
if (g_strcasecmp(ci->name, CLIPRDR_SVC_CHANNEL_NAME) == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
g_cliprdr_index = g_num_chan_items;
|
|
|
|
g_cliprdr_chan_id = ci->id;
|
|
|
|
}
|
2021-06-07 19:26:56 +03:00
|
|
|
else if (g_strcasecmp(ci->name, RDPSND_SVC_CHANNEL_NAME) == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
g_rdpsnd_index = g_num_chan_items;
|
|
|
|
g_rdpsnd_chan_id = ci->id;
|
|
|
|
}
|
2021-06-07 19:26:56 +03:00
|
|
|
else if (g_strcasecmp(ci->name, RDPDR_SVC_CHANNEL_NAME) == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
g_rdpdr_index = g_num_chan_items;
|
|
|
|
g_rdpdr_chan_id = ci->id;
|
|
|
|
}
|
2013-12-17 08:16:15 +04:00
|
|
|
/* disabled for now */
|
2021-06-07 19:26:56 +03:00
|
|
|
else if (g_strcasecmp(ci->name, RAIL_SVC_CHANNEL_NAME) == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
g_rail_index = g_num_chan_items;
|
|
|
|
g_rail_chan_id = ci->id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "other %s", ci->name);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_num_chan_items++;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
rv = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_cliprdr_index >= 0)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_init();
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_init();
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_rdpsnd_index >= 0)
|
2009-04-22 08:34:45 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
sound_init();
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_rdpdr_index >= 0)
|
2012-07-27 01:38:02 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_init();
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_init();
|
2012-07-27 01:38:02 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_rail_index >= 0)
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
rail_init();
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2019-07-04 07:31:52 +03:00
|
|
|
audin_init();
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
process_message_channel_data(struct stream *s)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
int chan_id;
|
|
|
|
int chan_flags;
|
|
|
|
int rv;
|
|
|
|
int length;
|
|
|
|
int total_length;
|
2014-08-13 10:14:49 +04:00
|
|
|
int index;
|
2018-10-12 08:09:20 +03:00
|
|
|
int found;
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *ls;
|
2014-08-13 10:14:49 +04:00
|
|
|
struct trans *ltran;
|
|
|
|
struct xrdp_api_data *api_data;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
in_uint16_le(s, chan_id);
|
|
|
|
in_uint16_le(s, chan_flags);
|
|
|
|
in_uint16_le(s, length);
|
|
|
|
in_uint32_le(s, total_length);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_channel_data: chan_id %d "
|
2020-11-30 03:36:20 +03:00
|
|
|
"chan_flags %d", chan_id, chan_flags);
|
2018-10-12 08:09:20 +03:00
|
|
|
rv = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (rv == 0)
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (chan_id == g_cliprdr_chan_id)
|
|
|
|
{
|
|
|
|
rv = clipboard_data_in(s, chan_id, chan_flags, length, total_length);
|
|
|
|
}
|
|
|
|
else if (chan_id == g_rdpsnd_chan_id)
|
|
|
|
{
|
|
|
|
rv = sound_data_in(s, chan_id, chan_flags, length, total_length);
|
|
|
|
}
|
|
|
|
else if (chan_id == g_rdpdr_chan_id)
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
rv = devredir_data_in(s, chan_id, chan_flags, length, total_length);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (chan_id == g_rail_chan_id)
|
|
|
|
{
|
|
|
|
rv = rail_data_in(s, chan_id, chan_flags, length, total_length);
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
else
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
found = 0;
|
2014-08-13 10:14:49 +04:00
|
|
|
for (index = 0; index < g_api_con_trans_list->count; index++)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-08-13 10:14:49 +04:00
|
|
|
ltran = (struct trans *) list_get_item(g_api_con_trans_list, index);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (ltran != NULL)
|
2014-08-13 10:14:49 +04:00
|
|
|
{
|
|
|
|
api_data = (struct xrdp_api_data *) (ltran->callback_data);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (api_data != NULL)
|
2014-08-13 10:14:49 +04:00
|
|
|
{
|
|
|
|
if (api_data->chan_id == chan_id)
|
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
found = 1;
|
2014-08-13 10:14:49 +04:00
|
|
|
ls = ltran->out_s;
|
|
|
|
if (chan_flags & 1) /* first */
|
|
|
|
{
|
|
|
|
init_stream(ls, total_length);
|
|
|
|
}
|
|
|
|
out_uint8a(ls, s->p, length);
|
|
|
|
if (chan_flags & 2) /* last */
|
|
|
|
{
|
|
|
|
s_mark_end(ls);
|
2018-10-12 08:09:20 +03:00
|
|
|
rv = trans_write_copy(ltran);
|
2014-08-13 10:14:49 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
if (found == 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "process_message_channel_data: not found channel %d", chan_id);
|
2018-10-12 08:09:20 +03:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2018-10-12 08:09:20 +03:00
|
|
|
/* open response from client */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2018-10-12 08:09:20 +03:00
|
|
|
process_message_drdynvc_open_response(struct stream *s)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
struct chansrv_drdynvc *drdynvc;
|
|
|
|
int chan_id;
|
|
|
|
int creation_status;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_drdynvc_open_response:");
|
2018-10-12 08:09:20 +03:00
|
|
|
if (!s_check_rem(s, 8))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint32_le(s, chan_id);
|
|
|
|
in_uint32_le(s, creation_status);
|
|
|
|
if ((chan_id < 0) || (chan_id > 255))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
drdynvc = g_drdynvcs + chan_id;
|
|
|
|
if (drdynvc->status != CHANSRV_DRDYNVC_STATUS_OPEN_SENT)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "process_message_drdynvc_open_response: status not right");
|
2018-10-12 08:09:20 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (creation_status == 0)
|
|
|
|
{
|
|
|
|
drdynvc->status = CHANSRV_DRDYNVC_STATUS_OPEN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
drdynvc->status = CHANSRV_DRDYNVC_STATUS_CLOSED;
|
|
|
|
}
|
|
|
|
if (drdynvc->open_response != NULL)
|
|
|
|
{
|
|
|
|
if (drdynvc->open_response(chan_id, creation_status) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
/* close response from client */
|
|
|
|
static int
|
|
|
|
process_message_drdynvc_close_response(struct stream *s)
|
|
|
|
{
|
|
|
|
struct chansrv_drdynvc *drdynvc;
|
|
|
|
int chan_id;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_drdynvc_close_response:");
|
2018-10-12 08:09:20 +03:00
|
|
|
if (!s_check_rem(s, 4))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint32_le(s, chan_id);
|
|
|
|
if ((chan_id < 0) || (chan_id > 255))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
drdynvc = g_drdynvcs + chan_id;
|
|
|
|
if (drdynvc->status != CHANSRV_DRDYNVC_STATUS_CLOSE_SENT)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "process_message_drdynvc_close_response: status not right");
|
2018-10-12 08:09:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
drdynvc->status = CHANSRV_DRDYNVC_STATUS_CLOSED;
|
|
|
|
if (drdynvc->close_response != NULL)
|
|
|
|
{
|
|
|
|
if (drdynvc->close_response(chan_id) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
/* data from client */
|
|
|
|
static int
|
|
|
|
process_message_drdynvc_data_first(struct stream *s)
|
|
|
|
{
|
|
|
|
struct chansrv_drdynvc *drdynvc;
|
|
|
|
int chan_id;
|
|
|
|
int bytes;
|
|
|
|
int total_bytes;
|
|
|
|
char *data;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_drdynvc_data_first:");
|
2018-10-12 08:09:20 +03:00
|
|
|
if (!s_check_rem(s, 12))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint32_le(s, chan_id);
|
|
|
|
in_uint32_le(s, bytes);
|
|
|
|
in_uint32_le(s, total_bytes);
|
|
|
|
if (!s_check_rem(s, bytes))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8p(s, data, bytes);
|
|
|
|
if ((chan_id < 0) || (chan_id > 255))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
drdynvc = g_drdynvcs + chan_id;
|
|
|
|
if (drdynvc->data_first != NULL)
|
|
|
|
{
|
|
|
|
if (drdynvc->data_first(chan_id, data, bytes, total_bytes) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
/* data from client */
|
|
|
|
static int
|
|
|
|
process_message_drdynvc_data(struct stream *s)
|
|
|
|
{
|
|
|
|
struct chansrv_drdynvc *drdynvc;
|
|
|
|
int chan_id;
|
|
|
|
int bytes;
|
|
|
|
char *data;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_drdynvc_data:");
|
2018-10-12 08:09:20 +03:00
|
|
|
if (!s_check_rem(s, 8))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint32_le(s, chan_id);
|
|
|
|
in_uint32_le(s, bytes);
|
|
|
|
if (!s_check_rem(s, bytes))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8p(s, data, bytes);
|
|
|
|
drdynvc = g_drdynvcs + chan_id;
|
|
|
|
if (drdynvc->data != NULL)
|
|
|
|
{
|
|
|
|
if (drdynvc->data(chan_id, data, bytes) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* open call from chansrv */
|
|
|
|
int
|
|
|
|
chansrv_drdynvc_open(const char *name, int flags,
|
|
|
|
struct chansrv_drdynvc_procs *procs, int *chan_id)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int name_bytes;
|
|
|
|
int lchan_id;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
lchan_id = 1;
|
|
|
|
while (g_drdynvcs[lchan_id].status != CHANSRV_DRDYNVC_STATUS_CLOSED)
|
|
|
|
{
|
|
|
|
lchan_id++;
|
|
|
|
if (lchan_id > 255)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
name_bytes = g_strlen(name);
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8 + 4 + name_bytes + 4 + 4);
|
|
|
|
out_uint32_le(s, 12); /* msg id */
|
|
|
|
out_uint32_le(s, 8 + 4 + name_bytes + 4 + 4);
|
|
|
|
out_uint32_le(s, name_bytes);
|
|
|
|
out_uint8a(s, name, name_bytes);
|
|
|
|
out_uint32_le(s, flags);
|
|
|
|
out_uint32_le(s, lchan_id);
|
|
|
|
s_mark_end(s);
|
|
|
|
error = trans_write_copy(g_con_trans);
|
|
|
|
if (error == 0)
|
|
|
|
{
|
|
|
|
if (chan_id != NULL)
|
|
|
|
{
|
|
|
|
*chan_id = lchan_id;
|
|
|
|
g_drdynvcs[lchan_id].open_response = procs->open_response;
|
|
|
|
g_drdynvcs[lchan_id].close_response = procs->close_response;
|
|
|
|
g_drdynvcs[lchan_id].data_first = procs->data_first;
|
|
|
|
g_drdynvcs[lchan_id].data = procs->data;
|
|
|
|
g_drdynvcs[lchan_id].status = CHANSRV_DRDYNVC_STATUS_OPEN_SENT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2024-04-26 13:43:18 +03:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* tell xrdp we can do Unicode input */
|
|
|
|
static int
|
|
|
|
chansrv_advertise_unicode_input(int status)
|
|
|
|
{
|
|
|
|
struct stream *s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8 + 4);
|
|
|
|
out_uint32_le(s, 20); /* msg id */
|
|
|
|
out_uint32_le(s, 8 + 4);
|
|
|
|
out_uint32_le(s, status);
|
|
|
|
s_mark_end(s);
|
|
|
|
return trans_write_copy(g_con_trans);
|
|
|
|
}
|
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* close call from chansrv */
|
|
|
|
int
|
|
|
|
chansrv_drdynvc_close(int chan_id)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 20);
|
|
|
|
out_uint32_le(s, 14); /* msg id */
|
|
|
|
out_uint32_le(s, 12);
|
|
|
|
out_uint32_le(s, chan_id);
|
|
|
|
s_mark_end(s);
|
|
|
|
error = trans_write_copy(g_con_trans);
|
|
|
|
g_drdynvcs[chan_id].status = CHANSRV_DRDYNVC_STATUS_CLOSE_SENT;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
int
|
|
|
|
chansrv_drdynvc_data_first(int chan_id, const char *data, int data_bytes,
|
|
|
|
int total_data_bytes)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int error;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "chansrv_drdynvc_data_first: data_bytes %d total_data_bytes %d",
|
2018-10-12 08:09:20 +03:00
|
|
|
// data_bytes, total_data_bytes);
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 28 + data_bytes);
|
|
|
|
out_uint32_le(s, 16); /* msg id */
|
|
|
|
out_uint32_le(s, 20 + data_bytes);
|
|
|
|
out_uint32_le(s, chan_id);
|
|
|
|
out_uint32_le(s, data_bytes);
|
|
|
|
out_uint32_le(s, total_data_bytes);
|
|
|
|
out_uint8a(s, data, data_bytes);
|
|
|
|
s_mark_end(s);
|
|
|
|
error = trans_write_copy(g_con_trans);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
int
|
|
|
|
chansrv_drdynvc_data(int chan_id, const char *data, int data_bytes)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int error;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
// LOG_DEVEL(LOG_LEVEL_DEBUG, "chansrv_drdynvc_data: data_bytes %d", data_bytes);
|
2018-10-12 08:09:20 +03:00
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 24 + data_bytes);
|
|
|
|
out_uint32_le(s, 18); /* msg id */
|
|
|
|
out_uint32_le(s, 16 + data_bytes);
|
|
|
|
out_uint32_le(s, chan_id);
|
|
|
|
out_uint32_le(s, data_bytes);
|
|
|
|
out_uint8a(s, data, data_bytes);
|
|
|
|
s_mark_end(s);
|
|
|
|
error = trans_write_copy(g_con_trans);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
int
|
|
|
|
chansrv_drdynvc_send_data(int chan_id, const char *data, int data_bytes)
|
|
|
|
{
|
|
|
|
int this_send_bytes;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
// LOG_DEVEL(LOG_LEVEL_DEBUG, "chansrv_drdynvc_send_data: data_bytes %d", data_bytes);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (data_bytes > 1590)
|
|
|
|
{
|
|
|
|
if (chansrv_drdynvc_data_first(chan_id, data, 1590, data_bytes) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
data_bytes -= 1590;
|
|
|
|
data += 1590;
|
|
|
|
}
|
|
|
|
while (data_bytes > 0)
|
|
|
|
{
|
|
|
|
this_send_bytes = MIN(1590, data_bytes);
|
|
|
|
if (chansrv_drdynvc_data(chan_id, data, this_send_bytes) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
data_bytes -= this_send_bytes;
|
|
|
|
data += this_send_bytes;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2024-03-25 13:35:58 +03:00
|
|
|
#ifdef XRDP_IBUS
|
2024-04-16 16:59:09 +03:00
|
|
|
/*****************************************************************************/
|
2024-03-25 13:35:58 +03:00
|
|
|
static int
|
2024-04-16 16:59:09 +03:00
|
|
|
process_message_unicode_data(struct stream *s)
|
2024-03-25 13:35:58 +03:00
|
|
|
{
|
|
|
|
int rv = 0;
|
|
|
|
int key_down;
|
2024-04-17 13:44:51 +03:00
|
|
|
char32_t unicode;
|
2024-03-25 13:35:58 +03:00
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_unicode_keypress:");
|
|
|
|
if (!s_check_rem(s, 8))
|
|
|
|
{
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
in_uint32_le(s, key_down);
|
2024-04-16 16:59:09 +03:00
|
|
|
in_uint32_le(s, unicode);
|
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "process_message_unicode_keypress: received unicode %i", unicode);
|
|
|
|
|
|
|
|
if (key_down)
|
|
|
|
{
|
|
|
|
xrdp_input_send_unicode(unicode);
|
|
|
|
}
|
2024-03-25 13:35:58 +03:00
|
|
|
}
|
2024-04-16 16:59:09 +03:00
|
|
|
|
2024-03-25 13:35:58 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2024-04-16 16:59:09 +03:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
process_message_unicode_setup(struct stream *s)
|
|
|
|
{
|
2024-04-26 13:43:18 +03:00
|
|
|
int rv = xrdp_input_unicode_init();
|
|
|
|
if (rv == 0)
|
|
|
|
{
|
|
|
|
// Tell xrdp we can support Unicode input
|
|
|
|
rv = chansrv_advertise_unicode_input(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Tell xrdp there's a problem starting the framework
|
|
|
|
chansrv_advertise_unicode_input(2);
|
|
|
|
}
|
|
|
|
return rv;
|
2024-04-16 16:59:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
process_message_unicode_shutdown(struct stream *s)
|
|
|
|
{
|
2024-05-04 08:24:20 +03:00
|
|
|
return xrdp_input_unicode_destroy();
|
2024-04-16 16:59:09 +03:00
|
|
|
}
|
2024-04-17 13:44:51 +03:00
|
|
|
#endif
|
2024-03-25 13:35:58 +03:00
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-04-19 21:16:46 +04:00
|
|
|
process_message(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s = (struct stream *)NULL;
|
|
|
|
int size = 0;
|
|
|
|
int id = 0;
|
|
|
|
int rv = 0;
|
|
|
|
char *next_msg = (char *)NULL;
|
|
|
|
|
|
|
|
if (g_con_trans == 0)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
|
|
|
|
s = trans_get_in_s(g_con_trans);
|
|
|
|
|
|
|
|
if (s == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
|
|
|
|
while (s_check_rem(s, 8))
|
|
|
|
{
|
|
|
|
next_msg = s->p;
|
|
|
|
in_uint32_le(s, id);
|
|
|
|
in_uint32_le(s, size);
|
|
|
|
next_msg += size;
|
|
|
|
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 3: /* channel setup */
|
|
|
|
rv = process_message_channel_setup(s);
|
|
|
|
break;
|
|
|
|
case 5: /* channel data */
|
|
|
|
rv = process_message_channel_data(s);
|
|
|
|
break;
|
|
|
|
case 13: /* drdynvc open response */
|
|
|
|
rv = process_message_drdynvc_open_response(s);
|
|
|
|
break;
|
|
|
|
case 15: /* drdynvc close response */
|
|
|
|
rv = process_message_drdynvc_close_response(s);
|
|
|
|
break;
|
|
|
|
case 17: /* drdynvc data first */
|
|
|
|
rv = process_message_drdynvc_data_first(s);
|
|
|
|
break;
|
|
|
|
case 19: /* drdynvc data */
|
|
|
|
rv = process_message_drdynvc_data(s);
|
|
|
|
break;
|
2024-04-16 16:59:09 +03:00
|
|
|
case 21: /* unicode setup */
|
2024-04-26 13:43:18 +03:00
|
|
|
#ifdef XRDP_IBUS
|
2024-04-16 16:59:09 +03:00
|
|
|
rv = process_message_unicode_setup(s);
|
2024-04-26 13:43:18 +03:00
|
|
|
#else
|
|
|
|
// We don't support this.
|
|
|
|
rv = chansrv_advertise_unicode_input(1);
|
|
|
|
#endif
|
2024-04-16 16:59:09 +03:00
|
|
|
break;
|
|
|
|
case 23: /* unicode key event */
|
2024-04-26 13:43:18 +03:00
|
|
|
#ifdef XRDP_IBUS
|
2024-04-16 16:59:09 +03:00
|
|
|
rv = process_message_unicode_data(s);
|
2024-04-26 13:43:18 +03:00
|
|
|
#endif
|
2024-04-16 16:59:09 +03:00
|
|
|
break;
|
|
|
|
case 25: /* unicode shut down */
|
2024-04-26 13:43:18 +03:00
|
|
|
#ifdef XRDP_IBUS
|
2024-04-16 16:59:09 +03:00
|
|
|
rv = process_message_unicode_shutdown(s);
|
2024-03-25 13:35:58 +03:00
|
|
|
#endif
|
2024-04-26 13:43:18 +03:00
|
|
|
break;
|
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "process_message: unknown msg %d", id);
|
2018-10-12 08:09:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
g_writeln("process_message: error rv %d id %d", rv, id);
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->p = next_msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2023-10-20 18:14:47 +03:00
|
|
|
static int
|
2018-10-12 08:09:20 +03:00
|
|
|
my_trans_data_in(struct trans *trans)
|
|
|
|
{
|
|
|
|
struct stream *s = (struct stream *)NULL;
|
|
|
|
int size = 0;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (trans == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trans != g_con_trans)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "my_trans_data_in:");
|
2018-10-12 08:09:20 +03:00
|
|
|
s = trans_get_in_s(trans);
|
|
|
|
in_uint8s(s, 4); /* id */
|
|
|
|
in_uint32_le(s, size);
|
|
|
|
error = trans_force_read(trans, size - 8);
|
|
|
|
|
|
|
|
if (error == 0)
|
|
|
|
{
|
|
|
|
/* here, the entire message block is read in, process it */
|
|
|
|
error = process_message();
|
|
|
|
if (error == 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_writeln("my_trans_data_in: process_message failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_writeln("my_trans_data_in: trans_force_read failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-10-20 18:14:47 +03:00
|
|
|
static struct trans *
|
2018-10-12 08:09:20 +03:00
|
|
|
get_api_trans_from_chan_id(int chan_id)
|
|
|
|
{
|
|
|
|
return g_drdynvcs[chan_id].xrdp_api_trans;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
my_api_open_response(int chan_id, int creation_status)
|
|
|
|
{
|
|
|
|
struct trans *trans;
|
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
//g_writeln("my_api_open_response: chan_id %d creation_status %d",
|
|
|
|
// chan_id, creation_status);
|
|
|
|
trans = get_api_trans_from_chan_id(chan_id);
|
|
|
|
if (trans == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
s = trans_get_out_s(trans, 8192);
|
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(s, creation_status);
|
|
|
|
s_mark_end(s);
|
|
|
|
if (trans_write_copy(trans) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
my_api_close_response(int chan_id)
|
|
|
|
{
|
|
|
|
//g_writeln("my_api_close_response:");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
my_api_data_first(int chan_id, char *data, int bytes, int total_bytes)
|
|
|
|
{
|
|
|
|
struct trans *trans;
|
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
//g_writeln("my_api_data_first: bytes %d total_bytes %d", bytes, total_bytes);
|
|
|
|
trans = get_api_trans_from_chan_id(chan_id);
|
|
|
|
if (trans == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
s = trans_get_out_s(trans, bytes);
|
|
|
|
if (s == NULL)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
out_uint8a(s, data, bytes);
|
|
|
|
s_mark_end(s);
|
|
|
|
if (trans_write_copy(trans) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
return 1;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2018-10-12 08:09:20 +03:00
|
|
|
static int
|
|
|
|
my_api_data(int chan_id, char *data, int bytes)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
struct trans *trans;
|
|
|
|
struct stream *s;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
//g_writeln("my_api_data: bytes %d", bytes);
|
|
|
|
trans = get_api_trans_from_chan_id(chan_id);
|
|
|
|
if (trans == NULL)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
s = trans_get_out_s(trans, bytes);
|
|
|
|
if (s == NULL)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
out_uint8a(s, data, bytes);
|
|
|
|
s_mark_end(s);
|
|
|
|
if (trans_write_copy(trans) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
/*
|
|
|
|
* called when WTSVirtualChannelWrite() is invoked in xrdpapi.c
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2023-10-20 18:14:47 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
my_api_trans_data_in(struct trans *trans)
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
struct stream *s;
|
|
|
|
struct stream *out_s;
|
2012-09-20 07:51:34 +04:00
|
|
|
struct xrdp_api_data *ad;
|
2018-10-12 08:09:20 +03:00
|
|
|
int index;
|
|
|
|
int rv;
|
|
|
|
int bytes;
|
|
|
|
int ver;
|
|
|
|
struct chansrv_drdynvc_procs procs;
|
2020-04-24 13:27:36 +03:00
|
|
|
/*
|
2020-04-27 17:01:56 +03:00
|
|
|
* Name is limited to CHANNEL_NAME_LEN for an SVC, or MAX_PATH
|
2020-04-24 13:27:36 +03:00
|
|
|
* bytes for a DVC
|
|
|
|
*/
|
2020-04-27 17:01:56 +03:00
|
|
|
char chan_name[MAX(CHANNEL_NAME_LEN, MAX_PATH) + 1];
|
2020-04-24 13:27:36 +03:00
|
|
|
unsigned int channel_name_bytes;
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: extra_flags %d", trans->extra_flags);
|
2018-10-12 08:09:20 +03:00
|
|
|
rv = 0;
|
|
|
|
ad = (struct xrdp_api_data *) (trans->callback_data);
|
|
|
|
s = trans_get_in_s(trans);
|
|
|
|
if (trans->extra_flags == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
in_uint32_le(s, bytes);
|
|
|
|
in_uint32_le(s, ver);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: bytes %d ver %d", bytes, ver);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (ver != 0)
|
2014-08-13 21:10:04 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
trans->header_size = bytes;
|
|
|
|
trans->extra_flags = 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
else if (trans->extra_flags == 1)
|
2012-12-18 05:29:24 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
rv = 1;
|
|
|
|
in_uint32_le(s, channel_name_bytes);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: channel_name_bytes %d", channel_name_bytes);
|
2020-04-24 13:27:36 +03:00
|
|
|
if (channel_name_bytes > (sizeof(chan_name) - 1))
|
2012-12-18 05:29:24 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
return 1;
|
2012-12-18 05:29:24 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
in_uint8a(s, chan_name, channel_name_bytes);
|
2020-04-24 13:27:36 +03:00
|
|
|
chan_name[channel_name_bytes] = '\0';
|
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
in_uint32_le(s, ad->chan_flags);
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: chan_name %s chan_flags 0x%8.8x", chan_name, ad->chan_flags);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (ad->chan_flags == 0)
|
2012-12-18 05:29:24 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
/* SVC */
|
|
|
|
for (index = 0; index < g_num_chan_items; index++)
|
2012-12-18 05:29:24 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
if (g_strcasecmp(g_chan_items[index].name, chan_name) == 0)
|
|
|
|
{
|
|
|
|
ad->chan_id = g_chan_items[index].id;
|
|
|
|
rv = 0;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-18 05:29:24 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
if (rv == 0)
|
|
|
|
{
|
|
|
|
/* open ok */
|
|
|
|
out_s = trans_get_out_s(trans, 8192);
|
|
|
|
if (out_s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(out_s, 0);
|
|
|
|
s_mark_end(out_s);
|
|
|
|
if (trans_write_copy(trans) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-09-28 06:48:44 +04:00
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
/* open failed */
|
|
|
|
out_s = trans_get_out_s(trans, 8192);
|
|
|
|
if (out_s == NULL)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
out_uint32_le(out_s, 1);
|
|
|
|
s_mark_end(out_s);
|
|
|
|
if (trans_write_copy(trans) != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-28 06:48:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
/* DVS */
|
|
|
|
g_memset(&procs, 0, sizeof(procs));
|
|
|
|
procs.open_response = my_api_open_response;
|
|
|
|
procs.close_response = my_api_close_response;
|
|
|
|
procs.data_first = my_api_data_first;
|
|
|
|
procs.data = my_api_data;
|
|
|
|
rv = chansrv_drdynvc_open(chan_name, ad->chan_flags,
|
|
|
|
&procs, &(ad->chan_id));
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: chansrv_drdynvc_open rv %d "
|
2018-10-12 08:09:20 +03:00
|
|
|
// "chan_id %d", rv, ad->chan_id);
|
|
|
|
g_drdynvcs[ad->chan_id].xrdp_api_trans = trans;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
init_stream(s, 0);
|
|
|
|
trans->extra_flags = 2;
|
|
|
|
trans->header_size = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
bytes = g_sck_recv(trans->sck, s->data, s->size, 0);
|
|
|
|
if (bytes < 1)
|
2012-09-28 06:48:44 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: disconnect");
|
2018-10-12 08:09:20 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (ad->chan_flags == 0)
|
|
|
|
{
|
|
|
|
/* SVC */
|
|
|
|
rv = send_channel_data(ad->chan_id, s->data, bytes);
|
2012-09-28 06:48:44 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
/* DVS */
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_data_in: s->size %d bytes %d", s->size, bytes);
|
2018-10-12 08:09:20 +03:00
|
|
|
rv = chansrv_drdynvc_send_data(ad->chan_id, s->data, bytes);
|
2012-09-28 06:48:44 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
init_stream(s, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
return rv;
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
2023-10-20 18:14:47 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
my_trans_conn_in(struct trans *trans, struct trans *new_trans)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (trans == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trans != g_lis_trans)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_con_trans != 0) /* if already set, error */
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_trans == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "my_trans_conn_in:");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_con_trans = new_trans;
|
|
|
|
g_con_trans->trans_data_in = my_trans_data_in;
|
|
|
|
g_con_trans->header_size = 8;
|
|
|
|
/* stop listening */
|
|
|
|
trans_delete(g_lis_trans);
|
|
|
|
g_lis_trans = 0;
|
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
/*
|
|
|
|
* called when WTSVirtualChannelOpenEx is invoked in xrdpapi.c
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2023-10-20 18:14:47 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
my_api_trans_conn_in(struct trans *trans, struct trans *new_trans)
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct xrdp_api_data *ad;
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
//LOG_DEVEL(LOG_LEVEL_DEBUG, "my_api_trans_conn_in:");
|
2018-10-12 08:09:20 +03:00
|
|
|
if ((trans == NULL) || (trans != g_api_lis_trans) || (new_trans == NULL))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "my_api_trans_conn_in: error");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
new_trans->trans_data_in = my_api_trans_data_in;
|
|
|
|
new_trans->header_size = 8;
|
|
|
|
new_trans->no_stream_init_on_data_in = 1;
|
|
|
|
ad = g_new0(struct xrdp_api_data, 1);
|
|
|
|
if (ad == NULL)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "my_api_trans_conn_in: error");
|
2014-08-02 22:13:12 +04:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
new_trans->callback_data = ad;
|
2018-10-12 08:09:20 +03:00
|
|
|
list_add_item(g_api_con_trans_list, (intptr_t) new_trans);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-04-22 08:34:45 +04:00
|
|
|
setup_listen(void)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2023-06-14 15:59:55 +03:00
|
|
|
char port[XRDP_SOCKETS_MAXPATH];
|
2012-09-20 07:51:34 +04:00
|
|
|
int error = 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_lis_trans != 0)
|
|
|
|
{
|
|
|
|
trans_delete(g_lis_trans);
|
|
|
|
}
|
|
|
|
|
2022-05-03 12:57:41 +03:00
|
|
|
g_lis_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
|
|
|
|
g_lis_trans->is_term = g_is_term;
|
2023-06-14 15:59:55 +03:00
|
|
|
g_snprintf(port, sizeof(port), XRDP_CHANSRV_STR, g_getuid(), g_display_num);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
g_lis_trans->trans_conn_in = my_trans_conn_in;
|
|
|
|
error = trans_listen(g_lis_trans, port);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "setup_listen: trans_listen failed for port %s",
|
2020-11-30 03:36:20 +03:00
|
|
|
port);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
|
|
|
|
2012-08-03 09:34:00 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-08-03 09:34:00 +04:00
|
|
|
setup_api_listen(void)
|
|
|
|
{
|
2023-06-14 15:59:55 +03:00
|
|
|
char port[XRDP_SOCKETS_MAXPATH];
|
2012-09-20 07:51:34 +04:00
|
|
|
int error = 0;
|
|
|
|
|
2012-10-30 07:12:24 +04:00
|
|
|
g_api_lis_trans = trans_create(TRANS_MODE_UNIX, 8192 * 4, 8192 * 4);
|
2013-08-18 00:32:53 +04:00
|
|
|
g_api_lis_trans->is_term = g_is_term;
|
2023-06-14 15:59:55 +03:00
|
|
|
g_snprintf(port, sizeof(port), CHANSRV_API_STR, g_getuid(), g_display_num);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_api_lis_trans->trans_conn_in = my_api_trans_conn_in;
|
|
|
|
error = trans_listen(g_api_lis_trans, port);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "setup_api_listen: trans_listen failed for port %s",
|
2020-11-30 03:36:20 +03:00
|
|
|
port);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
api_con_trans_list_get_wait_objs_rw(intptr_t *robjs, int *rcount,
|
|
|
|
intptr_t *wobjs, int *wcount,
|
|
|
|
int *timeout)
|
|
|
|
{
|
|
|
|
int api_con_index;
|
|
|
|
struct trans *ltran;
|
|
|
|
|
|
|
|
for (api_con_index = g_api_con_trans_list->count - 1;
|
2020-11-30 03:36:20 +03:00
|
|
|
api_con_index >= 0;
|
|
|
|
api_con_index--)
|
2018-10-12 08:09:20 +03:00
|
|
|
{
|
|
|
|
ltran = (struct trans *)
|
2020-11-30 03:36:20 +03:00
|
|
|
list_get_item(g_api_con_trans_list, api_con_index);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (ltran != NULL)
|
|
|
|
{
|
|
|
|
trans_get_wait_objs_rw(ltran, robjs, rcount, wobjs, wcount,
|
|
|
|
timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
api_con_trans_list_check_wait_objs(void)
|
|
|
|
{
|
|
|
|
int api_con_index;
|
|
|
|
int drdynvc_index;
|
|
|
|
struct trans *ltran;
|
|
|
|
struct xrdp_api_data *ad;
|
|
|
|
|
|
|
|
for (api_con_index = g_api_con_trans_list->count - 1;
|
2020-11-30 03:36:20 +03:00
|
|
|
api_con_index >= 0;
|
|
|
|
api_con_index--)
|
2018-10-12 08:09:20 +03:00
|
|
|
{
|
|
|
|
ltran = (struct trans *)
|
2020-11-30 03:36:20 +03:00
|
|
|
list_get_item(g_api_con_trans_list, api_con_index);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (ltran != NULL)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(ltran) != 0)
|
|
|
|
{
|
|
|
|
/* disconnect */
|
|
|
|
list_remove_item(g_api_con_trans_list, api_con_index);
|
|
|
|
ad = (struct xrdp_api_data *) (ltran->callback_data);
|
|
|
|
if (ad->chan_flags != 0)
|
|
|
|
{
|
|
|
|
chansrv_drdynvc_close(ad->chan_id);
|
|
|
|
}
|
|
|
|
for (drdynvc_index = 0;
|
2020-11-30 03:36:20 +03:00
|
|
|
drdynvc_index < (int) ARRAYSIZE(g_drdynvcs);
|
|
|
|
drdynvc_index++)
|
2018-10-12 08:09:20 +03:00
|
|
|
{
|
|
|
|
if (g_drdynvcs[drdynvc_index].xrdp_api_trans == ltran)
|
|
|
|
{
|
|
|
|
g_drdynvcs[drdynvc_index].xrdp_api_trans = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free(ad);
|
|
|
|
trans_delete(ltran);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
api_con_trans_list_remove_all(void)
|
|
|
|
{
|
|
|
|
int api_con_index;
|
|
|
|
struct trans *ltran;
|
|
|
|
|
|
|
|
for (api_con_index = g_api_con_trans_list->count - 1;
|
2020-11-30 03:36:20 +03:00
|
|
|
api_con_index >= 0;
|
|
|
|
api_con_index--)
|
2018-10-12 08:09:20 +03:00
|
|
|
{
|
|
|
|
ltran = (struct trans *)
|
2020-11-30 03:36:20 +03:00
|
|
|
list_get_item(g_api_con_trans_list, api_con_index);
|
2018-10-12 08:09:20 +03:00
|
|
|
if (ltran != NULL)
|
|
|
|
{
|
|
|
|
list_remove_item(g_api_con_trans_list, api_con_index);
|
|
|
|
g_free(ltran->callback_data);
|
|
|
|
trans_delete(ltran);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-22 08:34:45 +04:00
|
|
|
/*****************************************************************************/
|
2023-10-20 18:14:47 +03:00
|
|
|
static THREAD_RV THREAD_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
channel_thread_loop(void *in_val)
|
2009-04-22 08:34:45 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
tbus objs[32];
|
2013-09-24 05:08:22 +04:00
|
|
|
tbus wobjs[32];
|
2012-09-20 07:51:34 +04:00
|
|
|
int num_objs;
|
2013-09-24 05:08:22 +04:00
|
|
|
int num_wobjs;
|
2012-09-20 07:51:34 +04:00
|
|
|
int timeout;
|
|
|
|
int error;
|
|
|
|
THREAD_RV rv;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "channel_thread_loop: thread start");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 0;
|
2018-10-12 08:09:20 +03:00
|
|
|
g_api_con_trans_list = list_create();
|
2012-09-20 07:51:34 +04:00
|
|
|
setup_api_listen();
|
|
|
|
error = setup_listen();
|
|
|
|
|
|
|
|
if (error == 0)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
timeout = -1;
|
|
|
|
num_objs = 0;
|
2013-09-24 05:08:22 +04:00
|
|
|
num_wobjs = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
objs[num_objs] = g_term_event;
|
|
|
|
num_objs++;
|
|
|
|
trans_get_wait_objs(g_lis_trans, objs, &num_objs);
|
|
|
|
trans_get_wait_objs(g_api_lis_trans, objs, &num_objs);
|
|
|
|
|
2018-10-12 08:09:20 +03:00
|
|
|
//g_writeln("timeout %d", timeout);
|
2013-09-24 05:08:22 +04:00
|
|
|
while (g_obj_wait(objs, num_objs, wobjs, num_wobjs, timeout) == 0)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2013-09-08 10:54:36 +04:00
|
|
|
check_timeout();
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_is_wait_obj_set(g_term_event))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set");
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_deinit();
|
|
|
|
sound_deinit();
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_deinit();
|
2012-09-20 07:51:34 +04:00
|
|
|
rail_deinit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_lis_trans != 0)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(g_lis_trans) != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "channel_thread_loop: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"trans_check_wait_objs error");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_con_trans != 0)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(g_con_trans) != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "channel_thread_loop: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"trans_check_wait_objs error resetting");
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_deinit();
|
|
|
|
sound_deinit();
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_deinit();
|
2012-09-20 07:51:34 +04:00
|
|
|
rail_deinit();
|
|
|
|
/* delete g_con_trans */
|
|
|
|
trans_delete(g_con_trans);
|
|
|
|
g_con_trans = 0;
|
|
|
|
/* create new listener */
|
|
|
|
error = setup_listen();
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_api_lis_trans != 0)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(g_api_lis_trans) != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "channel_thread_loop: trans_check_wait_objs failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
2018-10-12 08:09:20 +03:00
|
|
|
/* check the wait_objs in g_api_con_trans_list */
|
|
|
|
api_con_trans_list_check_wait_objs();
|
2012-09-20 07:51:34 +04:00
|
|
|
xcommon_check_wait_objs();
|
|
|
|
sound_check_wait_objs();
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_check_wait_objs();
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_check_wait_objs();
|
2012-09-20 07:51:34 +04:00
|
|
|
timeout = -1;
|
|
|
|
num_objs = 0;
|
2013-09-24 05:08:22 +04:00
|
|
|
num_wobjs = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
objs[num_objs] = g_term_event;
|
|
|
|
num_objs++;
|
2018-10-12 08:09:20 +03:00
|
|
|
trans_get_wait_objs_rw(g_lis_trans, objs, &num_objs,
|
|
|
|
wobjs, &num_wobjs, &timeout);
|
2013-09-24 05:08:22 +04:00
|
|
|
trans_get_wait_objs_rw(g_con_trans, objs, &num_objs,
|
2015-07-13 11:10:48 +03:00
|
|
|
wobjs, &num_wobjs, &timeout);
|
2018-10-12 08:09:20 +03:00
|
|
|
trans_get_wait_objs_rw(g_api_lis_trans, objs, &num_objs,
|
|
|
|
wobjs, &num_wobjs, &timeout);
|
|
|
|
/* get the wait_objs from in g_api_con_trans_list */
|
|
|
|
api_con_trans_list_get_wait_objs_rw(objs, &num_objs,
|
|
|
|
wobjs, &num_wobjs,
|
|
|
|
&timeout);
|
2012-09-20 07:51:34 +04:00
|
|
|
xcommon_get_wait_objs(objs, &num_objs, &timeout);
|
|
|
|
sound_get_wait_objs(objs, &num_objs, &timeout);
|
2019-11-14 17:43:57 +03:00
|
|
|
devredir_get_wait_objs(objs, &num_objs, &timeout);
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_get_wait_objs(objs, &num_objs, &timeout);
|
2013-09-08 10:54:36 +04:00
|
|
|
get_timeout(&timeout);
|
2013-03-09 03:37:30 +04:00
|
|
|
} /* end while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0) */
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
trans_delete(g_lis_trans);
|
|
|
|
g_lis_trans = 0;
|
|
|
|
trans_delete(g_con_trans);
|
|
|
|
g_con_trans = 0;
|
|
|
|
trans_delete(g_api_lis_trans);
|
|
|
|
g_api_lis_trans = 0;
|
2018-10-12 08:09:20 +03:00
|
|
|
api_con_trans_list_remove_all();
|
|
|
|
list_delete(g_api_con_trans_list);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "channel_thread_loop: thread stop");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_set_wait_obj(g_thread_done_event);
|
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-05-15 16:16:29 +03:00
|
|
|
static void
|
2009-04-19 21:16:46 +04:00
|
|
|
term_signal_handler(int sig)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
g_set_wait_obj(g_term_event);
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-05-15 16:16:29 +03:00
|
|
|
static void
|
2009-04-19 21:16:46 +04:00
|
|
|
nil_signal_handler(int sig)
|
|
|
|
{
|
2012-08-01 03:54:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-05-15 16:16:29 +03:00
|
|
|
static void
|
|
|
|
set_sigchld_event(int sig)
|
|
|
|
{
|
|
|
|
g_set_wait_obj(g_sigchld_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
|
|
child_signal_handler(void)
|
2012-08-01 03:54:54 +04:00
|
|
|
{
|
2013-12-31 01:38:40 +04:00
|
|
|
int pid;
|
2012-08-01 03:54:54 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "child_signal_handler:");
|
2023-05-15 16:16:29 +03:00
|
|
|
while ((pid = g_waitchild(NULL)) > 0)
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "child_signal_handler: child pid %d", pid);
|
2023-05-15 16:16:29 +03:00
|
|
|
if (pid == g_exec_pid)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "child_signal_handler: found pid %d", pid);
|
2012-09-20 07:51:34 +04:00
|
|
|
//shutdownx();
|
|
|
|
}
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2013-12-31 01:38:40 +04:00
|
|
|
/*****************************************************************************/
|
2023-10-20 18:14:47 +03:00
|
|
|
static void
|
2013-09-04 06:44:20 +04:00
|
|
|
segfault_signal_handler(int sig)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "segfault_signal_handler: entered.......");
|
2013-09-04 06:44:20 +04:00
|
|
|
xfuse_deinit();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2018-07-19 10:04:28 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
static void
|
|
|
|
x_server_fatal_handler(void)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "xserver_fatal_handler: entered.......");
|
2018-07-19 10:04:28 +03:00
|
|
|
/* At this point the X server has gone away. Dont make any X calls. */
|
|
|
|
xfuse_deinit();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2009-08-23 04:48:20 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2009-09-02 06:52:30 +04:00
|
|
|
main_cleanup(void)
|
2009-08-21 21:30:14 +04:00
|
|
|
{
|
2020-07-06 13:53:56 +03:00
|
|
|
if (g_term_event != 0)
|
2009-09-06 09:58:26 +04:00
|
|
|
{
|
2020-07-06 13:53:56 +03:00
|
|
|
g_delete_wait_obj(g_term_event);
|
2009-09-06 09:58:26 +04:00
|
|
|
}
|
2023-05-15 16:16:29 +03:00
|
|
|
if (g_sigchld_event != 0)
|
|
|
|
{
|
|
|
|
g_delete_wait_obj(g_sigchld_event);
|
|
|
|
}
|
2020-07-06 13:53:56 +03:00
|
|
|
if (g_thread_done_event != 0)
|
|
|
|
{
|
|
|
|
g_delete_wait_obj(g_thread_done_event);
|
|
|
|
}
|
|
|
|
if (g_exec_event != 0)
|
|
|
|
{
|
|
|
|
g_delete_wait_obj(g_exec_event);
|
|
|
|
tc_mutex_delete(g_exec_mutex);
|
|
|
|
tc_sem_delete(g_exec_sem);
|
|
|
|
}
|
|
|
|
log_end();
|
|
|
|
config_free(g_cfg);
|
|
|
|
g_deinit(); /* os_calls */
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-09-06 09:58:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2016-11-19 10:31:36 +03:00
|
|
|
get_log_path(char *path, int bytes)
|
2013-08-08 08:02:22 +04:00
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
char *log_path;
|
2016-11-19 10:31:36 +03:00
|
|
|
int rv;
|
2013-08-08 08:02:22 +04:00
|
|
|
|
2016-11-19 10:31:36 +03:00
|
|
|
rv = 1;
|
2013-08-08 08:02:22 +04:00
|
|
|
log_path = g_getenv("CHANSRV_LOG_PATH");
|
2016-10-25 08:52:43 +03:00
|
|
|
if (log_path == 0)
|
|
|
|
{
|
|
|
|
log_path = g_getenv("XDG_DATA_HOME");
|
|
|
|
if (log_path != 0)
|
|
|
|
{
|
2016-11-19 10:31:36 +03:00
|
|
|
g_snprintf(path, bytes, "%s%s", log_path, "/xrdp");
|
|
|
|
if (g_directory_exist(path) || (g_mkdir(path) == 0))
|
2016-10-25 08:52:43 +03:00
|
|
|
{
|
2016-11-19 10:31:36 +03:00
|
|
|
rv = 0;
|
2016-10-25 08:52:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-19 10:31:36 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_snprintf(path, bytes, "%s", log_path);
|
|
|
|
if (g_directory_exist(path) || (g_mkdir(path) == 0))
|
|
|
|
{
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rv != 0)
|
2013-08-08 08:02:22 +04:00
|
|
|
{
|
|
|
|
log_path = g_getenv("HOME");
|
2016-10-25 08:52:43 +03:00
|
|
|
if (log_path != 0)
|
|
|
|
{
|
2016-11-19 10:31:36 +03:00
|
|
|
g_snprintf(path, bytes, "%s%s", log_path, "/.local");
|
|
|
|
if (g_directory_exist(path) || (g_mkdir(path) == 0))
|
2016-10-25 08:52:43 +03:00
|
|
|
{
|
2016-11-19 10:31:36 +03:00
|
|
|
g_snprintf(path, bytes, "%s%s", log_path, "/.local/share");
|
|
|
|
if (g_directory_exist(path) || (g_mkdir(path) == 0))
|
|
|
|
{
|
|
|
|
g_snprintf(path, bytes, "%s%s", log_path, "/.local/share/xrdp");
|
|
|
|
if (g_directory_exist(path) || (g_mkdir(path) == 0))
|
|
|
|
{
|
|
|
|
rv = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-10-25 08:52:43 +03:00
|
|
|
}
|
|
|
|
}
|
2013-08-08 08:02:22 +04:00
|
|
|
}
|
2016-11-19 10:31:36 +03:00
|
|
|
return rv;
|
2013-08-08 08:02:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-01 03:54:54 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-08-01 03:54:54 +04:00
|
|
|
run_exec(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int pid;
|
2012-08-01 03:54:54 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "run_exec:");
|
2012-09-20 07:51:34 +04:00
|
|
|
pid = g_fork();
|
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
trans_delete(g_con_trans);
|
|
|
|
g_close_wait_obj(g_term_event);
|
2023-05-15 16:16:29 +03:00
|
|
|
g_close_wait_obj(g_sigchld_event);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_close_wait_obj(g_thread_done_event);
|
|
|
|
g_close_wait_obj(g_exec_event);
|
|
|
|
tc_mutex_delete(g_exec_mutex);
|
|
|
|
tc_sem_delete(g_exec_sem);
|
|
|
|
g_execlp3(g_exec_name, g_exec_name, 0);
|
|
|
|
g_exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_exec_pid = pid;
|
|
|
|
tc_sem_inc(g_exec_sem);
|
|
|
|
|
|
|
|
return 0;
|
2012-08-01 03:54:54 +04:00
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
main(int argc, char **argv)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
tbus waiters[4];
|
|
|
|
int pid = 0;
|
|
|
|
char text[256];
|
2020-10-08 04:55:08 +03:00
|
|
|
const char *config_path;
|
2016-11-19 10:31:36 +03:00
|
|
|
char log_path[256];
|
2021-03-31 13:31:41 +03:00
|
|
|
const char *display_text;
|
2012-09-20 07:51:34 +04:00
|
|
|
char log_file[256];
|
|
|
|
enum logReturns error;
|
2020-10-08 04:55:08 +03:00
|
|
|
struct log_config *logconfig;
|
2012-09-20 07:51:34 +04:00
|
|
|
g_init("xrdp-chansrv"); /* os_calls */
|
2020-10-08 04:55:08 +03:00
|
|
|
g_memset(g_drdynvcs, 0, sizeof(g_drdynvcs));
|
2020-07-06 13:53:56 +03:00
|
|
|
|
2016-11-19 10:31:36 +03:00
|
|
|
log_path[255] = 0;
|
|
|
|
if (get_log_path(log_path, 255) != 0)
|
2012-05-27 19:17:39 +04:00
|
|
|
{
|
2013-08-08 08:02:22 +04:00
|
|
|
g_writeln("error reading CHANSRV_LOG_PATH and HOME environment variable");
|
2020-07-06 13:53:56 +03:00
|
|
|
main_cleanup();
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
2012-05-27 19:17:39 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-03-31 13:31:41 +03:00
|
|
|
display_text = g_getenv("DISPLAY");
|
|
|
|
if (display_text == NULL)
|
|
|
|
{
|
|
|
|
g_writeln("DISPLAY is not set");
|
|
|
|
main_cleanup();
|
|
|
|
return 1;
|
|
|
|
}
|
2021-04-13 14:11:19 +03:00
|
|
|
g_display_num = g_get_display_num_from_display(display_text);
|
2021-03-31 13:31:41 +03:00
|
|
|
if (g_display_num < 0)
|
|
|
|
{
|
|
|
|
g_writeln("Unable to get display from DISPLAY='%s'", display_text);
|
|
|
|
main_cleanup();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-07-06 13:53:56 +03:00
|
|
|
/*
|
|
|
|
* The user is unable at present to override the sysadmin-provided
|
|
|
|
* sesman.ini location */
|
2020-10-08 04:55:08 +03:00
|
|
|
config_path = XRDP_CFG_PATH "/sesman.ini";
|
|
|
|
if ((g_cfg = config_read(0, config_path)) == NULL)
|
2019-03-08 10:42:18 +03:00
|
|
|
{
|
2020-07-06 13:53:56 +03:00
|
|
|
main_cleanup();
|
|
|
|
return 1;
|
2019-03-02 17:36:56 +03:00
|
|
|
}
|
2020-07-06 13:53:56 +03:00
|
|
|
config_dump(g_cfg);
|
2019-03-02 17:36:56 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
pid = g_getpid();
|
|
|
|
|
|
|
|
/* starting logging subsystem */
|
2017-07-04 11:05:00 +03:00
|
|
|
g_snprintf(log_file, 255, "%s/xrdp-chansrv.%d.log", log_path, g_display_num);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_writeln("chansrv::main: using log file [%s]", log_file);
|
|
|
|
if (g_file_exist(log_file))
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
g_file_delete(log_file);
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
logconfig = log_config_init_from_config(config_path, "xrdp-chansrv", "Chansrv");
|
|
|
|
if (logconfig->log_file != NULL)
|
|
|
|
{
|
|
|
|
g_free(logconfig->log_file);
|
|
|
|
}
|
|
|
|
logconfig->log_file = log_file;
|
|
|
|
error = log_start_from_param(logconfig);
|
|
|
|
logconfig->log_file = NULL;
|
|
|
|
log_config_free(logconfig);
|
|
|
|
logconfig = NULL;
|
2020-11-30 03:36:20 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (error != LOG_STARTUP_OK)
|
|
|
|
{
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
g_writeln("log_start error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-06 13:53:56 +03:00
|
|
|
main_cleanup();
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-12-14 14:35:31 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "main: app started pid %d(0x%8.8x)", pid, pid);
|
2012-09-20 07:51:34 +04:00
|
|
|
/* set up signal handler */
|
|
|
|
g_signal_terminate(term_signal_handler); /* SIGTERM */
|
|
|
|
g_signal_user_interrupt(term_signal_handler); /* SIGINT */
|
|
|
|
g_signal_pipe(nil_signal_handler); /* SIGPIPE */
|
2023-05-15 16:16:29 +03:00
|
|
|
g_signal_child_stop(set_sigchld_event); /* SIGCHLD */
|
2013-09-04 06:44:20 +04:00
|
|
|
g_signal_segfault(segfault_signal_handler);
|
|
|
|
|
2018-07-19 10:04:28 +03:00
|
|
|
/* Cater for the X server exiting unexpectedly */
|
|
|
|
xcommon_set_x_server_fatal_handler(x_server_fatal_handler);
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text);
|
2015-01-20 15:33:37 +03:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
|
|
|
|
g_term_event = g_create_wait_obj(text);
|
2023-05-15 16:16:29 +03:00
|
|
|
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_sigchld", pid);
|
|
|
|
g_sigchld_event = g_create_wait_obj(text);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
|
|
|
|
g_thread_done_event = g_create_wait_obj(text);
|
|
|
|
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_exec", pid);
|
|
|
|
g_exec_event = g_create_wait_obj(text);
|
|
|
|
g_exec_mutex = tc_mutex_create();
|
|
|
|
g_exec_sem = tc_sem_create(0);
|
|
|
|
tc_thread_create(channel_thread_loop, 0);
|
|
|
|
|
|
|
|
while (g_term_event > 0 && !g_is_wait_obj_set(g_term_event))
|
2012-08-01 03:54:54 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
waiters[0] = g_term_event;
|
|
|
|
waiters[1] = g_exec_event;
|
2023-05-15 16:16:29 +03:00
|
|
|
waiters[2] = g_sigchld_event;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2024-01-07 10:53:21 +03:00
|
|
|
if (g_obj_wait(waiters, 3, 0, 0, -1) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "main: error, g_obj_wait failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_is_wait_obj_set(g_term_event))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-05-15 16:16:29 +03:00
|
|
|
if (g_is_wait_obj_set(g_sigchld_event))
|
|
|
|
{
|
|
|
|
g_reset_wait_obj(g_sigchld_event);
|
|
|
|
child_signal_handler();
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_is_wait_obj_set(g_exec_event))
|
|
|
|
{
|
|
|
|
g_reset_wait_obj(g_exec_event);
|
|
|
|
run_exec();
|
|
|
|
}
|
2012-08-01 03:54:54 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
while (g_thread_done_event > 0 && !g_is_wait_obj_set(g_thread_done_event))
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
/* wait for thread to exit */
|
2024-01-07 10:53:21 +03:00
|
|
|
if (g_obj_wait(&g_thread_done_event, 1, 0, 0, -1) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "main: error, g_obj_wait failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
main_cleanup();
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|