43 |
|
|
44 |
char g_title[64] = ""; |
char g_title[64] = ""; |
45 |
char g_username[64]; |
char g_username[64]; |
46 |
char hostname[16]; |
char g_hostname[16]; |
47 |
char keymapname[16]; |
char keymapname[16]; |
48 |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ |
49 |
|
|
50 |
int g_width = 800; /* width is special: If 0, the |
int g_width = 800; /* width is special: If 0, the |
51 |
geometry will be fetched from |
geometry will be fetched from |
53 |
absolute value specifies the |
absolute value specifies the |
54 |
percent of the whole screen. */ |
percent of the whole screen. */ |
55 |
int g_height = 600; |
int g_height = 600; |
56 |
int tcp_port_rdp = TCP_PORT_RDP; |
extern int g_tcp_port_rdp; |
57 |
int g_server_bpp = 8; |
int g_server_bpp = 8; |
58 |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
59 |
BOOL g_bitmap_compression = True; |
BOOL g_bitmap_compression = True; |
60 |
BOOL g_sendmotion = True; |
BOOL g_sendmotion = True; |
61 |
BOOL g_orders = True; |
BOOL g_bitmap_cache = True; |
62 |
BOOL g_encryption = True; |
BOOL g_encryption = True; |
63 |
BOOL packet_encryption = True; |
BOOL packet_encryption = True; |
64 |
BOOL g_desktop_save = True; |
BOOL g_desktop_save = True; |
148 |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
149 |
} |
} |
150 |
|
|
151 |
|
void |
152 |
|
print_disconnect_reason(uint16 reason) |
153 |
|
{ |
154 |
|
char *text; |
155 |
|
|
156 |
|
switch (reason) |
157 |
|
{ |
158 |
|
case exDiscReasonNoInfo: |
159 |
|
text = "No information available"; |
160 |
|
break; |
161 |
|
|
162 |
|
case exDiscReasonAPIInitiatedDisconnect: |
163 |
|
text = "Server initiated disconnect"; |
164 |
|
break; |
165 |
|
|
166 |
|
case exDiscReasonAPIInitiatedLogoff: |
167 |
|
text = "Server initiated logoff"; |
168 |
|
break; |
169 |
|
|
170 |
|
case exDiscReasonServerIdleTimeout: |
171 |
|
text = "Server idle timeout reached"; |
172 |
|
break; |
173 |
|
|
174 |
|
case exDiscReasonServerLogonTimeout: |
175 |
|
text = "Server logon timeout reached"; |
176 |
|
break; |
177 |
|
|
178 |
|
case exDiscReasonReplacedByOtherConnection: |
179 |
|
text = "The session was replaced"; |
180 |
|
break; |
181 |
|
|
182 |
|
case exDiscReasonOutOfMemory: |
183 |
|
text = "The server is out of memory"; |
184 |
|
break; |
185 |
|
|
186 |
|
case exDiscReasonServerDeniedConnection: |
187 |
|
text = "The server denied the connection"; |
188 |
|
break; |
189 |
|
|
190 |
|
case exDiscReasonServerDeniedConnectionFips: |
191 |
|
text = "The server denied the connection for security reason"; |
192 |
|
break; |
193 |
|
|
194 |
|
case exDiscReasonLicenseInternal: |
195 |
|
text = "Internal licensing error"; |
196 |
|
break; |
197 |
|
|
198 |
|
case exDiscReasonLicenseNoLicenseServer: |
199 |
|
text = "No license server available"; |
200 |
|
break; |
201 |
|
|
202 |
|
case exDiscReasonLicenseNoLicense: |
203 |
|
text = "No valid license available"; |
204 |
|
break; |
205 |
|
|
206 |
|
case exDiscReasonLicenseErrClientMsg: |
207 |
|
text = "Invalid licensing message"; |
208 |
|
break; |
209 |
|
|
210 |
|
case exDiscReasonLicenseHwidDoesntMatchLicense: |
211 |
|
text = "Hardware id doesn't match software license"; |
212 |
|
break; |
213 |
|
|
214 |
|
case exDiscReasonLicenseErrClientLicense: |
215 |
|
text = "Client license error"; |
216 |
|
break; |
217 |
|
|
218 |
|
case exDiscReasonLicenseCantFinishProtocol: |
219 |
|
text = "Network error during licensing protocol"; |
220 |
|
break; |
221 |
|
|
222 |
|
case exDiscReasonLicenseClientEndedProtocol: |
223 |
|
text = "Licensing protocol was not completed"; |
224 |
|
break; |
225 |
|
|
226 |
|
case exDiscReasonLicenseErrClientEncryption: |
227 |
|
text = "Incorrect client license enryption"; |
228 |
|
break; |
229 |
|
|
230 |
|
case exDiscReasonLicenseCantUpgradeLicense: |
231 |
|
text = "Can't upgrade license"; |
232 |
|
break; |
233 |
|
|
234 |
|
case exDiscReasonLicenseNoRemoteConnections: |
235 |
|
text = "The server is not licensed to accept remote connections"; |
236 |
|
break; |
237 |
|
|
238 |
|
default: |
239 |
|
if (reason > 0x1000 && reason < 0x7fff) |
240 |
|
{ |
241 |
|
text = "Internal protocol error"; |
242 |
|
} |
243 |
|
else |
244 |
|
{ |
245 |
|
text = "Unknown reason"; |
246 |
|
} |
247 |
|
} |
248 |
|
fprintf(stderr, "disconnect: %s.\n", text); |
249 |
|
} |
250 |
|
|
251 |
static BOOL |
static BOOL |
252 |
read_password(char *password, int size) |
read_password(char *password, int size) |
253 |
{ |
{ |
305 |
if (*server == '[' && p != NULL) |
if (*server == '[' && p != NULL) |
306 |
{ |
{ |
307 |
if (*(p + 1) == ':' && *(p + 2) != '\0') |
if (*(p + 1) == ':' && *(p + 2) != '\0') |
308 |
tcp_port_rdp = strtol(p + 2, NULL, 10); |
g_tcp_port_rdp = strtol(p + 2, NULL, 10); |
309 |
/* remove the port number and brackets from the address */ |
/* remove the port number and brackets from the address */ |
310 |
*p = '\0'; |
*p = '\0'; |
311 |
strncpy(server, server + 1, strlen(server)); |
strncpy(server, server + 1, strlen(server)); |
317 |
p = strchr(server, ':'); |
p = strchr(server, ':'); |
318 |
if (p != NULL) |
if (p != NULL) |
319 |
{ |
{ |
320 |
tcp_port_rdp = strtol(p + 1, NULL, 10); |
g_tcp_port_rdp = strtol(p + 1, NULL, 10); |
321 |
*p = 0; |
*p = 0; |
322 |
} |
} |
323 |
} |
} |
325 |
p = strchr(server, ':'); |
p = strchr(server, ':'); |
326 |
if (p != NULL) |
if (p != NULL) |
327 |
{ |
{ |
328 |
tcp_port_rdp = strtol(p + 1, NULL, 10); |
g_tcp_port_rdp = strtol(p + 1, NULL, 10); |
329 |
*p = 0; |
*p = 0; |
330 |
} |
} |
331 |
#endif /* IPv6 */ |
#endif /* IPv6 */ |
342 |
char password[64]; |
char password[64]; |
343 |
char shell[128]; |
char shell[128]; |
344 |
char directory[32]; |
char directory[32]; |
345 |
BOOL prompt_password, rdp_retval = False; |
BOOL prompt_password, deactivated; |
346 |
struct passwd *pw; |
struct passwd *pw; |
347 |
uint32 flags; |
uint32 flags, ext_disc_reason = 0; |
348 |
char *p; |
char *p; |
349 |
int c; |
int c; |
350 |
|
|
416 |
break; |
break; |
417 |
|
|
418 |
case 'n': |
case 'n': |
419 |
STRNCPY(hostname, optarg, sizeof(hostname)); |
STRNCPY(g_hostname, optarg, sizeof(g_hostname)); |
420 |
break; |
break; |
421 |
|
|
422 |
case 'k': |
case 'k': |
457 |
break; |
break; |
458 |
|
|
459 |
case 'b': |
case 'b': |
460 |
g_orders = False; |
g_bitmap_cache = False; |
461 |
break; |
break; |
462 |
|
|
463 |
case 'B': |
case 'B': |
569 |
#endif |
#endif |
570 |
|
|
571 |
if (strncmp("off", optarg, 3) == 0) |
if (strncmp("off", optarg, 3) == 0) |
572 |
|
#ifdef WITH_RDPSND |
573 |
g_rdpsnd = False; |
g_rdpsnd = False; |
574 |
|
#else |
575 |
|
warning("Not compiled with sound support"); |
576 |
|
#endif |
577 |
|
|
578 |
optarg = p; |
optarg = p; |
579 |
} |
} |
656 |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
657 |
} |
} |
658 |
|
|
659 |
if (hostname[0] == 0) |
if (g_hostname[0] == 0) |
660 |
{ |
{ |
661 |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
if (gethostname(fullhostname, sizeof(fullhostname)) == -1) |
662 |
{ |
{ |
668 |
if (p != NULL) |
if (p != NULL) |
669 |
*p = 0; |
*p = 0; |
670 |
|
|
671 |
STRNCPY(hostname, fullhostname, sizeof(hostname)); |
STRNCPY(g_hostname, fullhostname, sizeof(g_hostname)); |
672 |
} |
} |
673 |
|
|
674 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
708 |
|
|
709 |
if (ui_create_window()) |
if (ui_create_window()) |
710 |
{ |
{ |
711 |
rdp_retval = rdp_main_loop(); |
rdp_main_loop(&deactivated, &ext_disc_reason); |
712 |
ui_destroy_window(); |
ui_destroy_window(); |
713 |
} |
} |
714 |
|
|
716 |
rdp_disconnect(); |
rdp_disconnect(); |
717 |
ui_deinit(); |
ui_deinit(); |
718 |
|
|
719 |
if (True == rdp_retval) |
if (ext_disc_reason >= 2) |
720 |
|
print_disconnect_reason(ext_disc_reason); |
721 |
|
|
722 |
|
if (deactivated) |
723 |
|
{ |
724 |
|
/* clean disconnect */ |
725 |
return 0; |
return 0; |
726 |
|
} |
727 |
else |
else |
728 |
return 2; |
{ |
729 |
|
if (ext_disc_reason == exDiscReasonAPIInitiatedDisconnect |
730 |
|
|| ext_disc_reason == exDiscReasonAPIInitiatedLogoff) |
731 |
|
{ |
732 |
|
/* not so clean disconnect, but nothing to worry about */ |
733 |
|
return 0; |
734 |
|
} |
735 |
|
else |
736 |
|
{ |
737 |
|
/* return error */ |
738 |
|
return 2; |
739 |
|
} |
740 |
|
} |
741 |
|
|
742 |
#endif |
#endif |
743 |
|
|
1056 |
if (home == NULL) |
if (home == NULL) |
1057 |
return -1; |
return -1; |
1058 |
|
|
1059 |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence.")); |
1060 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1061 |
|
|
1062 |
fd = open(path, O_RDONLY); |
fd = open(path, O_RDONLY); |
1063 |
if (fd == -1) |
if (fd == -1) |
1083 |
if (home == NULL) |
if (home == NULL) |
1084 |
return; |
return; |
1085 |
|
|
1086 |
path = (char *) xmalloc(strlen(home) + strlen(hostname) + sizeof("/.rdesktop/licence.")); |
path = (char *) xmalloc(strlen(home) + strlen(g_hostname) + sizeof("/.rdesktop/licence.")); |
1087 |
|
|
1088 |
sprintf(path, "%s/.rdesktop", home); |
sprintf(path, "%s/.rdesktop", home); |
1089 |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
if ((mkdir(path, 0700) == -1) && errno != EEXIST) |
1094 |
|
|
1095 |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
/* write licence to licence.hostname.new, then atomically rename to licence.hostname */ |
1096 |
|
|
1097 |
sprintf(path, "%s/.rdesktop/licence.%s", home, hostname); |
sprintf(path, "%s/.rdesktop/licence.%s", home, g_hostname); |
1098 |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
tmppath = (char *) xmalloc(strlen(path) + sizeof(".new")); |
1099 |
strcpy(tmppath, path); |
strcpy(tmppath, path); |
1100 |
strcat(tmppath, ".new"); |
strcat(tmppath, ".new"); |