Support binding the RPC to a Unix socket on *nix platforms (#2574)

* Support binding the RPC to a Unix socket on *nix

This commit adds unix socket support for a RPC. Some refactoring was
required in order to split out the RPC server's address struct from the
normal network address struct used for peers. It would cause
unacceptable overhead to add the unix socket length to the union.

Co-authored-by: Malte Voos <malte@malvo.org>

* add RPC socket mode to control unix socket perms

Unix socket permissions are important to control for security reasons,
and libevent defaults to 0755, which may not be what users want.

Co-authored-by: LaserEyess <LaserEyess@users.noreply.github.com>
Co-authored-by: Malte Voos <malte@malvo.org>
This commit is contained in:
LaserEyess
2022-02-23 16:09:54 -05:00
committed by GitHub
parent 13ad2b58dc
commit 706735ca88
5 changed files with 222 additions and 24 deletions

View File

@@ -21,6 +21,7 @@
struct event;
struct evhttp;
struct tr_variant;
struct tr_rpc_address;
struct libdeflate_compressor;
class tr_rpc_server
@@ -43,7 +44,7 @@ public:
std::string whitelistStr;
std::string url;
struct tr_address bindAddress;
struct tr_rpc_address* bindAddress;
struct event* start_retry_timer = nullptr;
struct evhttp* httpd = nullptr;
@@ -52,6 +53,8 @@ public:
int antiBruteForceThreshold = 0;
int loginattempts = 0;
int start_retry_counter = 0;
static int constexpr DefaultRpcSocketMode = 0750;
int rpc_socket_mode = DefaultRpcSocketMode;
tr_port port = 0;
@@ -82,6 +85,8 @@ bool tr_rpcGetWhitelistEnabled(tr_rpc_server const* server);
void tr_rpcSetWhitelist(tr_rpc_server* server, std::string_view whitelist);
int tr_rpcGetRPCSocketMode(tr_rpc_server const* server);
std::string const& tr_rpcGetWhitelist(tr_rpc_server const* server);
void tr_rpcSetPassword(tr_rpc_server* server, std::string_view password);