ran indent (-bli0 -i8 -cli8 -npcs -npsl)

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@23 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Matt Chapman 2001-01-06 03:12:10 +00:00
parent 4c253c0df7
commit b9613445f9
11 changed files with 455 additions and 408 deletions

View File

@ -128,7 +128,9 @@ BOOL bitmap_decompress(unsigned char *output, int width, int height,
if (prevline == NULL) if (prevline == NULL)
line[x] = mix; line[x] = mix;
else else
line[x] = prevline[x] ^ mix; line[x] =
prevline[x] ^
mix;
insertmix = False; insertmix = False;
count--; count--;
@ -136,73 +138,79 @@ BOOL bitmap_decompress(unsigned char *output, int width, int height,
} }
if (prevline == NULL) if (prevline == NULL)
REPEAT(line[x] = 0) {
REPEAT(line[x] = 0);
}
else else
REPEAT(line[x] = prevline[x]) {
REPEAT(line[x] = prevline[x]);
}
break; break;
case 1: /* Mix */ case 1: /* Mix */
if (prevline == NULL) if (prevline == NULL)
REPEAT(line[x] = mix) {
REPEAT(line[x] = mix);
}
else else
REPEAT(line[x] = prevline[x] ^ mix) {
REPEAT(line[x] =
prevline[x] ^ mix);
}
break; break;
case 2: /* Fill or Mix */ case 2: /* Fill or Mix */
if (prevline == NULL) if (prevline == NULL)
REPEAT( {
MASK_UPDATE(); REPEAT(MASK_UPDATE();
if (mask & mixmask) if (mask & mixmask)
line[x] = mix; line[x] = mix;
else else
line[x] = 0; line[x] = 0;);
) }
else else
REPEAT( {
MASK_UPDATE(); REPEAT(MASK_UPDATE();
if (mask & mixmask) if (mask & mixmask)
line[x] = prevline[x] ^ mix; line[x] =
prevline[x] ^ mix;
else else
line[x] = prevline[x]; line[x] =
) prevline[x];);
}
break; break;
case 3: /* Colour */ case 3: /* Colour */
REPEAT(line[x] = colour2) REPEAT(line[x] = colour2);
break; break;
case 4: /* Copy */ case 4: /* Copy */
REPEAT(line[x] = CVAL(input)) REPEAT(line[x] = CVAL(input));
break; break;
case 8: /* Bicolour */ case 8: /* Bicolour */
REPEAT( REPEAT(if (bicolour)
if (bicolour)
{ {
line[x] = colour2; line[x] = colour2;
bicolour = False; bicolour = False;}
}
else else
{ {
line[x] = colour1; line[x] = colour1;
bicolour = True; bicolour = True; count++;}
count++; );
}
)
break; break;
case 13: /* White */ case 13: /* White */
REPEAT(line[x] = 0xff) REPEAT(line[x] = 0xff);
break; break;
case 14: /* Black */ case 14: /* Black */
REPEAT(line[x] = 0x00) REPEAT(line[x] = 0x00);
break; break;
default: default:
NOTIMP("bitmap opcode 0x%x\n", opcode); NOTIMP("bitmap opcode 0x%x\n",
opcode);
return False; return False;
} }
} }

View File

@ -86,7 +86,8 @@ FONTGLYPH *cache_get_font(uint8 font, uint16 character)
/* Store a glyph in the font cache */ /* Store a glyph in the font cache */
void cache_put_font(uint8 font, uint16 character, uint16 offset, void cache_put_font(uint8 font, uint16 character, uint16 offset,
uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap) uint16 baseline, uint16 width, uint16 height,
HGLYPH pixmap)
{ {
FONTGLYPH *glyph; FONTGLYPH *glyph;
@ -169,7 +170,8 @@ uint8 *cache_get_desktop(uint32 offset, int cx, int cy)
} }
/* Store desktop data in the cache */ /* Store desktop data in the cache */
void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, uint8 *data) void cache_put_desktop(uint32 offset, int cx, int cy, int scanline,
uint8 *data)
{ {
int length = cx * cy; int length = cx * cy;
@ -187,4 +189,3 @@ void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, uint8 *data)
ERROR("put desktop %d:%d\n", offset, length); ERROR("put desktop %d:%d\n", offset, length);
} }
} }

View File

