mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
Merge pull request #541
5131b26
Replace tabs and remove trailing whitespace (warptangent)0d40de4
Optionally restrict DNS queries to TCP (warptangent)
This commit is contained in:
commit
f7d41d6e28
@ -1,21 +1,21 @@
|
|||||||
// Copyright (c) 2014-2015, The Monero Project
|
// Copyright (c) 2014-2015, The Monero Project
|
||||||
//
|
//
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without modification, are
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
// permitted provided that the following conditions are met:
|
// permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
// conditions and the following disclaimer.
|
// conditions and the following disclaimer.
|
||||||
//
|
//
|
||||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
// of conditions and the following disclaimer in the documentation and/or other
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
// materials provided with the distribution.
|
// materials provided with the distribution.
|
||||||
//
|
//
|
||||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
// used to endorse or promote products derived from this software without specific
|
// used to endorse or promote products derived from this software without specific
|
||||||
// prior written permission.
|
// prior written permission.
|
||||||
//
|
//
|
||||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
@ -86,7 +86,7 @@ get_builtin_cert(void)
|
|||||||
static const char*
|
static const char*
|
||||||
get_builtin_ds(void)
|
get_builtin_ds(void)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5\n";
|
". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,30 +183,51 @@ struct DNSResolverData
|
|||||||
|
|
||||||
DNSResolver::DNSResolver() : m_data(new DNSResolverData())
|
DNSResolver::DNSResolver() : m_data(new DNSResolverData())
|
||||||
{
|
{
|
||||||
|
int use_dns_public = 0;
|
||||||
|
const char* dns_public_addr = "8.8.4.4";
|
||||||
|
if (auto res = getenv("DNS_PUBLIC"))
|
||||||
|
{
|
||||||
|
std::string dns_public(res);
|
||||||
|
// TODO: could allow parsing of IP and protocol: e.g. DNS_PUBLIC=tcp:8.8.8.8
|
||||||
|
if (dns_public == "tcp")
|
||||||
|
{
|
||||||
|
LOG_PRINT_L0("Using public DNS server: " << dns_public_addr << " (TCP)");
|
||||||
|
use_dns_public = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// init libunbound context
|
// init libunbound context
|
||||||
m_data->m_ub_context = ub_ctx_create();
|
m_data->m_ub_context = ub_ctx_create();
|
||||||
|
|
||||||
// look for "/etc/resolv.conf" and "/etc/hosts" or platform equivalent
|
if (use_dns_public)
|
||||||
ub_ctx_resolvconf(m_data->m_ub_context, NULL);
|
{
|
||||||
ub_ctx_hosts(m_data->m_ub_context, NULL);
|
ub_ctx_set_fwd(m_data->m_ub_context, dns_public_addr);
|
||||||
|
ub_ctx_set_option(m_data->m_ub_context, "do-udp:", "no");
|
||||||
|
ub_ctx_set_option(m_data->m_ub_context, "do-tcp:", "yes");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// look for "/etc/resolv.conf" and "/etc/hosts" or platform equivalent
|
||||||
|
ub_ctx_resolvconf(m_data->m_ub_context, NULL);
|
||||||
|
ub_ctx_hosts(m_data->m_ub_context, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEVELOPER_LIBUNBOUND_OLD
|
#ifdef DEVELOPER_LIBUNBOUND_OLD
|
||||||
#pragma message "Using the work around for old libunbound"
|
#pragma message "Using the work around for old libunbound"
|
||||||
{ // work around for bug https://www.nlnetlabs.nl/bugs-script/show_bug.cgi?id=515 needed for it to compile on e.g. Debian 7
|
{ // work around for bug https://www.nlnetlabs.nl/bugs-script/show_bug.cgi?id=515 needed for it to compile on e.g. Debian 7
|
||||||
char * ds_copy = NULL; // this will be the writable copy of string that bugged version of libunbound requires
|
char * ds_copy = NULL; // this will be the writable copy of string that bugged version of libunbound requires
|
||||||
try {
|
try {
|
||||||
char * ds_copy = strdup( ::get_builtin_ds() );
|
char * ds_copy = strdup( ::get_builtin_ds() );
|
||||||
ub_ctx_add_ta(m_data->m_ub_context, ds_copy);
|
ub_ctx_add_ta(m_data->m_ub_context, ds_copy);
|
||||||
} catch(...) { // probably not needed but to work correctly in every case...
|
} catch(...) { // probably not needed but to work correctly in every case...
|
||||||
if (ds_copy) { free(ds_copy); ds_copy=NULL; } // for the strdup
|
if (ds_copy) { free(ds_copy); ds_copy=NULL; } // for the strdup
|
||||||
throw ;
|
throw ;
|
||||||
}
|
}
|
||||||
if (ds_copy) { free(ds_copy); ds_copy=NULL; } // for the strdup
|
if (ds_copy) { free(ds_copy); ds_copy=NULL; } // for the strdup
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// normal version for fixed libunbound
|
// normal version for fixed libunbound
|
||||||
ub_ctx_add_ta(m_data->m_ub_context, ::get_builtin_ds() );
|
ub_ctx_add_ta(m_data->m_ub_context, ::get_builtin_ds() );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user