Fix changelog email address
[freerdp-ubuntu-pcb-backport.git] / libfreerdp-core / redirection.c
1 /**
2  * FreeRDP: A Remote Desktop Protocol Client
3  * RDP Server Redirection
4  *
5  * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include "connection.h"
21
22 #include "redirection.h"
23
24 void rdp_print_redirection_flags(uint32 flags)
25 {
26         printf("redirectionFlags = {\n");
27
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");
54
55         printf("}\n");
56 }
57
58 boolean rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s)
59 {
60         uint16 flags;
61         uint16 length;
62         rdpRedirection* redirection = rdp->redirection;
63
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) */
68
69         DEBUG_REDIR("flags: 0x%04X, length:%d, sessionID:0x%08X", flags, length, redirection->sessionID);
70
71 #ifdef WITH_DEBUG_REDIR
72         rdp_print_redirection_flags(redirection->flags);
73 #endif
74
75         if (redirection->flags & LB_TARGET_NET_ADDRESS)
76         {
77                 freerdp_string_read_length32(s, &redirection->targetNetAddress, rdp->settings->uniconv);
78                 DEBUG_REDIR("targetNetAddress: %s", redirection->targetNetAddress.ascii);
79         }
80
81         if (redirection->flags & LB_LOAD_BALANCE_INFO)
82         {
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);
90 #endif
91         }
92
93         if (redirection->flags & LB_USERNAME)
94         {
95                 freerdp_string_read_length32(s, &redirection->username, rdp->settings->uniconv);
96                 DEBUG_REDIR("username: %s", redirection->username.ascii);
97         }
98
99         if (redirection->flags & LB_DOMAIN)
100         {
101                 freerdp_string_read_length32(s, &redirection->domain, rdp->settings->uniconv);
102                 DEBUG_REDIR("domain: %s", redirection->domain.ascii);
103         }
104
105         if (redirection->flags & LB_PASSWORD)
106         {
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);
111
112 #ifdef WITH_DEBUG_REDIR
113                 DEBUG_REDIR("password_cookie:");
114                 freerdp_hexdump(redirection->password_cookie.data, redirection->password_cookie.length);
115 #endif
116         }
117
118         if (redirection->flags & LB_TARGET_FQDN)
119         {
120                 freerdp_string_read_length32(s, &redirection->targetFQDN, rdp->settings->uniconv);
121                 DEBUG_REDIR("targetFQDN: %s", redirection->targetFQDN.ascii);
122         }
123
124         if (redirection->flags & LB_TARGET_NETBIOS_NAME)
125         {
126                 freerdp_string_read_length32(s, &redirection->targetNetBiosName, rdp->settings->uniconv);
127                 DEBUG_REDIR("targetNetBiosName: %s", redirection->targetNetBiosName.ascii);
128         }
129
130         if (redirection->flags & LB_CLIENT_TSV_URL)
131         {
132                 freerdp_string_read_length32(s, &redirection->tsvUrl, rdp->settings->uniconv);
133                 DEBUG_REDIR("tsvUrl: %s", redirection->tsvUrl.ascii);
134         }
135
136         if (redirection->flags & LB_TARGET_NET_ADDRESSES)
137         {
138                 int i;
139                 uint32 count;
140                 uint32 targetNetAddressesLength;
141
142                 stream_read_uint32(s, targetNetAddressesLength);
143
144                 stream_read_uint32(s, redirection->targetNetAddressesCount);
145                 count = redirection->targetNetAddressesCount;
146
147                 redirection->targetNetAddresses = (rdpString*) xzalloc(count * sizeof(rdpString));
148
149                 for (i = 0; i < (int) count; i++)
150                 {
151                         freerdp_string_read_length32(s, &redirection->targetNetAddresses[i], rdp->settings->uniconv);
152                         DEBUG_REDIR("targetNetAddresses: %s", (&redirection->targetNetAddresses[i])->ascii);
153                 }
154         }
155
156         stream_seek(s, 8); /* pad (8 bytes) */
157
158         if (redirection->flags & LB_NOREDIRECT)
159                 return true;
160         else
161                 return rdp_client_redirect(rdp);
162 }
163
164 boolean rdp_recv_redirection_packet(rdpRdp* rdp, STREAM* s)
165 {
166         rdp_recv_server_redirection_pdu(rdp, s);
167         return true;
168 }
169
170 boolean rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp, STREAM* s)
171 {
172         stream_seek_uint16(s); /* pad2Octets (2 bytes) */
173         rdp_recv_server_redirection_pdu(rdp, s);
174         stream_seek_uint8(s); /* pad2Octets (1 byte) */
175         return true;
176 }
177
178 rdpRedirection* redirection_new()
179 {
180         rdpRedirection* redirection;
181
182         redirection = (rdpRedirection*) xzalloc(sizeof(rdpRedirection));
183
184         if (redirection != NULL)
185         {
186
187         }
188
189         return redirection;
190 }
191
192 void redirection_free(rdpRedirection* redirection)
193 {
194         if (redirection != NULL)
195         {
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;
201
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);
210
211                 if (redirection->targetNetAddresses != NULL)
212                 {
213                         int i;
214
215                         for (i = 0; i < (int) redirection->targetNetAddressesCount; i++)
216                                 freerdp_string_free(&redirection->targetNetAddresses[i]);
217
218                         xfree(redirection->targetNetAddresses);
219                 }
220
221                 xfree(redirection);
222         }
223 }
224
225