@ -151,7 +151,8 @@ static BOOL licence_parse_authreq(STREAM s, uint8 **token, uint8 **signature)
static void licence_process_authreq(STREAM s) static void licence_process_authreq(STREAM s)
{ {
uint8 *in_token, *in_sig; uint8 *in_token, *in_sig;
uint8 out_token[LICENCE_TOKEN_SIZE], decrypt_token[LICENCE_TOKEN_SIZE]; uint8 out_token[LICENCE_TOKEN_SIZE],
decrypt_token[LICENCE_TOKEN_SIZE];
uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE]; uint8 hwid[LICENCE_HWID_SIZE], crypt_hwid[LICENCE_HWID_SIZE];
uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE]; uint8 sealed_buffer[LICENCE_TOKEN_SIZE + LICENCE_HWID_SIZE];
uint8 out_sig[LICENCE_SIGNATURE_SIZE]; uint8 out_sig[LICENCE_SIGNATURE_SIZE];

11
mcs.c
View File

@ -33,8 +33,7 @@ static BOOL ber_parse_header(STREAM s, int tagval, int *length)
} }
else else
{ {
in_uint8(s, tag) in_uint8(s, tag)}
}
if (tag != tagval) if (tag != tagval)
{ {
@ -51,7 +50,8 @@ static BOOL ber_parse_header(STREAM s, int tagval, int *length)
while (len--) while (len--)
next_be(s, *length); next_be(s, *length);
} }
else *length = len; else
*length = len;
return s_check(s); return s_check(s);
} }
@ -73,7 +73,8 @@ static void ber_out_header(STREAM s, int tagval, int length)
out_uint8(s, 0x82); out_uint8(s, 0x82);
out_uint16_be(s, length); out_uint16_be(s, length);
} }
else out_uint8(s, length); else
out_uint8(s, length);
} }
/* Output an ASN.1 BER integer */ /* Output an ASN.1 BER integer */
@ -113,7 +114,7 @@ static BOOL mcs_parse_domain_params(STREAM s)
static void mcs_send_connect_initial(STREAM mcs_data) static void mcs_send_connect_initial(STREAM mcs_data)
{ {
int datalen = mcs_data->end - mcs_data->data; int datalen = mcs_data->end - mcs_data->data;
int length = 7 + 3*34 + 4 + datalen; int length = 7 + 3 * 34 + 4 + datalen;
STREAM s; STREAM s;
s = iso_init(length + 5); s = iso_init(length + 5);

View File

@ -59,7 +59,7 @@ static void rdp_in_coord(STREAM s, uint16 *coord, BOOL delta)
if (delta) if (delta)
{ {
in_uint8(s, change); in_uint8(s, change);
*coord += (char)change; *coord += (char) change;
} }
else else
{ {
@ -268,7 +268,7 @@ static void process_line(STREAM s, LINE_ORDER *os, uint32 present, BOOL delta)
return; return;
} }
ui_line(os->opcode-1, os->startx, os->starty, ui_line(os->opcode - 1, os->startx, os->starty,
os->endx, os->endy, &os->pen); os->endx, os->endy, &os->pen);
} }
@ -330,7 +330,8 @@ static void process_desksave(STREAM s, DESKSAVE_ORDER *os,
if (os->action == 0) if (os->action == 0)
ui_desktop_save(os->offset, os->left, os->top, width, height); ui_desktop_save(os->offset, os->left, os->top, width, height);
else else
ui_desktop_restore(os->offset, os->left, os->top, width, height); ui_desktop_restore(os->offset, os->left, os->top, width,
height);
} }
/* Process a memory blt order */ /* Process a memory blt order */
@ -428,7 +429,8 @@ static void process_triblt(STREAM s, TRIBLT_ORDER *os,
if (present & 0x010000) if (present & 0x010000)
in_uint16_le(s, os->unknown); in_uint16_le(s, os->unknown);
DEBUG("TRIBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d,bs=%d,bg=0x%x,fg=0x%x)\n", DEBUG
("TRIBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id,
os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour); os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour);
@ -529,7 +531,8 @@ static void process_polyline(STREAM s, POLYLINE_ORDER *os,
} }
/* Process a text order */ /* Process a text order */
static void process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta) static void process_text2(STREAM s, TEXT2_ORDER *os, uint32 present,
BOOL delta)
{ {
DATABLOB *entry; DATABLOB *entry;
int i; int i;
@ -588,7 +591,8 @@ static void process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta)
in_uint8a(s, os->text, os->length); in_uint8a(s, os->text, os->length);
} }
DEBUG("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,bb=%d,br=%d,fg=0x%x,bg=0x%x,font=%d,fl=0x%x,mix=%d,unk=0x%x,n=%d)\n", DEBUG
("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,bb=%d,br=%d,fg=0x%x,bg=0x%x,font=%d,fl=0x%x,mix=%d,unk=0x%x,n=%d)\n",
os->x, os->y, os->clipleft, os->cliptop, os->clipright, os->x, os->y, os->clipleft, os->cliptop, os->clipright,
os->clipbottom, os->boxleft, os->boxtop, os->boxright, os->clipbottom, os->boxleft, os->boxtop, os->boxright,
os->boxbottom, os->fgcolour, os->bgcolour, os->font, os->boxbottom, os->fgcolour, os->bgcolour, os->font,
@ -612,10 +616,11 @@ static void process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta)
memcpy(os->text, entry->data, entry->size); memcpy(os->text, entry->data, entry->size);
os->length = entry->size; os->length = entry->size;
} }
else if ((os->length >= 3) && (os->text[os->length-3] == 0xff)) else if ((os->length >= 3) && (os->text[os->length - 3] == 0xff))
{ {
os->length -= 3; os->length -= 3;
cache_put_text(os->text[os->length+1], os->text, os->length); cache_put_text(os->text[os->length + 1], os->text,
os->length);
} }
ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y, ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y,
@ -723,8 +728,8 @@ static void process_fontcache(STREAM s)
HGLYPH bitmap; HGLYPH bitmap;
uint8 font, nglyphs; uint8 font, nglyphs;
uint16 character, offset, baseline, width, height; uint16 character, offset, baseline, width, height;
uint8 *data, *rev_data, in, out; int i, datasize;
int i, j, datasize; uint8 *data;
in_uint8(s, font); in_uint8(s, font);
in_uint8(s, nglyphs); in_uint8(s, nglyphs);
@ -847,8 +852,10 @@ void process_orders(STREAM s)
ui_set_clip(os->bounds.left, ui_set_clip(os->bounds.left,
os->bounds.top, os->bounds.top,
os->bounds.right - os->bounds.left + 1, os->bounds.right -
os->bounds.bottom - os->bounds.top + 1); os->bounds.left + 1,
os->bounds.bottom -
os->bounds.top + 1);
} }
delta = order_flags & RDP_ORDER_DELTA; delta = order_flags & RDP_ORDER_DELTA;
@ -918,7 +925,7 @@ void process_orders(STREAM s)
} }
if (s->p != next_packet) if (s->p != next_packet)
WARN("%d bytes remaining\n", (int)(next_packet - s->p)); WARN("%d bytes remaining\n", (int) (next_packet - s->p));
} }
/* Reset order state */ /* Reset order state */
@ -926,4 +933,3 @@ void reset_order_state()
{ {
memset(&order_state, 0, sizeof(order_state)); memset(&order_state, 0, sizeof(order_state));
} }

