From 24ea31f68a4797d2703e8d4ba39b5c57a5496379 Mon Sep 17 00:00:00 2001 From: Matt Chapman Date: Fri, 14 Sep 2001 13:51:38 +0000 Subject: [PATCH] Portability fixes, including elimination of variable argument macros. Rudimentary configure script. Miscellaneous cleanups. git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@29 423420c4-83ab-492f-b58f-81f9feb106b5 --- Makefile | 51 +++++++++---- bitmap.c | 4 +- cache.c | 22 +++--- configure | 48 +++++++++++++ iso.c | 8 +-- licence.c | 7 +- mcs.c | 18 ++--- orders.c | 94 ++++++++++++------------ proto.h | 2 + rdesktop.c | 206 +++++++++++++++++++++++++++++++++-------------------- rdesktop.h | 13 ++-- rdp.c | 36 +++++----- secure.c | 28 ++++---- tcp.c | 12 ++-- xwin.c | 14 ++-- 15 files changed, 344 insertions(+), 219 deletions(-) create mode 100755 configure diff --git a/Makefile b/Makefile index 4d3c85d..5cba20d 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,45 @@ -############################################## -# rdesktop: A Remote Desktop Protocol client # -# Basic Makefile # -# Copyright (C) Matthew Chapman 1999-2000 # -############################################## +# +# rdesktop: A Remote Desktop Protocol client +# Makefile +# Copyright (C) Matthew Chapman 1999-2001 +# -# Uncomment to enable debugging -# DEBUG = -g -DRDP_DEBUG +# Configuration defaults -CC = gcc -CFLAGS = -O2 -Wall $(DEBUG) -I/usr/X11R6/include -LIBS = -L/usr/X11R6/lib -lX11 -lnsl +CC = cc +CFLAGS = -O2 +INCLUDES = -I/usr/X11R6/include +LDLIBS = -L/usr/X11R6/lib -lX11 -RDPOBJ = rdesktop.o tcp.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o xwin.o +PREFIX = /usr/local +EPREFIX = $(PREFIX) +BINDIR = $(EPREFIX)/bin +MANDIR = $(PREFIX)/man + +RDPOBJ = rdesktop.o tcp.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o xwin.o CRYPTOBJ = crypto/rc4_enc.o crypto/rc4_skey.o crypto/md5_dgst.o crypto/sha1dgst.o crypto/arith.o +include Makeconf # local configuration + + rdesktop: $(RDPOBJ) $(CRYPTOBJ) - $(CC) $(CFLAGS) -o rdesktop $(LIBS) $(RDPOBJ) $(CRYPTOBJ) + $(CC) $(CFLAGS) -o rdesktop $(RDPOBJ) $(CRYPTOBJ) $(LDDIRS) $(LDLIBS) + +Makeconf: + ./configure + +install: installbin + +installbin: rdesktop + mkdir -p $(BINDIR) + cp rdesktop $(BINDIR) + strip $(BINDIR)/rdesktop + chmod 755 $(BINDIR)/rdesktop + +installman: rdesktop.1 + mkdir -p $(MANDIR)/man1 + cp rdesktop.1 $(MANDIR)/man1 + chmod 755 $(MANDIR)/man1/rdesktop.1 proto: cproto -DMAKE_PROTO -o proto.h *.c @@ -27,4 +51,5 @@ clean: .SUFFIXES: .c .o .c.o: - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $< + diff --git a/bitmap.c b/bitmap.c index a171e28..f019c18 100644 --- a/bitmap.c +++ b/bitmap.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Bitmap decompression routines - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -244,7 +244,7 @@ bitmap_decompress(unsigned char *output, int width, int height, break; default: - NOTIMP("bitmap opcode 0x%x\n", + unimpl("bitmap opcode 0x%x\n", opcode); return False; } diff --git a/cache.c b/cache.c index 2cc110e..4e5fb60 100644 --- a/cache.c +++ b/cache.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Cache routines - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ cache_get_bitmap(uint8 cache_id, uint16 cache_idx) return bitmap; } - ERROR("get bitmap %d:%d\n", cache_id, cache_idx); + error("get bitmap %d:%d\n", cache_id, cache_idx); return NULL; } @@ -61,7 +61,7 @@ cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap) } else { - ERROR("put bitmap %d:%d\n", cache_id, cache_idx); + error("put bitmap %d:%d\n", cache_id, cache_idx); } } @@ -83,7 +83,7 @@ cache_get_font(uint8 font, uint16 character) return glyph; } - ERROR("get font %d:%d\n", font, character); + error("get font %d:%d\n", font, character); return NULL; } @@ -109,7 +109,7 @@ cache_put_font(uint8 font, uint16 character, uint16 offset, } else { - ERROR("put font %d:%d\n", font, character); + error("put font %d:%d\n", font, character); } } @@ -130,7 +130,7 @@ cache_get_text(uint8 cache_id) return text; } - ERROR("get text %d\n", cache_id); + error("get text %d\n", cache_id); return NULL; } @@ -152,7 +152,7 @@ cache_put_text(uint8 cache_id, void *data, int length) } else { - ERROR("put text %d\n", cache_id); + error("put text %d\n", cache_id); } } @@ -171,7 +171,7 @@ cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel) return &deskcache[offset]; } - ERROR("get desktop %d:%d\n", offset, length); + error("get desktop %d:%d\n", offset, length); return NULL; } @@ -194,7 +194,7 @@ cache_put_desktop(uint32 offset, int cx, int cy, int scanline, } else { - ERROR("put desktop %d:%d\n", offset, length); + error("put desktop %d:%d\n", offset, length); } } @@ -214,7 +214,7 @@ HCURSOR cache_get_cursor(uint16 cache_idx) return cursor; } - ERROR("get cursor %d\n", cache_idx); + error("get cursor %d\n", cache_idx); return NULL; } @@ -234,6 +234,6 @@ cache_put_cursor(uint16 cache_idx, HCURSOR cursor) } else { - ERROR("put cursor %d\n", cache_idx); + error("put cursor %d\n", cache_idx); } } diff --git a/configure b/configure new file mode 100755 index 0000000..e05f77f --- /dev/null +++ b/configure @@ -0,0 +1,48 @@ +#!/bin/sh +# +# rdesktop: A Remote Desktop Protocol client +# configure script +# Copyright (C) Matthew Chapman 1999-2001 +# + +echo "# Generated by $0 $*" >Makeconf + +for arg in $*; do +optarg=`echo $arg | sed 's/[-a-z]*=//'` +case $arg in + --prefix=*) + echo "PREFIX = $optarg" >>Makeconf + ;; + --exec-prefix=*) + echo "EPREFIX = $optarg" >>Makeconf + ;; + --bindir=*) + echo "BINDIR = $optarg" >>Makeconf + ;; + --mandir=*) + echo "MANDIR = $optarg" >>Makeconf + ;; + --with-debug*) + echo "CFLAGS += -g -DWITH_DEBUG" >>Makeconf + ;; + --without-debug*) + ;; + *) + echo "rdesktop build configuration script" + echo + echo "Target directories:" + echo " --prefix=PREFIX location for architecture-independent files" + echo " --exec-prefix=EPREFIX location for architecture-dependent files" + echo " --bindir=BINDIR location for program binaries [EPREFIX/bin]" + echo " --mandir=MANDIR location for man pages [PREFIX/man]" + echo + echo "Build configuration:" + echo " --with-debug enable debugging output" + echo + rm -f Makeconf + exit 1 + ;; +esac +done + +echo "configure complete - now run make" diff --git a/iso.c b/iso.c index f0ae7c7..d7d03ef 100644 --- a/iso.c +++ b/iso.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Protocol services - ISO layer - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -57,7 +57,7 @@ iso_recv_msg(uint8 *code) in_uint8(s, version); if (version != 3) { - ERROR("TPKT v%d\n", version); + error("TPKT v%d\n", version); return False; } @@ -123,7 +123,7 @@ iso_recv() s = iso_recv_msg(&code); if ((s == NULL) || (code != ISO_PDU_DT)) { - ERROR("expected DT, got %d\n", code); + error("expected DT, got %d\n", code); return False; } @@ -143,7 +143,7 @@ iso_connect(char *server) if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC)) { - ERROR("expected CC, got %d\n", code); + error("expected CC, got %d\n", code); tcp_disconnect(); return False; } diff --git a/licence.c b/licence.c index 95f0caa..017f201 100644 --- a/licence.c +++ b/licence.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. RDP licensing negotiation - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -142,7 +142,7 @@ licence_parse_authreq(STREAM s, uint8 **token, uint8 **signature) in_uint16_le(s, tokenlen); if (tokenlen != LICENCE_TOKEN_SIZE) { - ERROR("token len %d\n", tokenlen); + error("token len %d\n", tokenlen); return False; } @@ -216,7 +216,6 @@ licence_process_issue(STREAM s) licence_issued = True; /* We should save the licence here */ - STATUS("Server issued licence.\n"); } /* Process a licence packet */ @@ -246,6 +245,6 @@ licence_process(STREAM s) break; default: - NOTIMP("licence tag 0x%x\n", tag); + unimpl("licence tag 0x%x\n", tag); } } diff --git a/mcs.c b/mcs.c index 543e1d5..f334412 100644 --- a/mcs.c +++ b/mcs.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Protocol services - Multipoint Communications Service - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ ber_parse_header(STREAM s, int tagval, int *length) if (tag != tagval) { - ERROR("expected tag %d, got %d\n", tagval, tag); + error("expected tag %d, got %d\n", tagval, tag); return False; } @@ -161,7 +161,7 @@ mcs_recv_connect_response(STREAM mcs_data) in_uint8(s, result); if (result != 0) { - ERROR("MCS connect: %d\n", result); + error("MCS connect: %d\n", result); return False; } @@ -172,7 +172,7 @@ mcs_recv_connect_response(STREAM mcs_data) ber_parse_header(s, BER_TAG_OCTET_STRING, &length); if (length > mcs_data->size) { - WARN("MCS data length %d\n", length); + error("MCS data length %d\n", length); length = mcs_data->size; } @@ -227,14 +227,14 @@ mcs_recv_aucf(uint16 *mcs_userid) in_uint8(s, opcode); if ((opcode >> 2) != MCS_AUCF) { - ERROR("expected AUcf, got %d\n", opcode); + error("expected AUcf, got %d\n", opcode); return False; } in_uint8(s, result); if (result != 0) { - ERROR("AUrq: %d\n", result); + error("AUrq: %d\n", result); return False; } @@ -274,14 +274,14 @@ mcs_recv_cjcf() in_uint8(s, opcode); if ((opcode >> 2) != MCS_CJCF) { - ERROR("expected CJcf, got %d\n", opcode); + error("expected CJcf, got %d\n", opcode); return False; } in_uint8(s, result); if (result != 0) { - ERROR("CJrq: %d\n", result); + error("CJrq: %d\n", result); return False; } @@ -340,7 +340,7 @@ mcs_recv() { if (appid != MCS_DPUM) { - ERROR("expected data, got %d\n", opcode); + error("expected data, got %d\n", opcode); } return NULL; } diff --git a/orders.c b/orders.c index 88bd58f..20573f6 100644 --- a/orders.c +++ b/orders.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. RDP order processing - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -165,8 +165,8 @@ process_destblt(STREAM s, DESTBLT_ORDER *os, uint32 present, BOOL delta) if (present & 0x10) in_uint8(s, os->opcode); - DEBUG("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n", - os->opcode, os->x, os->y, os->cx, os->cy); + DEBUG(("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n", + os->opcode, os->x, os->y, os->cx, os->cy)); ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy); } @@ -198,9 +198,9 @@ process_patblt(STREAM s, PATBLT_ORDER *os, uint32 present, BOOL delta) rdp_parse_brush(s, &os->brush, present >> 7); - DEBUG("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n", - os->opcode, os->x, os->y, os->cx, os->cy, - os->brush.style, os->bgcolour, os->fgcolour); + DEBUG(("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n", + os->opcode, os->x, os->y, os->cx, os->cy, + os->brush.style, os->bgcolour, os->fgcolour)); ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy, &os->brush, os->bgcolour, os->fgcolour); @@ -231,8 +231,8 @@ process_screenblt(STREAM s, SCREENBLT_ORDER *os, uint32 present, BOOL delta) if (present & 0x0040) rdp_in_coord(s, &os->srcy, delta); - DEBUG("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n", - os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy); + DEBUG(("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n", + os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy)); ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, os->srcx, os->srcy); @@ -265,13 +265,13 @@ process_line(STREAM s, LINE_ORDER *os, uint32 present, BOOL delta) rdp_parse_pen(s, &os->pen, present >> 7); - DEBUG("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dx=%d,fg=0x%x)\n", - os->opcode, os->startx, os->starty, os->endx, os->endy, - os->pen.colour); + DEBUG(("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dx=%d,fg=0x%x)\n", + os->opcode, os->startx, os->starty, os->endx, os->endy, + os->pen.colour)); if (os->opcode < 0x01 || os->opcode > 0x10) { - ERROR("bad ROP2 0x%x\n", os->opcode); + error("bad ROP2 0x%x\n", os->opcode); return; } @@ -298,8 +298,8 @@ process_rect(STREAM s, RECT_ORDER *os, uint32 present, BOOL delta) if (present & 0x10) in_uint8(s, os->colour); - DEBUG("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n", - os->x, os->y, os->cx, os->cy, os->colour); + DEBUG(("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n", + os->x, os->y, os->cx, os->cy, os->colour)); ui_rect(os->x, os->y, os->cx, os->cy, os->colour); } @@ -328,9 +328,9 @@ process_desksave(STREAM s, DESKSAVE_ORDER *os, uint32 present, BOOL delta) if (present & 0x20) in_uint8(s, os->action); - DEBUG("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n", - os->left, os->top, os->right, os->bottom, os->offset, - os->action); + DEBUG(("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n", + os->left, os->top, os->right, os->bottom, os->offset, + os->action)); width = os->right - os->left + 1; height = os->bottom - os->top + 1; @@ -378,9 +378,9 @@ process_memblt(STREAM s, MEMBLT_ORDER *os, uint32 present, BOOL delta) if (present & 0x0100) in_uint16_le(s, os->cache_idx); - DEBUG("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n", - os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, - os->cache_idx); + DEBUG(("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n", + os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, + os->cache_idx)); bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); if (bitmap == NULL) @@ -437,10 +437,9 @@ process_triblt(STREAM s, TRIBLT_ORDER *os, uint32 present, BOOL delta) if (present & 0x010000) 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", - os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, - os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour); + 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->cache_idx, os->brush.style, os->bgcolour, os->fgcolour)); bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); if (bitmap == NULL) @@ -499,15 +498,15 @@ process_polyline(STREAM s, POLYLINE_ORDER *os, uint32 present, BOOL delta) in_uint8a(s, os->data, os->datasize); } - DEBUG("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n", - os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize); + DEBUG(("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n", + os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize)); - DEBUG("Data: "); + DEBUG(("Data: ")); for (index = 0; index < os->datasize; index++) - DEBUG("%02x ", os->data[index]); + DEBUG(("%02x ", os->data[index])); - DEBUG("\n"); + DEBUG(("\n")); x = os->x; y = os->y; @@ -600,19 +599,18 @@ process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta) 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", - os->x, os->y, os->clipleft, os->cliptop, os->clipright, - os->clipbottom, os->boxleft, os->boxtop, os->boxright, - os->boxbottom, os->fgcolour, os->bgcolour, os->font, - os->flags, os->mixmode, os->unknown, 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", + os->x, os->y, os->clipleft, os->cliptop, os->clipright, + os->clipbottom, os->boxleft, os->boxtop, os->boxright, + os->boxbottom, os->fgcolour, os->bgcolour, os->font, + os->flags, os->mixmode, os->unknown, os->length)); - DEBUG("Text: "); + DEBUG(("Text: ")); for (i = 0; i < os->length; i++) - DEBUG("%02x ", os->text[i]); + DEBUG(("%02x ", os->text[i])); - DEBUG("\n"); + DEBUG(("\n")); /* Process special cache strings */ if ((os->length >= 2) && (os->text[0] == 0xfe)) @@ -661,8 +659,8 @@ process_raw_bmpcache(STREAM s) in_uint16_le(s, cache_idx); in_uint8p(s, data, bufsize); - DEBUG("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", - width, height, cache_id, cache_idx); + DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", + width, height, cache_id, cache_idx)); inverted = xmalloc(width * height); for (y = 0; y < height; y++) { @@ -696,8 +694,8 @@ process_bmpcache(STREAM s) in_uint8s(s, 4); /* row_size, final_size */ in_uint8p(s, data, size); - DEBUG("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", - width, height, cache_id, cache_idx); + DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", + width, height, cache_id, cache_idx)); bmpdata = xmalloc(width * height); @@ -734,7 +732,7 @@ process_colcache(STREAM s) in_uint8s(s, 1); /* pad */ } - DEBUG("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours); + DEBUG(("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours)); hmap = ui_create_colourmap(&map); ui_set_colourmap(hmap); @@ -755,7 +753,7 @@ process_fontcache(STREAM s) in_uint8(s, font); in_uint8(s, nglyphs); - DEBUG("FONTCACHE(font=%d,n=%d)\n", font, nglyphs); + DEBUG(("FONTCACHE(font=%d,n=%d)\n", font, nglyphs)); for (i = 0; i < nglyphs; i++) { @@ -807,7 +805,7 @@ process_secondary_order(STREAM s) break; default: - NOTIMP("secondary order %d\n", type); + unimpl("secondary order %d\n", type); } s->p = next_order; @@ -834,7 +832,7 @@ process_orders(STREAM s) if (!(order_flags & RDP_ORDER_STANDARD)) { - ERROR("order parsing failed\n"); + error("order parsing failed\n"); break; } @@ -936,7 +934,7 @@ process_orders(STREAM s) break; default: - NOTIMP("order %d\n", os->order_type); + unimpl("order %d\n", os->order_type); return; } @@ -948,7 +946,7 @@ process_orders(STREAM s) } if (s->p != next_packet) - WARN("%d bytes remaining\n", (int) (next_packet - s->p)); + error("%d bytes remaining\n", (int) (next_packet - s->p)); } /* Reset order state */ diff --git a/proto.h b/proto.h index 30d0d08..8811369 100644 --- a/proto.h +++ b/proto.h @@ -35,6 +35,8 @@ void generate_random(uint8 *random); void *xmalloc(int size); void *xrealloc(void *oldmem, int size); void xfree(void *mem); +void error(char *format, ...); +void unimpl(char *format, ...); void hexdump(unsigned char *p, unsigned int len); /* rdp.c */ void rdp_out_unistr(STREAM s, char *string, int len); diff --git a/rdesktop.c b/rdesktop.c index 8046c95..b04d063 100644 --- a/rdesktop.c +++ b/rdesktop.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Entrypoint and utility functions - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,6 +19,7 @@ */ #include /* malloc realloc free */ +#include /* va_list va_start va_end */ #include /* read close getuid getgid getpid getppid gethostname */ #include /* open */ #include /* getpwuid */ @@ -29,14 +30,14 @@ char username[16]; char hostname[16]; -int width = 800; -int height = 600; +int width; +int height; int keylayout = 0x409; BOOL bitmap_compression = True; BOOL sendmotion = True; BOOL orders = True; BOOL licence = True; -BOOL use_encryption = True; +BOOL encryption = True; BOOL desktop_save = True; BOOL fullscreen = False; @@ -44,113 +45,114 @@ BOOL fullscreen = False; static void usage(char *program) { - STATUS("Usage: %s [options] server\n", program); - STATUS(" -u: user name\n"); - STATUS(" -d: domain\n"); - STATUS(" -s: shell\n"); - STATUS(" -c: working directory\n"); - STATUS(" -p: password (autologon)\n"); - STATUS(" -n: client hostname\n"); - STATUS(" -w: desktop width\n"); - STATUS(" -h: desktop height\n"); - STATUS(" -k: keyboard layout (hex)\n"); - STATUS(" -b: force bitmap updates\n"); - STATUS(" -m: do not send motion events\n"); - STATUS(" -l: do not request licence\n\n"); + printf("Usage: %s [options] server\n", program); + printf(" -u: user name\n"); + printf(" -d: domain\n"); + printf(" -s: shell\n"); + printf(" -c: working directory\n"); + printf(" -p: password (autologon)\n"); + printf(" -n: client hostname\n"); + printf(" -k: keyboard layout (hex)\n"); + printf(" -g: desktop geometry (WxH)\n"); + printf(" -f: full-screen mode\n"); + printf(" -b: force bitmap updates\n"); + printf(" -e: disable encryption (French TS)\n"); + printf(" -m: do not send motion events\n"); + printf(" -l: do not request licence\n\n"); } /* Client program */ int main(int argc, char *argv[]) { - struct passwd *pw; - char *server; - uint32 flags; + char fullhostname[64]; char domain[16]; char password[16]; char shell[32]; char directory[32]; char title[32]; + struct passwd *pw; + char *server, *p; + uint32 flags; int c; - STATUS("rdesktop: A Remote Desktop Protocol client.\n"); - STATUS("Version " VERSION - ". Copyright (C) 1999-2000 Matt Chapman.\n"); - STATUS("See http://www.rdesktop.org/ for more information.\n\n"); + printf("rdesktop: A Remote Desktop Protocol client.\n"); + printf("Version " VERSION ". Copyright (C) 1999-2001 Matt Chapman.\n"); + printf("See http://www.rdesktop.org/ for more information.\n\n"); flags = RDP_LOGON_NORMAL; domain[0] = password[0] = shell[0] = directory[0] = 0; - while ((c = getopt(argc, argv, "u:d:s:c:p:n:g:k:mbleKFVh?")) != -1) + while ((c = getopt(argc, argv, "u:d:s:c:p:n:k:g:fbemlh?")) != -1) { switch (c) { case 'u': - strncpy(username, optarg, sizeof(username)); + STRNCPY(username, optarg, sizeof(username)); break; case 'd': - strncpy(domain, optarg, sizeof(domain)); - break; - - case 'p': - flags |= RDP_LOGON_AUTO; - strncpy(password, optarg, sizeof(password)); + STRNCPY(domain, optarg, sizeof(domain)); break; case 's': - strncpy(shell, optarg, sizeof(shell)); + STRNCPY(shell, optarg, sizeof(shell)); break; case 'c': - strncpy(directory, optarg, sizeof(directory)); + STRNCPY(directory, optarg, sizeof(directory)); + break; + + case 'p': + STRNCPY(password, optarg, sizeof(password)); + flags |= RDP_LOGON_AUTO; break; case 'n': - strncpy(hostname, optarg, sizeof(hostname)); - break; - case 'g': - { - char *tgem = 0; - width = strtol(optarg, NULL, 10); - tgem = strchr(optarg, 'x'); - if ((tgem == 0) || (strlen(tgem) < 2)) - { - ERROR - ("-g: invalid parameter. Syntax example: -g 1024x768\n"); - exit(1); - } - height = strtol(tgem + 1, NULL, 10); - } + STRNCPY(hostname, optarg, sizeof(hostname)); break; case 'k': keylayout = strtol(optarg, NULL, 16); - /* keylayout = find_keyb_code(optarg); */ if (keylayout == 0) - return 0; + { + error("invalid keyboard layout\n"); + return 1; + } break; - case 'm': - sendmotion = False; + case 'g': + width = strtol(optarg, &p, 10); + if (*p == 'x') + height = strtol(p+1, NULL, 10); + + if ((width == 0) || (height == 0)) + { + error("invalid geometry\n"); + return 1; + } + break; + + case 'f': + fullscreen = True; break; case 'b': orders = False; break; + case 'e': + encryption = False; + break; + + case 'm': + sendmotion = False; + break; + case 'l': licence = False; break; - case 'e': - use_encryption = False; - break; - - case 'F': - fullscreen = True; - break; - case 'h': case '?': default: @@ -172,24 +174,47 @@ main(int argc, char *argv[]) pw = getpwuid(getuid()); if ((pw == NULL) || (pw->pw_name == NULL)) { - STATUS("Could not determine user name.\n"); + error("could not determine username, use -u\n"); return 1; } - strncpy(username, pw->pw_name, sizeof(username)); + STRNCPY(username, pw->pw_name, sizeof(username)); } if (hostname[0] == 0) { - if (gethostname(hostname, sizeof(hostname)) == -1) + if (gethostname(fullhostname, sizeof(fullhostname)) == -1) { - STATUS("Could not determine host name.\n"); + error("could not determine local hostname, use -n\n"); return 1; } + + p = strchr(fullhostname, '.'); + if (p != NULL) + *p = 0; + + STRNCPY(hostname, fullhostname, sizeof(hostname)); + } + + if (!strcmp(password, "-")) + { + p = getpass("Password: "); + if (p == NULL) + { + error("failed to read password\n"); + return 0; + } + STRNCPY(password, p, sizeof(password)); + } + + if ((width == 0) || (height == 0)) + { + width = 800; + height = 600; } strcpy(title, "rdesktop - "); - strncat(title, server, sizeof(title)); + strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); if (ui_create_window(title)) { @@ -197,7 +222,7 @@ main(int argc, char *argv[]) directory)) return 1; - STATUS("Connection successful.\n"); + printf("Connection successful.\n"); rdp_main_loop(); ui_destroy_window(); } @@ -216,7 +241,8 @@ generate_random(uint8 *random) int fd; /* If we have a kernel random device, use it. */ - if ((fd = open("/dev/urandom", O_RDONLY)) != -1) + if (((fd = open("/dev/urandom", O_RDONLY)) != -1) + || ((fd = open("/dev/random", O_RDONLY)) != -1)) { read(fd, random, 32); close(fd); @@ -241,7 +267,7 @@ xmalloc(int size) void *mem = malloc(size); if (mem == NULL) { - ERROR("xmalloc %d\n", size); + error("xmalloc %d\n", size); exit(1); } return mem; @@ -254,7 +280,7 @@ xrealloc(void *oldmem, int size) void *mem = realloc(oldmem, size); if (mem == NULL) { - ERROR("xrealloc %d\n", size); + error("xrealloc %d\n", size); exit(1); } return mem; @@ -267,7 +293,33 @@ xfree(void *mem) free(mem); } -/* Produce a hex dump */ +/* report an error */ +void +error(char *format, ...) +{ + va_list ap; + + fprintf(stderr, "ERROR: "); + + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); +} + +/* report an unimplemented protocol feature */ +void +unimpl(char *format, ...) +{ + va_list ap; + + fprintf(stderr, "NOT IMPLEMENTED: "); + + va_start(ap, format); + vfprintf(stderr, format, ap); + va_end(ap); +} + +/* produce a hex dump */ void hexdump(unsigned char *p, unsigned int len) { @@ -277,21 +329,23 @@ hexdump(unsigned char *p, unsigned int len) while (offset < len) { - STATUS("%04x ", offset); + printf("%04x ", offset); thisline = len - offset; if (thisline > 16) thisline = 16; for (i = 0; i < thisline; i++) - STATUS("%02x ", line[i]) for (; i < 16; i++) - STATUS(" "); + printf("%02x ", line[i]); + + for (; i < 16; i++) + printf(" "); for (i = 0; i < thisline; i++) - STATUS("%c", + printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.'); - STATUS("\n"); + printf("\n"); offset += thisline; line += thisline; } diff --git a/rdesktop.h b/rdesktop.h index 2ac36a6..bfda5c8 100644 --- a/rdesktop.h +++ b/rdesktop.h @@ -24,17 +24,14 @@ #define VERSION "1.1.0" -#define STATUS(args...) fprintf(stderr, args); -#define ERROR(args...) fprintf(stderr, "ERROR: "args); -#define WARN(args...) fprintf(stderr, "WARNING: "args); -#define NOTIMP(args...) fprintf(stderr, "NOTIMP: "args); - -#ifdef RDP_DEBUG -#define DEBUG(args...) fprintf(stderr, args); +#ifdef WITH_DEBUG +#define DEBUG(args) printf args; #else -#define DEBUG(args...) +#define DEBUG(args) #endif +#define STRNCPY(dst,src,n) { strncpy(dst,src,n-1); dst[n-1] = 0; } + #include "constants.h" #include "types.h" #include "parse.h" diff --git a/rdp.c b/rdp.c index e8f0599..6f0d6c5 100644 --- a/rdp.c +++ b/rdp.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Protocol services - RDP layer - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,7 +24,7 @@ extern uint16 mcs_userid; extern char username[16]; extern BOOL bitmap_compression; extern BOOL orders; -extern BOOL use_encryption; +extern BOOL encryption; extern BOOL desktop_save; uint8 *next_packet; @@ -36,7 +36,7 @@ rdp_init(int maxlen) { STREAM s; - s = sec_init(use_encryption ? SEC_ENCRYPT : 0, maxlen + 6); + s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 6); s_push_layer(s, rdp_hdr, 6); return s; @@ -55,7 +55,7 @@ rdp_send(STREAM s, uint8 pdu_type) out_uint16_le(s, (pdu_type | 0x10)); /* Version 1 */ out_uint16_le(s, (mcs_userid + 1001)); - sec_send(s, use_encryption ? SEC_ENCRYPT : 0); + sec_send(s, encryption ? SEC_ENCRYPT : 0); } /* Receive an RDP packet */ @@ -83,8 +83,8 @@ rdp_recv(uint8 *type) in_uint8s(rdp_s, 2); /* userid */ *type = pdu_type & 0xf; -#if RDP_DEBUG - DEBUG("RDP packet (type %x):\n", *type); +#if WITH_DEBUG + DEBUG(("RDP packet (type %x):\n", *type)); hexdump(next_packet, length); #endif /* */ @@ -98,7 +98,7 @@ rdp_init_data(int maxlen) { STREAM s; - s = sec_init(use_encryption ? SEC_ENCRYPT : 0, maxlen + 18); + s = sec_init(encryption ? SEC_ENCRYPT : 0, maxlen + 18); s_push_layer(s, rdp_hdr, 18); return s; @@ -125,7 +125,7 @@ rdp_send_data(STREAM s, uint8 data_pdu_type) out_uint8(s, 0); /* compress_type */ out_uint16(s, 0); /* compress_len */ - sec_send(s, use_encryption ? SEC_ENCRYPT : 0); + sec_send(s, encryption ? SEC_ENCRYPT : 0); } /* Output a string in Unicode */ @@ -155,7 +155,7 @@ rdp_send_logon_info(uint32 flags, char *domain, char *user, int len_password = 2 * strlen(password); int len_program = 2 * strlen(program); int len_directory = 2 * strlen(directory); - uint32 sec_flags = use_encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) + uint32 sec_flags = encryption ? (SEC_LOGON_INFO | SEC_ENCRYPT) : SEC_LOGON_INFO; STREAM s; @@ -479,7 +479,7 @@ process_demand_active(STREAM s) in_uint32_le(s, rdp_shareid); - DEBUG("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid); + DEBUG(("DEMAND_ACTIVE(id=0x%x)\n", rdp_shareid)); rdp_send_confirm_active(); rdp_send_synchronise(); @@ -538,7 +538,7 @@ process_pointer_pdu(STREAM s) break; default: - DEBUG("Pointer message 0x%x\n", message_type); + DEBUG(("Pointer message 0x%x\n", message_type)); } } @@ -569,8 +569,8 @@ process_bitmap_updates(STREAM s) cx = right - left + 1; cy = bottom - top + 1; - DEBUG("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n", - left, top, right, bottom, width, height, compress); + DEBUG(("UPDATE(l=%d,t=%d,r=%d,b=%d,w=%d,h=%d,cmp=%d)\n", + left, top, right, bottom, width, height, compress)); if (!compress) { @@ -610,11 +610,13 @@ process_palette(STREAM s) { HCOLOURMAP hmap; COLOURMAP map; + uint8 *colours; in_uint8s(s, 2); /* pad */ in_uint16_le(s, map.ncolours); in_uint8s(s, 2); /* pad */ - in_uint8p(s, (uint8 *) map.colours, (map.ncolours * 3)); + in_uint8p(s, colours, (map.ncolours * 3)); + map.colours = (COLOURENTRY *)colours; hmap = ui_create_colourmap(&map); ui_set_colourmap(hmap); @@ -646,7 +648,7 @@ process_update_pdu(STREAM s) break; default: - NOTIMP("update %d\n", update_type); + unimpl("update %d\n", update_type); } } @@ -680,7 +682,7 @@ process_data_pdu(STREAM s) break; default: - NOTIMP("data PDU %d\n", data_pdu_type); + unimpl("data PDU %d\n", data_pdu_type); } } @@ -707,7 +709,7 @@ rdp_main_loop() break; default: - NOTIMP("PDU %d\n", type); + unimpl("PDU %d\n", type); } } } diff --git a/secure.c b/secure.c index 96ae748..9bfac00 100644 --- a/secure.c +++ b/secure.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Protocol services - RDP encryption and licensing - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ extern char hostname[16]; extern int width; extern int height; extern int keylayout; -extern BOOL use_encryption; +extern BOOL encryption; extern BOOL licence_issued; static int rc4_key_len; @@ -126,7 +126,7 @@ sec_generate_keys(uint8 *client_key, uint8 *server_key, int rc4_key_size) if (rc4_key_size == 1) { - DEBUG("40-bit encryption enabled\n"); + DEBUG(("40-bit encryption enabled\n")); sec_make_40bit(sec_sign_key); sec_make_40bit(sec_decrypt_key); sec_make_40bit(sec_encrypt_key); @@ -134,7 +134,7 @@ sec_generate_keys(uint8 *client_key, uint8 *server_key, int rc4_key_size) } else { - DEBUG("128-bit encryption enabled\n"); + DEBUG(("128-bit encryption enabled\n")); rc4_key_len = 16; } @@ -339,8 +339,8 @@ sec_send(STREAM s, uint32 flags) flags &= ~SEC_ENCRYPT; datalen = s->end - s->p - 8; -#if RDP_DEBUG - DEBUG("Sending encrypted packet:\n"); +#if WITH_DEBUG + DEBUG(("Sending encrypted packet:\n")); hexdump(s->p + 8, datalen); #endif @@ -418,7 +418,7 @@ sec_out_mcs_data(STREAM s) /* Client encryption settings */ out_uint16_le(s, SEC_TAG_CLI_CRYPT); out_uint16(s, 8); /* length */ - out_uint32_le(s, use_encryption ? 1 : 0); /* encryption enabled */ + out_uint32_le(s, encryption ? 1 : 0); /* encryption enabled */ s_mark_end(s); } @@ -431,14 +431,14 @@ sec_parse_public_key(STREAM s, uint8 **modulus, uint8 **exponent) in_uint32_le(s, magic); if (magic != SEC_RSA_MAGIC) { - ERROR("RSA magic 0x%x\n", magic); + error("RSA magic 0x%x\n", magic); return False; } in_uint32_le(s, modulus_len); if (modulus_len != SEC_MODULUS_SIZE + SEC_PADDING_SIZE) { - ERROR("modulus len 0x%x\n", modulus_len); + error("modulus len 0x%x\n", modulus_len); return False; } @@ -466,7 +466,7 @@ sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size, if (random_len != SEC_RANDOM_SIZE) { - ERROR("random len %d\n", random_len); + error("random len %d\n", random_len); return False; } @@ -501,7 +501,7 @@ sec_parse_crypt_info(STREAM s, uint32 *rc4_key_size, break; default: - NOTIMP("crypt tag 0x%x\n", tag); + unimpl("crypt tag 0x%x\n", tag); } s->p = next_tag; @@ -559,7 +559,7 @@ sec_process_mcs_data(STREAM s) break; default: - NOTIMP("response tag 0x%x\n", tag); + unimpl("response tag 0x%x\n", tag); } s->p = next_tag; @@ -575,7 +575,7 @@ sec_recv() while ((s = mcs_recv()) != NULL) { - if (use_encryption || !licence_issued) + if (encryption || !licence_issued) { in_uint32_le(s, sec_flags); @@ -613,7 +613,7 @@ sec_connect(char *server) return False; sec_process_mcs_data(&mcs_data); - if (use_encryption) + if (encryption) sec_establish_key(); return True; } diff --git a/tcp.c b/tcp.c index 4f477f1..28119e3 100644 --- a/tcp.c +++ b/tcp.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. Protocol services - TCP layer - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -60,7 +60,7 @@ tcp_send(STREAM s) if (sent <= 0) { - STATUS("write: %s\n", strerror(errno)); + error("write: %s\n", strerror(errno)); return; } @@ -101,7 +101,7 @@ tcp_recv(int length) if (rcvd <= 0) { - STATUS("read: %s\n", strerror(errno)); + error("read: %s\n", strerror(errno)); return NULL; } @@ -128,13 +128,13 @@ tcp_connect(char *server) } else if (!(servaddr.sin_addr.s_addr = inet_addr(server))) { - STATUS("%s: unable to resolve host\n", server); + error("%s: unable to resolve host\n", server); return False; } if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - STATUS("socket: %s\n", strerror(errno)); + error("socket: %s\n", strerror(errno)); return False; } @@ -145,7 +145,7 @@ tcp_connect(char *server) (sock, (struct sockaddr *) &servaddr, sizeof(struct sockaddr)) < 0) { - STATUS("connect: %s\n", strerror(errno)); + error("connect: %s\n", strerror(errno)); close(sock); return False; } diff --git a/xwin.c b/xwin.c index 622e340..06bff30 100644 --- a/xwin.c +++ b/xwin.c @@ -1,7 +1,7 @@ /* rdesktop: A Remote Desktop Protocol client. User interface services - X-Windows - Copyright (C) Matthew Chapman 1999-2000 + Copyright (C) Matthew Chapman 1999-2001 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -151,7 +151,7 @@ ui_create_window(char *title) display = XOpenDisplay(NULL); if (display == NULL) { - ERROR("Failed to open display\n"); + error("Failed to open display\n"); return False; } @@ -177,7 +177,7 @@ ui_create_window(char *title) if (bpp < 8) { - ERROR("Less than 8 bpp not currently supported.\n"); + error("Less than 8 bpp not currently supported.\n"); XCloseDisplay(display); return False; } @@ -205,7 +205,7 @@ ui_create_window(char *title) attribs.override_redirect = False; } - width &= ~3; /* make width a multiple of 32 bits */ + width = (width + 3) & ~3; /* make width a multiple of 32 bits */ wnd = XCreateWindow(display, RootWindowOfScreen(screen), 0, 0, width, height, 0, CopyFromParent, @@ -259,7 +259,7 @@ ui_destroy_window() static uint8 xwin_translate_key(unsigned long key) { - DEBUG("KEY(code=0x%lx)\n", key); + DEBUG(("KEY(code=0x%lx)\n", key)); if ((key > 8) && (key <= 0x60)) return (key - 8); @@ -707,7 +707,7 @@ ui_patblt(uint8 opcode, break; default: - NOTIMP("brush %d\n", brush->style); + unimpl("brush %d\n", brush->style); } RESET_FUNCTION(opcode); @@ -765,7 +765,7 @@ ui_triblt(uint8 opcode, break; default: - NOTIMP("triblt 0x%x\n", opcode); + unimpl("triblt 0x%x\n", opcode); ui_memblt(ROP2_COPY, x, y, cx, cy, src, srcx, srcy); } }