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
|
|
|
|
|
|
|
#include "arch.h"
|
|
|
|
#include "os_calls.h"
|
|
|
|
#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"
|
|
|
|
#include "file_loc.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"
|
2013-07-02 11:45:40 +04:00
|
|
|
#include "drdynvc.h"
|
2009-04-19 21:16:46 +04:00
|
|
|
|
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;
|
2012-09-28 06:48:44 +04:00
|
|
|
static int g_drdynvc_index = -1;
|
|
|
|
|
|
|
|
/* state info for dynamic virtual channels */
|
|
|
|
static struct xrdp_api_data *g_dvc_channels[MAX_DVC_CHANNELS];
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2009-09-02 06:52:30 +04:00
|
|
|
static tbus g_term_event = 0;
|
|
|
|
static tbus g_thread_done_event = 0;
|
|
|
|
|
2009-09-06 09:58:26 +04:00
|
|
|
static int g_use_unix_socket = 0;
|
|
|
|
|
2016-06-22 02:30:17 +03:00
|
|
|
static const unsigned char g_xrdpapi_magic[12] =
|
2012-12-18 05:29:24 +04:00
|
|
|
{ 0x78, 0x32, 0x10, 0x67, 0x00, 0x92, 0x30, 0x56, 0xff, 0xd8, 0xa9, 0x1f };
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
int g_display_num = 0;
|
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 */
|
|
|
|
int g_drdynvc_chan_id = -1; /* drdynvc */
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
char *g_exec_name;
|
2012-08-01 03:54:54 +04:00
|
|
|
tbus g_exec_event;
|
|
|
|
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)))
|
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
/* each time we create a DVC we need a unique DVC channel id */
|
|
|
|
/* this variable gets bumped up once per DVC we create */
|
2012-10-05 21:13:53 +04:00
|
|
|
tui32 g_dvc_chan_id = 100;
|
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;
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
int APP_CC
|
|
|
|
add_timeout(int msoffset, void (*callback)(void *data), void *data)
|
|
|
|
{
|
|
|
|
struct timeout_obj *tobj;
|
|
|
|
tui32 now;
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2013-09-08 10:54:36 +04:00
|
|
|
LOG(10, ("add_timeout:"));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int APP_CC
|
|
|
|
get_timeout(int *timeout)
|
|
|
|
{
|
|
|
|
struct timeout_obj *tobj;
|
|
|
|
tui32 now;
|
|
|
|
int ltimeout;
|
|
|
|
|
|
|
|
LOG(10, ("get_timeout:"));
|
|
|
|
ltimeout = *timeout;
|
|
|
|
if (ltimeout < 1)
|
|
|
|
{
|
|
|
|
ltimeout = 0;
|
|
|
|
}
|
|
|
|
tobj = g_timeout_head;
|
|
|
|
if (tobj != 0)
|
|
|
|
{
|
|
|
|
now = g_time3();
|
|
|
|
while (tobj != 0)
|
|
|
|
{
|
|
|
|
LOG(10, (" now %u tobj->mstime %u", now, tobj->mstime));
|
|
|
|
if (now < tobj->mstime)
|
|
|
|
{
|
|
|
|
ltimeout = tobj->mstime - now;
|
|
|
|
}
|
|
|
|
tobj = tobj->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ltimeout > 0)
|
|
|
|
{
|
|
|
|
LOG(10, (" ltimeout %d", ltimeout));
|
|
|
|
if (*timeout < 1)
|
|
|
|
{
|
|
|
|
*timeout = ltimeout;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*timeout > ltimeout)
|
|
|
|
{
|
|
|
|
*timeout = ltimeout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int APP_CC
|
|
|
|
check_timeout(void)
|
|
|
|
{
|
|
|
|
struct timeout_obj *tobj;
|
|
|
|
struct timeout_obj *last_tobj;
|
|
|
|
struct timeout_obj *temp_tobj;
|
|
|
|
int count;
|
|
|
|
tui32 now;
|
|
|
|
|
|
|
|
LOG(10, ("check_timeout:"));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG(10, (" count %d", count));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-18 00:32:53 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
int DEFAULT_CC
|
|
|
|
g_is_term(void)
|
|
|
|
{
|
|
|
|
return g_is_wait_obj_set(g_term_event);
|
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
2012-08-20 06:45:31 +04:00
|
|
|
/* add data to chan_item, on its way to the client */
|
2009-04-19 21:16:46 +04:00
|
|
|
/* returns error */
|
2012-08-20 06:45:31 +04:00
|
|
|
static int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
add_data_to_chan_item(struct chan_item *chan_item, char *data, int size)
|
2012-08-20 06:45:31 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
struct chan_out_data *cod;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, size);
|
|
|
|
g_memcpy(s->data, data, size);
|
|
|
|
s->end = s->data + size;
|
|
|
|
cod = (struct chan_out_data *)g_malloc(sizeof(struct chan_out_data), 1);
|
|
|
|
cod->s = s;
|
|
|
|
|
|
|
|
if (chan_item->tail == 0)
|
|
|
|
{
|
|
|
|
chan_item->tail = cod;
|
|
|
|
chan_item->head = cod;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chan_item->tail->next = cod;
|
|
|
|
chan_item->tail = cod;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
send_data_from_chan_item(struct chan_item *chan_item)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
struct chan_out_data *cod;
|
|
|
|
int bytes_left;
|
|
|
|
int size;
|
|
|
|
int chan_flags;
|
|
|
|
int error;
|
|
|
|
|
2012-08-20 06:45:31 +04:00
|
|
|
if (chan_item->head == 0)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cod = chan_item->head;
|
|
|
|
bytes_left = (int)(cod->s->end - cod->s->p);
|
|
|
|
size = MIN(1600, bytes_left);
|
|
|
|
chan_flags = 0;
|
|
|
|
|
|
|
|
if (cod->s->p == cod->s->data)
|
|
|
|
{
|
|
|
|
chan_flags |= 1; /* first */
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (cod->s->p + size >= cod->s->end)
|
|
|
|
{
|
|
|
|
chan_flags |= 2; /* last */
|
|
|
|
}
|
|
|
|
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8 + 2 + 2 + 2 + 4 + size); /* size */
|
|
|
|
out_uint32_le(s, 8); /* msg id */
|
|
|
|
out_uint32_le(s, 8 + 2 + 2 + 2 + 4 + size); /* size */
|
|
|
|
out_uint16_le(s, chan_item->id);
|
|
|
|
out_uint16_le(s, chan_flags);
|
|
|
|
out_uint16_le(s, size);
|
|
|
|
out_uint32_le(s, cod->s->size);
|
|
|
|
out_uint8a(s, cod->s->p, size);
|
|
|
|
s_mark_end(s);
|
2013-09-23 23:16:52 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "chansrv::send_data_from_chan_item: -- "
|
2012-09-20 07:51:34 +04:00
|
|
|
"size %d chan_flags 0x%8.8x", size, chan_flags));
|
|
|
|
|
2013-09-24 05:08:22 +04:00
|
|
|
error = trans_write_copy(g_con_trans);
|
2012-09-20 07:51:34 +04:00
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cod->s->p += size;
|
|
|
|
|
|
|
|
if (cod->s->p >= cod->s->end)
|
|
|
|
{
|
|
|
|
free_stream(cod->s);
|
|
|
|
chan_item->head = chan_item->head->next;
|
|
|
|
|
|
|
|
if (chan_item->head == 0)
|
|
|
|
{
|
|
|
|
chan_item->tail = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(cod);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
|
|
|
check_chan_items(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int index;
|
2012-08-20 06:45:31 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
for (index = 0; index < g_num_chan_items; index++)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_chan_items[index].head != 0)
|
|
|
|
{
|
|
|
|
send_data_from_chan_item(g_chan_items + index);
|
|
|
|
}
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
send_channel_data(int chan_id, char *data, int size)
|
2012-08-20 06:45:31 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int index;
|
2012-08-20 06:45:31 +04:00
|
|
|
|
2012-10-30 07:12:24 +04:00
|
|
|
//g_writeln("send_channel_data chan_id %d size %d", chan_id, size);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "chansrv::send_channel_data: size %d", size));
|
|
|
|
|
|
|
|
if (chan_id == -1)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-10-30 07:12:24 +04:00
|
|
|
g_writeln("send_channel_data: error, chan_id is -1");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
for (index = 0; index < g_num_chan_items; index++)
|
|
|
|
{
|
|
|
|
if (g_chan_items[index].id == chan_id)
|
|
|
|
{
|
|
|
|
add_data_to_chan_item(g_chan_items + index, data, size);
|
2013-12-05 03:33:06 +04:00
|
|
|
check_chan_items();
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2013-06-30 23:36:01 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
int APP_CC
|
|
|
|
send_rail_drawing_orders(char* data, int size)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "chansrv::send_rail_drawing_orders: size %d", size));
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2013-06-30 23:36:01 +04:00
|
|
|
struct stream* s;
|
|
|
|
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);
|
|
|
|
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 */
|
|
|
|
static int APP_CC
|
|
|
|
send_init_response_message(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s = (struct stream *)NULL;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_INFO, "send_init_response_message:"));
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
|
|
|
|
if (s == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8); /* size */
|
|
|
|
out_uint32_le(s, 2); /* msg id */
|
|
|
|
out_uint32_le(s, 8); /* size */
|
|
|
|
s_mark_end(s);
|
2013-09-24 05:08:22 +04:00
|
|
|
return trans_write_copy(g_con_trans);
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
|
|
|
send_channel_setup_response_message(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s = (struct stream *)NULL;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "send_channel_setup_response_message:"));
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
|
|
|
|
if (s == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8); /* size */
|
|
|
|
out_uint32_le(s, 4); /* msg id */
|
|
|
|
out_uint32_le(s, 8); /* size */
|
|
|
|
s_mark_end(s);
|
2013-09-24 05:08:22 +04:00
|
|
|
return trans_write_copy(g_con_trans);
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
|
|
|
send_channel_data_response_message(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s = (struct stream *)NULL;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "send_channel_data_response_message:"));
|
|
|
|
s = trans_get_out_s(g_con_trans, 8192);
|
|
|
|
|
|
|
|
if (s == 0)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_uint32_le(s, 0); /* version */
|
|
|
|
out_uint32_le(s, 8 + 8); /* size */
|
|
|
|
out_uint32_le(s, 6); /* msg id */
|
|
|
|
out_uint32_le(s, 8); /* size */
|
|
|
|
s_mark_end(s);
|
2013-09-24 05:08:22 +04:00
|
|
|
return trans_write_copy(g_con_trans);
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
process_message_init(struct stream *s)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "process_message_init:"));
|
|
|
|
return send_init_response_message();
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
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;
|
2013-06-24 01:17:59 +04:00
|
|
|
struct chan_out_data *cod;
|
|
|
|
struct chan_out_data *old_cod;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
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;
|
2012-09-28 06:48:44 +04:00
|
|
|
g_drdynvc_chan_id = -1;
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup:"));
|
|
|
|
in_uint16_le(s, num_chans);
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup: num_chans %d",
|
|
|
|
num_chans));
|
|
|
|
|
|
|
|
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);
|
2013-06-24 01:17:59 +04:00
|
|
|
/* there might be leftover data from last session after reconnecting
|
|
|
|
so free it */
|
|
|
|
if (ci->head != 0)
|
|
|
|
{
|
|
|
|
cod = ci->head;
|
|
|
|
while (1)
|
|
|
|
{
|
2013-06-23 00:57:16 +04:00
|
|
|
free_stream(cod->s);
|
2013-06-24 01:17:59 +04:00
|
|
|
old_cod = cod;
|
2013-06-23 00:57:16 +04:00
|
|
|
cod = cod->next;
|
|
|
|
g_free(old_cod);
|
2013-06-24 01:17:59 +04:00
|
|
|
if (ci->tail == old_cod)
|
|
|
|
{
|
2013-06-23 00:57:16 +04:00
|
|
|
break;
|
2013-06-24 01:17:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ci->head = 0;
|
|
|
|
ci->tail = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, ci->flags);
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "process_message_channel_setup: chan name '%s' "
|
|
|
|
"id %d flags %8.8x", ci->name, ci->id, ci->flags));
|
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
g_writeln("process_message_channel_setup: chan name '%s' "
|
|
|
|
"id %d flags %8.8x", ci->name, ci->id, ci->flags);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_strcasecmp(ci->name, "cliprdr") == 0)
|
|
|
|
{
|
|
|
|
g_cliprdr_index = g_num_chan_items;
|
|
|
|
g_cliprdr_chan_id = ci->id;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(ci->name, "rdpsnd") == 0)
|
|
|
|
{
|
|
|
|
g_rdpsnd_index = g_num_chan_items;
|
|
|
|
g_rdpsnd_chan_id = ci->id;
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(ci->name, "rdpdr") == 0)
|
|
|
|
{
|
|
|
|
g_rdpdr_index = g_num_chan_items;
|
|
|
|
g_rdpdr_chan_id = ci->id;
|
|
|
|
}
|
2013-12-17 08:16:15 +04:00
|
|
|
/* disabled for now */
|
2014-02-01 07:57:52 +04:00
|
|
|
else if (g_strcasecmp(ci->name, "rail") == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
g_rail_index = g_num_chan_items;
|
|
|
|
g_rail_chan_id = ci->id;
|
|
|
|
}
|
2012-09-28 06:48:44 +04:00
|
|
|
else if (g_strcasecmp(ci->name, "drdynvc") == 0)
|
|
|
|
{
|
|
|
|
g_drdynvc_index = g_num_chan_items; // LK_TODO use this
|
|
|
|
g_drdynvc_chan_id = ci->id; // LK_TODO use this
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(10, ("other %s", ci->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_num_chan_items++;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
rv = send_channel_setup_response_message();
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
dev_redir_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
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
if (g_drdynvc_index >= 0)
|
|
|
|
{
|
2012-10-05 09:55:06 +04:00
|
|
|
g_memset(&g_dvc_channels[0], 0, sizeof(g_dvc_channels));
|
2012-09-28 06:48:44 +04:00
|
|
|
drdynvc_init();
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
process_message_channel_data(struct stream *s)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int chan_id = 0;
|
|
|
|
int chan_flags = 0;
|
|
|
|
int rv = 0;
|
|
|
|
int length = 0;
|
|
|
|
int total_length = 0;
|
2014-08-13 10:14:49 +04:00
|
|
|
int index;
|
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);
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "process_message_channel_data: chan_id %d "
|
|
|
|
"chan_flags %d", chan_id, chan_flags));
|
|
|
|
LOG(10, ("process_message_channel_data"));
|
|
|
|
rv = send_channel_data_response_message();
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
rv = dev_redir_data_in(s, chan_id, chan_flags, length, total_length);
|
|
|
|
}
|
|
|
|
else if (chan_id == g_rail_chan_id)
|
|
|
|
{
|
|
|
|
rv = rail_data_in(s, chan_id, chan_flags, length, total_length);
|
|
|
|
}
|
2012-09-28 06:48:44 +04:00
|
|
|
else if (chan_id == g_drdynvc_chan_id)
|
|
|
|
{
|
|
|
|
rv = drdynvc_data_in(s, chan_id, chan_flags, length, total_length);
|
|
|
|
}
|
2014-08-13 10:14:49 +04:00
|
|
|
else if (g_api_con_trans_list != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
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);
|
|
|
|
if (ltran != 0)
|
|
|
|
{
|
|
|
|
api_data = (struct xrdp_api_data *) (ltran->callback_data);
|
|
|
|
if (api_data != 0)
|
|
|
|
{
|
|
|
|
if (api_data->chan_id == chan_id)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
rv = trans_force_write(ltran);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04: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 */
|
|
|
|
static int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
process_message_channel_data_response(struct stream *s)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
LOG(10, ("process_message_channel_data_response:"));
|
|
|
|
check_chan_items();
|
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
static int APP_CC
|
|
|
|
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
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
s = trans_get_in_s(g_con_trans);
|
|
|
|
|
|
|
|
if (s == 0)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
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 1: /* init */
|
|
|
|
rv = process_message_init(s);
|
|
|
|
break;
|
|
|
|
case 3: /* channel setup */
|
|
|
|
rv = process_message_channel_setup(s);
|
|
|
|
break;
|
|
|
|
case 5: /* channel data */
|
|
|
|
rv = process_message_channel_data(s);
|
|
|
|
break;
|
|
|
|
case 7: /* channel data response */
|
|
|
|
rv = process_message_channel_data_response(s);
|
|
|
|
break;
|
|
|
|
default:
|
2016-06-22 02:30:16 +03:00
|
|
|
LOGM((LOG_LEVEL_ERROR, "process_message: unknown msg %d", id));
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->p = next_msg;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
int DEFAULT_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
my_trans_data_in(struct trans *trans)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s = (struct stream *)NULL;
|
|
|
|
int size = 0;
|
|
|
|
int error = 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (trans == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trans != g_con_trans)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "my_trans_data_in:"));
|
|
|
|
s = trans_get_in_s(trans);
|
2016-04-23 09:40:48 +03:00
|
|
|
in_uint8s(s, 4); /* id */
|
2012-09-20 07:51:34 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
/*
|
|
|
|
* called when WTSVirtualChannelWrite() is invoked in xrdpapi.c
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2012-08-03 09:34:00 +04:00
|
|
|
int DEFAULT_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
my_api_trans_data_in(struct trans *trans)
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2012-09-28 06:48:44 +04:00
|
|
|
struct stream *s;
|
|
|
|
int bytes_read;
|
2012-12-18 05:29:24 +04:00
|
|
|
int i32;
|
2012-09-20 07:51:34 +04:00
|
|
|
struct xrdp_api_data *ad;
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2012-10-30 07:12:24 +04:00
|
|
|
//g_writeln("my_api_trans_data_in:");
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOG(10, ("my_api_trans_data_in:"));
|
|
|
|
|
|
|
|
if (trans == 0)
|
2012-08-09 04:20:04 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2012-08-09 04:20:04 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-08-13 21:10:04 +04:00
|
|
|
if (g_api_con_trans_list != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-08-13 21:10:04 +04:00
|
|
|
if (list_index_of(g_api_con_trans_list, (tintptr) trans) == -1)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "my_api_trans_data_in:"));
|
2012-09-28 06:48:44 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s = trans_get_in_s(trans);
|
2012-12-18 05:29:24 +04:00
|
|
|
bytes_read = g_tcp_recv(trans->sck, s->data, 16, 0);
|
|
|
|
if (bytes_read == 16)
|
|
|
|
{
|
|
|
|
if (g_memcmp(s->data, g_xrdpapi_magic, 12) == 0)
|
|
|
|
{
|
|
|
|
in_uint8s(s, 12);
|
|
|
|
in_uint32_le(s, bytes_read);
|
|
|
|
init_stream(s, bytes_read);
|
2014-07-20 00:06:25 +04:00
|
|
|
if (trans_force_read(trans, bytes_read))
|
|
|
|
log_message(LOG_LEVEL_ERROR, "chansrv.c: error reading from transport");
|
2012-12-18 05:29:24 +04:00
|
|
|
}
|
|
|
|
else if (g_tcp_select(trans->sck, 0) & 1)
|
|
|
|
{
|
|
|
|
i32 = bytes_read;
|
|
|
|
bytes_read = g_tcp_recv(trans->sck, s->data + bytes_read,
|
|
|
|
8192 * 4 - bytes_read, 0);
|
|
|
|
if (bytes_read > 0)
|
|
|
|
{
|
|
|
|
bytes_read += i32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
|
|
|
|
//g_writeln("bytes_read %d", bytes_read);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
if (bytes_read > 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2012-09-28 06:48:44 +04:00
|
|
|
LOG(10, ("my_api_trans_data_in: got data %d", bytes_read));
|
|
|
|
ad = (struct xrdp_api_data *) trans->callback_data;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
if (ad->dvc_chan_id < 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2012-09-28 06:48:44 +04:00
|
|
|
/* writing data to a static virtual channel */
|
|
|
|
if (send_channel_data(ad->chan_id, s->data, bytes_read) != 0)
|
|
|
|
{
|
|
|
|
LOG(0, ("my_api_trans_data_in: send_channel_data failed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* writing data to a dynamic virtual channel */
|
|
|
|
drdynvc_write_data(ad->dvc_chan_id, s->data, bytes_read);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-30 07:12:24 +04:00
|
|
|
ad = (struct xrdp_api_data *) (trans->callback_data);
|
2012-09-28 06:48:44 +04:00
|
|
|
if ((ad != NULL) && (ad->dvc_chan_id > 0))
|
|
|
|
{
|
|
|
|
/* WTSVirtualChannelClose() was invoked, or connection dropped */
|
|
|
|
LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for DVC"));
|
|
|
|
ad->transp = NULL;
|
|
|
|
ad->is_connected = 0;
|
|
|
|
remove_struct_with_chan_id(ad->dvc_chan_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for SVC"));
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
int DEFAULT_CC
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "my_trans_conn_in:"));
|
|
|
|
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
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
2012-08-03 09:34:00 +04:00
|
|
|
int DEFAULT_CC
|
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-09-28 06:48:44 +04:00
|
|
|
struct stream *s;
|
|
|
|
int error;
|
|
|
|
int index;
|
|
|
|
char chan_pri;
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
if ((trans == 0) || (trans != g_api_lis_trans) || (new_trans == 0))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_DEBUG, "my_api_trans_conn_in:"));
|
|
|
|
LOG(10, ("my_api_trans_conn_in: got incoming"));
|
|
|
|
|
|
|
|
s = trans_get_in_s(new_trans);
|
|
|
|
s->end = s->data;
|
2012-09-28 06:48:44 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
error = trans_force_read(new_trans, 64);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
LOG(0, ("my_api_trans_conn_in: trans_force_read failed"));
|
|
|
|
trans_delete(new_trans);
|
2014-08-02 22:13:12 +04:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s->end = s->data;
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
ad = (struct xrdp_api_data *) g_malloc(sizeof(struct xrdp_api_data), 1);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_memcpy(ad->header, s->data, 64);
|
|
|
|
|
|
|
|
ad->flags = GGET_UINT32(ad->header, 16);
|
2012-09-28 06:48:44 +04:00
|
|
|
ad->chan_id = -1;
|
|
|
|
ad->dvc_chan_id = -1;
|
2012-08-09 09:21:32 +04:00
|
|
|
|
2012-09-28 06:48:44 +04:00
|
|
|
if (ad->flags > 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2012-09-28 06:48:44 +04:00
|
|
|
/* opening a dynamic virtual channel */
|
|
|
|
|
|
|
|
if ((index = find_empty_slot_in_dvc_channels()) < 0)
|
|
|
|
{
|
|
|
|
/* exceeded MAX_DVC_CHANNELS */
|
|
|
|
LOG(0, ("my_api_trans_conn_in: MAX_DVC_CHANNELS reached; giving up!"))
|
2012-10-05 09:55:06 +04:00
|
|
|
g_free(ad);
|
2012-09-28 06:48:44 +04:00
|
|
|
trans_delete(new_trans);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dvc_channels[index] = ad;
|
|
|
|
chan_pri = 4 - ad->flags;
|
|
|
|
ad->dvc_chan_id = g_dvc_chan_id++;
|
|
|
|
ad->is_connected = 0;
|
|
|
|
ad->transp = new_trans;
|
|
|
|
drdynvc_send_open_channel_request(chan_pri, ad->dvc_chan_id, ad->header);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-28 06:48:44 +04:00
|
|
|
/* opening a static virtual channel */
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
for (index = 0; index < g_num_chan_items; index++)
|
|
|
|
{
|
2012-11-10 07:55:21 +04:00
|
|
|
LOG(10, ("my_api_trans_conn_in: %s %s", ad->header,
|
|
|
|
g_chan_items[index].name));
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_strcasecmp(ad->header, g_chan_items[index].name) == 0)
|
|
|
|
{
|
|
|
|
LOG(10, ("my_api_trans_conn_in: found it at %d", index));
|
|
|
|
ad->chan_id = g_chan_items[index].id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-11-10 07:55:21 +04:00
|
|
|
if (index == g_num_chan_items)
|
|
|
|
{
|
|
|
|
g_writeln("did not find SVC named %s", ad->header);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
new_trans->callback_data = ad;
|
2012-08-03 09:34:00 +04:00
|
|
|
|
2014-08-13 10:14:49 +04:00
|
|
|
if (g_api_con_trans_list == 0)
|
|
|
|
{
|
|
|
|
g_api_con_trans_list = list_create();
|
|
|
|
}
|
|
|
|
new_trans->trans_data_in = my_api_trans_data_in;
|
|
|
|
new_trans->header_size = 0;
|
|
|
|
list_add_item(g_api_con_trans_list, (tintptr) new_trans);
|
2012-08-03 09:34:00 +04:00
|
|
|
|
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
|
|
|
/*****************************************************************************/
|
2009-04-22 08:34:45 +04:00
|
|
|
static int APP_CC
|
|
|
|
setup_listen(void)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
char port[256];
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_use_unix_socket)
|
|
|
|
{
|
2013-08-18 00:32:53 +04:00
|
|
|
g_lis_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
|
|
|
|
g_lis_trans->is_term = g_is_term;
|
2014-08-07 00:21:01 +04:00
|
|
|
g_snprintf(port, 255, XRDP_CHANSRV_STR, g_display_num);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-18 00:32:53 +04:00
|
|
|
g_lis_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
|
|
|
|
g_lis_trans->is_term = g_is_term;
|
2012-09-20 07:51:34 +04:00
|
|
|
g_snprintf(port, 255, "%d", 7200 + g_display_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_lis_trans->trans_conn_in = my_trans_conn_in;
|
|
|
|
error = trans_listen(g_lis_trans, port);
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "setup_listen: trans_listen failed for port %s",
|
|
|
|
port));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-04-22 08:34:45 +04:00
|
|
|
}
|
|
|
|
|
2012-08-03 09:34:00 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static int APP_CC
|
|
|
|
setup_api_listen(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
char port[256];
|
|
|
|
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;
|
2014-08-07 00:21:01 +04:00
|
|
|
g_snprintf(port, 255, CHANSRV_API_STR, 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)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "setup_api_listen: trans_listen failed for port %s",
|
|
|
|
port));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
|
|
|
|
2009-04-22 08:34:45 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
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;
|
2014-08-13 10:14:49 +04:00
|
|
|
int index;
|
2012-09-20 07:51:34 +04:00
|
|
|
THREAD_RV rv;
|
2014-08-13 10:14:49 +04:00
|
|
|
struct trans *ltran;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: thread start"));
|
|
|
|
rv = 0;
|
|
|
|
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);
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set"));
|
|
|
|
clipboard_deinit();
|
|
|
|
sound_deinit();
|
|
|
|
dev_redir_deinit();
|
|
|
|
rail_deinit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_lis_trans != 0)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(g_lis_trans) != 0)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: "
|
|
|
|
"trans_check_wait_objs error"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_con_trans != 0)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(g_con_trans) != 0)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: "
|
|
|
|
"trans_check_wait_objs error resetting"));
|
|
|
|
clipboard_deinit();
|
|
|
|
sound_deinit();
|
|
|
|
dev_redir_deinit();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
LOG(0, ("channel_thread_loop: trans_check_wait_objs failed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 10:14:49 +04:00
|
|
|
if (g_api_con_trans_list != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-08-13 10:14:49 +04:00
|
|
|
for (index = g_api_con_trans_list->count - 1; index >= 0; 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);
|
|
|
|
if (ltran != 0)
|
|
|
|
{
|
|
|
|
if (trans_check_wait_objs(ltran) != 0)
|
|
|
|
{
|
|
|
|
list_remove_item(g_api_con_trans_list, index);
|
|
|
|
g_free(ltran->callback_data);
|
|
|
|
trans_delete(ltran);
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xcommon_check_wait_objs();
|
|
|
|
sound_check_wait_objs();
|
|
|
|
dev_redir_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++;
|
|
|
|
trans_get_wait_objs(g_lis_trans, objs, &num_objs);
|
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);
|
2012-09-20 07:51:34 +04:00
|
|
|
trans_get_wait_objs(g_api_lis_trans, objs, &num_objs);
|
2014-08-13 10:14:49 +04:00
|
|
|
|
2014-08-13 21:10:04 +04:00
|
|
|
if (g_api_con_trans_list != 0)
|
2014-08-13 10:14:49 +04:00
|
|
|
{
|
2014-08-13 21:10:04 +04:00
|
|
|
for (index = g_api_con_trans_list->count - 1; index >= 0; index--)
|
2014-08-13 10:14:49 +04:00
|
|
|
{
|
2014-08-13 21:10:04 +04:00
|
|
|
ltran = (struct trans *) list_get_item(g_api_con_trans_list, index);
|
|
|
|
if (ltran != 0)
|
|
|
|
{
|
|
|
|
trans_get_wait_objs(ltran, objs, &num_objs);
|
|
|
|
}
|
2014-08-13 10:14:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
xcommon_get_wait_objs(objs, &num_objs, &timeout);
|
|
|
|
sound_get_wait_objs(objs, &num_objs, &timeout);
|
|
|
|
dev_redir_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;
|
2014-08-13 10:14:49 +04:00
|
|
|
if (g_api_con_trans_list != 0)
|
|
|
|
{
|
|
|
|
for (index = g_api_con_trans_list->count - 1; index >= 0; index--)
|
|
|
|
{
|
|
|
|
ltran = (struct trans *) list_get_item(g_api_con_trans_list, index);
|
|
|
|
if (ltran != 0)
|
|
|
|
{
|
|
|
|
list_remove_item(g_api_con_trans_list, index);
|
|
|
|
g_free(ltran->callback_data);
|
|
|
|
trans_delete(ltran);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list_delete(g_api_con_trans_list);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: thread stop"));
|
|
|
|
g_set_wait_obj(g_thread_done_event);
|
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void DEFAULT_CC
|
|
|
|
term_signal_handler(int sig)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_INFO, "term_signal_handler: got signal %d", sig));
|
|
|
|
g_set_wait_obj(g_term_event);
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void DEFAULT_CC
|
|
|
|
nil_signal_handler(int sig)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_INFO, "nil_signal_handler: got signal %d", sig));
|
2012-08-01 03:54:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void DEFAULT_CC
|
|
|
|
child_signal_handler(int sig)
|
|
|
|
{
|
2013-12-31 01:38:40 +04:00
|
|
|
int pid;
|
2012-08-01 03:54:54 +04:00
|
|
|
|
2013-09-04 06:44:20 +04:00
|
|
|
LOG(0, ("child_signal_handler:"));
|
2012-09-20 07:51:34 +04:00
|
|
|
do
|
2012-08-03 09:34:00 +04:00
|
|
|
{
|
2013-12-31 01:38:40 +04:00
|
|
|
pid = g_waitchild();
|
|
|
|
LOG(0, ("child_signal_handler: child pid %d", pid));
|
|
|
|
if ((pid == g_exec_pid) && (pid > 0))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2013-12-31 01:38:40 +04:00
|
|
|
LOG(0, ("child_signal_handler: found pid %d", pid));
|
2012-09-20 07:51:34 +04:00
|
|
|
//shutdownx();
|
|
|
|
}
|
2012-08-03 09:34:00 +04:00
|
|
|
}
|
2013-12-31 01:38:40 +04:00
|
|
|
while (pid >= 0);
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2013-12-31 01:38:40 +04:00
|
|
|
/*****************************************************************************/
|
2013-09-04 06:44:20 +04:00
|
|
|
void DEFAULT_CC
|
|
|
|
segfault_signal_handler(int sig)
|
|
|
|
{
|
|
|
|
LOG(0, ("segfault_signal_handler: entered......."));
|
|
|
|
xfuse_deinit();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static int APP_CC
|
2012-09-20 07:51:34 +04:00
|
|
|
get_display_num_from_display(char *display_text)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int index;
|
|
|
|
int mode;
|
|
|
|
int host_index;
|
|
|
|
int disp_index;
|
|
|
|
int scre_index;
|
|
|
|
char host[256];
|
|
|
|
char disp[256];
|
|
|
|
char scre[256];
|
|
|
|
|
|
|
|
g_memset(host, 0, 256);
|
|
|
|
g_memset(disp, 0, 256);
|
|
|
|
g_memset(scre, 0, 256);
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
host_index = 0;
|
|
|
|
disp_index = 0;
|
|
|
|
scre_index = 0;
|
|
|
|
mode = 0;
|
|
|
|
|
|
|
|
while (display_text[index] != 0)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (display_text[index] == ':')
|
|
|
|
{
|
|
|
|
mode = 1;
|
|
|
|
}
|
|
|
|
else if (display_text[index] == '.')
|
|
|
|
{
|
|
|
|
mode = 2;
|
|
|
|
}
|
|
|
|
else if (mode == 0)
|
|
|
|
{
|
|
|
|
host[host_index] = display_text[index];
|
|
|
|
host_index++;
|
|
|
|
}
|
|
|
|
else if (mode == 1)
|
|
|
|
{
|
|
|
|
disp[disp_index] = display_text[index];
|
|
|
|
disp_index++;
|
|
|
|
}
|
|
|
|
else if (mode == 2)
|
|
|
|
{
|
|
|
|
scre[scre_index] = display_text[index];
|
|
|
|
scre_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
host[host_index] = 0;
|
|
|
|
disp[disp_index] = 0;
|
|
|
|
scre[scre_index] = 0;
|
|
|
|
g_display_num = g_atoi(disp);
|
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2009-08-23 04:48:20 +04:00
|
|
|
/*****************************************************************************/
|
2009-09-02 06:52:30 +04:00
|
|
|
int APP_CC
|
|
|
|
main_cleanup(void)
|
2009-08-21 21:30:14 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
g_delete_wait_obj(g_term_event);
|
|
|
|
g_delete_wait_obj(g_thread_done_event);
|
|
|
|
g_delete_wait_obj(g_exec_event);
|
|
|
|
tc_mutex_delete(g_exec_mutex);
|
|
|
|
g_deinit(); /* os_calls */
|
|
|
|
return 0;
|
2009-08-21 21:30:14 +04:00
|
|
|
}
|
|
|
|
|
2009-09-06 09:58:26 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static int APP_CC
|
|
|
|
read_ini(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
char filename[256];
|
|
|
|
struct list *names;
|
|
|
|
struct list *values;
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
g_memset(filename, 0, (sizeof(char) * 256));
|
|
|
|
names = list_create();
|
|
|
|
names->auto_free = 1;
|
|
|
|
values = list_create();
|
|
|
|
values->auto_free = 1;
|
|
|
|
g_use_unix_socket = 0;
|
|
|
|
g_snprintf(filename, 255, "%s/sesman.ini", XRDP_CFG_PATH);
|
|
|
|
|
|
|
|
if (file_by_name_read_section(filename, "Globals", names, values) == 0)
|
2009-09-06 09:58:26 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
for (index = 0; index < names->count; index++)
|
2009-09-06 09:58:26 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
name = (char *)list_get_item(names, index);
|
|
|
|
value = (char *)list_get_item(values, index);
|
|
|
|
|
|
|
|
if (g_strcasecmp(name, "ListenAddress") == 0)
|
|
|
|
{
|
|
|
|
if (g_strcasecmp(value, "127.0.0.1") == 0)
|
|
|
|
{
|
|
|
|
g_use_unix_socket = 1;
|
|
|
|
}
|
|
|
|
}
|
2009-09-06 09:58:26 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
list_delete(names);
|
|
|
|
list_delete(values);
|
|
|
|
return 0;
|
2009-09-06 09:58:26 +04:00
|
|
|
}
|
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static char* APP_CC
|
|
|
|
get_log_path()
|
|
|
|
{
|
|
|
|
char* log_path = 0;
|
|
|
|
|
|
|
|
log_path = g_getenv("CHANSRV_LOG_PATH");
|
|
|
|
if (log_path == 0)
|
|
|
|
{
|
|
|
|
log_path = g_getenv("HOME");
|
|
|
|
}
|
|
|
|
return log_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static unsigned int APP_CC
|
|
|
|
get_log_level(const char* level_str, unsigned int default_level)
|
|
|
|
{
|
|
|
|
static const char* levels[] = {
|
|
|
|
"LOG_LEVEL_ALWAYS",
|
|
|
|
"LOG_LEVEL_ERROR",
|
|
|
|
"LOG_LEVEL_WARNING",
|
|
|
|
"LOG_LEVEL_INFO",
|
|
|
|
"LOG_LEVEL_DEBUG"
|
|
|
|
};
|
|
|
|
unsigned int i;
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
if (level_str == NULL || level_str[0] == 0)
|
|
|
|
{
|
|
|
|
return default_level;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ARRAYSIZE(levels); ++i)
|
|
|
|
{
|
|
|
|
if (g_strcasecmp(levels[i], level_str) == 0)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return default_level;
|
|
|
|
}
|
|
|
|
|
2012-08-01 03:54:54 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static int APP_CC
|
|
|
|
run_exec(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int pid;
|
2012-08-01 03:54:54 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
LOG(10, ("run_exec:"));
|
|
|
|
pid = g_fork();
|
|
|
|
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
trans_delete(g_con_trans);
|
|
|
|
g_close_wait_obj(g_term_event);
|
|
|
|
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
|
|
|
/*****************************************************************************/
|
|
|
|
int DEFAULT_CC
|
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];
|
2013-08-08 08:02:22 +04:00
|
|
|
char* log_path;
|
2012-09-20 07:51:34 +04:00
|
|
|
char *display_text;
|
|
|
|
char log_file[256];
|
|
|
|
enum logReturns error;
|
|
|
|
struct log_config logconfig;
|
2013-08-08 08:02:22 +04:00
|
|
|
unsigned int log_level;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
g_init("xrdp-chansrv"); /* os_calls */
|
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
log_path = get_log_path();
|
|
|
|
if (log_path == 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");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_deinit();
|
|
|
|
return 1;
|
2012-05-27 19:17:39 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
read_ini();
|
|
|
|
pid = g_getpid();
|
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
log_level = get_log_level(g_getenv("CHANSRV_LOG_LEVEL"), LOG_LEVEL_ERROR);
|
2013-12-05 03:33:06 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* starting logging subsystem */
|
|
|
|
g_memset(&logconfig, 0, sizeof(struct log_config));
|
2016-02-14 05:09:17 +03:00
|
|
|
logconfig.program_name = "xrdp-chansrv";
|
2013-08-08 08:02:22 +04:00
|
|
|
g_snprintf(log_file, 255, "%s/xrdp-chansrv.log", log_path);
|
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
|
|
|
|
|
|
|
logconfig.log_file = log_file;
|
|
|
|
logconfig.fd = -1;
|
2013-08-08 08:02:22 +04:00
|
|
|
logconfig.log_level = log_level;
|
2012-09-20 07:51:34 +04:00
|
|
|
logconfig.enable_syslog = 0;
|
|
|
|
logconfig.syslog_level = 0;
|
|
|
|
error = log_start_from_param(&logconfig);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_deinit();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGM((LOG_LEVEL_ALWAYS, "main: app started pid %d(0x%8.8x)", pid, pid));
|
|
|
|
/* 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 */
|
|
|
|
g_signal_child_stop(child_signal_handler); /* SIGCHLD */
|
2013-09-04 06:44:20 +04:00
|
|
|
g_signal_segfault(segfault_signal_handler);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
display_text = g_getenv("DISPLAY");
|
|
|
|
LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text));
|
2015-01-20 15:33:37 +03:00
|
|
|
|
|
|
|
if (display_text)
|
|
|
|
get_display_num_from_display(display_text);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_display_num == 0)
|
2012-08-01 03:54:54 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
LOGM((LOG_LEVEL_ERROR, "main: error, display is zero"));
|
|
|
|
g_deinit();
|
|
|
|
return 1;
|
2012-08-01 03:54:54 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
LOGM((LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num));
|
|
|
|
g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
|
|
|
|
g_term_event = g_create_wait_obj(text);
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (g_obj_wait(waiters, 2, 0, 0, 0) != 0)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_is_wait_obj_set(g_term_event))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
|
|
|
if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
|
|
|
|
{
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
|
|
|
|
break;
|
|
|
|
}
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
main_cleanup();
|
|
|
|
LOGM((LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid));
|
|
|
|
g_deinit();
|
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
2012-09-28 06:48:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* return unused slot in dvc_channels[]
|
|
|
|
*
|
|
|
|
* @return unused slot index on success, -1 on failure
|
|
|
|
******************************************************************************/
|
|
|
|
int APP_CC
|
|
|
|
find_empty_slot_in_dvc_channels()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DVC_CHANNELS; i++)
|
|
|
|
{
|
|
|
|
if (g_dvc_channels[i] == NULL)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return struct xrdp_api_data that contains specified dvc_chan_id
|
|
|
|
*
|
|
|
|
* @param dvc_chan_id channel id to look for
|
|
|
|
*
|
|
|
|
* @return xrdp_api_data struct containing dvc_chan_id or NULL on failure
|
|
|
|
******************************************************************************/
|
|
|
|
struct xrdp_api_data *APP_CC
|
2012-10-05 21:13:53 +04:00
|
|
|
struct_from_dvc_chan_id(tui32 dvc_chan_id)
|
2012-09-28 06:48:44 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DVC_CHANNELS; i++)
|
|
|
|
{
|
2016-06-22 02:30:19 +03:00
|
|
|
if (g_dvc_channels[i]->dvc_chan_id >= 0 &&
|
|
|
|
(tui32) g_dvc_channels[i]->dvc_chan_id == dvc_chan_id)
|
2012-09-28 06:48:44 +04:00
|
|
|
{
|
|
|
|
return g_dvc_channels[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-10-05 21:13:53 +04:00
|
|
|
remove_struct_with_chan_id(tui32 dvc_chan_id)
|
2012-09-28 06:48:44 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DVC_CHANNELS; i++)
|
|
|
|
{
|
2016-06-22 02:30:19 +03:00
|
|
|
if (g_dvc_channels[i]->dvc_chan_id >= 0 &&
|
|
|
|
(tui32) g_dvc_channels[i]->dvc_chan_id == dvc_chan_id)
|
2012-09-28 06:48:44 +04:00
|
|
|
{
|
|
|
|
g_dvc_channels[i] = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|