2 * FreeRDP: A Remote Desktop Protocol Client
3 * RDP Server Redirection
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include "connection.h"
22 #include "redirection.h"
24 void rdp_print_redirection_flags(uint32 flags)
26 printf("redirectionFlags = {\n");
28 if (flags & LB_TARGET_NET_ADDRESS)
29 printf("\tLB_TARGET_NET_ADDRESS\n");
30 if (flags & LB_LOAD_BALANCE_INFO)
31 printf("\tLB_LOAD_BALANCE_INFO\n");
32 if (flags & LB_USERNAME)
33 printf("\tLB_USERNAME\n");
34 if (flags & LB_DOMAIN)
35 printf("\tLB_DOMAIN\n");
36 if (flags & LB_PASSWORD)
37 printf("\tLB_PASSWORD\n");
38 if (flags & LB_DONTSTOREUSERNAME)
39 printf("\tLB_DONTSTOREUSERNAME\n");
40 if (flags & LB_SMARTCARD_LOGON)
41 printf("\tLB_SMARTCARD_LOGON\n");
42 if (flags & LB_NOREDIRECT)
43 printf("\tLB_NOREDIRECT\n");
44 if (flags & LB_TARGET_FQDN)
45 printf("\tLB_TARGET_FQDN\n");
46 if (flags & LB_TARGET_NETBIOS_NAME)
47 printf("\tLB_TARGET_NETBIOS_NAME\n");
48 if (flags & LB_TARGET_NET_ADDRESSES)
49 printf("\tLB_TARGET_NET_ADDRESSES\n");
50 if (flags & LB_CLIENT_TSV_URL)
51 printf("\tLB_CLIENT_TSV_URL\n");
52 if (flags & LB_SERVER_TSV_CAPABLE)
53 printf("\tLB_SERVER_TSV_CAPABLE\n");
58 boolean rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s)
62 rdpRedirection* redirection = rdp->redirection;
64 stream_read_uint16(s, flags); /* flags (2 bytes) */
65 stream_read_uint16(s, length); /* length (2 bytes) */
66 stream_read_uint32(s, redirection->sessionID); /* sessionID (4 bytes) */
67 stream_read_uint32(s, redirection->flags); /* redirFlags (4 bytes) */
69 DEBUG_REDIR("flags: 0x%04X, length:%d, sessionID:0x%08X", flags, length, redirection->sessionID);
71 #ifdef WITH_DEBUG_REDIR
72 rdp_print_redirection_flags(redirection->flags);
75 if (redirection->flags & LB_TARGET_NET_ADDRESS)
77 freerdp_string_read_length32(s, &redirection->targetNetAddress, rdp->settings->uniconv);
78 DEBUG_REDIR("targetNetAddress: %s", redirection->targetNetAddress.ascii);
81 if (redirection->flags & LB_LOAD_BALANCE_INFO)
83 uint32 loadBalanceInfoLength;
84 stream_read_uint32(s, loadBalanceInfoLength);
85 freerdp_blob_alloc(&redirection->loadBalanceInfo, loadBalanceInfoLength);
86 stream_read(s, redirection->loadBalanceInfo.data, loadBalanceInfoLength);
87 #ifdef WITH_DEBUG_REDIR
88 DEBUG_REDIR("loadBalanceInfo:");
89 freerdp_hexdump(redirection->loadBalanceInfo.data, redirection->loadBalanceInfo.length);
93 if (redirection->flags & LB_USERNAME)
95 freerdp_string_read_length32(s, &redirection->username, rdp->settings->uniconv);
96 DEBUG_REDIR("username: %s", redirection->username.ascii);
99 if (redirection->flags & LB_DOMAIN)
101 freerdp_string_read_length32(s, &redirection->domain, rdp->settings->uniconv);
102 DEBUG_REDIR("domain: %s", redirection->domain.ascii);
105 if (redirection->flags & LB_PASSWORD)
107 uint32 passwordLength;
108 stream_read_uint32(s, passwordLength);
109 freerdp_blob_alloc(&redirection->password_cookie, passwordLength);
110 stream_read(s, redirection->password_cookie.data, passwordLength);
112 #ifdef WITH_DEBUG_REDIR
113 DEBUG_REDIR("password_cookie:");
114 freerdp_hexdump(redirection->password_cookie.data, redirection->password_cookie.length);
118 if (redirection->flags & LB_TARGET_FQDN)
120 freerdp_string_read_length32(s, &redirection->targetFQDN, rdp->settings->uniconv);
121 DEBUG_REDIR("targetFQDN: %s", redirection->targetFQDN.ascii);
124 if (redirection->flags & LB_TARGET_NETBIOS_NAME)
126 freerdp_string_read_length32(s, &redirection->targetNetBiosName, rdp->settings->uniconv);
127 DEBUG_REDIR("targetNetBiosName: %s", redirection->targetNetBiosName.ascii);
130 if (redirection->flags & LB_CLIENT_TSV_URL)
132 freerdp_string_read_length32(s, &redirection->tsvUrl, rdp->settings->uniconv);
133 DEBUG_REDIR("tsvUrl: %s", redirection->tsvUrl.ascii);
136 if (redirection->flags & LB_TARGET_NET_ADDRESSES)
140 uint32 targetNetAddressesLength;
142 stream_read_uint32(s, targetNetAddressesLength);
144 stream_read_uint32(s, redirection->targetNetAddressesCount);
145 count = redirection->targetNetAddressesCount;
147 redirection->targetNetAddresses = (rdpString*) xzalloc(count * sizeof(rdpString));
149 for (i = 0; i < (int) count; i++)
151 freerdp_string_read_length32(s, &redirection->targetNetAddresses[i], rdp->settings->uniconv);
152 DEBUG_REDIR("targetNetAddresses: %s", (&redirection->targetNetAddresses[i])->ascii);
156 stream_seek(s, 8); /* pad (8 bytes) */
158 if (redirection->flags & LB_NOREDIRECT)
161 return rdp_client_redirect(rdp);
164 boolean rdp_recv_redirection_packet(rdpRdp* rdp, STREAM* s)
166 rdp_recv_server_redirection_pdu(rdp, s);
170 boolean rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp, STREAM* s)
172 stream_seek_uint16(s); /* pad2Octets (2 bytes) */
173 rdp_recv_server_redirection_pdu(rdp, s);
174 stream_seek_uint8(s); /* pad2Octets (1 byte) */
178 rdpRedirection* redirection_new()
180 rdpRedirection* redirection;
182 redirection = (rdpRedirection*) xzalloc(sizeof(rdpRedirection));
184 if (redirection != NULL)
192 void redirection_free(rdpRedirection* redirection)
194 if (redirection != NULL)
196 //these four have already been freed in settings_free() and freerdp_string_free() checks for NULL
197 redirection->username.ascii = NULL;
198 redirection->domain.ascii = NULL;
199 redirection->targetNetAddress.ascii = NULL;
200 redirection->targetNetBiosName.ascii = NULL;
202 freerdp_string_free(&redirection->tsvUrl);
203 freerdp_string_free(&redirection->username);
204 freerdp_string_free(&redirection->domain);
205 freerdp_blob_free(&redirection->password_cookie);
206 freerdp_string_free(&redirection->targetFQDN);
207 freerdp_string_free(&redirection->targetNetBiosName);
208 freerdp_string_free(&redirection->targetNetAddress);
209 freerdp_blob_free(&redirection->loadBalanceInfo);
211 if (redirection->targetNetAddresses != NULL)
215 for (i = 0; i < (int) redirection->targetNetAddressesCount; i++)
216 freerdp_string_free(&redirection->targetNetAddresses[i]);
218 xfree(redirection->targetNetAddresses);