Use freerdp_settings_[s|g]et* api to access proxy vaiables.

Fixes #6414
This commit is contained in:
akallabeth 2020-08-04 08:49:46 +02:00 committed by Armin Novak
parent fde4867574
commit 44ea09e7ad
4 changed files with 79 additions and 62 deletions

View File

@ -1567,9 +1567,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
else else
compatibility = freerdp_client_detect_command_line(argc - 1, &argv[1], &flags); compatibility = freerdp_client_detect_command_line(argc - 1, &argv[1], &flags);
settings->ProxyHostname = NULL; freerdp_settings_set_string(settings, FreeRDP_ProxyHostname, NULL);
settings->ProxyUsername = NULL; freerdp_settings_set_string(settings, FreeRDP_ProxyUsername, NULL);
settings->ProxyPassword = NULL; freerdp_settings_set_string(settings, FreeRDP_ProxyPassword, NULL);
if (compatibility) if (compatibility)
{ {
@ -2089,7 +2089,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
CommandLineSwitchCase(arg, "proxy") CommandLineSwitchCase(arg, "proxy")
{ {
/* initial value */ /* initial value */
settings->ProxyType = PROXY_TYPE_HTTP; if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_HTTP))
return COMMAND_LINE_ERROR_MEMORY;
if (arg->Flags & COMMAND_LINE_VALUE_PRESENT) if (arg->Flags & COMMAND_LINE_VALUE_PRESENT)
{ {
@ -2104,12 +2105,23 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
*p = '\0'; *p = '\0';
if (_stricmp("no_proxy", arg->Value) == 0) if (_stricmp("no_proxy", arg->Value) == 0)
settings->ProxyType = PROXY_TYPE_IGNORE; {
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType,
PROXY_TYPE_IGNORE))
return COMMAND_LINE_ERROR_MEMORY;
}
if (_stricmp("http", arg->Value) == 0) if (_stricmp("http", arg->Value) == 0)
settings->ProxyType = PROXY_TYPE_HTTP; {
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType,
PROXY_TYPE_HTTP))
return COMMAND_LINE_ERROR_MEMORY;
}
else if (_stricmp("socks5", arg->Value) == 0) else if (_stricmp("socks5", arg->Value) == 0)
settings->ProxyType = PROXY_TYPE_SOCKS; {
if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType,
PROXY_TYPE_SOCKS))
return COMMAND_LINE_ERROR_MEMORY;
}
else else
{ {
WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now"); WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now");
@ -2142,18 +2154,15 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
*colonPtr = '\0'; *colonPtr = '\0';
settings->ProxyUsername = _strdup(arg->Value); if (!freerdp_settings_set_string(settings, FreeRDP_ProxyUsername, arg->Value))
if (!settings->ProxyUsername)
{ {
WLog_ERR(TAG, "unable to allocate proxy username"); WLog_ERR(TAG, "unable to allocate proxy username");
return COMMAND_LINE_ERROR_MEMORY; return COMMAND_LINE_ERROR_MEMORY;
} }
*atPtr = '\0'; *atPtr = '\0';
settings->ProxyPassword = _strdup(colonPtr + 1);
if (!settings->ProxyPassword) if (!freerdp_settings_set_string(settings, FreeRDP_ProxyPassword, colonPtr + 1))
{ {
WLog_ERR(TAG, "unable to allocate proxy password"); WLog_ERR(TAG, "unable to allocate proxy password");
return COMMAND_LINE_ERROR_MEMORY; return COMMAND_LINE_ERROR_MEMORY;
@ -2172,11 +2181,16 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE; return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
length = (size_t)(p - arg->Value); length = (size_t)(p - arg->Value);
settings->ProxyPort = (UINT16)val; if (!freerdp_settings_set_uint16(settings, FreeRDP_ProxyPort, val))
settings->ProxyHostname = (char*)malloc(length + 1); return FALSE;
strncpy(settings->ProxyHostname, arg->Value, length); *p = '\0';
settings->ProxyHostname[length] = '\0';
} }
p = strchr(arg->Value, '/');
if (p)
*p = '\0';
if (!freerdp_settings_set_string(settings, FreeRDP_ProxyHostname, arg->Value))
return FALSE;
} }
else else
{ {

View File

@ -647,8 +647,8 @@ static BOOL rpc_channel_tls_connect(RpcChannel* channel, int timeout)
context = channel->client->context; context = channel->client->context;
settings = context->settings; settings = context->settings;
proxyUsername = settings->ProxyUsername; proxyUsername = freerdp_settings_get_string(settings, FreeRDP_ProxyUsername);
proxyPassword = settings->ProxyPassword; proxyPassword = freerdp_settings_get_string(settings, FreeRDP_ProxyPassword);
{ {
sockfd = freerdp_tcp_connect(context, settings, channel->client->host, sockfd = freerdp_tcp_connect(context, settings, channel->client->host,
channel->client->port, timeout); channel->client->port, timeout);

View File

@ -1022,10 +1022,10 @@ static BOOL rpc_client_resolve_gateway(rdpSettings* settings, char** host, UINT1
return FALSE; return FALSE;
else else
{ {
const char* peerHostname = settings->GatewayHostname; const char* peerHostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname);
const char* proxyUsername = settings->ProxyUsername; const char* proxyUsername = freerdp_settings_get_string(settings, FreeRDP_GatewayUsername);
const char* proxyPassword = settings->ProxyPassword; const char* proxyPassword = freerdp_settings_get_string(settings, FreeRDP_GatewayPassword);
*port = settings->GatewayPort; *port = freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort);
*isProxy = proxy_prepare(settings, &peerHostname, port, &proxyUsername, &proxyPassword); *isProxy = proxy_prepare(settings, &peerHostname, port, &proxyUsername, &proxyPassword);
result = freerdp_tcp_resolve_host(peerHostname, *port, 0); result = freerdp_tcp_resolve_host(peerHostname, *port, 0);

View File

@ -71,28 +71,28 @@ static BOOL proxy_parse_uri(rdpSettings* settings, const char* uri);
BOOL proxy_prepare(rdpSettings* settings, const char** lpPeerHostname, UINT16* lpPeerPort, BOOL proxy_prepare(rdpSettings* settings, const char** lpPeerHostname, UINT16* lpPeerPort,
const char** lpProxyUsername, const char** lpProxyPassword) const char** lpProxyUsername, const char** lpProxyPassword)
{ {
if (settings->ProxyType == PROXY_TYPE_IGNORE) if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) == PROXY_TYPE_IGNORE)
return FALSE; return FALSE;
/* For TSGateway, find the system HTTPS proxy automatically */ /* For TSGateway, find the system HTTPS proxy automatically */
if (settings->ProxyType == PROXY_TYPE_NONE) if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) == PROXY_TYPE_NONE)
proxy_read_environment(settings, "https_proxy"); proxy_read_environment(settings, "https_proxy");
if (settings->ProxyType == PROXY_TYPE_NONE) if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) == PROXY_TYPE_NONE)
proxy_read_environment(settings, "HTTPS_PROXY"); proxy_read_environment(settings, "HTTPS_PROXY");
if (settings->ProxyType != PROXY_TYPE_NONE) if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) != PROXY_TYPE_NONE)
proxy_read_environment(settings, "no_proxy"); proxy_read_environment(settings, "no_proxy");
if (settings->ProxyType != PROXY_TYPE_NONE) if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) != PROXY_TYPE_NONE)
proxy_read_environment(settings, "NO_PROXY"); proxy_read_environment(settings, "NO_PROXY");
if (settings->ProxyType != PROXY_TYPE_NONE) if (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType) != PROXY_TYPE_NONE)
{ {
*lpPeerHostname = settings->ProxyHostname; *lpPeerHostname = freerdp_settings_get_string(settings, FreeRDP_ProxyHostname);
*lpPeerPort = settings->ProxyPort; *lpPeerPort = freerdp_settings_get_uint32(settings, FreeRDP_ProxyPort);
*lpProxyUsername = settings->ProxyUsername; *lpProxyUsername = freerdp_settings_get_string(settings, FreeRDP_ProxyUsername);
*lpProxyPassword = settings->ProxyPassword; *lpProxyPassword = freerdp_settings_get_string(settings, FreeRDP_ProxyPassword);
return TRUE; return TRUE;
} }
@ -274,9 +274,10 @@ void proxy_read_environment(rdpSettings* settings, char* envname)
{ {
if (check_no_proxy(settings, env)) if (check_no_proxy(settings, env))
{ {
WLog_INFO(TAG, "deactivating proxy: %s [%s=%s]", settings->ServerHostname, envname, WLog_INFO(TAG, "deactivating proxy: %s [%s=%s]",
freerdp_settings_get_string(settings, FreeRDP_ServerHostname), envname,
env); env);
settings->ProxyType = PROXY_TYPE_NONE; freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_NONE);
} }
} }
else else
@ -288,31 +289,38 @@ void proxy_read_environment(rdpSettings* settings, char* envname)
free(env); free(env);
} }
BOOL proxy_parse_uri(rdpSettings* settings, const char* uri) BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in)
{ {
const char *hostname, *pport; BOOL rc = FALSE;
char *hostname, *pport;
const char* protocol; const char* protocol;
const char* p; char* p;
UINT16 port; UINT16 port;
int hostnamelen; char* uri_copy = _strdup(uri_in);
char* uri = uri_copy;
if (!uri)
return FALSE;
p = strstr(uri, "://"); p = strstr(uri, "://");
if (p) if (p)
{ {
if (p == uri + 4 && !strncmp("http", uri, 4)) if (p == uri + 4 && !strncmp("http", uri, 4))
{ {
settings->ProxyType = PROXY_TYPE_HTTP; if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_HTTP))
goto fail;
protocol = "http"; protocol = "http";
} }
else if (p == uri + 6 && !strncmp("socks5", uri, 6)) else if (p == uri + 6 && !strncmp("socks5", uri, 6))
{ {
settings->ProxyType = PROXY_TYPE_SOCKS; if (!freerdp_settings_set_uint32(settings, FreeRDP_ProxyType, PROXY_TYPE_SOCKS))
goto fail;
protocol = "socks5"; protocol = "socks5";
} }
else else
{ {
WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now"); WLog_ERR(TAG, "Only HTTP and SOCKS5 proxies supported by now");
return FALSE; goto fail;
} }
uri = p + 3; uri = p + 3;
@ -320,7 +328,7 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
else else
{ {
WLog_ERR(TAG, "No scheme in proxy URI"); WLog_ERR(TAG, "No scheme in proxy URI");
return FALSE; goto fail;
} }
hostname = uri; hostname = uri;
@ -345,33 +353,28 @@ BOOL proxy_parse_uri(rdpSettings* settings, const char* uri)
} }
if (pport) if (pport)
{ *pport = '\0';
hostnamelen = pport - hostname;
}
else
{
hostnamelen = strlen(hostname);
}
settings->ProxyHostname = calloc(hostnamelen + 1, 1); if (!freerdp_settings_set_string(settings, FreeRDP_ProxyHostname, hostname))
goto fail;
if (!settings->ProxyHostname) if (!freerdp_settings_set_uint16(settings, FreeRDP_ProxyPort, port))
{ goto fail;
WLog_ERR(TAG, "Not enough memory");
return FALSE;
}
memcpy(settings->ProxyHostname, hostname, hostnamelen); WLog_INFO(TAG, "Parsed proxy configuration: %s://%s:%d", protocol,
settings->ProxyPort = port; freerdp_settings_get_string(settings, FreeRDP_ProxyHostname),
WLog_INFO(TAG, "Parsed proxy configuration: %s://%s:%d", protocol, settings->ProxyHostname, freerdp_settings_get_uint16(settings, FreeRDP_ProxyPort));
settings->ProxyPort); rc = TRUE;
return TRUE;
fail:
free(uri_copy);
return rc;
} }
BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char* proxyUsername, BOOL proxy_connect(rdpSettings* settings, BIO* bufferedBio, const char* proxyUsername,
const char* proxyPassword, const char* hostname, UINT16 port) const char* proxyPassword, const char* hostname, UINT16 port)
{ {
switch (settings->ProxyType) switch (freerdp_settings_get_uint32(settings, FreeRDP_ProxyType))
{ {
case PROXY_TYPE_NONE: case PROXY_TYPE_NONE:
case PROXY_TYPE_IGNORE: case PROXY_TYPE_IGNORE: