Cleaned up redirection code

This commit is contained in:
Armin Novak 2021-12-15 09:30:18 +01:00 committed by akallabeth
parent bb0eeeb264
commit b545094664
4 changed files with 69 additions and 92 deletions

View File

@ -1236,16 +1236,16 @@ struct rdp_settings
UINT64 padding1856[1856 - 1795]; /* 1795 */
/* Recording */
ALIGN64 BOOL DumpRemoteFx; /* 1856 */
ALIGN64 BOOL PlayRemoteFx; /* 1857 */
ALIGN64 char* DumpRemoteFxFile; /* 1858 */
ALIGN64 char* PlayRemoteFxFile; /* 1859 */
ALIGN64 BOOL TransportDump; /* 1860 */
ALIGN64 char* TransportDumpFile; /* 1861 */
ALIGN64 BOOL DumpRemoteFx; /* 1856 */
ALIGN64 BOOL PlayRemoteFx; /* 1857 */
ALIGN64 char* DumpRemoteFxFile; /* 1858 */
ALIGN64 char* PlayRemoteFxFile; /* 1859 */
ALIGN64 BOOL TransportDump; /* 1860 */
ALIGN64 char* TransportDumpFile; /* 1861 */
ALIGN64 BOOL TransportDumpReplay; /* 1862 */
ALIGN64 BOOL DeactivateClientDecoding; /* 1863 */
UINT64 padding1920[1920 - 1864]; /* 1864 */
UINT64 padding1984[1984 - 1920]; /* 1920 */
UINT64 padding1984[1984 - 1920]; /* 1920 */
/**
* Gateway
@ -1373,8 +1373,8 @@ struct rdp_settings
* If used by an implementation ensure proper state resync after reenabling
* input
*/
ALIGN64 BOOL SuspendInput; /* 2636 */
UINT64 padding2688[2688 - 2637]; /* 2637 */
ALIGN64 BOOL SuspendInput; /* 2636 */
UINT64 padding2688[2688 - 2637]; /* 2637 */
/* Brush Capabilities */
ALIGN64 UINT32 BrushSupportLevel; /* 2688 */
@ -1675,6 +1675,8 @@ extern "C"
FREERDP_API void freerdp_dynamic_channel_collection_free(rdpSettings* settings);
FREERDP_API void freerdp_target_net_addresses_free(rdpSettings* settings);
FREERDP_API BOOL freerdp_target_net_addresses_copy(rdpSettings* settings, char** addresses,
UINT32 count);
FREERDP_API void freerdp_performance_flags_make(rdpSettings* settings);
FREERDP_API void freerdp_performance_flags_split(rdpSettings* settings);

View File

@ -1376,3 +1376,35 @@ ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel)
return freerdp_addin_argv_clone(channel);
}
#endif
BOOL freerdp_target_net_addresses_copy(rdpSettings* settings, char** addresses, UINT32 count)
{
UINT32 i;
WINPR_ASSERT(settings);
WINPR_ASSERT(addresses);
freerdp_target_net_addresses_free(settings);
settings->TargetNetAddressCount = count;
settings->TargetNetAddresses = (char**)calloc(settings->TargetNetAddressCount, sizeof(char*));
if (!settings->TargetNetAddresses)
{
freerdp_target_net_addresses_free(settings);
return FALSE;
}
for (i = 0; i < settings->TargetNetAddressCount; i++)
{
settings->TargetNetAddresses[i] = _strdup(addresses[i]);
if (!settings->TargetNetAddresses[i])
{
freerdp_target_net_addresses_free(settings);
return FALSE;
}
}
return TRUE;
}

View File

@ -592,19 +592,17 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
if (settings->RedirectionFlags & LB_USERNAME)
{
free(settings->Username);
settings->Username = _strdup(settings->RedirectionUsername);
if (!settings->Username)
if (!freerdp_settings_set_string(
settings, FreeRDP_Username,
freerdp_settings_get_string(settings, FreeRDP_RedirectionUsername)))
return FALSE;
}
if (settings->RedirectionFlags & LB_DOMAIN)
{
free(settings->Domain);
settings->Domain = _strdup(settings->RedirectionDomain);
if (!settings->Domain)
if (!freerdp_settings_set_string(
settings, FreeRDP_Domain,
freerdp_settings_get_string(settings, FreeRDP_RedirectionDomain)))
return FALSE;
}

View File

