client: add option to use SOCKS5 for DNS

Added <socks5_remote_dns> option to cc_config.xml.
Tells Curl to use the SOCKS proxy for domain name resolution.
This commit is contained in:
David Anderson 2017-01-05 21:34:34 -08:00
parent 93b9f8fefb
commit 31a95ba10f
6 changed files with 17 additions and 8 deletions

View File

@ -865,7 +865,9 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) {
} else if (pi.use_socks_proxy) {
// CURL only supports SOCKS version 5
curl_easy_setopt(curlEasy, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_easy_setopt(curlEasy, CURLOPT_PROXYTYPE,
pi.socks5_remote_dns?CURLPROXY_SOCKS5_HOSTNAME:CURLPROXY_SOCKS5
);
curl_easy_setopt(curlEasy, CURLOPT_PROXYPORT, (long) pi.socks_server_port);
curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.socks_server_name);
// libcurl uses blocking sockets with socks proxy, so limit timeout.

View File

@ -671,16 +671,12 @@ function post_int($name, $optional=false) {
return $y;
}
function get_array($name, $optional=false) {
function get_array($name) {
if (isset($_GET[$name])) {
$x = $_GET[$name];
return $_GET[$name];
} else {
if (!$optional) {
error_page("missing or bad parameter: $name");
}
$x = null;
return array();
}
return $x;
}
function get_str($name, $optional=false) {

View File

@ -364,6 +364,7 @@ struct GR_PROXY_INFO {
int socks_server_port;
std::string socks5_user_name;
std::string socks5_user_passwd;
bool socks5_remote_dns;
std::string noproxy_hosts;

View File

@ -855,6 +855,7 @@ int GR_PROXY_INFO::parse(XML_PARSER& xp) {
if (xp.parse_int("socks_server_port", socks_server_port)) continue;
if (xp.parse_string("socks5_user_name", socks5_user_name)) continue;
if (xp.parse_string("socks5_user_passwd", socks5_user_passwd)) continue;
if (xp.parse_bool("socks5_remote_dns", socks5_remote_dns)) continue;
if (xp.parse_string("http_server_name", http_server_name)) continue;
if (xp.parse_int("http_server_port", http_server_port)) continue;
if (xp.parse_string("http_user_name", http_user_name)) continue;
@ -879,6 +880,7 @@ void GR_PROXY_INFO::clear() {
http_user_passwd.clear();
socks5_user_name.clear();
socks5_user_passwd.clear();
socks5_remote_dns = false;
noproxy_hosts.clear();
}
@ -1956,6 +1958,7 @@ int RPC_CLIENT::set_proxy_settings(GR_PROXY_INFO& procinfo) {
" <socks_server_port>%d</socks_server_port>\n"
" <socks5_user_name>%s</socks5_user_name>\n"
" <socks5_user_passwd>%s</socks5_user_passwd>\n"
" <socks5_remote_dns>%d</socks5_remote_dns>\n"
" <no_proxy>%s</no_proxy>\n"
" </proxy_info>\n"
"</set_proxy_settings>\n",
@ -1970,6 +1973,7 @@ int RPC_CLIENT::set_proxy_settings(GR_PROXY_INFO& procinfo) {
procinfo.socks_server_port,
procinfo.socks5_user_name.c_str(),
procinfo.socks5_user_passwd.c_str(),
procinfo.socks5_remote_dns?1:0,
procinfo.noproxy_hosts.c_str()
);
buf[sizeof(buf)-1] = 0;

View File

@ -39,6 +39,7 @@ int PROXY_INFO::parse(XML_PARSER& xp) {
if (xp.parse_int("http_server_port", http_server_port)) continue;
if (xp.parse_str("socks5_user_name", socks5_user_name,sizeof(socks5_user_name))) continue;
if (xp.parse_str("socks5_user_passwd", socks5_user_passwd,sizeof(socks5_user_passwd))) continue;
if (xp.parse_bool("socks5_remote_dns", socks5_remote_dns)) continue;
if (xp.parse_str("http_user_name", http_user_name,sizeof(http_user_name))) continue;
if (xp.parse_str("http_user_passwd", http_user_passwd,sizeof(http_user_passwd))) continue;
if (xp.parse_str("no_proxy", noproxy_hosts, sizeof(noproxy_hosts))) continue;
@ -73,6 +74,7 @@ int PROXY_INFO::write(MIOFILE& out) {
" <http_server_port>%d</http_server_port>\n"
" <socks5_user_name>%s</socks5_user_name>\n"
" <socks5_user_passwd>%s</socks5_user_passwd>\n"
" <socks5_remote_dns>%d</socks5_remote_dns>\n"
" <http_user_name>%s</http_user_name>\n"
" <http_user_passwd>%s</http_user_passwd>\n"
" <no_proxy>%s</no_proxy>\n"
@ -86,6 +88,7 @@ int PROXY_INFO::write(MIOFILE& out) {
http_server_port,
s5un,
s5up,
socks5_remote_dns?1:0,
hun,
hup,
noproxy_hosts,
@ -119,6 +122,7 @@ void PROXY_INFO::clear() {
http_server_port = 80;
safe_strcpy(socks5_user_name, "");
safe_strcpy(socks5_user_passwd, "");
socks5_remote_dns = false;
safe_strcpy(http_user_name, "");
safe_strcpy(http_user_passwd, "");
safe_strcpy(noproxy_hosts, "");

View File

@ -44,6 +44,8 @@ struct PROXY_INFO {
int socks_server_port;
char socks5_user_name[256];
char socks5_user_passwd[256];
bool socks5_remote_dns;
// send DNS requests to the proxy
// a list of hosts for which we should NOT go through a proxy
// (e.g. a company PC attached to both local and remote projects)