mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface
This commit is contained in:
parent
fcef6dbc15
commit
9574de86ad
11 changed files with 74 additions and 54 deletions
|
@ -172,7 +172,7 @@ static bool InitHTTPAllowList()
|
||||||
rpc_allow_subnets.push_back(CSubNet(localv6)); // always allow IPv6 localhost
|
rpc_allow_subnets.push_back(CSubNet(localv6)); // always allow IPv6 localhost
|
||||||
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
|
for (const std::string& strAllow : gArgs.GetArgs("-rpcallowip")) {
|
||||||
CSubNet subnet;
|
CSubNet subnet;
|
||||||
LookupSubNet(strAllow.c_str(), subnet);
|
LookupSubNet(strAllow, subnet);
|
||||||
if (!subnet.IsValid()) {
|
if (!subnet.IsValid()) {
|
||||||
uiInterface.ThreadSafeMessageBox(
|
uiInterface.ThreadSafeMessageBox(
|
||||||
strprintf("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24).", strAllow),
|
strprintf("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24).", strAllow),
|
||||||
|
@ -324,7 +324,7 @@ static bool HTTPBindAddresses(struct evhttp* http)
|
||||||
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
|
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
|
||||||
if (bind_handle) {
|
if (bind_handle) {
|
||||||
CNetAddr addr;
|
CNetAddr addr;
|
||||||
if (i->first.empty() || (LookupHost(i->first.c_str(), addr, false) && addr.IsBindAny())) {
|
if (i->first.empty() || (LookupHost(i->first, addr, false) && addr.IsBindAny())) {
|
||||||
LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
|
LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
|
||||||
}
|
}
|
||||||
boundSockets.push_back(bind_handle);
|
boundSockets.push_back(bind_handle);
|
||||||
|
|
|
@ -1354,7 +1354,7 @@ bool AppInitMain(NodeContext& node)
|
||||||
SetReachable(NET_ONION, false);
|
SetReachable(NET_ONION, false);
|
||||||
if (proxyArg != "" && proxyArg != "0") {
|
if (proxyArg != "" && proxyArg != "0") {
|
||||||
CService proxyAddr;
|
CService proxyAddr;
|
||||||
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
|
if (!Lookup(proxyArg, proxyAddr, 9050, fNameLookup)) {
|
||||||
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'").translated, proxyArg));
|
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'").translated, proxyArg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1378,7 +1378,7 @@ bool AppInitMain(NodeContext& node)
|
||||||
SetReachable(NET_ONION, false);
|
SetReachable(NET_ONION, false);
|
||||||
} else {
|
} else {
|
||||||
CService onionProxy;
|
CService onionProxy;
|
||||||
if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) {
|
if (!Lookup(onionArg, onionProxy, 9050, fNameLookup)) {
|
||||||
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'").translated, onionArg));
|
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'").translated, onionArg));
|
||||||
}
|
}
|
||||||
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
|
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
|
||||||
|
@ -1396,7 +1396,7 @@ bool AppInitMain(NodeContext& node)
|
||||||
|
|
||||||
for (const std::string& strAddr : gArgs.GetArgs("-externalip")) {
|
for (const std::string& strAddr : gArgs.GetArgs("-externalip")) {
|
||||||
CService addrLocal;
|
CService addrLocal;
|
||||||
if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
|
if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
|
||||||
AddLocal(addrLocal, LOCAL_MANUAL);
|
AddLocal(addrLocal, LOCAL_MANUAL);
|
||||||
else
|
else
|
||||||
return InitError(ResolveErrMsg("externalip", strAddr));
|
return InitError(ResolveErrMsg("externalip", strAddr));
|
||||||
|
@ -1776,7 +1776,7 @@ bool AppInitMain(NodeContext& node)
|
||||||
|
|
||||||
for (const std::string& strBind : gArgs.GetArgs("-bind")) {
|
for (const std::string& strBind : gArgs.GetArgs("-bind")) {
|
||||||
CService addrBind;
|
CService addrBind;
|
||||||
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false)) {
|
if (!Lookup(strBind, addrBind, GetListenPort(), false)) {
|
||||||
return InitError(ResolveErrMsg("bind", strBind));
|
return InitError(ResolveErrMsg("bind", strBind));
|
||||||
}
|
}
|
||||||
connOptions.vBinds.push_back(addrBind);
|
connOptions.vBinds.push_back(addrBind);
|
||||||
|
|
|
@ -410,7 +410,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
if (hSocket == INVALID_SOCKET) {
|
if (hSocket == INVALID_SOCKET) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
connected = ConnectThroughProxy(proxy, addrConnect.ToStringIP(), addrConnect.GetPort(), hSocket, nConnectTimeout, &proxyConnectionFailed);
|
connected = ConnectThroughProxy(proxy, addrConnect.ToStringIP(), addrConnect.GetPort(), hSocket, nConnectTimeout, proxyConnectionFailed);
|
||||||
} else {
|
} else {
|
||||||
// no proxy needed (none set for target network)
|
// no proxy needed (none set for target network)
|
||||||
hSocket = CreateSocket(addrConnect);
|
hSocket = CreateSocket(addrConnect);
|
||||||
|
@ -432,7 +432,8 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
|
||||||
std::string host;
|
std::string host;
|
||||||
int port = default_port;
|
int port = default_port;
|
||||||
SplitHostPort(std::string(pszDest), port, host);
|
SplitHostPort(std::string(pszDest), port, host);
|
||||||
connected = ConnectThroughProxy(proxy, host, port, hSocket, nConnectTimeout, nullptr);
|
bool proxyConnectionFailed;
|
||||||
|
connected = ConnectThroughProxy(proxy, host, port, hSocket, nConnectTimeout, proxyConnectionFailed);
|
||||||
}
|
}
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
CloseSocket(hSocket);
|
CloseSocket(hSocket);
|
||||||
|
@ -1609,7 +1610,7 @@ void CConnman::ThreadDNSAddressSeed()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unsigned int nMaxIPs = 256; // Limits number of IPs learned from a DNS seed
|
unsigned int nMaxIPs = 256; // Limits number of IPs learned from a DNS seed
|
||||||
if (LookupHost(host.c_str(), vIPs, nMaxIPs, true)) {
|
if (LookupHost(host, vIPs, nMaxIPs, true)) {
|
||||||
for (const CNetAddr& ip : vIPs) {
|
for (const CNetAddr& ip : vIPs) {
|
||||||
int nOneDay = 24*3600;
|
int nOneDay = 24*3600;
|
||||||
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
|
CAddress addr = CAddress(CService(ip, Params().GetDefaultPort()), requiredServiceBits);
|
||||||
|
@ -1907,7 +1908,7 @@ std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const std::string& strAddNode : lAddresses) {
|
for (const std::string& strAddNode : lAddresses) {
|
||||||
CService service(LookupNumeric(strAddNode.c_str(), Params().GetDefaultPort()));
|
CService service(LookupNumeric(strAddNode, Params().GetDefaultPort()));
|
||||||
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
AddedNodeInfo addedNode{strAddNode, CService(), false, false};
|
||||||
if (service.IsValid()) {
|
if (service.IsValid()) {
|
||||||
// strAddNode is an IP:port
|
// strAddNode is an IP:port
|
||||||
|
|
|
@ -71,7 +71,7 @@ bool NetWhitebindPermissions::TryParse(const std::string str, NetWhitebindPermis
|
||||||
|
|
||||||
const std::string strBind = str.substr(offset);
|
const std::string strBind = str.substr(offset);
|
||||||
CService addrBind;
|
CService addrBind;
|
||||||
if (!Lookup(strBind.c_str(), addrBind, 0, false)) {
|
if (!Lookup(strBind, addrBind, 0, false)) {
|
||||||
error = ResolveErrMsg("whitebind", strBind);
|
error = ResolveErrMsg("whitebind", strBind);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ bool NetWhitelistPermissions::TryParse(const std::string str, NetWhitelistPermis
|
||||||
|
|
||||||
const std::string net = str.substr(offset);
|
const std::string net = str.substr(offset);
|
||||||
CSubNet subnet;
|
CSubNet subnet;
|
||||||
LookupSubNet(net.c_str(), subnet);
|
LookupSubNet(net, subnet);
|
||||||
if (!subnet.IsValid()) {
|
if (!subnet.IsValid()) {
|
||||||
error = strprintf(_("Invalid netmask specified in -whitelist: '%s'").translated, net);
|
error = strprintf(_("Invalid netmask specified in -whitelist: '%s'").translated, net);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
|
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/system.h>
|
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
#include <util/system.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
@ -59,10 +60,14 @@ std::string GetNetworkName(enum Network net) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
bool static LookupIntern(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
||||||
{
|
{
|
||||||
vIP.clear();
|
vIP.clear();
|
||||||
|
|
||||||
|
if (!ValidAsCString(name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
CNetAddr addr;
|
CNetAddr addr;
|
||||||
// From our perspective, onion addresses are not hostnames but rather
|
// From our perspective, onion addresses are not hostnames but rather
|
||||||
|
@ -71,7 +76,7 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
|
||||||
// getaddrinfo to decode them and it wouldn't make sense to resolve
|
// getaddrinfo to decode them and it wouldn't make sense to resolve
|
||||||
// them, we return a network address representing it instead. See
|
// them, we return a network address representing it instead. See
|
||||||
// CNetAddr::SetSpecial(const std::string&) for more details.
|
// CNetAddr::SetSpecial(const std::string&) for more details.
|
||||||
if (addr.SetSpecial(std::string(pszName))) {
|
if (addr.SetSpecial(name)) {
|
||||||
vIP.push_back(addr);
|
vIP.push_back(addr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +98,7 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
|
||||||
// hostname lookups.
|
// hostname lookups.
|
||||||
aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
|
aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
|
||||||
struct addrinfo *aiRes = nullptr;
|
struct addrinfo *aiRes = nullptr;
|
||||||
int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
|
int nErr = getaddrinfo(name.c_str(), nullptr, &aiHint, &aiRes);
|
||||||
if (nErr)
|
if (nErr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -131,7 +136,7 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
|
||||||
/**
|
/**
|
||||||
* Resolve a host string to its corresponding network addresses.
|
* Resolve a host string to its corresponding network addresses.
|
||||||
*
|
*
|
||||||
* @param pszName The string representing a host. Could be a name or a numerical
|
* @param name The string representing a host. Could be a name or a numerical
|
||||||
* IP address (IPv6 addresses in their bracketed form are
|
* IP address (IPv6 addresses in their bracketed form are
|
||||||
* allowed).
|
* allowed).
|
||||||
* @param[out] vIP The resulting network addresses to which the specified host
|
* @param[out] vIP The resulting network addresses to which the specified host
|
||||||
|
@ -143,28 +148,34 @@ bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsign
|
||||||
* @see Lookup(const char *, std::vector<CService>&, int, bool, unsigned int)
|
* @see Lookup(const char *, std::vector<CService>&, int, bool, unsigned int)
|
||||||
* for additional parameter descriptions.
|
* for additional parameter descriptions.
|
||||||
*/
|
*/
|
||||||
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
|
||||||
{
|
{
|
||||||
std::string strHost(pszName);
|
if (!ValidAsCString(name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::string strHost = name;
|
||||||
if (strHost.empty())
|
if (strHost.empty())
|
||||||
return false;
|
return false;
|
||||||
if (strHost.front() == '[' && strHost.back() == ']') {
|
if (strHost.front() == '[' && strHost.back() == ']') {
|
||||||
strHost = strHost.substr(1, strHost.size() - 2);
|
strHost = strHost.substr(1, strHost.size() - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LookupIntern(strHost.c_str(), vIP, nMaxSolutions, fAllowLookup);
|
return LookupIntern(strHost, vIP, nMaxSolutions, fAllowLookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a host string to its first corresponding network address.
|
* Resolve a host string to its first corresponding network address.
|
||||||
*
|
*
|
||||||
* @see LookupHost(const char *, std::vector<CNetAddr>&, unsigned int, bool) for
|
* @see LookupHost(const std::string&, std::vector<CNetAddr>&, unsigned int, bool) for
|
||||||
* additional parameter descriptions.
|
* additional parameter descriptions.
|
||||||
*/
|
*/
|
||||||
bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup)
|
bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup)
|
||||||
{
|
{
|
||||||
|
if (!ValidAsCString(name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
std::vector<CNetAddr> vIP;
|
std::vector<CNetAddr> vIP;
|
||||||
LookupHost(pszName, vIP, 1, fAllowLookup);
|
LookupHost(name, vIP, 1, fAllowLookup);
|
||||||
if(vIP.empty())
|
if(vIP.empty())
|
||||||
return false;
|
return false;
|
||||||
addr = vIP.front();
|
addr = vIP.front();
|
||||||
|
@ -174,7 +185,7 @@ bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup)
|
||||||
/**
|
/**
|
||||||
* Resolve a service string to its corresponding service.
|
* Resolve a service string to its corresponding service.
|
||||||
*
|
*
|
||||||
* @param pszName The string representing a service. Could be a name or a
|
* @param name The string representing a service. Could be a name or a
|
||||||
* numerical IP address (IPv6 addresses should be in their
|
* numerical IP address (IPv6 addresses should be in their
|
||||||
* disambiguated bracketed form), optionally followed by a port
|
* disambiguated bracketed form), optionally followed by a port
|
||||||
* number. (e.g. example.com:8333 or
|
* number. (e.g. example.com:8333 or
|
||||||
|
@ -191,16 +202,17 @@ bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup)
|
||||||
* @returns Whether or not the service string successfully resolved to any
|
* @returns Whether or not the service string successfully resolved to any
|
||||||
* resulting services.
|
* resulting services.
|
||||||
*/
|
*/
|
||||||
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
|
bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
|
||||||
{
|
{
|
||||||
if (pszName[0] == 0)
|
if (name.empty() || !ValidAsCString(name)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
int port = portDefault;
|
int port = portDefault;
|
||||||
std::string hostname;
|
std::string hostname;
|
||||||
SplitHostPort(std::string(pszName), port, hostname);
|
SplitHostPort(name, port, hostname);
|
||||||
|
|
||||||
std::vector<CNetAddr> vIP;
|
std::vector<CNetAddr> vIP;
|
||||||
bool fRet = LookupIntern(hostname.c_str(), vIP, nMaxSolutions, fAllowLookup);
|
bool fRet = LookupIntern(hostname, vIP, nMaxSolutions, fAllowLookup);
|
||||||
if (!fRet)
|
if (!fRet)
|
||||||
return false;
|
return false;
|
||||||
vAddr.resize(vIP.size());
|
vAddr.resize(vIP.size());
|
||||||
|
@ -215,10 +227,13 @@ bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault,
|
||||||
* @see Lookup(const char *, std::vector<CService>&, int, bool, unsigned int)
|
* @see Lookup(const char *, std::vector<CService>&, int, bool, unsigned int)
|
||||||
* for additional parameter descriptions.
|
* for additional parameter descriptions.
|
||||||
*/
|
*/
|
||||||
bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup)
|
bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup)
|
||||||
{
|
{
|
||||||
|
if (!ValidAsCString(name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
std::vector<CService> vService;
|
std::vector<CService> vService;
|
||||||
bool fRet = Lookup(pszName, vService, portDefault, fAllowLookup, 1);
|
bool fRet = Lookup(name, vService, portDefault, fAllowLookup, 1);
|
||||||
if (!fRet)
|
if (!fRet)
|
||||||
return false;
|
return false;
|
||||||
addr = vService[0];
|
addr = vService[0];
|
||||||
|
@ -235,12 +250,15 @@ bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLoo
|
||||||
* @see Lookup(const char *, CService&, int, bool) for additional parameter
|
* @see Lookup(const char *, CService&, int, bool) for additional parameter
|
||||||
* descriptions.
|
* descriptions.
|
||||||
*/
|
*/
|
||||||
CService LookupNumeric(const char *pszName, int portDefault)
|
CService LookupNumeric(const std::string& name, int portDefault)
|
||||||
{
|
{
|
||||||
|
if (!ValidAsCString(name)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
CService addr;
|
CService addr;
|
||||||
// "1.2:345" will fail to resolve the ip, but will still set the port.
|
// "1.2:345" will fail to resolve the ip, but will still set the port.
|
||||||
// If the ip fails to resolve, re-init the result.
|
// If the ip fails to resolve, re-init the result.
|
||||||
if(!Lookup(pszName, addr, portDefault, false))
|
if(!Lookup(name, addr, portDefault, false))
|
||||||
addr = CService();
|
addr = CService();
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
@ -768,12 +786,11 @@ bool IsProxy(const CNetAddr &addr) {
|
||||||
*
|
*
|
||||||
* @returns Whether or not the operation succeeded.
|
* @returns Whether or not the operation succeeded.
|
||||||
*/
|
*/
|
||||||
bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocket, int nTimeout, bool *outProxyConnectionFailed)
|
bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocket, int nTimeout, bool& outProxyConnectionFailed)
|
||||||
{
|
{
|
||||||
// first connect to proxy server
|
// first connect to proxy server
|
||||||
if (!ConnectSocketDirectly(proxy.proxy, hSocket, nTimeout, true)) {
|
if (!ConnectSocketDirectly(proxy.proxy, hSocket, nTimeout, true)) {
|
||||||
if (outProxyConnectionFailed)
|
outProxyConnectionFailed = true;
|
||||||
*outProxyConnectionFailed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// do socks negotiation
|
// do socks negotiation
|
||||||
|
@ -796,23 +813,25 @@ bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int
|
||||||
* Parse and resolve a specified subnet string into the appropriate internal
|
* Parse and resolve a specified subnet string into the appropriate internal
|
||||||
* representation.
|
* representation.
|
||||||
*
|
*
|
||||||
* @param pszName A string representation of a subnet of the form `network
|
* @param strSubnet A string representation of a subnet of the form `network
|
||||||
* address [ "/", ( CIDR-style suffix | netmask ) ]`(e.g.
|
* address [ "/", ( CIDR-style suffix | netmask ) ]`(e.g.
|
||||||
* `2001:db8::/32`, `192.0.2.0/255.255.255.0`, or `8.8.8.8`).
|
* `2001:db8::/32`, `192.0.2.0/255.255.255.0`, or `8.8.8.8`).
|
||||||
* @param ret The resulting internal representation of a subnet.
|
* @param ret The resulting internal representation of a subnet.
|
||||||
*
|
*
|
||||||
* @returns Whether the operation succeeded or not.
|
* @returns Whether the operation succeeded or not.
|
||||||
*/
|
*/
|
||||||
bool LookupSubNet(const char* pszName, CSubNet& ret)
|
bool LookupSubNet(const std::string& strSubnet, CSubNet& ret)
|
||||||
{
|
{
|
||||||
std::string strSubnet(pszName);
|
if (!ValidAsCString(strSubnet)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
size_t slash = strSubnet.find_last_of('/');
|
size_t slash = strSubnet.find_last_of('/');
|
||||||
std::vector<CNetAddr> vIP;
|
std::vector<CNetAddr> vIP;
|
||||||
|
|
||||||
std::string strAddress = strSubnet.substr(0, slash);
|
std::string strAddress = strSubnet.substr(0, slash);
|
||||||
// TODO: Use LookupHost(const char *, CNetAddr&, bool) instead to just get
|
// TODO: Use LookupHost(const std::string&, CNetAddr&, bool) instead to just get
|
||||||
// one CNetAddr.
|
// one CNetAddr.
|
||||||
if (LookupHost(strAddress.c_str(), vIP, 1, false))
|
if (LookupHost(strAddress, vIP, 1, false))
|
||||||
{
|
{
|
||||||
CNetAddr network = vIP[0];
|
CNetAddr network = vIP[0];
|
||||||
if (slash != strSubnet.npos)
|
if (slash != strSubnet.npos)
|
||||||
|
@ -827,7 +846,7 @@ bool LookupSubNet(const char* pszName, CSubNet& ret)
|
||||||
else // If not a valid number, try full netmask syntax
|
else // If not a valid number, try full netmask syntax
|
||||||
{
|
{
|
||||||
// Never allow lookup for netmask
|
// Never allow lookup for netmask
|
||||||
if (LookupHost(strNetmask.c_str(), vIP, 1, false)) {
|
if (LookupHost(strNetmask, vIP, 1, false)) {
|
||||||
ret = CSubNet(network, vIP[0]);
|
ret = CSubNet(network, vIP[0]);
|
||||||
return ret.IsValid();
|
return ret.IsValid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,15 @@ bool IsProxy(const CNetAddr &addr);
|
||||||
bool SetNameProxy(const proxyType &addrProxy);
|
bool SetNameProxy(const proxyType &addrProxy);
|
||||||
bool HaveNameProxy();
|
bool HaveNameProxy();
|
||||||
bool GetNameProxy(proxyType &nameProxyOut);
|
bool GetNameProxy(proxyType &nameProxyOut);
|
||||||
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
|
bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup);
|
||||||
bool LookupHost(const char *pszName, CNetAddr& addr, bool fAllowLookup);
|
bool LookupHost(const std::string& name, CNetAddr& addr, bool fAllowLookup);
|
||||||
bool Lookup(const char *pszName, CService& addr, int portDefault, bool fAllowLookup);
|
bool Lookup(const std::string& name, CService& addr, int portDefault, bool fAllowLookup);
|
||||||
bool Lookup(const char *pszName, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
|
bool Lookup(const std::string& name, std::vector<CService>& vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions);
|
||||||
CService LookupNumeric(const char *pszName, int portDefault = 0);
|
CService LookupNumeric(const std::string& name, int portDefault = 0);
|
||||||
bool LookupSubNet(const char *pszName, CSubNet& subnet);
|
bool LookupSubNet(const std::string& strSubnet, CSubNet& subnet);
|
||||||
SOCKET CreateSocket(const CService &addrConnect);
|
SOCKET CreateSocket(const CService &addrConnect);
|
||||||
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocketRet, int nTimeout, bool manual_connection);
|
bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocketRet, int nTimeout, bool manual_connection);
|
||||||
bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed);
|
bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int port, const SOCKET& hSocketRet, int nTimeout, bool& outProxyConnectionFailed);
|
||||||
/** Return readable error string for a network error code */
|
/** Return readable error string for a network error code */
|
||||||
std::string NetworkErrorString(int err);
|
std::string NetworkErrorString(int err);
|
||||||
/** Close socket and set hSocket to INVALID_SOCKET */
|
/** Close socket and set hSocket to INVALID_SOCKET */
|
||||||
|
|
|
@ -375,7 +375,7 @@ QValidator::State ProxyAddressValidator::validate(QString &input, int &pos) cons
|
||||||
{
|
{
|
||||||
Q_UNUSED(pos);
|
Q_UNUSED(pos);
|
||||||
// Validate the proxy
|
// Validate the proxy
|
||||||
CService serv(LookupNumeric(input.toStdString().c_str(), DEFAULT_GUI_PROXY_PORT));
|
CService serv(LookupNumeric(input.toStdString(), DEFAULT_GUI_PROXY_PORT));
|
||||||
proxyType addrProxy = proxyType(serv, true);
|
proxyType addrProxy = proxyType(serv, true);
|
||||||
if (addrProxy.IsValid())
|
if (addrProxy.IsValid())
|
||||||
return QValidator::Acceptable;
|
return QValidator::Acceptable;
|
||||||
|
|
|
@ -1240,7 +1240,7 @@ void RPCConsole::unbanSelectedNode()
|
||||||
QString strNode = nodes.at(i).data().toString();
|
QString strNode = nodes.at(i).data().toString();
|
||||||
CSubNet possibleSubnet;
|
CSubNet possibleSubnet;
|
||||||
|
|
||||||
LookupSubNet(strNode.toStdString().c_str(), possibleSubnet);
|
LookupSubNet(strNode.toStdString(), possibleSubnet);
|
||||||
if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet))
|
if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet))
|
||||||
{
|
{
|
||||||
clientModel->getBanTableModel()->refresh();
|
clientModel->getBanTableModel()->refresh();
|
||||||
|
|
|
@ -562,11 +562,11 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||||
|
|
||||||
if (!isSubnet) {
|
if (!isSubnet) {
|
||||||
CNetAddr resolved;
|
CNetAddr resolved;
|
||||||
LookupHost(request.params[0].get_str().c_str(), resolved, false);
|
LookupHost(request.params[0].get_str(), resolved, false);
|
||||||
netAddr = resolved;
|
netAddr = resolved;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LookupSubNet(request.params[0].get_str().c_str(), subNet);
|
LookupSubNet(request.params[0].get_str(), subNet);
|
||||||
|
|
||||||
if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) )
|
if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) )
|
||||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Invalid IP/Subnet");
|
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Invalid IP/Subnet");
|
||||||
|
|
|
@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(netbase_splithost)
|
||||||
|
|
||||||
bool static TestParse(std::string src, std::string canon)
|
bool static TestParse(std::string src, std::string canon)
|
||||||
{
|
{
|
||||||
CService addr(LookupNumeric(src.c_str(), 65535));
|
CService addr(LookupNumeric(src, 65535));
|
||||||
return canon == addr.ToString();
|
return canon == addr.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -501,7 +501,7 @@ void TorController::add_onion_cb(TorControlConnection& _conn, const TorControlRe
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
service = LookupNumeric(std::string(service_id+".onion").c_str(), Params().GetDefaultPort());
|
service = LookupNumeric(std::string(service_id+".onion"), Params().GetDefaultPort());
|
||||||
LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString());
|
LogPrintf("tor: Got service ID %s, advertising service %s\n", service_id, service.ToString());
|
||||||
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
|
if (WriteBinaryFile(GetPrivateKeyFile(), private_key)) {
|
||||||
LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", GetPrivateKeyFile().string());
|
LogPrint(BCLog::TOR, "tor: Cached service private key to %s\n", GetPrivateKeyFile().string());
|
||||||
|
|
Loading…
Reference in a new issue