@ -153,15 +153,10 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
if (settings->RedirectionFlags & LB_LOAD_BALANCE_INFO)
{
/* LoadBalanceInfo may not contain a null terminator */
free(settings->LoadBalanceInfo);
settings->LoadBalanceInfoLength = redirection->LoadBalanceInfoLength;
settings->LoadBalanceInfo = (BYTE*)malloc(settings->LoadBalanceInfoLength);
if (!settings->LoadBalanceInfo)
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_LoadBalanceInfo,
redirection->LoadBalanceInfo,
redirection->LoadBalanceInfoLength))
return -1;
CopyMemory(settings->LoadBalanceInfo, redirection->LoadBalanceInfo,
settings->LoadBalanceInfoLength);
}
else
{
@ -169,116 +164,66 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
* Free previous LoadBalanceInfo, if any, otherwise it may end up
* being reused for the redirected session, which is not what we want.
*/
free(settings->LoadBalanceInfo);
settings->LoadBalanceInfo = NULL;
settings->LoadBalanceInfoLength = 0;
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_LoadBalanceInfo, NULL, 0))
return -1;
}
if (settings->RedirectionFlags & LB_TARGET_FQDN)
{
free(settings->RedirectionTargetFQDN);
settings->RedirectionTargetFQDN = _strdup(redirection->TargetFQDN);
if (!settings->RedirectionTargetFQDN)
if (!freerdp_settings_set_string(settings, FreeRDP_RedirectionTargetFQDN,
redirection->TargetFQDN))
return -1;
}
if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESS)
{
free(settings->TargetNetAddress);
settings->TargetNetAddress = _strdup(redirection->TargetNetAddress);
if (!settings->TargetNetAddress)
if (!freerdp_settings_set_string(settings, FreeRDP_TargetNetAddress,
redirection->TargetNetAddress))
return -1;
}
if (settings->RedirectionFlags & LB_TARGET_NETBIOS_NAME)
{
free(settings->RedirectionTargetNetBiosName);
settings->RedirectionTargetNetBiosName = _strdup(redirection->TargetNetBiosName);
if (!settings->RedirectionTargetNetBiosName)
if (!freerdp_settings_set_string(settings, FreeRDP_RedirectionTargetNetBiosName,
redirection->TargetNetBiosName))
return -1;
}
if (settings->RedirectionFlags & LB_USERNAME)
{
free(settings->RedirectionUsername);
settings->RedirectionUsername = _strdup(redirection->Username);
if (!settings->RedirectionUsername)
if (!freerdp_settings_set_string(settings, FreeRDP_RedirectionUsername,
redirection->Username))
return -1;
}
if (settings->RedirectionFlags & LB_DOMAIN)
{
free(settings->RedirectionDomain);
settings->RedirectionDomain = _strdup(redirection->Domain);
if (!settings->RedirectionDomain)
if (!freerdp_settings_set_string(settings, FreeRDP_RedirectionDomain, redirection->Domain))
return -1;
}
if (settings->RedirectionFlags & LB_PASSWORD)
{
/* Password may be a cookie without a null terminator */
free(settings->RedirectionPassword);
settings->RedirectionPasswordLength = redirection->PasswordLength;
/* For security reasons we'll allocate an additional zero WCHAR at the
* end of the buffer that is not included in RedirectionPasswordLength
*/
settings->RedirectionPassword =
(BYTE*)calloc(1, settings->RedirectionPasswordLength + sizeof(WCHAR));
if (!settings->RedirectionPassword)
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RedirectionPassword,
redirection->Password, redirection->PasswordLength))
return -1;
CopyMemory(settings->RedirectionPassword, redirection->Password,
settings->RedirectionPasswordLength);
}
if (settings->RedirectionFlags & LB_CLIENT_TSV_URL)
{
/* TsvUrl may not contain a null terminator */
free(settings->RedirectionTsvUrl);
settings->RedirectionTsvUrlLength = redirection->TsvUrlLength;
settings->RedirectionTsvUrl = (BYTE*)malloc(settings->RedirectionTsvUrlLength);
if (!settings->RedirectionTsvUrl)
if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RedirectionTsvUrl,
redirection->TsvUrl, redirection->TsvUrlLength))
return -1;
CopyMemory(settings->RedirectionTsvUrl, redirection->TsvUrl,
settings->RedirectionTsvUrlLength);
}
if (settings->RedirectionFlags & LB_TARGET_NET_ADDRESSES)
{
UINT32 i;
freerdp_target_net_addresses_free(settings);
settings->TargetNetAddressCount = redirection->TargetNetAddressesCount;
settings->TargetNetAddresses =
(char**)calloc(settings->TargetNetAddressCount, sizeof(char*));
if (!settings->TargetNetAddresses)
{
settings->TargetNetAddressCount = 0;
if (!freerdp_target_net_addresses_copy(settings, redirection->TargetNetAddresses,
redirection->TargetNetAddressesCount))
return -1;
}
for (i = 0; i < settings->TargetNetAddressCount; i++)
{
settings->TargetNetAddresses[i] = _strdup(redirection->TargetNetAddresses[i]);
if (!settings->TargetNetAddresses[i])
{
UINT32 j;
for (j = 0; j < i; j++)
free(settings->TargetNetAddresses[j]);
return -1;
}
}
}
return 0;