diff options
| author | selsta <selsta@sent.at> | 2026-03-25 20:37:18 +0100 |
|---|---|---|
| committer | selsta <selsta@sent.at> | 2026-04-01 18:06:10 +0200 |
| commit | 7f2cfe9294ec1fa7bece2a8069114c1b6985650f (patch) | |
| tree | 06a5d19a645f700b02b9bdcacaff915c7bd9974a /src/rpc/daemon_handler.cpp | |
| parent | dd0fb6c7552330a088033b0cfba0ba570bbbfd15 (diff) | |
| download | monzero-core-7f2cfe9294ec1fa7bece2a8069114c1b6985650f.tar.gz monzero-core-7f2cfe9294ec1fa7bece2a8069114c1b6985650f.tar.xz monzero-core-7f2cfe9294ec1fa7bece2a8069114c1b6985650f.zip | |
zmq: add restricted rpc mode
Diffstat (limited to 'src/rpc/daemon_handler.cpp')
| -rw-r--r-- | src/rpc/daemon_handler.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp index c1e4c10bf..671889ddd 100644 --- a/src/rpc/daemon_handler.cpp +++ b/src/rpc/daemon_handler.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "daemon_handler.h" +#include "rpc/zmq_restricted_methods.h" #include <algorithm> #include <cstring> @@ -109,12 +110,14 @@ namespace rpc }; } // anonymous - DaemonHandler::DaemonHandler(cryptonote::core& c, t_p2p& p2p) - : m_core(c), m_p2p(p2p) + DaemonHandler::DaemonHandler(cryptonote::core& c, t_p2p& p2p, bool restricted) + : m_core(c), m_p2p(p2p), m_restricted(restricted) { const auto last_sorted = std::is_sorted_until(std::begin(handlers), std::end(handlers)); if (last_sorted != std::end(handlers)) throw std::logic_error{std::string{"ZMQ JSON-RPC handlers map is not properly sorted, see "} + last_sorted->method_name}; + + check_blocked_methods_sorted(); } void DaemonHandler::handle(const GetHeight::Request& req, GetHeight::Response& res) @@ -930,13 +933,24 @@ namespace rpc epee::byte_slice DaemonHandler::handle(std::string&& request) { - MDEBUG("Handling RPC request: " << request); + if (m_restricted) + MDEBUG("Handling RPC request"); + else + MDEBUG("Handling RPC request: " << request); try { FullMessage req_full(std::move(request), true); const std::string request_type = req_full.getRequestType(); + if (m_restricted && is_blocked_in_restricted_mode(request_type)) + { + Message fail; + fail.status = Message::STATUS_FAILED; + fail.error_details = "\"" + request_type + "\" is not available in restricted mode."; + return FullMessage::getResponse(fail, req_full.getID()); + } + const auto matched_handler = std::lower_bound(std::begin(handlers), std::end(handlers), request_type); if (matched_handler == std::end(handlers) || matched_handler->method_name != request_type) return BAD_REQUEST(request_type, req_full.getID()); |
