22 #include <freerdp/config.h>
26 #include <winpr/crt.h>
27 #include <winpr/string.h>
28 #include <freerdp/log.h>
29 #include <freerdp/crypto/certificate.h>
30 #include <freerdp/redirection.h>
31 #include <freerdp/utils/string.h>
33 #include "../crypto/certificate.h"
34 #include "redirection.h"
37 #define TAG FREERDP_TAG("core.redirection")
39 struct rdp_redirection
48 UINT32 PasswordLength;
50 BYTE* LoadBalanceInfo;
51 UINT32 LoadBalanceInfoLength;
52 char* TargetNetBiosName;
53 char* TargetNetAddress;
54 UINT32 TargetNetAddressesCount;
55 char** TargetNetAddresses;
56 UINT32 RedirectionGuidLength;
57 BYTE* RedirectionGuid;
59 rdpCertificate* TargetCertificate;
62 static void redirection_free_array(
char*** what, UINT32* count)
69 for (UINT32 x = 0; x < *count; x++)
78 static void redirection_free_string(
char** str)
85 static void redirection_free_data(BYTE** str, UINT32* length)
94 static BOOL redirection_copy_string(
char** dst,
const char* str)
96 redirection_free_string(dst);
104 static BOOL redirection_copy_data(BYTE** dst, UINT32* plen,
const BYTE* str,
size_t len)
106 redirection_free_data(dst, plen);
108 if (!str || (len == 0))
110 if (len > UINT32_MAX)
116 memcpy(*dst, str, len);
121 static BOOL redirection_copy_array(
char*** dst, UINT32* plen,
const char** str,
size_t len)
123 redirection_free_array(dst, plen);
125 if (len > UINT32_MAX)
127 if (!str || (len == 0))
130 *dst = calloc(len,
sizeof(
char*));
135 for (
size_t x = 0; x < len; x++)
138 (*dst)[x] = _strdup(str[x]);
142 redirection_free_array(dst, plen);
150 static BOOL rdp_redirection_get_data(
wStream* s, UINT32* pLength,
const BYTE** pData)
152 WINPR_ASSERT(pLength);
155 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
158 Stream_Read_UINT32(s, *pLength);
160 if (!Stream_CheckAndLogRequiredLength(TAG, s, *pLength))
163 *pData = Stream_ConstPointer(s);
164 Stream_Seek(s, *pLength);
168 static BOOL rdp_redirection_read_unicode_string(
wStream* s,
char** str,
size_t maxLength)
171 const BYTE* data = NULL;
173 if (!rdp_redirection_get_data(s, &length, &data))
176 const WCHAR* wstr = (
const WCHAR*)data;
178 if ((length % 2) || length < 2 || length > maxLength)
180 WLog_ERR(TAG,
"failure: invalid unicode string length: %" PRIu32
"", length);
184 if (wstr[length / 2 - 1])
186 WLog_ERR(TAG,
"failure: unterminated unicode string");
190 redirection_free_string(str);
191 *str = ConvertWCharNToUtf8Alloc(wstr, length /
sizeof(WCHAR), NULL);
194 WLog_ERR(TAG,
"failure: string conversion failed");
201 static BOOL rdp_redirection_write_data(
wStream* s,
size_t length,
const void* data)
203 WINPR_ASSERT(data || (length == 0));
204 WINPR_ASSERT(length <= UINT32_MAX);
206 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 4))
209 Stream_Write_UINT32(s, (UINT32)length);
211 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, length))
214 Stream_Write(s, data, length);
218 static BOOL rdp_redirection_write_base64_wchar(UINT32 flag,
wStream* s,
size_t length,
223 char* base64 = crypto_base64_encode(data, length);
227 size_t wbase64len = 0;
228 WCHAR* wbase64 = ConvertUtf8ToWCharAlloc(base64, &wbase64len);
233 rc = rdp_redirection_write_data(s, wbase64len *
sizeof(WCHAR), wbase64);
238 static BOOL rdp_redirection_read_base64_wchar(UINT32 flag,
wStream* s, UINT32* pLength,
242 char buffer[64] = { 0 };
243 const BYTE* ptr = NULL;
245 if (!rdp_redirection_get_data(s, pLength, &ptr))
247 const WCHAR* wchar = (
const WCHAR*)ptr;
250 char* utf8 = ConvertWCharNToUtf8Alloc(wchar, *pLength /
sizeof(WCHAR), &utf8_len);
254 redirection_free_data(pData, NULL);
256 utf8_len = strnlen(utf8, utf8_len);
259 *pData = calloc(utf8_len,
sizeof(BYTE));
263 size_t rlen = utf8_len;
265 char* saveptr = NULL;
266 char* tok = strtok_s(utf8,
"\r\n", &saveptr);
269 const size_t len = strnlen(tok, rlen);
274 crypto_base64_decode(tok, len, &bptr, &bplen);
277 memcpy(&(*pData)[wpos], bptr, bplen);
281 tok = strtok_s(NULL,
"\r\n", &saveptr);
283 if (wpos > UINT32_MAX)
286 *pLength = (UINT32)wpos;
288 WLog_DBG(TAG,
"%s:", rdp_redirection_flags_to_string(flag, buffer,
sizeof(buffer)));
293 WLog_ERR(TAG,
"failed to read base64 data");
298 static BOOL rdp_target_cert_get_element(
wStream* s, UINT32* pType, UINT32* pEncoding,
299 const BYTE** ptr,
size_t* pLength)
302 WINPR_ASSERT(pEncoding);
304 WINPR_ASSERT(pLength);
306 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
311 UINT32 elementSize = 0;
313 Stream_Read_UINT32(s, type);
314 Stream_Read_UINT32(s, encoding);
315 Stream_Read_UINT32(s, elementSize);
317 if (!Stream_CheckAndLogRequiredLength(TAG, s, elementSize))
320 *ptr = Stream_ConstPointer(s);
321 *pLength = elementSize;
322 Stream_Seek(s, elementSize);
325 *pEncoding = encoding;
329 static BOOL rdp_target_cert_write_element(
wStream* s, UINT32 Type, UINT32 Encoding,
330 const BYTE* data,
size_t length)
332 WINPR_ASSERT(data || (length == 0));
333 WINPR_ASSERT(length <= UINT32_MAX);
335 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, 12))
338 Stream_Write_UINT32(s, Type);
339 Stream_Write_UINT32(s, Encoding);
340 Stream_Write_UINT32(s, (UINT32)length);
342 if (!Stream_CheckAndLogRequiredCapacity(TAG, s, length))
345 Stream_Write(s, data, length);
349 BOOL rdp_redirection_read_target_cert(rdpCertificate** ptargetCertificate,
const BYTE* data,
352 WINPR_ASSERT(ptargetCertificate);
355 wStream* s = Stream_StaticConstInit(&sbuffer, data, length);
357 freerdp_certificate_free(*ptargetCertificate);
358 *ptargetCertificate = NULL;
361 const BYTE* ptr = NULL;
362 while (Stream_GetRemainingLength(s) > 0)
366 if (!rdp_target_cert_get_element(s, &type, &encoding, &ptr, &plength))
371 case CERT_cert_file_element:
372 if (encoding == ENCODING_TYPE_ASN1_DER)
374 if (*ptargetCertificate)
375 WLog_WARN(TAG,
"Duplicate TargetCertificate in data detected!");
378 *ptargetCertificate = freerdp_certificate_new_from_der(ptr, plength);
379 if (!*ptargetCertificate)
380 WLog_ERR(TAG,
"TargetCertificate parsing DER data failed");
386 "TargetCertificate data in unknown encoding %" PRIu32
" detected!");
391 "Unknown TargetCertificate field type %" PRIu32
", encoding %" PRIu32
392 " of length %" PRIu32,
393 type, encoding, plength);
398 return *ptargetCertificate != NULL;
401 static BOOL rdp_redirection_write_target_cert(
wStream* s,
const rdpRedirection* redirection)
404 WINPR_ASSERT(redirection);
406 const rdpCertificate* cert = redirection->TargetCertificate;
412 BYTE* der = freerdp_certificate_get_der(cert, &derlen);
413 if (!rdp_target_cert_write_element(s, CERT_cert_file_element, ENCODING_TYPE_ASN1_DER, der,
424 static BOOL rdp_redireciton_write_target_cert_stream(
wStream* s,
const rdpRedirection* redirection)
427 wStream* serialized = Stream_New(NULL, 2048);
431 if (!rdp_redirection_write_target_cert(serialized, redirection))
434 rc = rdp_redirection_write_base64_wchar(
435 LB_TARGET_CERTIFICATE, s, Stream_GetPosition(serialized), Stream_Buffer(serialized));
438 Stream_Free(serialized, TRUE);
442 static BOOL rdp_redirection_read_target_cert_stream(
wStream* s, rdpRedirection* redirection)
447 WINPR_ASSERT(redirection);
450 if (rdp_redirection_read_base64_wchar(LB_TARGET_CERTIFICATE, s, &length, &ptr))
451 rc = rdp_redirection_read_target_cert(&redirection->TargetCertificate, ptr, length);
456 int rdp_redirection_apply_settings(rdpRdp* rdp)
458 rdpSettings* settings = NULL;
459 rdpRedirection* redirection = NULL;
461 if (!rdp_reset_runtime_settings(rdp))
464 settings = rdp->settings;
465 WINPR_ASSERT(settings);
467 redirection = rdp->redirection;
468 WINPR_ASSERT(redirection);
470 settings->RedirectionFlags = redirection->flags;
471 settings->RedirectedSessionId = redirection->sessionID;
473 if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS)
476 redirection->TargetNetAddress))
480 if (settings->RedirectionFlags & LB_USERNAME)
483 redirection->Username))
487 if (settings->RedirectionFlags & LB_DOMAIN)
493 if (settings->RedirectionFlags & LB_PASSWORD)
497 redirection->Password, redirection->PasswordLength))
501 if (settings->RedirectionFlags & LB_DONTSTOREUSERNAME)
506 if (settings->RedirectionFlags & LB_SMARTCARD_LOGON)
511 if (settings->RedirectionFlags & LB_NOREDIRECT)
516 if (settings->RedirectionFlags & LB_TARGET_FQDN)
519 redirection->TargetFQDN))
523 if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME)
526 redirection->TargetNetBiosName))
530 if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESSES)
532 if (!freerdp_target_net_addresses_copy(settings, redirection->TargetNetAddresses,
533 redirection->TargetNetAddressesCount))
537 if (settings->RedirectionFlags & LB_CLIENT_TSV_URL)
541 redirection->TsvUrl, redirection->TsvUrlLength))
552 ConvertWCharNToUtf8Alloc((
const WCHAR*)redirection->TsvUrl,
553 redirection->TsvUrlLength /
sizeof(WCHAR), &tsvlen);
556 else if (tsvlen != lblen)
558 else if (memcmp(tsv, lb, lblen) != 0)
564 "[redirection] Expected TsvUrl '%s' [%" PRIuz
"], but got '%s' [%" PRIuz
566 lb, lblen, tsv, tsvlen);
575 if (settings->RedirectionFlags & LB_SERVER_TSV_CAPABLE)
580 if (settings->RedirectionFlags & LB_LOAD_BALANCE_INFO)
584 redirection->LoadBalanceInfo,
585 redirection->LoadBalanceInfoLength))
598 if (settings->RedirectionFlags & LB_PASSWORD_IS_PK_ENCRYPTED)
603 if (settings->RedirectionFlags & LB_REDIRECTION_GUID)
606 redirection->RedirectionGuid,
607 redirection->RedirectionGuidLength))
611 if (settings->RedirectionFlags & LB_TARGET_CERTIFICATE)
613 rdpCertificate* cert = freerdp_certificate_clone(redirection->TargetCertificate);
619 char* pem = freerdp_certificate_get_pem(cert, &length);
620 if (pem && (length <= UINT32_MAX))
636 static BOOL rdp_redirection_read_data(UINT32 flag,
wStream* s, UINT32* pLength, BYTE** pData)
638 char buffer[64] = { 0 };
639 const BYTE* ptr = NULL;
641 if (!rdp_redirection_get_data(s, pLength, &ptr))
644 redirection_free_data(pData, NULL);
645 *pData = (BYTE*)malloc(*pLength);
649 memcpy(*pData, ptr, *pLength);
651 WLog_DBG(TAG,
"%s:", rdp_redirection_flags_to_string(flag, buffer,
sizeof(buffer)));
656 static state_run_t rdp_recv_server_redirection_pdu(rdpRdp* rdp,
wStream* s)
658 char buffer[256] = { 0 };
661 rdpRedirection* redirection = rdp->redirection;
663 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
664 return STATE_RUN_FAILED;
666 Stream_Read_UINT16(s, flags);
667 if (flags != SEC_REDIRECTION_PKT)
669 char buffer1[1024] = { 0 };
670 char buffer2[1024] = { 0 };
671 WLog_ERR(TAG,
"received invalid flags=%s, expected %s",
672 rdp_security_flag_string(flags, buffer1,
sizeof(buffer1)),
673 rdp_security_flag_string(SEC_REDIRECTION_PKT, buffer2,
sizeof(buffer2)));
674 return STATE_RUN_FAILED;
676 Stream_Read_UINT16(s, length);
677 Stream_Read_UINT32(s, redirection->sessionID);
678 Stream_Read_UINT32(s, redirection->flags);
680 "flags: 0x%04" PRIX16
", length: %" PRIu16
", sessionID: 0x%08" PRIX32
681 ", redirFlags: %s [0x%08" PRIX32
"]",
682 flags, length, redirection->sessionID,
683 rdp_redirection_flags_to_string(redirection->flags, buffer,
sizeof(buffer)),
698 if (redirection->flags & LB_TARGET_NET_ADDRESS)
700 if (!rdp_redirection_read_unicode_string(s, &(redirection->TargetNetAddress), 80))
701 return STATE_RUN_FAILED;
704 if (redirection->flags & LB_LOAD_BALANCE_INFO)
712 if (!rdp_redirection_read_data(LB_LOAD_BALANCE_INFO, s, &redirection->LoadBalanceInfoLength,
713 &redirection->LoadBalanceInfo))
714 return STATE_RUN_FAILED;
717 if (redirection->flags & LB_USERNAME)
719 if (!rdp_redirection_read_unicode_string(s, &(redirection->Username), 512))
720 return STATE_RUN_FAILED;
722 WLog_DBG(TAG,
"Username: %s", redirection->Username);
725 if (redirection->flags & LB_DOMAIN)
727 if (!rdp_redirection_read_unicode_string(s, &(redirection->Domain), 52))
728 return STATE_RUN_FAILED;
730 WLog_DBG(TAG,
"Domain: %s", redirection->Domain);
733 if (redirection->flags & LB_PASSWORD)
756 if (!rdp_redirection_read_data(LB_PASSWORD, s, &redirection->PasswordLength,
757 &redirection->Password))
758 return STATE_RUN_FAILED;
764 if ((redirection->flags & LB_PASSWORD_IS_PK_ENCRYPTED) == 0)
766 const size_t charLen = redirection->PasswordLength /
sizeof(WCHAR);
767 if (redirection->PasswordLength > LB_PASSWORD_MAX_LENGTH)
769 WLog_ERR(TAG,
"LB_PASSWORD: %" PRIuz
" exceeds limit of %d", charLen,
770 LB_PASSWORD_MAX_LENGTH);
771 return STATE_RUN_FAILED;
775 if (_wcsnlen((
const WCHAR*)redirection->Password, charLen) == charLen)
777 WLog_ERR(TAG,
"LB_PASSWORD: missing '\0' termination");
778 return STATE_RUN_FAILED;
783 if (redirection->flags & LB_TARGET_FQDN)
785 if (!rdp_redirection_read_unicode_string(s, &(redirection->TargetFQDN), 512))
786 return STATE_RUN_FAILED;
788 WLog_DBG(TAG,
"TargetFQDN: %s", redirection->TargetFQDN);
791 if (redirection->flags & LB_TARGET_NETBIOS_NAME)
793 if (!rdp_redirection_read_unicode_string(s, &(redirection->TargetNetBiosName), 32))
794 return STATE_RUN_FAILED;
796 WLog_DBG(TAG,
"TargetNetBiosName: %s", redirection->TargetNetBiosName);
799 if (redirection->flags & LB_CLIENT_TSV_URL)
801 if (!rdp_redirection_read_data(LB_CLIENT_TSV_URL, s, &redirection->TsvUrlLength,
802 &redirection->TsvUrl))
803 return STATE_RUN_FAILED;
806 if (redirection->flags & LB_REDIRECTION_GUID)
808 if (!rdp_redirection_read_data(LB_REDIRECTION_GUID, s, &redirection->RedirectionGuidLength,
809 &redirection->RedirectionGuid))
810 return STATE_RUN_FAILED;
813 if (redirection->flags & LB_TARGET_CERTIFICATE)
815 if (!rdp_redirection_read_target_cert_stream(s, redirection))
816 return STATE_RUN_FAILED;
819 if (redirection->flags & LB_TARGET_NET_ADDRESSES)
821 UINT32 targetNetAddressesLength = 0;
822 UINT32 TargetNetAddressesCount = 0;
824 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
825 return STATE_RUN_FAILED;
827 Stream_Read_UINT32(s, targetNetAddressesLength);
828 Stream_Read_UINT32(s, TargetNetAddressesCount);
833 const size_t size = TargetNetAddressesCount *
sizeof(WCHAR);
834 if ((size > Stream_GetRemainingLength(s)) || (size > targetNetAddressesLength))
837 "Invalid RDP_SERVER_REDIRECTION_PACKET::TargetNetAddressLength %" PRIuz
838 ", sanity limit is %" PRIuz,
839 TargetNetAddressesCount *
sizeof(WCHAR), Stream_GetRemainingLength(s));
840 return STATE_RUN_FAILED;
843 redirection_free_array(&redirection->TargetNetAddresses,
844 &redirection->TargetNetAddressesCount);
845 if (TargetNetAddressesCount > 0)
847 redirection->TargetNetAddresses =
848 (
char**)calloc(TargetNetAddressesCount,
sizeof(
char*));
850 if (!redirection->TargetNetAddresses)
852 WLog_ERR(TAG,
"TargetNetAddresses %" PRIu32
" failed to allocate",
853 TargetNetAddressesCount);
854 return STATE_RUN_FAILED;
857 redirection->TargetNetAddressesCount = TargetNetAddressesCount;
859 WLog_DBG(TAG,
"TargetNetAddressesCount: %" PRIu32
"", TargetNetAddressesCount);
861 for (UINT32 i = 0; i < TargetNetAddressesCount; i++)
863 if (!rdp_redirection_read_unicode_string(s, &(redirection->TargetNetAddresses[i]), 80))
864 return STATE_RUN_FAILED;
866 WLog_DBG(TAG,
"TargetNetAddresses[%" PRIu32
"]: %s", i,
867 redirection->TargetNetAddresses[i]);
871 if (Stream_GetRemainingLength(s) >= 8)
877 if (redirection->flags & LB_NOREDIRECT)
878 return STATE_RUN_SUCCESS;
880 return STATE_RUN_REDIRECT;
883 state_run_t rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp,
wStream* s)
885 state_run_t status = STATE_RUN_SUCCESS;
887 if (!Stream_SafeSeek(s, 2))
888 return STATE_RUN_FAILED;
890 status = rdp_recv_server_redirection_pdu(rdp, s);
892 if (state_run_failed(status))
895 if (Stream_GetRemainingLength(s) >= 1)
904 rdpRedirection* redirection_new(
void)
906 rdpRedirection* redirection = (rdpRedirection*)calloc(1,
sizeof(rdpRedirection));
915 void redirection_free(rdpRedirection* redirection)
919 redirection_free_data(&redirection->TsvUrl, &redirection->TsvUrlLength);
920 redirection_free_string(&redirection->Username);
921 redirection_free_string(&redirection->Domain);
922 redirection_free_string(&redirection->TargetFQDN);
923 redirection_free_string(&redirection->TargetNetBiosName);
924 redirection_free_string(&redirection->TargetNetAddress);
925 redirection_free_data(&redirection->LoadBalanceInfo, &redirection->LoadBalanceInfoLength);
926 redirection_free_data(&redirection->Password, &redirection->PasswordLength);
927 redirection_free_data(&redirection->RedirectionGuid, &redirection->RedirectionGuidLength);
928 freerdp_certificate_free(redirection->TargetCertificate);
929 redirection_free_array(&redirection->TargetNetAddresses,
930 &redirection->TargetNetAddressesCount);
936 static SSIZE_T redir_write_string(UINT32 flag,
wStream* s,
const char* str)
938 const size_t length = (strlen(str) + 1);
939 if (!Stream_EnsureRemainingCapacity(s, 4ull + length *
sizeof(WCHAR)))
942 const size_t pos = Stream_GetPosition(s);
943 Stream_Write_UINT32(s, (UINT32)length *
sizeof(WCHAR));
944 if (Stream_Write_UTF16_String_From_UTF8(s, length, str, length, TRUE) < 0)
946 return (SSIZE_T)(Stream_GetPosition(s) - pos);
949 static BOOL redir_write_data(UINT32 flag,
wStream* s, UINT32 length,
const BYTE* data)
951 if (!Stream_EnsureRemainingCapacity(s, 4ull + length))
954 Stream_Write_UINT32(s, length);
955 Stream_Write(s, data, length);
959 BOOL rdp_write_enhanced_security_redirection_packet(
wStream* s,
const rdpRedirection* redirection)
964 WINPR_ASSERT(redirection);
966 if (!Stream_EnsureRemainingCapacity(s, 14))
969 Stream_Write_UINT16(s, 0);
971 const size_t start = Stream_GetPosition(s);
972 Stream_Write_UINT16(s, SEC_REDIRECTION_PKT);
973 const size_t lengthOffset = Stream_GetPosition(s);
974 Stream_Seek_UINT16(s);
976 if (redirection->sessionID)
977 Stream_Write_UINT32(s, redirection->sessionID);
979 Stream_Write_UINT32(s, 0);
981 Stream_Write_UINT32(s, redirection->flags);
983 if (redirection->flags & LB_TARGET_NET_ADDRESS)
985 if (redir_write_string(LB_TARGET_NET_ADDRESS, s, redirection->TargetNetAddress) < 0)
989 if (redirection->flags & LB_LOAD_BALANCE_INFO)
991 const UINT32 length = 13 + redirection->LoadBalanceInfoLength + 2;
992 if (!Stream_EnsureRemainingCapacity(s, length))
994 Stream_Write_UINT32(s, length);
995 Stream_Write(s,
"Cookie: msts=", 13);
996 Stream_Write(s, redirection->LoadBalanceInfo, redirection->LoadBalanceInfoLength);
997 Stream_Write_UINT8(s, 0x0d);
998 Stream_Write_UINT8(s, 0x0a);
1001 if (redirection->flags & LB_USERNAME)
1003 if (redir_write_string(LB_USERNAME, s, redirection->Username) < 0)
1007 if (redirection->flags & LB_DOMAIN)
1009 if (redir_write_string(LB_DOMAIN, s, redirection->Domain) < 0)
1013 if (redirection->flags & LB_PASSWORD)
1016 if (!redir_write_data(LB_PASSWORD, s, redirection->PasswordLength, redirection->Password))
1020 if (redirection->flags & LB_TARGET_FQDN)
1022 if (redir_write_string(LB_TARGET_FQDN, s, redirection->TargetFQDN) < 0)
1026 if (redirection->flags & LB_TARGET_NETBIOS_NAME)
1028 if (redir_write_string(LB_TARGET_NETBIOS_NAME, s, redirection->TargetNetBiosName) < 0)
1032 if (redirection->flags & LB_CLIENT_TSV_URL)
1034 if (!redir_write_data(LB_CLIENT_TSV_URL, s, redirection->TsvUrlLength, redirection->TsvUrl))
1038 if (redirection->flags & LB_REDIRECTION_GUID)
1040 if (!redir_write_data(LB_REDIRECTION_GUID, s, redirection->RedirectionGuidLength,
1041 redirection->RedirectionGuid))
1045 if (redirection->flags & LB_TARGET_CERTIFICATE)
1047 if (!rdp_redireciton_write_target_cert_stream(s, redirection))
1051 if (redirection->flags & LB_TARGET_NET_ADDRESSES)
1053 UINT32 length =
sizeof(UINT32);
1055 if (!Stream_EnsureRemainingCapacity(s, 2 *
sizeof(UINT32)))
1058 const size_t lstart = Stream_GetPosition(s);
1059 Stream_Seek_UINT32(s);
1060 Stream_Write_UINT32(s, redirection->TargetNetAddressesCount);
1061 for (UINT32 i = 0; i < redirection->TargetNetAddressesCount; i++)
1064 redir_write_string(LB_TARGET_NET_ADDRESSES, s, redirection->TargetNetAddresses[i]);
1067 length += (UINT32)rcc;
1071 const size_t lend = Stream_GetPosition(s);
1072 Stream_SetPosition(s, lstart);
1073 Stream_Write_UINT32(s, length);
1074 Stream_SetPosition(s, lend);
1078 if (!Stream_EnsureRemainingCapacity(s, 8))
1082 const size_t end = Stream_GetPosition(s);
1083 Stream_SetPosition(s, lengthOffset);
1084 Stream_Write_UINT16(s, (UINT16)(end - start));
1085 Stream_SetPosition(s, end);
1092 BOOL redirection_settings_are_valid(rdpRedirection* redirection, UINT32* pFlags)
1096 WINPR_ASSERT(redirection);
1098 if (redirection->flags & LB_CLIENT_TSV_URL)
1100 if (!redirection->TsvUrl || (redirection->TsvUrlLength == 0))
1101 flags |= LB_CLIENT_TSV_URL;
1104 if (redirection->flags & LB_SERVER_TSV_CAPABLE)
1106 if ((redirection->flags & LB_CLIENT_TSV_URL) == 0)
1107 flags |= LB_SERVER_TSV_CAPABLE;
1110 if (redirection->flags & LB_USERNAME)
1112 if (utils_str_is_empty(redirection->Username))
1113 flags |= LB_USERNAME;
1116 if (redirection->flags & LB_DOMAIN)
1118 if (utils_str_is_empty(redirection->Domain))
1122 if (redirection->flags & LB_PASSWORD)
1124 if (!redirection->Password || (redirection->PasswordLength == 0))
1125 flags |= LB_PASSWORD;
1128 if (redirection->flags & LB_TARGET_FQDN)
1130 if (utils_str_is_empty(redirection->TargetFQDN))
1131 flags |= LB_TARGET_FQDN;
1134 if (redirection->flags & LB_LOAD_BALANCE_INFO)
1136 if (!redirection->LoadBalanceInfo || (redirection->LoadBalanceInfoLength == 0))
1137 flags |= LB_LOAD_BALANCE_INFO;
1140 if (redirection->flags & LB_TARGET_NETBIOS_NAME)
1142 if (utils_str_is_empty(redirection->TargetNetBiosName))
1143 flags |= LB_TARGET_NETBIOS_NAME;
1146 if (redirection->flags & LB_TARGET_NET_ADDRESS)
1148 if (utils_str_is_empty(redirection->TargetNetAddress))
1149 flags |= LB_TARGET_NET_ADDRESS;
1152 if (redirection->flags & LB_TARGET_NET_ADDRESSES)
1154 if (!redirection->TargetNetAddresses || (redirection->TargetNetAddressesCount == 0))
1155 flags |= LB_TARGET_NET_ADDRESSES;
1158 for (UINT32 x = 0; x < redirection->TargetNetAddressesCount; x++)
1160 if (!redirection->TargetNetAddresses[x])
1161 flags |= LB_TARGET_NET_ADDRESSES;
1166 if (redirection->flags & LB_REDIRECTION_GUID)
1168 if (!redirection->RedirectionGuid || (redirection->RedirectionGuidLength == 0))
1169 flags |= LB_REDIRECTION_GUID;
1172 if (redirection->flags & LB_TARGET_CERTIFICATE)
1174 if (!redirection->TargetCertificate)
1175 flags |= LB_TARGET_CERTIFICATE;
1183 BOOL redirection_set_flags(rdpRedirection* redirection, UINT32 flags)
1185 WINPR_ASSERT(redirection);
1186 redirection->flags = flags;
1190 BOOL redirection_set_session_id(rdpRedirection* redirection, UINT32 session_id)
1192 WINPR_ASSERT(redirection);
1193 redirection->sessionID = session_id;
1197 static BOOL redirection_unsupported(
const char* fkt, UINT32 flag, UINT32 mask)
1199 char buffer[1024] = { 0 };
1200 char buffer2[1024] = { 0 };
1201 WLog_WARN(TAG,
"[%s] supported flags are {%s}, have {%s}", fkt,
1202 rdp_redirection_flags_to_string(mask, buffer,
sizeof(buffer)),
1203 rdp_redirection_flags_to_string(flag, buffer2,
sizeof(buffer2)));
1207 BOOL redirection_set_byte_option(rdpRedirection* redirection, UINT32 flag,
const BYTE* data,
1210 WINPR_ASSERT(redirection);
1213 case LB_CLIENT_TSV_URL:
1214 return redirection_copy_data(&redirection->TsvUrl, &redirection->TsvUrlLength, data,
1217 return redirection_copy_data(&redirection->Password, &redirection->PasswordLength, data,
1219 case LB_LOAD_BALANCE_INFO:
1220 return redirection_copy_data(&redirection->LoadBalanceInfo,
1221 &redirection->LoadBalanceInfoLength, data, length);
1222 case LB_REDIRECTION_GUID:
1223 return redirection_copy_data(&redirection->RedirectionGuid,
1224 &redirection->RedirectionGuidLength, data, length);
1225 case LB_TARGET_CERTIFICATE:
1226 return rdp_redirection_read_target_cert(&redirection->TargetCertificate, data, length);
1228 return redirection_unsupported(__func__, flag,
1229 LB_CLIENT_TSV_URL | LB_PASSWORD | LB_LOAD_BALANCE_INFO |
1230 LB_REDIRECTION_GUID | LB_TARGET_CERTIFICATE);
1234 BOOL redirection_set_string_option(rdpRedirection* redirection, UINT32 flag,
const char* str)
1236 WINPR_ASSERT(redirection);
1240 return redirection_copy_string(&redirection->Username, str);
1242 return redirection_copy_string(&redirection->Domain, str);
1243 case LB_TARGET_FQDN:
1244 return redirection_copy_string(&redirection->TargetFQDN, str);
1245 case LB_TARGET_NETBIOS_NAME:
1246 return redirection_copy_string(&redirection->TargetNetBiosName, str);
1247 case LB_TARGET_NET_ADDRESS:
1248 return redirection_copy_string(&redirection->TargetNetAddress, str);
1250 return redirection_unsupported(__func__, flag,
1251 LB_USERNAME | LB_DOMAIN | LB_TARGET_FQDN |
1252 LB_TARGET_NETBIOS_NAME | LB_TARGET_NET_ADDRESS);
1256 BOOL redirection_set_array_option(rdpRedirection* redirection, UINT32 flag,
const char** str,
1259 WINPR_ASSERT(redirection);
1262 case LB_TARGET_NET_ADDRESSES:
1263 return redirection_copy_array(&redirection->TargetNetAddresses,
1264 &redirection->TargetNetAddressesCount, str, count);
1266 return redirection_unsupported(__func__, flag, LB_TARGET_NET_ADDRESSES);
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_string(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param)
Sets a string settings value. The param is copied.
FREERDP_API const void * freerdp_settings_get_pointer(const rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id)
Returns a immutable pointer settings value.
FREERDP_API BOOL freerdp_settings_set_pointer_len(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id, const void *data, size_t len)
Set a pointer to value data.
FREERDP_API BOOL freerdp_settings_set_pointer(rdpSettings *settings, FreeRDP_Settings_Keys_Pointer id, const void *data)
Set a pointer to value data.
FREERDP_API BOOL freerdp_settings_set_string_len(rdpSettings *settings, FreeRDP_Settings_Keys_String id, const char *param, size_t len)
Sets a string settings value. The param is copied.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.