View File

@ -68,7 +68,8 @@ int main(int argc, char *argv[])
int c; int c;
STATUS("rdesktop: A Remote Desktop Protocol client.\n"); STATUS("rdesktop: A Remote Desktop Protocol client.\n");
STATUS("Version "VERSION". Copyright (C) 1999-2000 Matt Chapman.\n"); STATUS("Version " VERSION
". Copyright (C) 1999-2000 Matt Chapman.\n");
STATUS("See http://www.rdesktop.org/ for more information.\n\n"); STATUS("See http://www.rdesktop.org/ for more information.\n\n");
flags = RDP_LOGON_NORMAL; flags = RDP_LOGON_NORMAL;
@ -186,7 +187,7 @@ void generate_random(uint8 *random)
{ {
struct stat st; struct stat st;
struct tms tmsbuf; struct tms tmsbuf;
uint32 *r = (uint32 *)random; uint32 *r = (uint32 *) random;
int fd; int fd;
/* If we have a kernel random device, use it. */ /* If we have a kernel random device, use it. */
@ -201,7 +202,7 @@ void generate_random(uint8 *random)
r[0] = (getpid()) | (getppid() << 16); r[0] = (getpid()) | (getppid() << 16);
r[1] = (getuid()) | (getgid() << 16); r[1] = (getuid()) | (getgid() << 16);
r[2] = times(&tmsbuf); /* system uptime (clocks) */ r[2] = times(&tmsbuf); /* system uptime (clocks) */
gettimeofday((struct timeval *)&r[3], NULL); /* sec and usec */ gettimeofday((struct timeval *) &r[3], NULL); /* sec and usec */
stat("/tmp", &st); stat("/tmp", &st);
r[5] = st.st_atime; r[5] = st.st_atime;
r[6] = st.st_mtime; r[6] = st.st_mtime;
@ -253,13 +254,13 @@ void hexdump(unsigned char *p, unsigned int len)
thisline = 16; thisline = 16;
for (i = 0; i < thisline; i++) for (i = 0; i < thisline; i++)
STATUS("%02x ", line[i]) STATUS("%02x ", line[i]) for (; i < 16; i++)
for (; i < 16; i++)
STATUS(" "); STATUS(" ");
for (i = 0; i < thisline; i++) for (i = 0; i < thisline; i++)
STATUS("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); STATUS("%c",
(line[i] >= 0x20
&& line[i] < 0x7f) ? line[i] : '.');
STATUS("\n"); STATUS("\n");
offset += thisline; offset += thisline;

49
rdp.c
View File

@ -139,7 +139,8 @@ void rdp_out_unistr(STREAM s, char *string, int len)
/* Parse a logon info packet */ /* Parse a logon info packet */
static void rdp_send_logon_info(uint32 flags, char *domain, char *user, static void rdp_send_logon_info(uint32 flags, char *domain, char *user,
char *password, char *program, char *directory) char *password, char *program,
char *directory)
{ {
int len_domain = 2 * strlen(domain); int len_domain = 2 * strlen(domain);
int len_user = 2 * strlen(user); int len_user = 2 * strlen(user);
@ -368,16 +369,25 @@ static void rdp_out_colcache_caps(STREAM s)
} }
static uint8 canned_caps[] = { static uint8 canned_caps[] = {
0x01,0x00,0x00,0x00,0x09,0x04,0x00,0x00,0x04, 0x01, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x04,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x08,0x00,0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x00,0x0E,0x00,0x08,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x34,0x00,0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x04,0x00,0xFE,0x00,0x04,0x00,0xFE,0x00,0x08,0x00,0xFE,0x00,0x08,0x00,0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x10,0x00,0xFE,0x00,0x20,0x00,0xFE,0x00,0x40,0x00,0xFE,0x00,0x80,0x00,0xFE, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,0x00,0x01,0x40,0x00,0x00,0x08,0x00,0x01,0x00,0x01,0x02,0x00,0x00,0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0C, 0x00, 0x08, 0x00, 0x01,
0x00, 0x00, 0x00, 0x0E, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00,
0x10, 0x00, 0x34, 0x00, 0xFE,
0x00, 0x04, 0x00, 0xFE, 0x00, 0x04, 0x00, 0xFE, 0x00, 0x08, 0x00,
0xFE, 0x00, 0x08, 0x00, 0xFE,
0x00, 0x10, 0x00, 0xFE, 0x00, 0x20, 0x00, 0xFE, 0x00, 0x40, 0x00,
0xFE, 0x00, 0x80, 0x00, 0xFE,
0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x01,
0x02, 0x00, 0x00, 0x00
}; };
/* Output unknown capability set */ /* Output unknown capability set */
@ -386,17 +396,18 @@ static void rdp_out_unknown_caps(STREAM s)
out_uint16_le(s, RDP_CAPSET_UNKNOWN); out_uint16_le(s, RDP_CAPSET_UNKNOWN);
out_uint16_le(s, 0x58); out_uint16_le(s, 0x58);
out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN-4); out_uint8p(s, canned_caps, RDP_CAPLEN_UNKNOWN - 4);
} }
/* Send a confirm active PDU */ /* Send a confirm active PDU */
static void rdp_send_confirm_active() static void rdp_send_confirm_active()
{ {
STREAM s; STREAM s;
uint16 caplen = RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER uint16 caplen =
+ RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + RDP_CAPLEN_ACTIVATE RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER +
+ RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE +
+ RDP_CAPLEN_UNKNOWN; RDP_CAPLEN_ACTIVATE + RDP_CAPLEN_CONTROL +
RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE + RDP_CAPLEN_UNKNOWN;
s = rdp_init(14 + caplen + sizeof(RDP_SOURCE)); s = rdp_init(14 + caplen + sizeof(RDP_SOURCE));
@ -502,7 +513,8 @@ static void process_bitmap_updates(STREAM s)
if (!compress) if (!compress)
{ {
in_uint8p(s, data, bufsize); in_uint8p(s, data, bufsize);
ui_paint_bitmap(left, top, cx, cy, width, height, data); ui_paint_bitmap(left, top, cx, cy, width, height,
data);
return; return;
} }
@ -531,7 +543,7 @@ static void process_palette(STREAM s)
in_uint8s(s, 2); /* pad */ in_uint8s(s, 2); /* pad */
in_uint16_le(s, map.ncolours); in_uint16_le(s, map.ncolours);
in_uint8s(s, 2); /* pad */ in_uint8s(s, 2); /* pad */
in_uint8p(s, (uint8 *)map.colours, (map.ncolours * 3)); in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3));
hmap = ui_create_colourmap(&map); hmap = ui_create_colourmap(&map);
ui_set_colourmap(hmap); ui_set_colourmap(hmap);
@ -643,4 +655,3 @@ void rdp_disconnect()
{ {
sec_disconnect(); sec_disconnect();
} }

