1
1
/* -*- c-basic-offset: 8 -*-
2
2
rdesktop: A Remote Desktop Protocol client.
3
3
Entrypoint and utility functions
4
Copyright (C) Matthew Chapman 1999-2008
4
Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
5
Copyright 2002-2011 Peter Astrand <astrand@cendio.se> for Cendio AB
6
Copyright 2010-2011 Henrik Andersson <hean01@cendio.se> for Cendio AB
6
This program is free software; you can redistribute it and/or modify
8
This program is free software: you can redistribute it and/or modify
7
9
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
10
the Free Software Foundation, either version 3 of the License, or
9
11
(at your option) any later version.
11
13
This program is distributed in the hope that it will be useful,
14
16
GNU General Public License for more details.
16
18
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
64
66
char g_title[64] = "";
66
68
char g_hostname[16];
67
69
char g_keymapname[PATH_MAX] = "";
68
70
unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */
69
71
int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */
70
72
int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */
71
73
int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */
73
int g_width = 800; /* width is special: If 0, the
74
geometry will be fetched from
75
_NET_WORKAREA. If negative,
76
absolute value specifies the
77
percent of the whole screen. */
74
int g_sizeopt = 0; /* If non-zero, a special size has been
75
requested. If 1, the geometry will be fetched
76
from _NET_WORKAREA. If negative, absolute value
77
specifies the percent of the whole screen. */
78
79
int g_height = 600;
118
120
char g_redirect_server[64];
119
121
char g_redirect_domain[16];
120
122
char g_redirect_password[64];
121
char g_redirect_username[64];
123
char *g_redirect_username;
122
124
char g_redirect_cookie[128];
123
125
uint32 g_redirect_flags = 0;
127
uint32 g_reconnect_logonid = 0;
128
char g_reconnect_random[16];
129
RD_BOOL g_has_reconnect_random = False;
130
uint8 g_client_random[SEC_RANDOM_SIZE];
131
RD_BOOL g_pending_resize = False;
125
133
#ifdef WITH_RDPSND
126
134
RD_BOOL g_rdpsnd = False;
150
158
usage(char *program)
152
160
fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
153
fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2008 Matthew Chapman.\n");
162
"Version " PACKAGE_VERSION ". Copyright (C) 1999-2011 Matthew Chapman et al.\n");
155
fprintf(stderr, "Modified for VirtualBox by " VBOX_VENDOR "\n");
164
fprintf(stderr, "Modified for VirtualBox by " VBOX_VENDOR "\n");
157
166
fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
243
252
fprintf(stderr, " -5: use RDP version 5 (default)\n");
247
print_disconnect_reason(uint16 reason)
256
handle_disconnect_reason(RD_BOOL deactivated, uint16 reason)
253
263
case exDiscReasonNoInfo:
254
264
text = "No information available";
268
retval = EXRD_UNKNOWN;
257
271
case exDiscReasonAPIInitiatedDisconnect:
272
case exDiscReasonWindows7Disconnect:
258
273
text = "Server initiated disconnect";
274
retval = EXRD_API_DISCONNECT;
261
277
case exDiscReasonAPIInitiatedLogoff:
262
278
text = "Server initiated logoff";
279
retval = EXRD_API_LOGOFF;
265
282
case exDiscReasonServerIdleTimeout:
266
283
text = "Server idle timeout reached";
284
retval = EXRD_IDLE_TIMEOUT;
269
287
case exDiscReasonServerLogonTimeout:
270
288
text = "Server logon timeout reached";
289
retval = EXRD_LOGON_TIMEOUT;
273
292
case exDiscReasonReplacedByOtherConnection:
274
293
text = "The session was replaced";
294
retval = EXRD_REPLACED;
277
297
case exDiscReasonOutOfMemory:
278
298
text = "The server is out of memory";
299
retval = EXRD_OUT_OF_MEM;
281
302
case exDiscReasonServerDeniedConnection:
282
303
text = "The server denied the connection";
304
retval = EXRD_DENIED;
285
307
case exDiscReasonServerDeniedConnectionFips:
286
308
text = "The server denied the connection for security reason";
309
retval = EXRD_DENIED_FIPS;
289
312
case exDiscReasonLicenseInternal:
290
313
text = "Internal licensing error";
314
retval = EXRD_LIC_INTERNAL;
293
317
case exDiscReasonLicenseNoLicenseServer:
294
318
text = "No license server available";
319
retval = EXRD_LIC_NOSERVER;
297
322
case exDiscReasonLicenseNoLicense:
298
323
text = "No valid license available";
324
retval = EXRD_LIC_NOLICENSE;
301
327
case exDiscReasonLicenseErrClientMsg:
302
328
text = "Invalid licensing message";
329
retval = EXRD_LIC_MSG;
305
332
case exDiscReasonLicenseHwidDoesntMatchLicense:
306
333
text = "Hardware id doesn't match software license";
334
retval = EXRD_LIC_HWID;
309
337
case exDiscReasonLicenseErrClientLicense:
310
338
text = "Client license error";
339
retval = EXRD_LIC_CLIENT;
313
342
case exDiscReasonLicenseCantFinishProtocol:
314
343
text = "Network error during licensing protocol";
344
retval = EXRD_LIC_NET;
317
347
case exDiscReasonLicenseClientEndedProtocol:
318
348
text = "Licensing protocol was not completed";
349
retval = EXRD_LIC_PROTO;
321
352
case exDiscReasonLicenseErrClientEncryption:
322
353
text = "Incorrect client license enryption";
354
retval = EXRD_LIC_ENC;
325
357
case exDiscReasonLicenseCantUpgradeLicense:
326
358
text = "Can't upgrade license";
359
retval = EXRD_LIC_UPGRADE;
329
362
case exDiscReasonLicenseNoRemoteConnections:
330
363
text = "The server is not licensed to accept remote connections";
364
retval = EXRD_LIC_NOREMOTE;
520
/* Ignore SIGPIPE, since we are using popen() */
521
struct sigaction act;
522
memset(&act, 0, sizeof(act));
523
act.sa_handler = SIG_IGN;
524
sigemptyset(&act.sa_mask);
526
sigaction(SIGPIPE, &act, NULL);
477
528
flags = RDP_LOGON_NORMAL;
478
529
prompt_password = False;
479
530
domain[0] = password[0] = shell[0] = directory[0] = 0;
890
943
if ((pw == NULL) || (pw->pw_name == NULL))
892
945
error("could not determine username, use -u\n");
896
STRNCPY(g_username, pw->pw_name, sizeof(g_username));
948
/* +1 for trailing \0 */
949
int pwlen = strlen(pw->pw_name) + 1;
950
g_username = (char *) xmalloc(pwlen);
951
STRNCPY(g_username, pw->pw_name, pwlen);
899
954
#ifdef HAVE_ICONV
980
while (run_count < 2 && continue_connect) /* add support for Session Directory; only reconnect once */
1035
rdesktop_reset_state();
984
if (!rdp_connect(server, flags, domain, password, shell, directory))
1039
STRNCPY(domain, g_redirect_domain, sizeof(domain));
1041
g_username = (char *) xmalloc(strlen(g_redirect_username) + 1);
1042
STRNCPY(g_username, g_redirect_username, sizeof(g_username));
1043
STRNCPY(password, g_redirect_password, sizeof(password));
1044
STRNCPY(server, g_redirect_server, sizeof(server));
1045
flags |= RDP_LOGON_AUTO;
987
else if (!rdp_reconnect
988
(server, flags, domain, password, shell, directory, g_redirect_cookie))
1048
ui_init_connection();
1049
if (!rdp_connect(server, flags, domain, password, shell, directory, g_redirect))
991
1052
/* By setting encryption to False here, we have an encrypted login
992
1053
packet but unencrypted transfer of other packets */
997
1058
DEBUG(("Connection successful.\n"));
998
1059
memset(password, 0, sizeof(password));
1001
1062
if (!ui_create_window())
1002
continue_connect = False;
1004
if (continue_connect)
1005
rdp_main_loop(&deactivated, &ext_disc_reason);
1066
rdp_main_loop(&deactivated, &ext_disc_reason);
1007
1068
DEBUG(("Disconnecting...\n"));
1008
1069
rdp_disconnect();
1010
if ((g_redirect == True) && (run_count == 0)) /* Support for Session Directory */
1012
/* reset state of major globals */
1013
rdesktop_reset_state();
1015
STRNCPY(domain, g_redirect_domain, sizeof(domain));
1016
STRNCPY(g_username, g_redirect_username, sizeof(g_username));
1017
STRNCPY(password, g_redirect_password, sizeof(password));
1018
STRNCPY(server, g_redirect_server, sizeof(server));
1019
flags |= RDP_LOGON_AUTO;
1025
continue_connect = False;
1026
ui_destroy_window();
1075
ui_destroy_window();
1076
if (g_pending_resize)
1078
/* If we have a pending resize, reconnect using the new size, rather than exit */
1079
g_pending_resize = False;
1033
1085
cache_save_state();
1036
1088
#ifdef WITH_RDPUSB
1041
if (ext_disc_reason >= 2)
1042
print_disconnect_reason(ext_disc_reason);
1046
/* clean disconnect */
1051
if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect
1052
|| ext_disc_reason == exDiscReasonAPIInitiatedLogoff)
1054
/* not so clean disconnect, but nothing to worry about */
1094
return EXRD_WINDOW_CLOSED;
1096
return handle_disconnect_reason(deactivated, ext_disc_reason);
1099
if (g_redirect_username)
1100
xfree(g_redirect_username);
1068
1105
#ifdef EGD_SOCKET