init: allow UNIX socket path for -proxy and -onion

pull/27375/head
Matthew Zipkin 1 year ago
parent c3bd43142e
commit c65c0d0163
No known key found for this signature in database
GPG Key ID: E7E2984B6289C93A

@ -1298,8 +1298,15 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
std::string host_out; std::string host_out;
uint16_t port_out{0}; uint16_t port_out{0};
if (!SplitHostPort(socket_addr, port_out, host_out)) { if (!SplitHostPort(socket_addr, port_out, host_out)) {
#if HAVE_SOCKADDR_UN
// Allow unix domain sockets for -proxy and -onion e.g. unix:/some/file/path
if ((port_option != "-proxy" && port_option != "-onion") || socket_addr.find(ADDR_PREFIX_UNIX) != 0) {
return InitError(InvalidPortErrMsg(port_option, socket_addr)); return InitError(InvalidPortErrMsg(port_option, socket_addr));
} }
#else
return InitError(InvalidPortErrMsg(port_option, socket_addr));
#endif
}
} }
} }
@ -1365,12 +1372,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default // -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
std::string proxyArg = args.GetArg("-proxy", ""); std::string proxyArg = args.GetArg("-proxy", "");
if (proxyArg != "" && proxyArg != "0") { if (proxyArg != "" && proxyArg != "0") {
Proxy addrProxy;
if (IsUnixSocketPath(proxyArg)) {
addrProxy = Proxy(proxyArg, proxyRandomize);
} else {
const std::optional<CService> proxyAddr{Lookup(proxyArg, 9050, fNameLookup)}; const std::optional<CService> proxyAddr{Lookup(proxyArg, 9050, fNameLookup)};
if (!proxyAddr.has_value()) { if (!proxyAddr.has_value()) {
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg)); return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
} }
Proxy addrProxy = Proxy(proxyAddr.value(), proxyRandomize); addrProxy = Proxy(proxyAddr.value(), proxyRandomize);
}
if (!addrProxy.IsValid()) if (!addrProxy.IsValid())
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg)); return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
@ -1395,12 +1408,17 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
_("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for " _("Outbound connections restricted to Tor (-onlynet=onion) but the proxy for "
"reaching the Tor network is explicitly forbidden: -onion=0")); "reaching the Tor network is explicitly forbidden: -onion=0"));
} }
} else {
if (IsUnixSocketPath(onionArg)) {
onion_proxy = Proxy(onionArg, proxyRandomize);
} else { } else {
const std::optional<CService> addr{Lookup(onionArg, 9050, fNameLookup)}; const std::optional<CService> addr{Lookup(onionArg, 9050, fNameLookup)};
if (!addr.has_value() || !addr->IsValid()) { if (!addr.has_value() || !addr->IsValid()) {
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg)); return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
} }
onion_proxy = Proxy{addr.value(), proxyRandomize};
onion_proxy = Proxy(addr.value(), proxyRandomize);
}
} }
} }

Loading…
Cancel
Save