diff options
author | Gabriel Davidian <gabrielius.dav@gmail.com> | 2018-03-25 18:25:09 +0000 |
---|---|---|
committer | Gabriel Davidian <gabrielius.dav@gmail.com> | 2018-03-25 18:25:09 +0000 |
commit | 4d74c78c69123a3d97293f40337e2efa5dadbff0 (patch) | |
tree | 8a5bb1358c8aff0e88e92d2534cd8eb4dc1ba8be | |
parent | 7466a26cab5d66665991433947964a638f5b957e (diff) |
Add username and ip logging for RPC method requests
-rw-r--r-- | src/httprpc.cpp | 3 | ||||
-rw-r--r-- | src/rpc/server.cpp | 6 | ||||
-rw-r--r-- | src/rpc/server.h | 1 |
3 files changed, 8 insertions, 2 deletions
diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 82ae733006..7eb9fa671c 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -158,8 +158,9 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &) } JSONRPCRequest jreq; + jreq.peerAddr = req->GetPeer().ToString(); if (!RPCAuthorized(authHeader.second, jreq.authUser)) { - LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", req->GetPeer().ToString()); + LogPrintf("ThreadRPCServer incorrect password attempt from %s\n", jreq.peerAddr); /* Deter brute-forcing If this results in a DoS the user really diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 54995ef000..c7c3b1f0d3 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -367,7 +367,11 @@ void JSONRPCRequest::parse(const UniValue& valRequest) if (!valMethod.isStr()) throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); strMethod = valMethod.get_str(); - LogPrint(BCLog::RPC, "ThreadRPCServer method=%s\n", SanitizeString(strMethod)); + if (fLogIPs) + LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s peeraddr=%s\n", SanitizeString(strMethod), + this->authUser, this->peerAddr); + else + LogPrint(BCLog::RPC, "ThreadRPCServer method=%s user=%s\n", SanitizeString(strMethod), this->authUser); // Parse params UniValue valParams = find_value(request, "params"); diff --git a/src/rpc/server.h b/src/rpc/server.h index d25268a8ab..7fc300f554 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -45,6 +45,7 @@ public: bool fHelp; std::string URI; std::string authUser; + std::string peerAddr; JSONRPCRequest() : id(NullUniValue), params(NullUniValue), fHelp(false) {} void parse(const UniValue& valRequest); |