1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
Entrypoint and utility functions |
Entrypoint and utility functions |
4 |
Copyright (C) Matthew Chapman 1999-2007 |
Copyright (C) Matthew Chapman 1999-2008 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
47 |
|
|
48 |
#include "ssl.h" |
#include "ssl.h" |
49 |
|
|
50 |
|
/* DJ globals begin */ |
51 |
|
unsigned long long g_time_last_write = 0; |
52 |
|
unsigned long long g_time_last_change = 0; |
53 |
|
uint32 g_pixels_changed; |
54 |
|
uint8 * g_bitmap_data = 0; |
55 |
|
uint8 * g_bitmap_data_last_write = 0; |
56 |
|
/* DJ globals end */ |
57 |
|
|
58 |
char g_title[64] = ""; |
char g_title[64] = ""; |
59 |
char g_username[64]; |
char *g_username; |
60 |
char g_hostname[16]; |
char g_hostname[16]; |
61 |
char g_keymapname[PATH_MAX] = ""; |
char g_keymapname[PATH_MAX] = ""; |
62 |
unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
85 |
RD_BOOL g_bitmap_cache_persist_enable = False; |
RD_BOOL g_bitmap_cache_persist_enable = False; |
86 |
RD_BOOL g_bitmap_cache_precache = True; |
RD_BOOL g_bitmap_cache_precache = True; |
87 |
RD_BOOL g_encryption = True; |
RD_BOOL g_encryption = True; |
88 |
RD_BOOL packet_encryption = True; |
RD_BOOL g_packet_encryption = True; |
89 |
RD_BOOL g_desktop_save = True; /* desktop save order */ |
RD_BOOL g_desktop_save = True; /* desktop save order */ |
90 |
RD_BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */ |
RD_BOOL g_polygon_ellipse_orders = True; /* polygon / ellipse orders */ |
91 |
RD_BOOL g_fullscreen = False; |
RD_BOOL g_fullscreen = False; |
95 |
RD_BOOL g_rdpclip = True; |
RD_BOOL g_rdpclip = True; |
96 |
RD_BOOL g_console_session = False; |
RD_BOOL g_console_session = False; |
97 |
RD_BOOL g_numlock_sync = False; |
RD_BOOL g_numlock_sync = False; |
98 |
RD_BOOL lspci_enabled = False; |
RD_BOOL g_lspci_enabled = False; |
99 |
RD_BOOL g_owncolmap = False; |
RD_BOOL g_owncolmap = False; |
100 |
RD_BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
RD_BOOL g_ownbackstore = True; /* We can't rely on external BackingStore */ |
101 |
RD_BOOL g_seamless_rdp = False; |
RD_BOOL g_seamless_rdp = False; |
107 |
char g_redirect_server[64]; |
char g_redirect_server[64]; |
108 |
char g_redirect_domain[16]; |
char g_redirect_domain[16]; |
109 |
char g_redirect_password[64]; |
char g_redirect_password[64]; |
110 |
char g_redirect_username[64]; |
char *g_redirect_username; |
111 |
char g_redirect_cookie[128]; |
char g_redirect_cookie[128]; |
112 |
uint32 g_redirect_flags = 0; |
uint32 g_redirect_flags = 0; |
113 |
|
|
135 |
usage(char *program) |
usage(char *program) |
136 |
{ |
{ |
137 |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n"); |
138 |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2007 Matt Chapman.\n"); |
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2008 Matthew Chapman.\n"); |
139 |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n"); |
140 |
|
|
141 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
481 |
break; |
break; |
482 |
|
|
483 |
case 'u': |
case 'u': |
484 |
STRNCPY(g_username, optarg, sizeof(g_username)); |
g_username = (char *) xmalloc(strlen(optarg) + 1); |
485 |
|
STRNCPY(g_username, optarg, strlen(optarg) + 1); |
486 |
username_option = 1; |
username_option = 1; |
487 |
break; |
break; |
488 |
|
|
591 |
g_encryption = False; |
g_encryption = False; |
592 |
break; |
break; |
593 |
case 'E': |
case 'E': |
594 |
packet_encryption = False; |
g_packet_encryption = False; |
595 |
break; |
break; |
596 |
case 'm': |
case 'm': |
597 |
g_sendmotion = False; |
g_sendmotion = False; |
642 |
g_server_depth = strtol(optarg, NULL, 10); |
g_server_depth = strtol(optarg, NULL, 10); |
643 |
if (g_server_depth != 8 && |
if (g_server_depth != 8 && |
644 |
g_server_depth != 16 && |
g_server_depth != 16 && |
645 |
g_server_depth != 15 && g_server_depth != 24) |
g_server_depth != 15 && g_server_depth != 24 |
646 |
|
&& g_server_depth != 32) |
647 |
{ |
{ |
648 |
error("Invalid server colour depth.\n"); |
error("Invalid server colour depth.\n"); |
649 |
return 1; |
return 1; |
736 |
} |
} |
737 |
else if (str_startswith(optarg, "lspci")) |
else if (str_startswith(optarg, "lspci")) |
738 |
{ |
{ |
739 |
lspci_enabled = True; |
g_lspci_enabled = True; |
740 |
} |
} |
741 |
else if (str_startswith(optarg, "lptport")) |
else if (str_startswith(optarg, "lptport")) |
742 |
{ |
{ |
855 |
error("could not determine username, use -u\n"); |
error("could not determine username, use -u\n"); |
856 |
return 1; |
return 1; |
857 |
} |
} |
858 |
|
/* +1 for trailing \0 */ |
859 |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
int pwlen = strlen(pw->pw_name) + 1; |
860 |
|
g_username = (char *) xmalloc(pwlen); |
861 |
|
STRNCPY(g_username, pw->pw_name, pwlen); |
862 |
} |
} |
863 |
|
|
864 |
#ifdef HAVE_ICONV |
#ifdef HAVE_ICONV |
932 |
} |
} |
933 |
#endif |
#endif |
934 |
|
|
935 |
if (lspci_enabled) |
if (g_lspci_enabled) |
936 |
lspci_init(); |
lspci_init(); |
937 |
|
|
938 |
rdpdr_init(); |
rdpdr_init(); |
950 |
|
|
951 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
952 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
953 |
if (!packet_encryption) |
if (!g_packet_encryption) |
954 |
g_encryption = False; |
g_encryption = False; |
955 |
|
|
956 |
|
|
973 |
rdesktop_reset_state(); |
rdesktop_reset_state(); |
974 |
|
|
975 |
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
STRNCPY(domain, g_redirect_domain, sizeof(domain)); |
976 |
|
xfree(g_username); |
977 |
|
g_username = (char *) xmalloc(strlen(g_redirect_username) + 1); |
978 |
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
STRNCPY(g_username, g_redirect_username, sizeof(g_username)); |
979 |
STRNCPY(password, g_redirect_password, sizeof(password)); |
STRNCPY(password, g_redirect_password, sizeof(password)); |
980 |
STRNCPY(server, g_redirect_server, sizeof(server)); |
STRNCPY(server, g_redirect_server, sizeof(server)); |
1019 |
} |
} |
1020 |
|
|
1021 |
#endif |
#endif |
1022 |
|
if (g_redirect_username) |
1023 |
|
xfree(g_redirect_username); |
1024 |
|
|
1025 |
|
xfree(g_username); |
1026 |
} |
} |
1027 |
|
|
1028 |
#ifdef EGD_SOCKET |
#ifdef EGD_SOCKET |
1147 |
|
|
1148 |
/* realloc; exit if out of memory */ |
/* realloc; exit if out of memory */ |
1149 |
void * |
void * |
1150 |
xrealloc(void *oldmem, int size) |
xrealloc(void *oldmem, size_t size) |
1151 |
{ |
{ |
1152 |
void *mem; |
void *mem; |
1153 |
|
|
1154 |
if (size < 1) |
if (size == 0) |
1155 |
size = 1; |
size = 1; |
1156 |
mem = realloc(oldmem, size); |
mem = realloc(oldmem, size); |
1157 |
if (mem == NULL) |
if (mem == NULL) |
1158 |
{ |
{ |
1159 |
error("xrealloc %d\n", size); |
error("xrealloc %ld\n", size); |
1160 |
exit(1); |
exit(1); |
1161 |
} |
} |
1162 |
return mem; |
return mem; |