Remove librdp.so sources, it's obsoleted by neutrinordp

Remove "rdp-any" section from xrdp.ini.
master
Pavel Roskin 7 years ago committed by Jay Sorg
parent c5e6eec12f
commit 2b614ed4ab

@ -50,7 +50,6 @@ endif
SUBDIRS = \
common \
vnc \
rdp \
xup \
mc \
$(NEUTRINORDPDIR) \

@ -307,7 +307,6 @@ AC_CONFIG_FILES([
pkgconfig/Makefile
pkgconfig/xrdp.pc
pkgconfig/xrdp-uninstalled.pc
rdp/Makefile
sesman/chansrv/Makefile
sesman/libscp/Makefile
sesman/Makefile

@ -4,7 +4,6 @@ default build will install the following
/usr/local/lib/xrdp
libcommon.so
libmc.so
librdp.so
libscp.so
libvnc.so
libxrdp.so

@ -1,30 +0,0 @@
AM_CPPFLAGS = \
-DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \
-DXRDP_SBIN_PATH=\"${sbindir}\" \
-DXRDP_SHARE_PATH=\"${datadir}/xrdp\" \
-DXRDP_PID_PATH=\"${localstatedir}/run\" \
-I$(top_srcdir)/common
if XRDP_DEBUG
AM_CPPFLAGS += -DXRDP_DEBUG
endif
module_LTLIBRARIES = \
librdp.la
librdp_la_SOURCES = \
rdp.c \
rdp.h \
rdp_bitmap.c \
rdp_iso.c \
rdp_lic.c \
rdp_mcs.c \
rdp_orders.c \
rdp_rdp.c \
rdp_sec.c \
rdp_tcp.c
librdp_la_LIBADD = \
$(top_builddir)/common/libcommon.la
librdp_la_LDFLAGS = -avoid-version -module

@ -1,354 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp main file
*/
#include "rdp.h"
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_start(struct mod *mod, int w, int h, int bpp)
{
DEBUG(("in lib_mod_start"));
mod->width = w;
mod->height = h;
mod->rdp_bpp = bpp;
mod->xrdp_bpp = bpp;
mod->keylayout = 0x409;
g_strncpy(mod->port, "3389", 255); /* default */
DEBUG(("out lib_mod_start"));
return 0;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_connect(struct mod *mod)
{
DEBUG(("in lib_mod_connect"));
/* clear screen */
mod->server_begin_update(mod);
mod->server_set_fgcolor(mod, 0);
mod->server_fill_rect(mod, 0, 0, mod->width, mod->height);
mod->server_end_update(mod);
/* connect */
if (rdp_rdp_connect(mod->rdp_layer, mod->ip, mod->port) == 0)
{
mod->sck = mod->rdp_layer->sec_layer->mcs_layer->iso_layer->tcp_layer->sck;
g_tcp_set_non_blocking(mod->sck);
g_tcp_set_no_delay(mod->sck);
mod->sck_obj = g_create_wait_obj_from_socket(mod->sck, 0);
DEBUG(("out lib_mod_connect"));
return 0;
}
DEBUG(("out lib_mod_connect error"));
return 1;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_event(struct mod *mod, int msg, long param1, long param2,
long param3, long param4)
{
struct stream *s;
if (!mod->up_and_running)
{
return 0;
}
DEBUG(("in lib_mod_event"));
make_stream(s);
init_stream(s, 8192 * 2);
switch (msg)
{
case 15:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SCANCODE,
param4, param3, 0);
break;
case 16:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SCANCODE,
param4, param3, 0);
break;
case 17:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_SYNCHRONIZE,
param4, param3, 0);
break;
case 100:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_MOVE, param1, param2);
break;
case 101:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON1, param1, param2);
break;
case 102:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON1 | MOUSE_FLAG_DOWN,
param1, param2);
break;
case 103:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON2, param1, param2);
break;
case 104:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON2 | MOUSE_FLAG_DOWN,
param1, param2);
break;
case 105:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON3, param1, param2);
break;
case 106:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON3 | MOUSE_FLAG_DOWN,
param1, param2);
break;
case 107:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON4, param1, param2);
break;
case 108:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON4 | MOUSE_FLAG_DOWN,
param1, param2);
break;
case 109:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON5, param1, param2);
break;
case 110:
rdp_rdp_send_input(mod->rdp_layer, s, 0, RDP_INPUT_MOUSE,
MOUSE_FLAG_BUTTON5 | MOUSE_FLAG_DOWN,
param1, param2);
break;
case 200:
rdp_rdp_send_invalidate(mod->rdp_layer, s,
(param1 >> 16) & 0xffff, param1 & 0xffff,
(param2 >> 16) & 0xffff, param2 & 0xffff);
break;
}
free_stream(s);
DEBUG(("out lib_mod_event"));
return 0;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_signal(struct mod *mod)
{
int type;
int cont;
struct stream *s;
DEBUG(("in lib_mod_signal"));
if (mod->in_s == 0)
{
make_stream(mod->in_s);
}
s = mod->in_s;
init_stream(s, 8192 * 2);
cont = 1;
while (cont)
{
type = 0;
if (rdp_rdp_recv(mod->rdp_layer, s, &type) != 0)
{
DEBUG(("out lib_mod_signal error rdp_rdp_recv failed"));
return 1;
}
DEBUG(("lib_mod_signal type %d", type));
switch (type)
{
case RDP_PDU_DATA:
rdp_rdp_process_data_pdu(mod->rdp_layer, s);
break;
case RDP_PDU_DEMAND_ACTIVE:
rdp_rdp_process_demand_active(mod->rdp_layer, s);
mod->up_and_running = 1;
break;
case RDP_PDU_DEACTIVATE:
mod->up_and_running = 0;
break;
case RDP_PDU_REDIRECT:
break;
case 0:
break;
default:
break;
}
cont = s->next_packet < s->end;
}
DEBUG(("out lib_mod_signal"));
return 0;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_end(struct mod *mod)
{
rdp_rdp_delete(mod->rdp_layer);
mod->rdp_layer = 0;
free_stream(mod->in_s);
mod->in_s = 0;
if (mod->sck_obj != 0)
{
g_delete_wait_obj_from_socket(mod->sck_obj);
mod->sck_obj = 0;
}
if (mod->sck != 0)
{
g_tcp_close(mod->sck);
mod->sck = 0;
}
return 0;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_set_param(struct mod *mod, const char *name, const char *value)
{
if (g_strncasecmp(name, "ip", 255) == 0)
{
g_strncpy(mod->ip, value, 255);
}
else if (g_strncasecmp(name, "port", 255) == 0)
{
g_strncpy(mod->port, value, 255);
}
else if (g_strncasecmp(name, "username", 255) == 0)
{
g_strncpy(mod->username, value, 255);
}
else if (g_strncasecmp(name, "password", 255) == 0)
{
g_strncpy(mod->password, value, 255);
}
else if (g_strncasecmp(name, "hostname", 255) == 0)
{
g_strncpy(mod->hostname, value, 255);
}
else if (g_strncasecmp(name, "keylayout", 255) == 0)
{
mod->keylayout = g_atoi(value);
}
return 0;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_get_wait_objs(struct mod *mod, tbus *read_objs, int *rcount,
tbus *write_objs, int *wcount, int *timeout)
{
int i;
i = *rcount;
if (mod != 0)
{
if (mod->sck_obj != 0)
{
read_objs[i++] = mod->sck_obj;
}
}
*rcount = i;
return 0;
}
/******************************************************************************/
/* return error */
int DEFAULT_CC
lib_mod_check_wait_objs(struct mod *mod)
{
int rv;
rv = 0;
if (mod != 0)
{
if (mod->sck_obj != 0)
{
if (g_is_wait_obj_set(mod->sck_obj))
{
rv = lib_mod_signal(mod);
}
}
}
return rv;
}
/******************************************************************************/
tintptr EXPORT_CC
mod_init(void)
{
struct mod *mod;
DEBUG(("in mod_init"));
mod = (struct mod *)g_malloc(sizeof(struct mod), 1);
mod->size = sizeof(struct mod);
mod->version = CURRENT_MOD_VER;
mod->handle = (tintptr) mod;
mod->mod_connect = lib_mod_connect;
mod->mod_start = lib_mod_start;
mod->mod_event = lib_mod_event;
mod->mod_signal = lib_mod_signal;
mod->mod_end = lib_mod_end;
mod->mod_set_param = lib_mod_set_param;
mod->mod_get_wait_objs = lib_mod_get_wait_objs;
mod->mod_check_wait_objs = lib_mod_check_wait_objs;
mod->rdp_layer = rdp_rdp_create(mod);
DEBUG(("out mod_init"));
return (tintptr) mod;
}
/******************************************************************************/
int EXPORT_CC
mod_exit(tintptr handle)
{
struct mod *mod = (struct mod *) handle;
DEBUG(("in mod_exit"));
g_free(mod);
DEBUG(("out mod_exit"));
return 0;
}

@ -1,465 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp main header file
*/
/* include other h files */
#include "arch.h"
#include "parse.h"
#include "os_calls.h"
#include "ssl_calls.h"
#include "xrdp_constants.h"
#include "defines.h"
struct rdp_brush
{
int xorigin;
int yorigin;
int style;
char pattern[8];
};
struct rdp_pen
{
int style;
int width;
int color;
};
struct rdp_colormap
{
int ncolors;
int colors[256];
};
struct rdp_bitmap
{
int width;
int height;
int bpp;
char* data;
};
struct rdp_cursor
{
int x;
int y;
int width;
int height;
char mask[(32 * 32) / 8];
char data[(32 * 32) * 3];
};
/* tcp */
struct rdp_tcp
{
int sck;
int sck_closed;
struct rdp_iso* iso_layer; /* owner */
};
/* iso */
struct rdp_iso
{
struct rdp_mcs* mcs_layer; /* owner */
struct rdp_tcp* tcp_layer;
};
/* mcs */
struct rdp_mcs
{
struct rdp_sec* sec_layer; /* owner */
struct rdp_iso* iso_layer;
int userid;
struct stream* client_mcs_data;
struct stream* server_mcs_data;
};
/* sec */
struct rdp_sec
{
struct rdp_rdp* rdp_layer; /* owner */
struct rdp_mcs* mcs_layer;
struct rdp_lic* lic_layer;
char server_random[32];
char client_random[64];
char client_crypt_random[72];
struct stream* client_mcs_data;
struct stream* server_mcs_data;
int decrypt_use_count;
int encrypt_use_count;
char decrypt_key[16];
char encrypt_key[16];
char decrypt_update_key[16];
char encrypt_update_key[16];
int rc4_key_size; /* 1 = 40-bit, 2 = 128-bit */
int rc4_key_len; /* 8 or 16 */
int crypt_level; /* 1 = low, 2 = medium, 3 = high */
char sign_key[16];
void* decrypt_rc4_info;
void* encrypt_rc4_info;
};
/* licence */
struct rdp_lic
{
struct rdp_sec* sec_layer; /* owner */
char licence_key[16];
char licence_sign_key[16];
int licence_issued;
};
/* rdp */
struct rdp_rdp
{
struct mod* mod;
struct rdp_sec* sec_layer;
struct rdp_orders* orders;
int share_id;
int use_rdp5;
int bitmap_compression;
int bitmap_cache;
int desktop_save;
int polygon_ellipse_orders;
int rec_mode;
int rec_fd;
/* cache */
struct rdp_colormap colormap;
struct rdp_cursor cursors[32];
};
struct rdp_orders_state
{
/* order stuff */
int order_type;
/* clip state */
int clip_left;
int clip_top;
int clip_right;
int clip_bottom;
/* text order state */
int text_font;
int text_flags;
int text_opcode;
int text_mixmode;
int text_fgcolor;
int text_bgcolor;
int text_clipleft;
int text_cliptop;
int text_clipright;
int text_clipbottom;
int text_boxleft;
int text_boxtop;
int text_boxright;
int text_boxbottom;
struct rdp_brush text_brush;
int text_x;
int text_y;
int text_length;
char text_text[256];
/* destblt order state */
int dest_x;
int dest_y;
int dest_cx;
int dest_cy;
int dest_opcode;
/* patblt order state */
int pat_x;
int pat_y;
int pat_cx;
int pat_cy;
int pat_opcode;
int pat_bgcolor;
int pat_fgcolor;
struct rdp_brush pat_brush;
/* screenblt order state */
int screenblt_x;
int screenblt_y;
int screenblt_cx;
int screenblt_cy;
int screenblt_opcode;
int screenblt_srcx;
int screenblt_srcy;
/* line order state */
int line_mixmode;
int line_startx;
int line_starty;
int line_endx;
int line_endy;
int line_bgcolor;
int line_opcode;
struct rdp_pen line_pen;
/* rect order state */
int rect_x;
int rect_y;
int rect_cx;
int rect_cy;
int rect_color;
/* desksave order state */
int desksave_offset;
int desksave_left;
int desksave_top;
int desksave_right;
int desksave_bottom;
int desksave_action;
/* memblt order state */
int memblt_cache_id;
int memblt_color_table;
int memblt_x;
int memblt_y;
int memblt_cx;
int memblt_cy;
int memblt_opcode;
int memblt_srcx;
int memblt_srcy;
int memblt_cache_idx;
/* polyline order state */
int polyline_x;
int polyline_y;
int polyline_opcode;
int polyline_fgcolor;
int polyline_lines;
int polyline_datasize;
char polyline_data[256];
};
/* orders */
struct rdp_orders
{
struct rdp_rdp* rdp_layer;
/* order state */
struct rdp_orders_state state;
/* cache */
struct rdp_colormap* cache_colormap[6];
struct rdp_bitmap* cache_bitmap[3][600];
};
#define CURRENT_MOD_VER 2
struct mod
{
int size; /* size of this struct */
int version; /* internal version */
/* client functions */
int (*mod_start)(struct mod* v, int w, int h, int bpp);
int (*mod_connect)(struct mod* v);
int (*mod_event)(struct mod* v, int msg, long param1, long param2,
long param3, long param4);
int (*mod_signal)(struct mod* v);
int (*mod_end)(struct mod* v);
int (*mod_set_param)(struct mod *v, const char *name, const char *value);
int (*mod_session_change)(struct mod* v, int, int);
int (*mod_get_wait_objs)(struct mod* v, tbus* read_objs, int* rcount,
tbus* write_objs, int* wcount, int* timeout);
int (*mod_check_wait_objs)(struct mod* v);
long mod_dumby[100 - 9]; /* align, 100 minus the number of mod
functions above */
/* server functions */
int (*server_begin_update)(struct mod* v);
int (*server_end_update)(struct mod* v);
int (*server_fill_rect)(struct mod* v, int x, int y, int cx, int cy);
int (*server_screen_blt)(struct mod* v, int x, int y, int cx, int cy,
int srcx, int srcy);
int (*server_paint_rect)(struct mod* v, int x, int y, int cx, int cy,
char* data, int width, int height, int srcx, int srcy);
int (*server_set_cursor)(struct mod* v, int x, int y, char* data, char* mask);
int (*server_palette)(struct mod* v, int* palette);
int (*server_msg)(struct mod* v, char* msg, int code);
int (*server_is_term)(struct mod* v);
int (*server_set_clip)(struct mod* v, int x, int y, int cx, int cy);
int (*server_reset_clip)(struct mod* v);
int (*server_set_fgcolor)(struct mod* v, int fgcolor);
int (*server_set_bgcolor)(struct mod* v, int bgcolor);
int (*server_set_opcode)(struct mod* v, int opcode);
int (*server_set_mixmode)(struct mod* v, int mixmode);
int (*server_set_brush)(struct mod* v, int x_origin, int y_origin,
int style, char* pattern);
int (*server_set_pen)(struct mod* v, int style,
int width);
int (*server_draw_line)(struct mod* v, int x1, int y1, int x2, int y2);
int (*server_add_char)(struct mod* v, int font, int character,
int offset, int baseline,
int width, int height, char* data);
int (*server_draw_text)(struct mod* v, int font,
int flags, int mixmode, int clip_left, int clip_top,
int clip_right, int clip_bottom,
int box_left, int box_top,
int box_right, int box_bottom,
int x, int y, char* data, int data_len);
int (*server_reset)(struct mod* v, int width, int height, int bpp);
int (*server_query_channel)(struct mod* v, int index,
char* channel_name,
int* channel_flags);
int (*server_get_channel_id)(struct mod* v, const char *name);
int (*server_send_to_channel)(struct mod* v, int channel_id,
char* data, int data_len,
int total_data_len, int flags);
int (*server_bell_trigger)(struct mod* v);
long server_dumby[100 - 25]; /* align, 100 minus the number of server
functions above */
/* common */
long handle; /* pointer to self as long */
long wm;
long painter;
int sck;
/* mod data */
struct rdp_rdp* rdp_layer;
int width;
int height;
int rdp_bpp;
int xrdp_bpp;
char ip[256];
char port[256];
char username[256];
char password[256];
char hostname[256];
char domain[256];
char program[256];
char directory[256];
int keylayout;
int up_and_running;
struct stream* in_s;
tbus sck_obj;
};
/* rdp_tcp.c */
struct rdp_tcp* APP_CC
rdp_tcp_create(struct rdp_iso* owner);
void APP_CC
rdp_tcp_delete(struct rdp_tcp* self);
int APP_CC
rdp_tcp_init(struct rdp_tcp* self, struct stream* s);
int APP_CC
rdp_tcp_recv(struct rdp_tcp* self, struct stream* s, int len);
int APP_CC
rdp_tcp_send(struct rdp_tcp* self, struct stream* s);
int APP_CC
rdp_tcp_connect(struct rdp_tcp* self, char* ip, char* port);
int APP_CC
rdp_tcp_disconnect(struct rdp_tcp* self);
/* rdp_ico.c */
struct rdp_iso* APP_CC
rdp_iso_create(struct rdp_mcs* owner);
void APP_CC
rdp_iso_delete(struct rdp_iso* self);
int APP_CC
rdp_iso_recv(struct rdp_iso* self, struct stream* s);
int APP_CC
rdp_iso_init(struct rdp_iso* self, struct stream* s);
int APP_CC
rdp_iso_send(struct rdp_iso* self, struct stream* s);
int APP_CC
rdp_iso_connect(struct rdp_iso* self, char* ip, char* port);
int APP_CC
rdp_iso_disconnect(struct rdp_iso* self);
/* rdp_mcs.c */
struct rdp_mcs* APP_CC
rdp_mcs_create(struct rdp_sec* owner,
struct stream* client_mcs_data,
struct stream* server_mcs_data);
void APP_CC
rdp_mcs_delete(struct rdp_mcs* self);
int APP_CC
rdp_mcs_init(struct rdp_mcs* self, struct stream* s);
int APP_CC
rdp_mcs_send(struct rdp_mcs* self, struct stream* s);
int APP_CC
rdp_mcs_connect(struct rdp_mcs* self, char* ip, char* port);
int APP_CC
rdp_mcs_recv(struct rdp_mcs* self, struct stream* s, int* chan);
/* rdp_sec.c */
struct rdp_sec* APP_CC
rdp_sec_create(struct rdp_rdp* owner);
void APP_CC
rdp_sec_delete(struct rdp_sec* self);
int APP_CC
rdp_sec_init(struct rdp_sec* self, struct stream* s, int flags);
int APP_CC
rdp_sec_send(struct rdp_sec* self, struct stream* s, int flags);
int APP_CC
rdp_sec_recv(struct rdp_sec* self, struct stream* s, int* chan);
int APP_CC
rdp_sec_connect(struct rdp_sec* self, char* ip, char* port);
void APP_CC
rdp_sec_buf_out_uint32(char* buffer, int value);
void APP_CC
rdp_sec_hash_16(char* out, char* in, char* salt1, char* salt2);
void APP_CC
rdp_sec_hash_48(char* out, char* in, char* salt1, char* salt2, int salt);
void APP_CC
rdp_sec_sign(char* signature, int siglen, char* session_key, int keylen,
char* data, int datalen);
/* rdp_rdp.c */
struct rdp_rdp* APP_CC
rdp_rdp_create(struct mod* owner);
void APP_CC
rdp_rdp_delete(struct rdp_rdp* self);
int APP_CC
rdp_rdp_connect(struct rdp_rdp* self, char* ip, char* port);
int APP_CC
rdp_rdp_send_input(struct rdp_rdp* self, struct stream* s,
int time, int message_type,
int device_flags, int param1, int param2);
int APP_CC
rdp_rdp_send_invalidate(struct rdp_rdp* self, struct stream* s,
int left, int top, int width, int height);
int APP_CC
rdp_rdp_recv(struct rdp_rdp* self, struct stream* s, int* type);
int APP_CC
rdp_rdp_process_data_pdu(struct rdp_rdp* self, struct stream* s);
int APP_CC
rdp_rdp_process_demand_active(struct rdp_rdp* self, struct stream* s);
void APP_CC
rdp_rdp_out_unistr(struct stream* s, char* text);
int APP_CC
rdp_rec_check_file(struct rdp_rdp* self);
int APP_CC
rdp_rec_write_item(struct rdp_rdp* self, struct stream* s);
/* rdp_bitmap.c */
int APP_CC
rdp_bitmap_decompress(char* output, int width, int height, char* input,
int size, int Bpp);
/* rdp_orders.c */
struct rdp_orders* APP_CC
rdp_orders_create(struct rdp_rdp* owner);
void APP_CC
rdp_orders_delete(struct rdp_orders* self);
void APP_CC
rdp_orders_reset_state(struct rdp_orders* self);
int APP_CC
rdp_orders_process_orders(struct rdp_orders* self, struct stream* s,
int num_orders);
char* APP_CC
rdp_orders_convert_bitmap(int in_bpp, int out_bpp, char* bmpdata,
int width, int height, int* palette);
int APP_CC
rdp_orders_convert_color(int in_bpp, int out_bpp, int in_color, int* palette);
/* rdp_lic.c */
struct rdp_lic* APP_CC
rdp_lic_create(struct rdp_sec* owner);
void APP_CC
rdp_lic_delete(struct rdp_lic* self);
void APP_CC
rdp_lic_process(struct rdp_lic* self, struct stream* s);

@ -1,999 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp bitmap routines
*/
#include "rdp.h"
/******************************************************************************/
#define CVAL(p) ((unsigned char)(*(p++)))
#if defined(B_ENDIAN)
#define EIK0 1
#define EIK1 0
#else
#define EIK0 0
#define EIK1 1
#endif
/******************************************************************************/
#define REPEAT(statement) \
{ \
while ((count > 0) && (x < width)) \
{ \
statement; \
count--; \
x++; \
} \
}
/******************************************************************************/
#define MASK_UPDATE \
{ \
mixmask <<= 1; \
if ((mixmask & 0xff) == 0) \
{ \
mask = fom_mask ? fom_mask : CVAL(input); \
mixmask = 1; \
} \
}
/******************************************************************************/
/* 1 byte bitmap decompress */
/* returns boolean */
static int APP_CC
bitmap_decompress1(char *output, int width, int height, char *input, int size)
{
char *prevline;
char *line;
char *end;
char color1;
char color2;
char mix;
int code;
int mixmask;
int mask;
int opcode;
int count;
int offset;
int isfillormix;
int x;
int lastopcode;
int insertmix;
int bicolor;
int fom_mask;
end = input + size;
prevline = 0;
line = 0;
x = width;
lastopcode = -1;
insertmix = 0;
bicolor = 0;
color1 = 0;
color2 = 0;
mix = 0xff;
mask = 0;
fom_mask = 0;
while (input < end)
{
fom_mask = 0;
code = CVAL(input);
opcode = code >> 4;
/* Handle different opcode forms */
switch (opcode)
{
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
count = code & 0xf;
offset = 16;
break;
case 0xf:
opcode = code & 0xf;
if (opcode < 9)
{
count = CVAL(input);
count |= CVAL(input) << 8;
}
else
{
count = (opcode < 0xb) ? 8 : 1;
}
offset = 0;
break;
default:
opcode >>= 1;
count = code & 0x1f;
offset = 32;
break;
}
/* Handle strange cases for counts */
if (offset != 0)
{
isfillormix = ((opcode == 2) || (opcode == 7));
if (count == 0)
{
if (isfillormix)
{
count = CVAL(input) + 1;
}
else
{
count = CVAL(input) + offset;
}
}
else if (isfillormix)
{
count <<= 3;
}
}
/* Read preliminary data */
switch (opcode)
{
case 0: /* Fill */
if ((lastopcode == opcode) && !((x == width) && (prevline == 0)))
{
insertmix = 1;
}
break;
case 8: /* Bicolor */
color1 = CVAL(input);
/* fall through is intentional */
case 3: /* Color */
color2 = CVAL(input);
break;
case 6: /* SetMix/Mix */
case 7: /* SetMix/FillOrMix */
mix = CVAL(input);
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0)
{
if (x >= width)
{
if (height <= 0)
{
return 0;
}
x = 0;
height--;
prevline = line;
line = output + height * width;
}
switch (opcode)
{
case 0: /* Fill */
if (insertmix)
{
if (prevline == 0)
{
line[x] = mix;
}
else
{
line[x] = prevline[x] ^ mix;
}
insertmix = 0;
count--;
x++;
}
if (prevline == 0)
{
REPEAT(line[x] = 0)
}
else
{
REPEAT(line[x] = prevline[x])
}
break;
case 1: /* Mix */
if (prevline == 0)
{
REPEAT(line[x] = mix)
}
else
{
REPEAT(line[x] = prevline[x] ^ mix)
}
break;
case 2: /* Fill or Mix */
if (prevline == 0)
{
REPEAT
(
MASK_UPDATE;
if (mask & mixmask)
{
line[x] = mix;
}
else
{
line[x] = 0;
}
)
}
else
{
REPEAT
(
MASK_UPDATE;
if (mask & mixmask)
{
line[x] = prevline[x] ^ mix;
}
else
{
line[x] = prevline[x];
}
)
}
break;
case 3: /* Color */
REPEAT(line[x] = color2)
break;
case 4: /* Copy */
REPEAT(line[x] = CVAL(input))
break;
case 8: /* Bicolor */
REPEAT
(
if (bicolor)
{
line[x] = color2;
bicolor = 0;
}
else
{
line[x] = color1;
bicolor = 1;
count++;
}
)
break;
case 0xd: /* White */
REPEAT(line[x] = 0xff)
break;
case 0xe: /* Black */
REPEAT(line[x] = 0)
break;
default:
return 0;
break;
}
}
}
return 1;
}
/******************************************************************************/
/* 2 byte bitmap decompress */
/* returns boolean */
static int APP_CC
bitmap_decompress2(char *output, int width, int height, char *input, int size)
{
char *prevline;
char *line;
char *end;
char color1[2];
char color2[2];
char mix[2];
int code;
int mixmask;
int mask;
int opcode;
int count;
int offset;
int isfillormix;
int x;
int lastopcode;
int insertmix;
int bicolor;
int fom_mask;
end = input + size;
prevline = 0;
line = 0;
x = width;
lastopcode = -1;
insertmix = 0;
bicolor = 0;
color1[0] = 0;
color1[1] = 0;
color2[0] = 0;
color2[1] = 0;
mix[0] = 0xff;
mix[1] = 0xff;
mask = 0;
fom_mask = 0;
while (input < end)
{
fom_mask = 0;
code = CVAL(input);
opcode = code >> 4;
/* Handle different opcode forms */
switch (opcode)
{
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
count = code & 0xf;
offset = 16;
break;
case 0xf:
opcode = code & 0xf;
if (opcode < 9)
{
count = CVAL(input);
count |= CVAL(input) << 8;
}
else
{
count = (opcode < 0xb) ? 8 : 1;
}
offset = 0;
break;
default:
opcode >>= 1;
count = code & 0x1f;
offset = 32;
break;
}
/* Handle strange cases for counts */
if (offset != 0)
{
isfillormix = ((opcode == 2) || (opcode == 7));
if (count == 0)
{
if (isfillormix)
{
count = CVAL(input) + 1;
}
else
{
count = CVAL(input) + offset;
}
}
else if (isfillormix)
{
count <<= 3;
}
}
/* Read preliminary data */
switch (opcode)
{
case 0: /* Fill */
if ((lastopcode == opcode) && !((x == width) && (prevline == 0)))
{
insertmix = 1;
}
break;
case 8: /* Bicolor */
color1[EIK0] = CVAL(input);
color1[EIK1] = CVAL(input);
/* fall through is intentional */
case 3: /* Color */
color2[EIK0] = CVAL(input);
color2[EIK1] = CVAL(input);
break;
case 6: /* SetMix/Mix */
case 7: /* SetMix/FillOrMix */
mix[EIK0] = CVAL(input);
mix[EIK1] = CVAL(input);
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0)
{
if (x >= width)
{
if (height <= 0)
{
return 0;
}
x = 0;
height--;
prevline = line;
line = output + height * (width * 2);
}
switch (opcode)
{
case 0: /* Fill */
if (insertmix)
{
if (prevline == 0)
{
line[x * 2 + 0] = mix[0];
line[x * 2 + 1] = mix[1];
}
else
{
line[x * 2 + 0] = prevline[x * 2 + 0] ^ mix[0];
line[x * 2 + 1] = prevline[x * 2 + 1] ^ mix[1];
}
insertmix = 0;
count--;
x++;
}
if (prevline == 0)
{
REPEAT
(
line[x * 2 + 0] = 0;
line[x * 2 + 1] = 0;
)
}
else
{
REPEAT
(
line[x * 2 + 0] = prevline[x * 2 + 0];
line[x * 2 + 1] = prevline[x * 2 + 1];
)
}
break;
case 1: /* Mix */
if (prevline == 0)
{
REPEAT
(
line[x * 2 + 0] = mix[0];
line[x * 2 + 1] = mix[1];
)
}
else
{
REPEAT
(
line[x * 2 + 0] = prevline[x * 2 + 0] ^ mix[0];
line[x * 2 + 1] = prevline[x * 2 + 1] ^ mix[1];
)
}
break;
case 2: /* Fill or Mix */
if (prevline == 0)
{
REPEAT
(
MASK_UPDATE;
if (mask & mixmask)
{
line[x * 2 + 0] = mix[0];
line[x * 2 + 1] = mix[1];
}
else
{
line[x * 2 + 0] = 0;
line[x * 2 + 1] = 0;
}
)
}
else
{
REPEAT
(
MASK_UPDATE;
if (mask & mixmask)
{
line[x * 2 + 0] = prevline[x * 2 + 0] ^ mix[0];
line[x * 2 + 1] = prevline[x * 2 + 1] ^ mix[1];
}
else
{
line[x * 2 + 0] = prevline[x * 2 + 0];
line[x * 2 + 1] = prevline[x * 2 + 1];
}
)
}
break;
case 3: /* Color */
REPEAT
(
line[x * 2 + 0] = color2[0];
line[x * 2 + 1] = color2[1];
)
break;
case 4: /* Copy */
REPEAT
(
line[x * 2 + EIK0] = CVAL(input);
line[x * 2 + EIK1] = CVAL(input);
)
break;
case 8: /* Bicolor */
REPEAT
(
if (bicolor)
{
line[x * 2 + 0] = color2[0];
line[x * 2 + 1] = color2[1];
bicolor = 0;
}
else
{
line[x * 2 + 0] = color1[0];
line[x * 2 + 1] = color1[1];
bicolor = 1;
count++;
}
)
break;
case 0xd: /* White */
REPEAT
(
line[x * 2 + 0] = 0xff;
line[x * 2 + 1] = 0xff;
)
break;
case 0xe: /* Black */
REPEAT
(
line[x * 2 + 0] = 0;
line[x * 2 + 1] = 0;
)
break;
default:
return 0;
break;
}
}
}
return 1;
}
/******************************************************************************/
/* 3 byte bitmap decompress */
/* returns boolean */
static int APP_CC
bitmap_decompress3(char *output, int width, int height, char *input, int size)
{
char *prevline;
char *line;
char *end;
char color1[3];
char color2[3];
char mix[3];
int code;
int mixmask;
int mask;
int opcode;
int count;
int offset;
int isfillormix;
int x;
int lastopcode;
int insertmix;
int bicolor;
int fom_mask;
end = input + size;
prevline = 0;
line = 0;
x = width;
lastopcode = -1;
insertmix = 0;
bicolor = 0;
color1[0] = 0;
color1[1] = 0;
color1[2] = 0;
color2[0] = 0;
color2[1] = 0;
color2[2] = 0;
mix[0] = 0xff;
mix[1] = 0xff;
mix[2] = 0xff;
mask = 0;
fom_mask = 0;
while (input < end)
{
fom_mask = 0;
code = CVAL(input);
opcode = code >> 4;
/* Handle different opcode forms */
switch (opcode)
{
case 0xc:
case 0xd:
case 0xe:
opcode -= 6;
count = code & 0xf;
offset = 16;
break;
case 0xf:
opcode = code & 0xf;
if (opcode < 9)
{
count = CVAL(input);
count |= CVAL(input) << 8;
}
else
{
count = (opcode < 0xb) ? 8 : 1;
}
offset = 0;
break;
default:
opcode >>= 1;
count = code & 0x1f;
offset = 32;
break;
}
/* Handle strange cases for counts */
if (offset != 0)
{
isfillormix = ((opcode == 2) || (opcode == 7));
if (count == 0)
{
if (isfillormix)
{
count = CVAL(input) + 1;
}
else
{
count = CVAL(input) + offset;
}
}
else if (isfillormix)
{
count <<= 3;
}
}
/* Read preliminary data */
switch (opcode)
{
case 0: /* Fill */
if ((lastopcode == opcode) && !((x == width) && (prevline == 0)))
{
insertmix = 1;
}
break;
case 8: /* Bicolor */
color1[0] = CVAL(input);
color1[1] = CVAL(input);
color1[2] = CVAL(input);
/* fall through is intentional */
case 3: /* Color */
color2[0] = CVAL(input);
color2[1] = CVAL(input);
color2[2] = CVAL(input);
break;
case 6: /* SetMix/Mix */
case 7: /* SetMix/FillOrMix */
mix[0] = CVAL(input);
mix[1] = CVAL(input);
mix[2] = CVAL(input);
opcode -= 5;
break;
case 9: /* FillOrMix_1 */
mask = 0x03;
opcode = 0x02;
fom_mask = 3;
break;
case 0x0a: /* FillOrMix_2 */
mask = 0x05;
opcode = 0x02;
fom_mask = 5;
break;
}
lastopcode = opcode;
mixmask = 0;
/* Output body */
while (count > 0)
{
if (x >= width)
{
if (height <= 0)
{
return 0;
}
x = 0;
height--;
prevline = line;
line = output + height * (width * 3);
}
switch (opcode)
{
case 0: /* Fill */
if (insertmix)
{
if (prevline == 0)
{
line[x * 3 + 0] = mix[0];
line[x * 3 + 1] = mix[1];
line[x * 3 + 2] = mix[2];
}
else
{
line[x * 3 + 0] = prevline[x * 3 + 0] ^ mix[0];
line[x * 3 + 1] = prevline[x * 3 + 1] ^ mix[1];
line[x * 3 + 2] = prevline[x * 3 + 2] ^ mix[2];
}
insertmix = 0;
count--;
x++;
}
if (prevline == 0)
{
REPEAT
(
line[x * 3 + 0] = 0;
line[x * 3 + 1] = 0;
line[x * 3 + 2] = 0;
)
}
else
{
REPEAT
(
line[x * 3 + 0] = prevline[x * 3 + 0];
line[x * 3 + 1] = prevline[x * 3 + 1];
line[x * 3 + 2] = prevline[x * 3 + 2];
)
}
break;
case 1: /* Mix */
if (prevline == 0)
{
REPEAT
(
line[x * 3 + 0] = mix[0];
line[x * 3 + 1] = mix[1];
line[x * 3 + 2] = mix[2];
)
}
else
{
REPEAT
(
line[x * 3 + 0] = prevline[x * 3 + 0] ^ mix[0];
line[x * 3 + 1] = prevline[x * 3 + 1] ^ mix[1];
line[x * 3 + 2] = prevline[x * 3 + 2] ^ mix[2];
)
}
break;
case 2: /* Fill or Mix */
if (prevline == 0)
{
REPEAT
(
MASK_UPDATE;
if (mask & mixmask)
{
line[x * 3 + 0] = mix[0];
line[x * 3 + 1] = mix[1];
line[x * 3 + 2] = mix[2];
}
else
{
line[x * 3 + 0] = 0;
line[x * 3 + 1] = 0;
line[x * 3 + 2] = 0;
}
)
}
else
{
REPEAT
(
MASK_UPDATE;
if (mask & mixmask)
{
line[x * 3 + 0] = prevline[x * 3 + 0] ^ mix[0];
line[x * 3 + 1] = prevline[x * 3 + 1] ^ mix[1];
line[x * 3 + 2] = prevline[x * 3 + 2] ^ mix[2];
}
else
{
line[x * 3 + 0] = prevline[x * 3 + 0];
line[x * 3 + 1] = prevline[x * 3 + 1];
line[x * 3 + 2] = prevline[x * 3 + 2];
}
)
}
break;
case 3: /* Color */
REPEAT
(
line[x * 3 + 0] = color2[0];
line[x * 3 + 1] = color2[1];
line[x * 3 + 2] = color2[2];
)
break;
case 4: /* Copy */
REPEAT
(
line[x * 3 + 0] = CVAL(input);
line[x * 3 + 1] = CVAL(input);
line[x * 3 + 2] = CVAL(input);
)
break;
case 8: /* Bicolor */
REPEAT
(
if (bicolor)
{
line[x * 3 + 0] = color2[0];
line[x * 3 + 1] = color2[1];
line[x * 3 + 2] = color2[2];
bicolor = 0;
}
else
{
line[x * 3 + 0] = color1[0];
line[x * 3 + 1] = color1[1];
line[x * 3 + 2] = color1[2];
bicolor = 1;
count++;
}
)
break;
case 0xd: /* White */
REPEAT
(
line[x * 3 + 0] = 0xff;
line[x * 3 + 1] = 0xff;
line[x * 3 + 2] = 0xff;
)
break;
case 0xe: /* Black */
REPEAT
(
line[x * 3 + 0] = 0;
line[x * 3 + 1] = 0;
line[x * 3 + 2] = 0;
)
break;
default:
return 0;
break;
}
}
}
return 1;
}
/*****************************************************************************/
/* returns boolean */
int APP_CC
rdp_bitmap_decompress(char *output, int width, int height, char *input,
int size, int Bpp)
{
int rv;
switch (Bpp)
{
case 1:
rv = bitmap_decompress1(output, width, height, input, size);
break;
case 2:
rv = bitmap_decompress2(output, width, height, input, size);
break;
case 3:
rv = bitmap_decompress3(output, width, height, input, size);
break;
default:
rv = 0;
break;
}
return rv;
}

@ -1,239 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp iso layer
*/
#include "rdp.h"
/*****************************************************************************/
struct rdp_iso *APP_CC
rdp_iso_create(struct rdp_mcs *owner)
{
struct rdp_iso *self;
self = (struct rdp_iso *)g_malloc(sizeof(struct rdp_iso), 1);
self->mcs_layer = owner;
self->tcp_layer = rdp_tcp_create(self);
return self;
}
/*****************************************************************************/
void APP_CC
rdp_iso_delete(struct rdp_iso *self)
{
if (self == 0)
{
return;
}
rdp_tcp_delete(self->tcp_layer);
g_free(self);
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_iso_recv_msg(struct rdp_iso *self, struct stream *s, int *code)
{
int ver;
int len;
*code = 0;
if (rdp_tcp_recv(self->tcp_layer, s, 4) != 0)
{
DEBUG((" out rdp_iso_recv_msg error rdp_tcp_recv 1 failed"));
return 1;
}
in_uint8(s, ver);
if (ver != 3)
{
DEBUG((" out rdp_iso_recv_msg error ver != 3"));
return 1;
}
in_uint8s(s, 1);
in_uint16_be(s, len);
if (rdp_tcp_recv(self->tcp_layer, s, len - 4) != 0)
{
DEBUG((" out rdp_iso_recv_msg error rdp_tcp_recv 2 failed"));
return 1;
}
in_uint8s(s, 1);
in_uint8(s, *code);
if (*code == ISO_PDU_DT)
{
in_uint8s(s, 1);
}
else
{
in_uint8s(s, 5);
}
return 0;
}
/*****************************************************************************/
static int APP_CC
rdp_iso_send_msg(struct rdp_iso *self, struct stream *s, int code)
{
if (rdp_tcp_init(self->tcp_layer, s) != 0)
{
return 1;
}
out_uint8(s, 3);
out_uint8(s, 0);
out_uint16_be(s, 11); /* length */
out_uint8(s, 6);
out_uint8(s, code);
out_uint16_le(s, 0);
out_uint16_le(s, 0);
out_uint8(s, 0);
s_mark_end(s);
if (rdp_tcp_send(self->tcp_layer, s) != 0)
{
return 1;
}
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_iso_recv(struct rdp_iso *self, struct stream *s)
{
int code;
if (rdp_iso_recv_msg(self, s, &code) != 0)
{
return 1;
}
if (code != ISO_PDU_DT)
{
return 1;
}
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_iso_init(struct rdp_iso *self, struct stream *s)
{
rdp_tcp_init(self->tcp_layer, s);
s_push_layer(s, iso_hdr, 7);
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_iso_send(struct rdp_iso *self, struct stream *s)
{
int len;
s_pop_layer(s, iso_hdr);
len = s->end - s->p;
out_uint8(s, 3);
out_uint8(s, 0);
out_uint16_be(s, len);
out_uint8(s, 2);
out_uint8(s, ISO_PDU_DT);
out_uint8(s, 0x80);
if (rdp_tcp_send(self->tcp_layer, s) != 0)
{
return 1;
}
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_iso_connect(struct rdp_iso *self, char *ip, char *port)
{
int code;
struct stream *s;
DEBUG((" in rdp_iso_connect"));
make_stream(s);
init_stream(s, 8192);
if (rdp_tcp_connect(self->tcp_layer, ip, port) != 0)
{
free_stream(s);
DEBUG((" out rdp_iso_connect error rdp_tcp_connect failed"));
return 1;
}
if (rdp_iso_send_msg(self, s, ISO_PDU_CR) != 0)
{
free_stream(s);
rdp_tcp_disconnect(self->tcp_layer);
DEBUG((" out rdp_iso_connect error rdp_iso_send_msg failed"));
return 1;
}
init_stream(s, 8192);
if (rdp_iso_recv_msg(self, s, &code) != 0)
{
free_stream(s);
rdp_tcp_disconnect(self->tcp_layer);
DEBUG((" out rdp_iso_connect error rdp_iso_recv_msg failed"));
return 1;
}
if (code != ISO_PDU_CC)
{
free_stream(s);
rdp_tcp_disconnect(self->tcp_layer);
DEBUG((" out rdp_iso_connect error code != ISO_PDU_CC"));
return 1;
}
free_stream(s);
DEBUG((" out rdp_iso_connect"));
return 0;
}
/*****************************************************************************/
int APP_CC
rdp_iso_disconnect(struct rdp_iso *self)
{
struct stream *s;
make_stream(s);
init_stream(s, 8192);
rdp_iso_send_msg(self, s, ISO_PDU_DR);
rdp_tcp_disconnect(self->tcp_layer);
free_stream(s);
return 0;
}

@ -1,375 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* licence
*/
#include "rdp.h"
/*****************************************************************************/
struct rdp_lic *APP_CC
rdp_lic_create(struct rdp_sec *owner)
{
struct rdp_lic *self;
self = (struct rdp_lic *)g_malloc(sizeof(struct rdp_lic), 1);
self->sec_layer = owner;
return self;
}
/*****************************************************************************/
void APP_CC
rdp_lic_delete(struct rdp_lic *self)
{
if (self == 0)
{
return;
}
g_free(self);
}
/*****************************************************************************/
/* Generate a session key and RC4 keys, given client and server randoms */
static void APP_CC
rdp_lic_generate_keys(struct rdp_lic *self, char *client_random,
char *server_random, char *pre_master_secret)
{
char master_secret[48];
char key_block[48];
/* Generate master secret and then key material */
rdp_sec_hash_48(master_secret, pre_master_secret, client_random,
server_random, 65);
rdp_sec_hash_48(key_block, master_secret, server_random,
client_random, 65);
/* Store first 16 bytes of session key as MAC secret */
g_memcpy(self->licence_sign_key, key_block, 16);
/* Generate RC4 key from next 16 bytes */
rdp_sec_hash_16(self->licence_key, key_block + 16, client_random,
server_random);
}
/*****************************************************************************/
static void APP_CC
rdp_lic_generate_hwid(struct rdp_lic *self, char *hwid)
{
rdp_sec_buf_out_uint32(hwid, 2);
g_strncpy(hwid + 4, self->sec_layer->rdp_layer->mod->hostname,
LICENCE_HWID_SIZE - 4);
}
#if 0
/*****************************************************************************/
/* Present an existing licence to the server */
static void APP_CC
rdp_lic_present(struct rdp_lic *self, char *client_random, char *rsa_data,
char *licence_data, int licence_size, char *hwid,
char *signature)
{
int sec_flags;
int length;
struct stream *s;
sec_flags = SEC_LICENCE_NEG;
length = 16 + SEC_RANDOM_SIZE + SEC_MODULUS_SIZE + SEC_PADDING_SIZE +
licence_size + LICENCE_HWID_SIZE + LICENCE_SIGNATURE_SIZE;
make_stream(s);
init_stream(s, 8192);
rdp_sec_init(self->sec_layer, s, sec_flags);
out_uint8(s, LICENCE_TAG_PRESENT);
out_uint8(s, 2); /* version */
out_uint16_le(s, length);
out_uint32_le(s, 1);
out_uint16_le(s, 0);
out_uint16_le(s, 0x0201);
out_uint8p(s, client_random, SEC_RANDOM_SIZE);
out_uint16_le(s, 0);
out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
out_uint8s(s, SEC_PADDING_SIZE);
out_uint16_le(s, 1);
out_uint16_le(s, licence_size);
out_uint8p(s, licence_data, licence_size);
out_uint16_le(s, 1);
out_uint16_le(s, LICENCE_HWID_SIZE);
out_uint8p(s, hwid, LICENCE_HWID_SIZE);
out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
s_mark_end(s);
rdp_sec_send(self->sec_layer, s, sec_flags);
free_stream(s);
}
#endif
/*****************************************************************************/
/* Send a licence request packet */
static void APP_CC
rdp_lic_send_request(struct rdp_lic *self, char *client_random,
char *rsa_data, char *user, char *host)
{
int sec_flags;
int userlen;
int hostlen;
int length;
struct stream *s;
sec_flags = SEC_LICENCE_NEG;
userlen = g_strlen(user) + 1;
hostlen = g_strlen(host) + 1;
length = 128 + userlen + hostlen;
make_stream(s);
init_stream(s, 8192);
rdp_sec_init(self->sec_layer, s, sec_flags);
out_uint8(s, LICENCE_TAG_REQUEST);
out_uint8(s, 2); /* version */
out_uint16_le(s, length);
out_uint32_le(s, 1);
out_uint16_le(s, 0);
out_uint16_le(s, 0xff01);
out_uint8p(s, client_random, SEC_RANDOM_SIZE);
out_uint16_le(s, 0);
out_uint16_le(s, (SEC_MODULUS_SIZE + SEC_PADDING_SIZE));
out_uint8p(s, rsa_data, SEC_MODULUS_SIZE);
out_uint8s(s, SEC_PADDING_SIZE);
out_uint16_le(s, LICENCE_TAG_USER);
out_uint16_le(s, userlen);
out_uint8p(s, user, userlen);
out_uint16_le(s, LICENCE_TAG_HOST);
out_uint16_le(s, hostlen);
out_uint8p(s, host, hostlen);
s_mark_end(s);
rdp_sec_send(self->sec_layer, s, sec_flags);
free_stream(s);
}
/*****************************************************************************/
/* Process a licence demand packet */
static void APP_CC
rdp_lic_process_demand(struct rdp_lic *self, struct stream *s)
{
char null_data[SEC_MODULUS_SIZE];
char *server_random;
/* Retrieve the server random from the incoming packet */
in_uint8p(s, server_random, SEC_RANDOM_SIZE);
/* We currently use null client keys. This is a bit naughty but, hey,
the security of licence negotiation isn't exactly paramount. */
g_memset(null_data, 0, sizeof(null_data));
rdp_lic_generate_keys(self, null_data, server_random, null_data);
#if 0
int licence_size;
char *licence_data;
licence_size = 0; /* todo load_licence(&licence_data); */
if (licence_size > 0)
{
void *crypt_key;
char hwid[LICENCE_HWID_SIZE];
char signature[LICENCE_SIGNATURE_SIZE];
/* Generate a signature for the HWID buffer */
rdp_lic_generate_hwid(self, hwid);
rdp_sec_sign(signature, 16, self->licence_sign_key, 16,
hwid, sizeof(hwid));
/* Now encrypt the HWID */
crypt_key = ssl_rc4_info_create();
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
ssl_rc4_crypt(crypt_key, hwid, sizeof(hwid));
ssl_rc4_info_delete(crypt_key);
rdp_lic_present(self, null_data, null_data, licence_data,
licence_size, hwid, signature);
g_free(licence_data);
return;
}
#endif
rdp_lic_send_request(self, null_data, null_data,
self->sec_layer->rdp_layer->mod->username,
self->sec_layer->rdp_layer->mod->hostname);
}
/*****************************************************************************/
/* Send an authentication response packet */
static void APP_CC
rdp_lic_send_authresp(struct rdp_lic *self, char *token, char *crypt_hwid,
char *signature)
{
int sec_flags;
int length;
struct stream *s;
sec_flags = SEC_LICENCE_NEG;
length = 58;
make_stream(s);
init_stream(s, 8192);
rdp_sec_init(self->sec_layer, s, sec_flags);
out_uint8(s, LICENCE_TAG_AUTHRESP);
out_uint8(s, 2); /* version */
out_uint16_le(s, length);
out_uint16_le(s, 1);
out_uint16_le(s, LICENCE_TOKEN_SIZE);
out_uint8p(s, token, LICENCE_TOKEN_SIZE);
out_uint16_le(s, 1);
out_uint16_le(s, LICENCE_HWID_SIZE);
out_uint8p(s, crypt_hwid, LICENCE_HWID_SIZE);
out_uint8p(s, signature, LICENCE_SIGNATURE_SIZE);
s_mark_end(s);
rdp_sec_send(self->sec_layer, s, sec_flags);
free_stream(s);
}
/*****************************************************************************/
/* Parse an authentication request packet */
/* returns boolean */
static int APP_CC
rdp_lic_parse_authreq(struct rdp_lic *self, struct stream *s,
char **token, char **signature)
{
int tokenlen;
in_uint8s(s, 6); /* unknown: f8 3d 15 00 04 f6 */
in_uint16_le(s, tokenlen);
if (tokenlen != LICENCE_TOKEN_SIZE)
{
/* error("token len %d\n", tokenlen); */
return 0;
}
in_uint8p(s, *token, tokenlen);
in_uint8p(s, *signature, LICENCE_SIGNATURE_SIZE);
return s_check_end(s);
}
/*****************************************************************************/
/* Process an authentication request packet */
static void APP_CC
rdp_lic_process_authreq(struct rdp_lic *self, struct stream *s)
{
char *in_token;
char *in_sig;
char out_token[LICENCE_TOKEN_SIZE];
char decrypt_token[LICENCE_TOKEN_SIZE];
char hwid[LICENCE_HWID_SIZE];
char crypt_hwid[LICENCE_HWID_SIZE];
char sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
char out_sig[LICENCE_SIGNATURE_SIZE];
void *crypt_key;
in_token = 0;
in_sig = 0;
/* Parse incoming packet and save the encrypted token */
rdp_lic_parse_authreq(self, s, &in_token, &in_sig);
g_memcpy(out_token, in_token, LICENCE_TOKEN_SIZE);
/* Decrypt the token. It should read TEST in Unicode. */
crypt_key = ssl_rc4_info_create();
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
g_memcpy(decrypt_token, in_token, LICENCE_TOKEN_SIZE);
ssl_rc4_crypt(crypt_key, decrypt_token, LICENCE_TOKEN_SIZE);
/* Generate a signature for a buffer of token and HWID */
rdp_lic_generate_hwid(self, hwid);
g_memcpy(sealed_buffer, decrypt_token, LICENCE_TOKEN_SIZE);
g_memcpy(sealed_buffer + LICENCE_TOKEN_SIZE, hwid, LICENCE_HWID_SIZE);
rdp_sec_sign(out_sig, 16, self->licence_sign_key, 16, sealed_buffer,
sizeof(sealed_buffer));
/* Now encrypt the HWID */
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
g_memcpy(crypt_hwid, hwid, LICENCE_HWID_SIZE);
ssl_rc4_crypt(crypt_key, crypt_hwid, LICENCE_HWID_SIZE);
rdp_lic_send_authresp(self, out_token, crypt_hwid, out_sig);
ssl_rc4_info_delete(crypt_key);
}
/*****************************************************************************/
/* Process an licence issue packet */
static void APP_CC
rdp_lic_process_issue(struct rdp_lic *self, struct stream *s)
{
void *crypt_key;
int length;
int check;
int i;
in_uint8s(s, 2); /* 3d 45 - unknown */
in_uint16_le(s, length);
if (!s_check_rem(s, length))
{
return;
}
crypt_key = ssl_rc4_info_create();
ssl_rc4_set_key(crypt_key, self->licence_key, 16);
ssl_rc4_crypt(crypt_key, s->p, length);
ssl_rc4_info_delete(crypt_key);
in_uint16_le(s, check);
if (check != 0)
{
return;
}
self->licence_issued = 1;
in_uint8s(s, 2); /* pad */
/* advance to fourth string */
length = 0;
for (i = 0; i < 4; i++)
{
in_uint8s(s, length);
in_uint32_le(s, length);
if (!s_check_rem(s, length))
{
return;
}
}
/* todo save_licence(s->p, length); */
}
/******************************************************************************/
/* Process a licence packet */
void APP_CC
rdp_lic_process(struct rdp_lic *self, struct stream *s)
{
int tag;
in_uint8(s, tag);
in_uint8s(s, 3); /* version, length */
switch (tag)
{
case LICENCE_TAG_DEMAND:
rdp_lic_process_demand(self, s);
break;
case LICENCE_TAG_AUTHREQ:
rdp_lic_process_authreq(self, s);
break;
case LICENCE_TAG_ISSUE:
rdp_lic_process_issue(self, s);
break;
case LICENCE_TAG_REISSUE:
case LICENCE_TAG_RESULT:
break;
default:
break;
/* todo unimpl("licence tag 0x%x\n", tag); */
}
}

@ -1,630 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp mcs layer
*/
#include "rdp.h"
#include "log.h"
/*****************************************************************************/
struct rdp_mcs *APP_CC
rdp_mcs_create(struct rdp_sec *owner,
struct stream *client_mcs_data,
struct stream *server_mcs_data)
{
struct rdp_mcs *self;
self = (struct rdp_mcs *)g_malloc(sizeof(struct rdp_mcs), 1);
self->sec_layer = owner;
self->userid = 1;
self->client_mcs_data = client_mcs_data;
self->server_mcs_data = server_mcs_data;
self->iso_layer = rdp_iso_create(self);
return self;
}
/*****************************************************************************/
void APP_CC
rdp_mcs_delete(struct rdp_mcs *self)
{
if (self == 0)
{
return;
}
rdp_iso_delete(self->iso_layer);
g_free(self);
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_mcs_recv(struct rdp_mcs *self, struct stream *s, int *chan)
{
int appid;
int opcode;
int len;
DEBUG((" in rdp_mcs_recv"));
if (rdp_iso_recv(self->iso_layer, s) != 0)
{
return 1;
}
in_uint8(s, opcode);
appid = opcode >> 2;
if (appid != MCS_SDIN)
{
DEBUG((" out rdp_mcs_recv error"));
return 1;
}
in_uint8s(s, 2);
in_uint16_be(s, *chan);
in_uint8s(s, 1);
in_uint8(s, len);
if (len & 0x80)
{
in_uint8s(s, 1);
}
DEBUG((" out rdp_mcs_recv"));
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_ber_out_header(struct rdp_mcs *self, struct stream *s,
int tag_val, int len)
{
if (tag_val > 0xff)
{
out_uint16_be(s, tag_val);
}
else
{
out_uint8(s, tag_val);
}
if (len >= 0x80)
{
out_uint8(s, 0x82);
out_uint16_be(s, len);
}
else
{
out_uint8(s, len);
}
return 0;
}
#if 0
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_ber_out_int8(struct rdp_mcs *self, struct stream *s, int value)
{
rdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 1);
out_uint8(s, value);
return 0;
}
#endif
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_ber_out_int16(struct rdp_mcs *self, struct stream *s, int value)
{
rdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 2);
out_uint8(s, (value >> 8));
out_uint8(s, value);
return 0;
}
#if 0
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_ber_out_int24(struct rdp_mcs *self, struct stream *s, int value)
{
rdp_mcs_ber_out_header(self, s, BER_TAG_INTEGER, 3);
out_uint8(s, (value >> 16));
out_uint8(s, (value >> 8));
out_uint8(s, value);
return 0;
}
#endif
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_out_domain_params(struct rdp_mcs *self, struct stream *s,
int max_channels,
int max_users, int max_tokens,
int max_pdu_size)
{
rdp_mcs_ber_out_header(self, s, MCS_TAG_DOMAIN_PARAMS, 32);
rdp_mcs_ber_out_int16(self, s, max_channels);
rdp_mcs_ber_out_int16(self, s, max_users);
rdp_mcs_ber_out_int16(self, s, max_tokens);
rdp_mcs_ber_out_int16(self, s, 1);
rdp_mcs_ber_out_int16(self, s, 0);
rdp_mcs_ber_out_int16(self, s, 1);
rdp_mcs_ber_out_int16(self, s, max_pdu_size);
rdp_mcs_ber_out_int16(self, s, 2);
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_send_connection_initial(struct rdp_mcs *self)
{
int data_len;
int len;
struct stream *s;
make_stream(s);
init_stream(s, 8192);
data_len = self->client_mcs_data->end - self->client_mcs_data->data;
len = 7 + 3 * 34 + 4 + data_len;
if (rdp_iso_init(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
rdp_mcs_ber_out_header(self, s, MCS_CONNECT_INITIAL, len);
rdp_mcs_ber_out_header(self, s, BER_TAG_OCTET_STRING, 0); /* calling domain */
rdp_mcs_ber_out_header(self, s, BER_TAG_OCTET_STRING, 0); /* called domain */
rdp_mcs_ber_out_header(self, s, BER_TAG_BOOLEAN, 1);
out_uint8(s, 0xff); /* upward flag */
rdp_mcs_out_domain_params(self, s, 2, 2, 0, 0xffff); /* target params */
rdp_mcs_out_domain_params(self, s, 1, 1, 1, 0x420); /* min params */
rdp_mcs_out_domain_params(self, s, 0xffff, 0xfc17, 0xffff, 0xffff); /* max params */
rdp_mcs_ber_out_header(self, s, BER_TAG_OCTET_STRING, data_len);
out_uint8p(s, self->client_mcs_data->data, data_len);
s_mark_end(s);
if (rdp_iso_send(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_ber_parse_header(struct rdp_mcs *self, struct stream *s,
int tag_val, int *len)
{
int tag;
int l;
int i;
if (tag_val > 0xff)
{
in_uint16_be(s, tag);
}
else
{
in_uint8(s, tag);
}
if (tag != tag_val)
{
return 1;
}
in_uint8(s, l);
if (l & 0x80)
{
l = l & ~0x80;
*len = 0;
while (l > 0)
{
in_uint8(s, i);
*len = (*len << 8) | i;
l--;
}
}
else
{
*len = l;
}
if (s_check(s))
{
return 0;
}
else
{
return 1;
}
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_parse_domain_params(struct rdp_mcs *self, struct stream *s)
{
int len;
if (rdp_mcs_ber_parse_header(self, s, MCS_TAG_DOMAIN_PARAMS, &len) != 0)
{
return 1;
}
in_uint8s(s, len);
if (s_check(s))
{
return 0;
}
else
{
return 1;
}
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_recv_connection_response(struct rdp_mcs *self)
{
int len;
int res;
struct stream *s;
make_stream(s);
init_stream(s, 8192);
if (rdp_iso_recv(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
rdp_mcs_ber_parse_header(self, s, MCS_CONNECT_RESPONSE, &len);
rdp_mcs_ber_parse_header(self, s, BER_TAG_RESULT, &len);
in_uint8(s, res);
if (res != 0)
{
free_stream(s);
return 1;
}
rdp_mcs_ber_parse_header(self, s, BER_TAG_INTEGER, &len);
in_uint8s(s, len); /* connect id */
rdp_mcs_parse_domain_params(self, s);
rdp_mcs_ber_parse_header(self, s, BER_TAG_OCTET_STRING, &len);
if (len > self->server_mcs_data->size)
{
len = self->server_mcs_data->size;
}
in_uint8a(s, self->server_mcs_data->data, len);
self->server_mcs_data->p = self->server_mcs_data->data;
self->server_mcs_data->end = self->server_mcs_data->data + len;
if (s_check_end(s))
{
free_stream(s);
return 0;
}
else
{
free_stream(s);
return 1;
}
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_send_edrq(struct rdp_mcs *self)
{
struct stream *s;
make_stream(s);
init_stream(s, 8192);
if (rdp_iso_init(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
out_uint8(s, (MCS_EDRQ << 2));
out_uint16_be(s, 0x100); /* height */
out_uint16_be(s, 0x100); /* interval */
s_mark_end(s);
if (rdp_iso_send(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_send_aurq(struct rdp_mcs *self)
{
struct stream *s;
make_stream(s);
init_stream(s, 8192);
if (rdp_iso_init(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
out_uint8(s, (MCS_AURQ << 2));
s_mark_end(s);
if (rdp_iso_send(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_recv_aucf(struct rdp_mcs *self)
{
int opcode;
int res;
struct stream *s;
make_stream(s);
init_stream(s, 8192);
if (rdp_iso_recv(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
in_uint8(s, opcode);
if ((opcode >> 2) != MCS_AUCF)
{
free_stream(s);
return 1;
}
in_uint8(s, res);
if (res != 0)
{
free_stream(s);
return 1;
}
if (opcode & 2)
{
in_uint16_be(s, self->userid);
}
if (!(s_check_end(s)))
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_send_cjrq(struct rdp_mcs *self, int chanid)
{
struct stream *s;
make_stream(s);
init_stream(s, 8192);
if (rdp_iso_init(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
out_uint8(s, (MCS_CJRQ << 2));
out_uint16_be(s, self->userid);
out_uint16_be(s, chanid);
s_mark_end(s);
if (rdp_iso_send(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* returns error */
static int APP_CC
rdp_mcs_recv_cjcf(struct rdp_mcs *self)
{
int opcode;
int res;
struct stream *s;
make_stream(s);
init_stream(s, 8192);
if (rdp_iso_recv(self->iso_layer, s) != 0)
{
free_stream(s);
return 1;
}
in_uint8(s, opcode);
if ((opcode >> 2) != MCS_CJCF)
{
free_stream(s);
return 1;
}
in_uint8(s, res);
if (res != 0)
{
free_stream(s);
return 1;
}
in_uint8s(s, 4); /* mcs_userid, req_chanid */
if (opcode & 2)
{
in_uint8s(s, 2); /* join_chanid */
}
if (!(s_check_end(s)))
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_mcs_connect(struct rdp_mcs *self, char *ip, char *port)
{
DEBUG((" in rdp_mcs_connect"));
if (rdp_iso_connect(self->iso_layer, ip, port) != 0)
{
DEBUG((" out rdp_mcs_connect error rdp_iso_connect failed"));
return 1;
}
rdp_mcs_send_connection_initial(self);
if (rdp_mcs_recv_connection_response(self) != 0)
{
rdp_iso_disconnect(self->iso_layer);
DEBUG((" out rdp_mcs_connect error rdp_mcs_recv_connection_response \
failed"));
return 1;
}
rdp_mcs_send_edrq(self);
rdp_mcs_send_aurq(self);
if (rdp_mcs_recv_aucf(self) != 0)
{
rdp_iso_disconnect(self->iso_layer);
DEBUG((" out rdp_mcs_connect error rdp_mcs_recv_aucf failed"));
return 1;
}
rdp_mcs_send_cjrq(self, self->userid + 1001);
if (rdp_mcs_recv_cjcf(self) != 0)
{
rdp_iso_disconnect(self->iso_layer);
DEBUG((" out rdp_mcs_connect error rdp_mcs_recv_cjcf 1 failed"));
return 1;
}
rdp_mcs_send_cjrq(self, MCS_GLOBAL_CHANNEL);
if (rdp_mcs_recv_cjcf(self) != 0)
{
rdp_iso_disconnect(self->iso_layer);
DEBUG((" out rdp_mcs_connect error rdp_mcs_recv_cjcf 2 failed"));
return 1;
}
DEBUG((" out rdp_mcs_connect"));
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_mcs_init(struct rdp_mcs *self, struct stream *s)
{
if (rdp_iso_init(self->iso_layer, s))
log_message(LOG_LEVEL_ERROR, "rdp_mcs.c: rdp_iso_init() failed");
s_push_layer(s, mcs_hdr, 8);
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_mcs_send(struct rdp_mcs *self, struct stream *s)
{
int len;
s_pop_layer(s, mcs_hdr);
len = (s->end - s->p) - 8;
len = len | 0x8000;
out_uint8(s, MCS_SDRQ << 2);
out_uint16_be(s, self->userid);
out_uint16_be(s, MCS_GLOBAL_CHANNEL);
out_uint8(s, 0x70);
out_uint16_be(s, len);
if (rdp_iso_send(self->iso_layer, s) != 0)
{
return 1;
}
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,713 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp secure layer
*/
#include "rdp.h"
static char g_pad_54[40] =
{
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
54, 54, 54, 54, 54, 54, 54, 54
};
static char g_pad_92[48] =
{
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92
};
/*****************************************************************************/
struct rdp_sec *APP_CC
rdp_sec_create(struct rdp_rdp *owner)
{
struct rdp_sec *self;
self = (struct rdp_sec *)g_malloc(sizeof(struct rdp_sec), 1);
self->rdp_layer = owner;
make_stream(self->client_mcs_data);
init_stream(self->client_mcs_data, 8192);
make_stream(self->server_mcs_data);
init_stream(self->server_mcs_data, 8192);
self->mcs_layer = rdp_mcs_create(self, self->client_mcs_data,
self->server_mcs_data);
if (self->decrypt_rc4_info != NULL)
{
g_writeln("rdp_sec_create - decrypt_rc4_info already created !!!");
}
self->decrypt_rc4_info = ssl_rc4_info_create();
if (self->encrypt_rc4_info != NULL)
{
g_writeln("rdp_sec_create - encrypt_rc4_info already created !!!");
}
self->encrypt_rc4_info = ssl_rc4_info_create();
self->lic_layer = rdp_lic_create(self);
return self;
}
/*****************************************************************************/
void APP_CC
rdp_sec_delete(struct rdp_sec *self)
{
if (self == 0)
{
return;
}
rdp_lic_delete(self->lic_layer);
rdp_mcs_delete(self->mcs_layer);
free_stream(self->client_mcs_data);
free_stream(self->server_mcs_data);
ssl_rc4_info_delete(self->decrypt_rc4_info);
ssl_rc4_info_delete(self->encrypt_rc4_info);
g_free(self);
}
/*****************************************************************************/
/* Reduce key entropy from 64 to 40 bits */
static void APP_CC
rdp_sec_make_40bit(char *key)
{
key[0] = 0xd1;
key[1] = 0x26;
key[2] = 0x9e;
}
/*****************************************************************************/
/* returns error */
/* update an encryption key */
static int APP_CC
rdp_sec_update(char *key, char *update_key, int key_len)
{
char shasig[20];
void *sha1_info;
void *md5_info;
void *rc4_info;
sha1_info = ssl_sha1_info_create();
md5_info = ssl_md5_info_create();
rc4_info = ssl_rc4_info_create();
ssl_sha1_clear(sha1_info);
ssl_sha1_transform(sha1_info, update_key, key_len);
ssl_sha1_transform(sha1_info, g_pad_54, 40);
ssl_sha1_transform(sha1_info, key, key_len);
ssl_sha1_complete(sha1_info, shasig);
ssl_md5_clear(md5_info);
ssl_md5_transform(md5_info, update_key, key_len);
ssl_md5_transform(md5_info, g_pad_92, 48);
ssl_md5_transform(md5_info, shasig, 20);
ssl_md5_complete(md5_info, key);
ssl_rc4_set_key(rc4_info, key, key_len);
ssl_rc4_crypt(rc4_info, key, key_len);
if (key_len == 8)
{
rdp_sec_make_40bit(key);
}
ssl_sha1_info_delete(sha1_info);
ssl_md5_info_delete(md5_info);
ssl_rc4_info_delete(rc4_info);
return 0;
}
/*****************************************************************************/
static void APP_CC
rdp_sec_decrypt(struct rdp_sec *self, char *data, int len)
{
if (self->decrypt_use_count == 4096)
{
rdp_sec_update(self->decrypt_key, self->decrypt_update_key,
self->rc4_key_len);
ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key,
self->rc4_key_len);
self->decrypt_use_count = 0;
}
ssl_rc4_crypt(self->decrypt_rc4_info, data, len);
self->decrypt_use_count++;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_sec_recv(struct rdp_sec *self, struct stream *s, int *chan)
{
int flags;
DEBUG((" in rdp_sec_recv"));
if (rdp_mcs_recv(self->mcs_layer, s, chan) != 0)
{
DEBUG((" error in rdp_sec_recv, rdp_mcs_recv failed"));
return 1;
}
in_uint32_le(s, flags);
DEBUG((" rdp_sec_recv flags %8.8x", flags));
if (flags & SEC_ENCRYPT) /* 0x08 */
{
in_uint8s(s, 8); /* signature */
rdp_sec_decrypt(self, s->p, s->end - s->p);
}
if (flags & SEC_LICENCE_NEG) /* 0x80 */
{
DEBUG((" in rdp_sec_recv, got SEC_LICENCE_NEG"));
rdp_lic_process(self->lic_layer, s);
*chan = 0;
}
DEBUG((" out rdp_sec_recv"));
return 0;
}
/*****************************************************************************/
/* prepare client mcs data to send in mcs layer */
static void APP_CC
rdp_sec_out_mcs_data(struct rdp_sec *self)
{
struct stream *s;
int hostlen;
int length;
s = self->client_mcs_data;
init_stream(s, 512);
self->rdp_layer->mod->hostname[15] = 0; /* limit length to 15 */
hostlen = 2 * g_strlen(self->rdp_layer->mod->hostname);
length = 158 + 76 + 12 + 4;
/* Generic Conference Control (T.124) ConferenceCreateRequest */
out_uint16_be(s, 5);
out_uint16_be(s, 0x14);
out_uint8(s, 0x7c);
out_uint16_be(s, 1);
out_uint16_be(s, (length | 0x8000)); /* remaining length */
out_uint16_be(s, 8); /* length? */
out_uint16_be(s, 16);
out_uint8(s, 0);
out_uint16_le(s, 0xc001);
out_uint8(s, 0);
out_uint32_le(s, 0x61637544); /* OEM ID: "Duca", as in Ducati. */
out_uint16_be(s, ((length - 14) | 0x8000)); /* remaining length */
/* Client information */
out_uint16_le(s, SEC_TAG_CLI_INFO);
out_uint16_le(s, 212); /* length */
out_uint16_le(s, 1); /* RDP version. 1 == RDP4, 4 == RDP5. */
out_uint16_le(s, 8);
out_uint16_le(s, self->rdp_layer->mod->width);
out_uint16_le(s, self->rdp_layer->mod->height);
out_uint16_le(s, 0xca01);
out_uint16_le(s, 0xaa03);
out_uint32_le(s, self->rdp_layer->mod->keylayout);
out_uint32_le(s, 2600); /* Client build */
/* Unicode name of client, padded to 32 bytes */
rdp_rdp_out_unistr(s, self->rdp_layer->mod->hostname);
out_uint8s(s, 30 - hostlen);
out_uint32_le(s, 4);
out_uint32_le(s, 0);
out_uint32_le(s, 12);
out_uint8s(s, 64); /* reserved? 4 + 12 doublewords */
out_uint16_le(s, 0xca01); /* color depth? */
out_uint16_le(s, 1);
out_uint32_le(s, 0);
out_uint8(s, self->rdp_layer->mod->rdp_bpp);
out_uint16_le(s, 0x0700);
out_uint8(s, 0);
out_uint32_le(s, 1);
out_uint8s(s, 64); /* End of client info */
out_uint16_le(s, SEC_TAG_CLI_4);
out_uint16_le(s, 12);
out_uint32_le(s, 9);
out_uint32_le(s, 0);
/* Client encryption settings */
out_uint16_le(s, SEC_TAG_CLI_CRYPT);
out_uint16_le(s, 12); /* length */
/* encryption supported, 128-bit supported */
out_uint32_le(s, 0x3);
out_uint32_le(s, 0); /* Unknown */
s_mark_end(s);
}
/*****************************************************************************/
/* Parse a public key structure */
/* returns boolean */
static int APP_CC
rdp_sec_parse_public_key(struct rdp_sec *self, struct stream *s,
char *modulus, char *exponent)
{
int magic;
int modulus_len;
in_uint32_le(s, magic);
if (magic != SEC_RSA_MAGIC)
{
return 0;
}
in_uint32_le(s, modulus_len);
if (modulus_len != SEC_MODULUS_SIZE + SEC_PADDING_SIZE)
{
return 0;
}
in_uint8s(s, 8);
in_uint8a(s, exponent, SEC_EXPONENT_SIZE);
in_uint8a(s, modulus, SEC_MODULUS_SIZE);
in_uint8s(s, SEC_PADDING_SIZE);
return s_check(s);
}
/*****************************************************************************/
/* Parse a crypto information structure */
/* returns boolean */
static int APP_CC
rdp_sec_parse_crypt_info(struct rdp_sec *self, struct stream *s,
char *modulus, char *exponent)
{
int random_len;
int rsa_info_len;
int flags;
int tag;
int length;
char *next_tag;
char *end;
in_uint32_le(s, self->rc4_key_size); /* 1 = 40-bit, 2 = 128-bit */
in_uint32_le(s, self->crypt_level); /* 1 = low, 2 = medium, 3 = high */
if (self->crypt_level == 0) /* no encryption */
{
return 0;
}
in_uint32_le(s, random_len);
in_uint32_le(s, rsa_info_len);
if (random_len != SEC_RANDOM_SIZE)
{
return 0;
}
in_uint8a(s, self->server_random, random_len);
/* RSA info */
end = s->p + rsa_info_len;
if (end > s->end)
{
return 0;
}
in_uint32_le(s, flags); /* 1 = RDP4-style, 0x80000002 = X.509 */
if (flags & 1)
{
in_uint8s(s, 8); /* unknown */
while (s->p < end)
{
in_uint16_le(s, tag);
in_uint16_le(s, length);
next_tag = s->p + length;
DEBUG((" rdp_sec_parse_crypt_info tag %d length %d", tag, length));
switch (tag)
{
case SEC_TAG_PUBKEY:
if (!rdp_sec_parse_public_key(self, s, modulus, exponent))
{
return 0;
}
break;
case SEC_TAG_KEYSIG:
break;
default:
break;
}
s->p = next_tag;
}
}
else
{
/* todo */
return 0;
}
return s_check_end(s);
}
/*****************************************************************************/
static void APP_CC
rdp_sec_rsa_op(char *out, char *in, char *mod, char *exp)
{
ssl_mod_exp(out, SEC_MODULUS_SIZE, /* 64 */
in, SEC_RANDOM_SIZE, /* 32 */
mod, SEC_MODULUS_SIZE, /* 64 */
exp, SEC_EXPONENT_SIZE); /* 4 */
}
/*****************************************************************************/
void APP_CC
rdp_sec_hash_48(char *out, char *in, char *salt1, char *salt2, int salt)
{
int i;
void *sha1_info;
void *md5_info;
char pad[4];
char sha1_sig[20];
char md5_sig[16];
sha1_info = ssl_sha1_info_create();
md5_info = ssl_md5_info_create();
for (i = 0; i < 3; i++)
{
g_memset(pad, salt + i, 4);
ssl_sha1_clear(sha1_info);
ssl_sha1_transform(sha1_info, pad, i + 1);
ssl_sha1_transform(sha1_info, in, 48);
ssl_sha1_transform(sha1_info, salt1, 32);
ssl_sha1_transform(sha1_info, salt2, 32);
ssl_sha1_complete(sha1_info, sha1_sig);
ssl_md5_clear(md5_info);
ssl_md5_transform(md5_info, in, 48);
ssl_md5_transform(md5_info, sha1_sig, 20);
ssl_md5_complete(md5_info, md5_sig);
g_memcpy(out + i * 16, md5_sig, 16);
}
ssl_sha1_info_delete(sha1_info);
ssl_md5_info_delete(md5_info);
}
/*****************************************************************************/
void APP_CC
rdp_sec_hash_16(char *out, char *in, char *salt1, char *salt2)
{
void *md5_info;
md5_info = ssl_md5_info_create();
ssl_md5_clear(md5_info);
ssl_md5_transform(md5_info, in, 16);
ssl_md5_transform(md5_info, salt1, 32);
ssl_md5_transform(md5_info, salt2, 32);
ssl_md5_complete(md5_info, out);
ssl_md5_info_delete(md5_info);
}
/*****************************************************************************/
static int APP_CC
rdp_sec_generate_keys(struct rdp_sec *self)
{
char session_key[48];
char temp_hash[48];
char input[48];
g_memcpy(input, self->client_random, 24);
g_memcpy(input + 24, self->server_random, 24);
rdp_sec_hash_48(temp_hash, input, self->client_random,
self->server_random, 65);
rdp_sec_hash_48(session_key, temp_hash, self->client_random,
self->server_random, 88);
g_memcpy(self->sign_key, session_key, 16);
rdp_sec_hash_16(self->decrypt_key, session_key + 16, self->client_random,
self->server_random);
rdp_sec_hash_16(self->encrypt_key, session_key + 32, self->client_random,
self->server_random);
DEBUG((" rdp_sec_generate_keys, rc4_key_size is %d", self->rc4_key_size));
DEBUG((" rdp_sec_generate_keys, crypt_level is %d", self->crypt_level));
if (self->rc4_key_size == 1)
{
rdp_sec_make_40bit(self->sign_key);
rdp_sec_make_40bit(self->encrypt_key);
rdp_sec_make_40bit(self->decrypt_key);
self->rc4_key_len = 8;
}
else
{
self->rc4_key_len = 16;
}
g_memcpy(self->decrypt_update_key, self->decrypt_key, 16);
g_memcpy(self->encrypt_update_key, self->encrypt_key, 16);
ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key, self->rc4_key_len);
ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key, self->rc4_key_len);
return 0;
}
/*****************************************************************************/
/* Process crypto information blob */
static void APP_CC
rdp_sec_process_crypt_info(struct rdp_sec *self, struct stream *s)
{
char modulus[64];
char exponent[64];
g_memset(modulus, 0, sizeof(modulus));
g_memset(exponent, 0, sizeof(exponent));
if (!rdp_sec_parse_crypt_info(self, s, modulus, exponent))
{
DEBUG((" error in rdp_sec_process_crypt_info"));
return;
}
/* Generate a client random, and determine encryption keys */
g_random(self->client_random, 32);
rdp_sec_rsa_op(self->client_crypt_random, self->client_random,
modulus, exponent);
rdp_sec_generate_keys(self);
}
/*****************************************************************************/
/* Process connect response data blob */
static void APP_CC
rdp_sec_process_mcs_data(struct rdp_sec *self)
{
int tag;
int length;
int len;
char *next_tag;
struct stream *s;
s = self->server_mcs_data;
s->p = s->data;
in_uint8s(s, 21); /* header (T.124 ConferenceCreateResponse) */
in_uint8(s, len);
if (len & 0x80)
{
in_uint8(s, len);
}
while (s->p < s->end)
{
in_uint16_le(s, tag);
in_uint16_le(s, length);
DEBUG((" rdp_sec_process_mcs_data tag %d length %d", tag, length));
if (length <= 4)
{
return;
}
next_tag = (s->p + length) - 4;
switch (tag)
{
case SEC_TAG_SRV_INFO:
//rdp_sec_process_srv_info(self, s);
break;
case SEC_TAG_SRV_CRYPT:
rdp_sec_process_crypt_info(self, s);
break;
case SEC_TAG_SRV_CHANNELS:
break;
default:
break;
}
s->p = next_tag;
}
}
/*****************************************************************************/
/* Transfer the client random to the server */
/* returns error */
static int APP_CC
rdp_sec_establish_key(struct rdp_sec *self)
{
int length;
int flags;
struct stream *s;
DEBUG((" sending client random"));
make_stream(s);
init_stream(s, 8192);
length = SEC_MODULUS_SIZE + SEC_PADDING_SIZE;
flags = SEC_CLIENT_RANDOM;
if (rdp_sec_init(self, s, flags) != 0)
{
free_stream(s);
return 1;
}
out_uint32_le(s, length);
out_uint8p(s, self->client_crypt_random, SEC_MODULUS_SIZE);
out_uint8s(s, SEC_PADDING_SIZE);
s_mark_end(s);
if (rdp_sec_send(self, s, flags) != 0)
{
free_stream(s);
return 1;
}
free_stream(s);
return 0;
}
/*****************************************************************************/
/* Establish a secure connection */
int APP_CC
rdp_sec_connect(struct rdp_sec *self, char *ip, char *port)
{
DEBUG((" in rdp_sec_connect"));
rdp_sec_out_mcs_data(self);
if (rdp_mcs_connect(self->mcs_layer, ip, port) != 0)
{
DEBUG((" out rdp_sec_connect error rdp_mcs_connect failed"));
return 1;
}
rdp_sec_process_mcs_data(self);
if (rdp_sec_establish_key(self) != 0)
{
DEBUG((" out rdp_sec_connect error rdp_sec_establish_key failed"));
return 1;
}
DEBUG((" out rdp_sec_connect"));
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_sec_init(struct rdp_sec *self, struct stream *s, int flags)
{
if (rdp_mcs_init(self->mcs_layer, s) != 0)
{
return 1;
}
if (flags & SEC_ENCRYPT)
{
s_push_layer(s, sec_hdr, 12);
}
else
{
s_push_layer(s, sec_hdr, 4);
}
return 0;
}
/*****************************************************************************/
/* Output a uint32 into a buffer (little-endian) */
void APP_CC
rdp_sec_buf_out_uint32(char *buffer, int value)
{
buffer[0] = value & 0xff;
buffer[1] = (value >> 8) & 0xff;
buffer[2] = (value >> 16) & 0xff;
buffer[3] = (value >> 24) & 0xff;
}
/*****************************************************************************/
/* Generate a MAC hash (5.2.3.1), using a combination of SHA1 and MD5 */
void APP_CC
rdp_sec_sign(char *signature, int siglen, char *session_key, int keylen,
char *data, int datalen)
{
char shasig[20];
char md5sig[16];
char lenhdr[4];
void *sha1_context;
void *md5_context;
rdp_sec_buf_out_uint32(lenhdr, datalen);
sha1_context = ssl_sha1_info_create();
ssl_sha1_clear(sha1_context);
ssl_sha1_transform(sha1_context, session_key, keylen);
ssl_sha1_transform(sha1_context, g_pad_54, 40);
ssl_sha1_transform(sha1_context, lenhdr, 4);
ssl_sha1_transform(sha1_context, data, datalen);
ssl_sha1_complete(sha1_context, shasig);
ssl_sha1_info_delete(sha1_context);
md5_context = ssl_md5_info_create();
ssl_md5_clear(md5_context);
ssl_md5_transform(md5_context, session_key, keylen);
ssl_md5_transform(md5_context, g_pad_92, 48);
ssl_md5_transform(md5_context, shasig, 20);
ssl_md5_complete(md5_context, md5sig);
ssl_md5_info_delete(md5_context);
g_memcpy(signature, md5sig, siglen);
}
/*****************************************************************************/
/* Encrypt data using RC4 */
static void APP_CC
rdp_sec_encrypt(struct rdp_sec *self, char *data, int length)
{
if (self->encrypt_use_count == 4096)
{
rdp_sec_update(self->encrypt_key, self->encrypt_update_key,
self->rc4_key_len);
ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key,
self->rc4_key_len);
self->encrypt_use_count = 0;
}
ssl_rc4_crypt(self->encrypt_rc4_info, data, length);
self->encrypt_use_count++;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_sec_send(struct rdp_sec *self, struct stream *s, int flags)
{
int datalen;
DEBUG((" in rdp_sec_send flags %8.8x", flags));
s_pop_layer(s, sec_hdr);
out_uint32_le(s, flags);
if (flags & SEC_ENCRYPT)
{
datalen = (s->end - s->p) - 8;
rdp_sec_sign(s->p, 8, self->sign_key, self->rc4_key_len, s->p + 8,
datalen);
rdp_sec_encrypt(self, s->p + 8, datalen);
}
if (rdp_mcs_send(self->mcs_layer, s) != 0)
{
DEBUG((" out rdp_sec_send, rdp_mcs_send failed"));
return 1;
}
DEBUG((" out rdp_sec_send"));
return 0;
}

@ -1,191 +0,0 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2013
*
* 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.
*
* librdp tcp layer
*/
#include "rdp.h"
/*****************************************************************************/
struct rdp_tcp *APP_CC
rdp_tcp_create(struct rdp_iso *owner)
{
struct rdp_tcp *self;
self = (struct rdp_tcp *)g_malloc(sizeof(struct rdp_tcp), 1);
self->iso_layer = owner;
return self;
}
/*****************************************************************************/
void APP_CC
rdp_tcp_delete(struct rdp_tcp *self)
{
g_free(self);
}
/*****************************************************************************/
/* get out stream ready for data */
/* returns error */
int APP_CC
rdp_tcp_init(struct rdp_tcp *self, struct stream *s)
{
init_stream(s, 8192);
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_tcp_recv(struct rdp_tcp *self, struct stream *s, int len)
{
int rcvd;
DEBUG((" in rdp_tcp_recv will get %d bytes on sck %d",
len, self->sck));
if (self->sck_closed)
{
DEBUG((" out rdp_tcp_recv error sck closed"));
return 1;
}
init_stream(s, len);
while (len > 0)
{
rcvd = g_tcp_recv(self->sck, s->end, len, 0);
if (rcvd == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
g_sck_can_recv(self->sck, 10);
}
else
{
self->sck_closed = 1;
DEBUG((" out rdp_tcp_recv error unknown"));
return 1;
}
}
else if (rcvd == 0)
{
self->sck_closed = 1;
DEBUG((" out rdp_tcp_recv error connection dropped"));
return 1;
}
else
{
s->end += rcvd;
len -= rcvd;
}
}
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_tcp_send(struct rdp_tcp *self, struct stream *s)
{
int len;
int total;
int sent;
if (self->sck_closed)
{
DEBUG((" out rdp_tcp_send error sck closed"));
return 1;
}
len = s->end - s->data;
DEBUG((" in rdp_tcp_send will send %d bytes on sck %d", len,
self->sck));
total = 0;
while (total < len)
{
sent = g_tcp_send(self->sck, s->data + total, len - total, 0);
if (sent == -1)
{
if (g_tcp_last_error_would_block(self->sck))
{
g_tcp_can_send(self->sck, 10);
}
else
{
self->sck_closed = 1;
DEBUG((" out rdp_tcp_send error unknown"));
return 1;
}
}
else if (sent == 0)
{
self->sck_closed = 1;
DEBUG((" out rdp_tcp_send error connection dropped"));
return 1;
}
else
{
total = total + sent;
}
}
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_tcp_connect(struct rdp_tcp *self, char *ip, char *port)
{
DEBUG((" in rdp_tcp_connect ip %s port %s", ip, port));
self->sck = g_tcp_socket();
if (self->sck < 0)
return 1;
if (g_tcp_connect(self->sck, ip, port) == 0)
{
g_tcp_set_non_blocking(self->sck);
}
else
{
DEBUG((" out rdp_tcp_connect error g_tcp_connect failed"));
return 1;
}
DEBUG((" out rdp_tcp_connect"));
return 0;
}
/*****************************************************************************/
/* returns error */
int APP_CC
rdp_tcp_disconnect(struct rdp_tcp *self)
{
if (self->sck != 0)
{
g_tcp_close(self->sck);
}
self->sck = 0;
return 0;
}

@ -206,12 +206,6 @@ username=ask
password=ask
#delay_ms=2000
[rdp-any]
name=rdp-any
lib=librdp.so
ip=ask
port=ask3389
[neutrinordp-any]
name=neutrinordp-any
lib=libxrdpneutrinordp.so

Loading…
Cancel
Save