View File

@ -45,7 +45,8 @@ static uint8 sec_crypted_random[64];
* a client and server salt) and a global salt value used for padding. * a client and server salt) and a global salt value used for padding.
* Both SHA1 and MD5 algorithms are used. * Both SHA1 and MD5 algorithms are used.
*/ */
void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt) void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2,
uint8 salt)
{ {
uint8 shasig[20]; uint8 shasig[20];
uint8 pad[4]; uint8 pad[4];
@ -55,10 +56,10 @@ void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt)
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
memset(pad, salt+i, i+1); memset(pad, salt + i, i + 1);
SHA1_Init(&sha); SHA1_Init(&sha);
SHA1_Update(&sha, pad, i+1); SHA1_Update(&sha, pad, i + 1);
SHA1_Update(&sha, in, 48); SHA1_Update(&sha, in, 48);
SHA1_Update(&sha, salt1, 32); SHA1_Update(&sha, salt1, 32);
SHA1_Update(&sha, salt2, 32); SHA1_Update(&sha, salt2, 32);
@ -67,7 +68,7 @@ void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt)
MD5_Init(&md5); MD5_Init(&md5);
MD5_Update(&md5, in, 48); MD5_Update(&md5, in, 48);
MD5_Update(&md5, shasig, 20); MD5_Update(&md5, shasig, 20);
MD5_Final(&out[i*16], &md5); MD5_Final(&out[i * 16], &md5);
} }
} }
@ -104,7 +105,7 @@ static void sec_generate_keys(uint8 *client_key, uint8 *server_key,
/* Construct input data to hash */ /* Construct input data to hash */
memcpy(input, client_key, 24); memcpy(input, client_key, 24);
memcpy(input+24, server_key, 24); memcpy(input + 24, server_key, 24);
/* Generate session key - two rounds of sec_hash_48 */ /* Generate session key - two rounds of sec_hash_48 */
sec_hash_48(temp_hash, input, client_key, server_key, 65); sec_hash_48(temp_hash, input, client_key, server_key, 65);
@ -114,8 +115,10 @@ static void sec_generate_keys(uint8 *client_key, uint8 *server_key,
memcpy(sec_sign_key, session_key, 8); memcpy(sec_sign_key, session_key, 8);
/* Generate RC4 keys */ /* Generate RC4 keys */
sec_hash_16(sec_decrypt_key, &session_key[16], client_key, server_key); sec_hash_16(sec_decrypt_key, &session_key[16], client_key,
sec_hash_16(sec_encrypt_key, &session_key[32], client_key, server_key); server_key);
sec_hash_16(sec_encrypt_key, &session_key[32], client_key,
server_key);
if (rc4_key_size == 1) if (rc4_key_size == 1)
{ {
@ -140,16 +143,18 @@ static void sec_generate_keys(uint8 *client_key, uint8 *server_key,
RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key); RC4_set_key(&rc4_encrypt_key, rc4_key_len, sec_encrypt_key);
} }
static uint8 pad_54[40] = static uint8 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,
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 uint8 pad_92[48] = static uint8 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,
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
}; };
/* Output a uint32 into a buffer (little-endian) */ /* Output a uint32 into a buffer (little-endian) */
@ -249,19 +254,19 @@ static void sec_decrypt(uint8 *data, int length)
} }
/* Read in a NUMBER from a buffer */ /* Read in a NUMBER from a buffer */
static void sec_read_number(NUMBER *num, uint8 *buffer, int len) static void sec_read_number(NUMBER * num, uint8 *buffer, int len)
{ {
INT *data = num->n_part; INT *data = num->n_part;
int i, j; int i, j;
for (i = 0, j = 0; j < len; i++, j += 2) for (i = 0, j = 0; j < len; i++, j += 2)
data[i] = buffer[j] | (buffer[j+1] << 8); data[i] = buffer[j] | (buffer[j + 1] << 8);
num->n_len = i; num->n_len = i;
} }
/* Write a NUMBER to a buffer */ /* Write a NUMBER to a buffer */
static void sec_write_number(NUMBER *num, uint8 *buffer, int len) static void sec_write_number(NUMBER * num, uint8 *buffer, int len)
{ {
INT *data = num->n_part; INT *data = num->n_part;
int i, j; int i, j;
@ -269,7 +274,7 @@ static void sec_write_number(NUMBER *num, uint8 *buffer, int len)
for (i = 0, j = 0; j < len; i++, j += 2) for (i = 0, j = 0; j < len; i++, j += 2)
{ {
buffer[j] = data[i] & 0xff; buffer[j] = data[i] & 0xff;
buffer[j+1] = data[i] >> 8; buffer[j + 1] = data[i] >> 8;
} }
} }
@ -318,11 +323,11 @@ void sec_send(STREAM s, uint32 flags)
#if RDP_DEBUG #if RDP_DEBUG
DEBUG("Sending encrypted packet:\n"); DEBUG("Sending encrypted packet:\n");
hexdump(s->p+8, datalen); hexdump(s->p + 8, datalen);
#endif #endif
sec_sign(s->p, sec_sign_key, 8, s->p+8, datalen); sec_sign(s->p, sec_sign_key, 8, s->p + 8, datalen);
sec_encrypt(s->p+8, datalen); sec_encrypt(s->p + 8, datalen);
} }
mcs_send(s); mcs_send(s);
@ -380,7 +385,7 @@ static void sec_out_mcs_data(STREAM s)
/* Unicode name of client, padded to 32 bytes */ /* Unicode name of client, padded to 32 bytes */
rdp_out_unistr(s, hostname, hostlen); rdp_out_unistr(s, hostname, hostlen);
out_uint8s(s, 30-hostlen); out_uint8s(s, 30 - hostlen);
out_uint32_le(s, 4); out_uint32_le(s, 4);
out_uint32(s, 0); out_uint32(s, 0);
@ -426,7 +431,8 @@ static BOOL sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent)
/* Parse a crypto information structure */ /* Parse a crypto information structure */
static BOOL sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size, static BOOL sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size,
uint8 **server_random, uint8 **modulus, uint8 **exponent) uint8 **server_random, uint8 **modulus,
uint8 **exponent)
{ {
uint32 crypt_level, random_len, rsa_info_len; uint32 crypt_level, random_len, rsa_info_len;
uint16 tag, length; uint16 tag, length;
@ -462,7 +468,8 @@ static BOOL sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size,
switch (tag) switch (tag)
{ {
case SEC_TAG_PUBKEY: case SEC_TAG_PUBKEY:
if (!sec_parse_public_key(s, modulus, exponent)) if (!sec_parse_public_key
(s, modulus, exponent))
return False; return False;
break; break;

12
tcp.c
View File

@ -90,7 +90,7 @@ STREAM tcp_recv(int length)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 100; tv.tv_usec = 100;
ret = select(sock+1, &rfds, NULL, NULL, &tv); ret = select(sock + 1, &rfds, NULL, NULL, &tv);
if (ret) if (ret)
{ {
@ -119,7 +119,8 @@ BOOL tcp_connect(char *server)
if ((nslookup = gethostbyname(server)) != NULL) if ((nslookup = gethostbyname(server)) != NULL)
{ {
memcpy(&servaddr.sin_addr, nslookup->h_addr, sizeof(servaddr.sin_addr)); memcpy(&servaddr.sin_addr, nslookup->h_addr,
sizeof(servaddr.sin_addr));
} }
else if (!(servaddr.sin_addr.s_addr = inet_addr(server))) else if (!(servaddr.sin_addr.s_addr = inet_addr(server)))
{ {
@ -136,14 +137,17 @@ BOOL tcp_connect(char *server)
servaddr.sin_family = AF_INET; servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(TCP_PORT_RDP); servaddr.sin_port = htons(TCP_PORT_RDP);
if (connect(sock, (struct sockaddr *)&servaddr, sizeof(struct sockaddr)) < 0) if (connect
(sock, (struct sockaddr *) &servaddr,
sizeof(struct sockaddr)) < 0)
{ {
STATUS("connect: %s\n", strerror(errno)); STATUS("connect: %s\n", strerror(errno));
close(sock); close(sock);
return False; return False;
} }
setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *)&true, sizeof(true)); setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *) &true,
sizeof(true));
in.size = 4096; in.size = 4096;
in.data = xmalloc(in.size); in.data = xmalloc(in.size);

55
xwin.c
View File

@ -61,7 +61,8 @@ BOOL ui_create_window(char *title)
visual = DefaultVisual(display, DefaultScreen(display)); visual = DefaultVisual(display, DefaultScreen(display));
attribs.background_pixel = BlackPixel(display, DefaultScreen(display)); attribs.background_pixel =
BlackPixel(display, DefaultScreen(display));
attribs.backing_store = Always; attribs.backing_store = Always;
wnd = XCreateWindow(display, DefaultRootWindow(display), wnd = XCreateWindow(display, DefaultRootWindow(display),
0, 0, width, height, 0, 8, InputOutput, visual, 0, 0, width, height, 0, 8, InputOutput, visual,
@ -146,7 +147,9 @@ void ui_process_events()
switch (event.type) switch (event.type)
{ {
case KeyPress: case KeyPress:
scancode = xwin_translate_key(event.xkey.keycode); scancode =
xwin_translate_key(event.xkey.
keycode);
if (scancode == 0) if (scancode == 0)
break; break;
@ -155,7 +158,9 @@ void ui_process_events()
break; break;
case KeyRelease: case KeyRelease:
scancode = xwin_translate_key(event.xkey.keycode); scancode =
xwin_translate_key(event.xkey.
keycode);
if (scancode == 0) if (scancode == 0)
break; break;
@ -165,7 +170,9 @@ void ui_process_events()
break; break;
case ButtonPress: case ButtonPress:
button = xwin_translate_mouse(event.xbutton.button); button =
xwin_translate_mouse(event.xbutton.
button);
if (button == 0) if (button == 0)
break; break;
@ -177,7 +184,9 @@ void ui_process_events()
break; break;
case ButtonRelease: case ButtonRelease:
button = xwin_translate_mouse(event.xbutton.button); button =
xwin_translate_mouse(event.xbutton.
button);
if (button == 0) if (button == 0)
break; break;
@ -214,7 +223,7 @@ HBITMAP ui_create_bitmap(int width, int height, uint8 *data)
XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height); XPutImage(display, bitmap, gc, image, 0, 0, 0, 0, width, height);
XFree(image); XFree(image);
return (HBITMAP)bitmap; return (HBITMAP) bitmap;
} }
void ui_paint_bitmap(int x, int y, int cx, int cy, void ui_paint_bitmap(int x, int y, int cx, int cy,
@ -231,7 +240,7 @@ void ui_paint_bitmap(int x, int y, int cx, int cy,
void ui_destroy_bitmap(HBITMAP bmp) void ui_destroy_bitmap(HBITMAP bmp)
{ {
XFreePixmap(display, (Pixmap)bmp); XFreePixmap(display, (Pixmap) bmp);
} }
HGLYPH ui_create_glyph(int width, int height, uint8 *data) HGLYPH ui_create_glyph(int width, int height, uint8 *data)
@ -257,12 +266,12 @@ HGLYPH ui_create_glyph(int width, int height, uint8 *data)
XFree(image); XFree(image);
XFreeGC(display, gc); XFreeGC(display, gc);
return (HGLYPH)bitmap; return (HGLYPH) bitmap;
} }
void ui_destroy_glyph(HGLYPH glyph) void ui_destroy_glyph(HGLYPH glyph)
{ {
XFreePixmap(display, (Pixmap)glyph); XFreePixmap(display, (Pixmap) glyph);
} }
HCOLOURMAP ui_create_colourmap(COLOURMAP *colours) HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)
@ -289,17 +298,17 @@ HCOLOURMAP ui_create_colourmap(COLOURMAP *colours)
XStoreColors(display, map, xcolours, ncolours); XStoreColors(display, map, xcolours, ncolours);
xfree(xcolours); xfree(xcolours);
return (HCOLOURMAP)map; return (HCOLOURMAP) map;
} }
void ui_destroy_colourmap(HCOLOURMAP map) void ui_destroy_colourmap(HCOLOURMAP map)
{ {
XFreeColormap(display, (Colormap)map); XFreeColormap(display, (Colormap) map);
} }
void ui_set_colourmap(HCOLOURMAP map) void ui_set_colourmap(HCOLOURMAP map)
{ {
XSetWindowColormap(display, wnd, (Colormap)map); XSetWindowColormap(display, wnd, (Colormap) map);
} }
void ui_set_clip(int x, int y, int cx, int cy) void ui_set_clip(int x, int y, int cx, int cy)
@ -378,7 +387,7 @@ void ui_patblt(uint8 opcode,
break; break;
case 3: /* Pattern */ case 3: /* Pattern */
fill = (Pixmap)ui_create_glyph(8, 8, brush->pattern); fill = (Pixmap) ui_create_glyph(8, 8, brush->pattern);
XSetForeground(dpy, gc, fgcolour); XSetForeground(dpy, gc, fgcolour);
XSetBackground(dpy, gc, bgcolour); XSetBackground(dpy, gc, bgcolour);
@ -388,7 +397,7 @@ void ui_patblt(uint8 opcode,
XFillRectangle(dpy, wnd, gc, x, y, cx, cy); XFillRectangle(dpy, wnd, gc, x, y, cx, cy);
XSetFillStyle(dpy, gc, FillSolid); XSetFillStyle(dpy, gc, FillSolid);
ui_destroy_glyph((HGLYPH)fill); ui_destroy_glyph((HGLYPH) fill);
break; break;
default: default:
@ -402,8 +411,7 @@ void ui_screenblt(uint8 opcode,
{ {
xwin_set_function(opcode); xwin_set_function(opcode);
XCopyArea(display, wnd, wnd, gc, srcx, srcy, XCopyArea(display, wnd, wnd, gc, srcx, srcy, cx, cy, x, y);
cx, cy, x, y);
} }
void ui_memblt(uint8 opcode, void ui_memblt(uint8 opcode,
@ -412,8 +420,7 @@ void ui_memblt(uint8 opcode,
{ {
xwin_set_function(opcode); xwin_set_function(opcode);
XCopyArea(display, (Pixmap)src, wnd, gc, srcx, srcy, XCopyArea(display, (Pixmap) src, wnd, gc, srcx, srcy, cx, cy, x, y);
cx, cy, x, y);
} }
void ui_triblt(uint8 opcode, void ui_triblt(uint8 opcode,
@ -468,9 +475,10 @@ void ui_rect(
void ui_draw_glyph(int mixmode, void ui_draw_glyph(int mixmode,
/* dest */ int x, int y, int cx, int cy, /* dest */ int x, int y, int cx, int cy,
/* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour) /* src */ HGLYPH glyph, int srcx, int srcy, int bgcolour,
int fgcolour)
{ {
Pixmap pixmap = (Pixmap)glyph; Pixmap pixmap = (Pixmap) glyph;
xwin_set_function(ROP2_COPY); xwin_set_function(ROP2_COPY);
@ -482,8 +490,7 @@ void ui_draw_glyph(int mixmode,
XSetStipple(display, gc, pixmap); XSetStipple(display, gc, pixmap);
XSetFillStyle(display, gc, FillStippled); XSetFillStyle(display, gc, FillStippled);
XSetTSOrigin(display, gc, x, y); XSetTSOrigin(display, gc, x, y);
XFillRectangle(display, wnd, gc, XFillRectangle(display, wnd, gc, x, y, cx, cy);
x, y, cx, cy);
XSetFillStyle(display, gc, FillSolid); XSetFillStyle(display, gc, FillSolid);
break; break;
@ -525,8 +532,8 @@ void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y,
if (glyph != NULL) if (glyph != NULL)
{ {
ui_draw_glyph(mixmode, x + (short)glyph->offset, ui_draw_glyph(mixmode, x + (short) glyph->offset,
y + (short)glyph->baseline, y + (short) glyph->baseline,
glyph->width, glyph->height, glyph->width, glyph->height,
glyph->pixmap, 0, 0, glyph->pixmap, 0, 0,
bgcolour, fgcolour); bgcolour, fgcolour);