1#include <xrpld/rpc/Role.h>
3#include <boost/beast/http/field.hpp>
4#include <boost/utility/string_view.hpp>
15 "ripple::passwordUnrequiredOrSentCorrect : non-empty admin nets");
16 bool const passwordRequired =
19 return !passwordRequired ||
20 ((params[
"admin_password"].
isString() &&
22 (params[
"admin_user"].isString() &&
44 auto ipNet = boost::asio::ip::make_network_v4(addrString);
45 for (
auto const& net : nets4)
47 if (ipNet.is_subnet_of(net) || ipNet == net)
54 auto ipNet = boost::asio::ip::make_network_v6(addrString);
55 for (
auto const& net : nets6)
57 if (ipNet.is_subnet_of(net) || ipNet == net)
113 Role const& required,
148 if (firstNonSpace == std::string_view::npos)
153 ret = ret.
substr(firstNonSpace);
159 if (
unsigned char const c = ret.
back();
160 c ==
' ' || c ==
'\r' || c ==
'\n')
163 if (lastNonSpace == std::string_view::npos)
168 ret = ret.
substr(0, lastNonSpace + 1);
179 if (ret.
front() ==
'"')
195 if (ret.
front() ==
'[')
202 auto const closeBracket =
204 return std::isxdigit(c) || c ==
':' || c ==
'.' || c ==
' ';
209 if (closeBracket == ret.
end() || (*closeBracket) !=
']')
225 return std::isxdigit(c) || c ==
' ';
230 if (colon == ret.
end() || (*colon) ==
':')
236 if (
std::size_t colon = ret.
find(
':'); colon != std::string_view::npos)
237 ret = ret.
substr(0, colon);
246 if (
auto it = request.find(boost::beast::http::field::forwarded);
249 auto ascii_tolower = [](
char c) ->
char {
250 return ((
static_cast<unsigned>(c) - 65U) < 26) ? c +
'a' -
'A' : c;
260 [&ascii_tolower](
char c1,
char c2) {
261 return ascii_tolower(c1) == ascii_tolower(c2);
264 if (found == it->value().end())
267 found += forStr.size();
273 if (pos != std::string_view::npos)
276 return it->value().size() - forStr.size();
283 if (
auto it = request.find(
"X-Forwarded-For"); it != request.end())
287 if (found == boost::string_view::npos)
288 found = it->value().length();
std::string asString() const
Returns the unquoted string value.
A version-independent IP address and port combination.
Address const & address() const
Returns the address portion of this endpoint.
Tracks load and resource consumption.
virtual Consumer newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
virtual Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)=0
Create a new unlimited endpoint keyed by forwarded IP.
T find_first_not_of(T... args)
T find_first_of(T... args)
T find_last_not_of(T... args)
boost::asio::ip::address Address
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Resource::Consumer requestInboundEndpoint(Resource::Manager &manager, beast::IP::Endpoint const &remoteAddress, Role const &role, std::string_view user, std::string_view forwardedFor)
static std::string_view extractIpAddrFromField(std::string_view field)
bool isAdmin(Port const &port, Json::Value const ¶ms, beast::IP::Address const &remoteIp)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
std::string_view forwardedFor(http_request_type const &request)
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
bool passwordUnrequiredOrSentCorrect(Port const &port, Json::Value const ¶ms)
Role
Indicates the level of administrative permission to grant.
Role requestRole(Role const &required, Port const &port, Json::Value const ¶ms, beast::IP::Endpoint const &remoteIp, std::string_view user)
Return the allowed privilege role.
bool ipAllowed(beast::IP::Address const &remoteIp, std::vector< boost::asio::ip::network_v4 > const &nets4, std::vector< boost::asio::ip::network_v6 > const &nets6)
True if remoteIp is in any of adminIp.
T remove_prefix(T... args)
T remove_suffix(T... args)
Configuration information for a Server listening port.
std::vector< boost::asio::ip::network_v6 > admin_nets_v6
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
std::string admin_password
std::vector< boost::asio::ip::network_v4 > admin_nets_v4