#include "OSDCap.h"
#include "common/config.h"
#include "common/debug.h"
+#include "include/ipaddr.h"
using std::ostream;
using std::vector;
return out;
}
+void OSDCapGrant::set_network(const string& n)
+{
+ network = n;
+ network_valid = ::parse_network(n.c_str(), &network_parsed, &network_prefix);
+}
+
bool OSDCapGrant::allow_all() const
{
if (profile.is_valid()) {
std::vector<bool>* class_allowed) const
{
osd_rwxa_t allow = 0;
+
+ if (network.size() &&
+ (!network_valid ||
+ !network_contains(network_parsed,
+ network_prefix,
+ addr))) {
+ return false;
+ }
+
if (profile.is_valid()) {
return std::any_of(profile_grants.cbegin(), profile_grants.cend(),
[&](const OSDCapGrant& grant) {
OSDCapSpec spec;
OSDCapProfile profile;
string network;
+ entity_addr_t network_parsed;
+ unsigned network_prefix = 0;
+ bool network_valid = true;
// explicit grants that a profile grant expands to; populated as
// needed by expand_profile() and cached here.
boost::optional<string> n = {})
: match(m), spec(s) {
if (n) {
- network = *n;
+ set_network(*n);
}
}
explicit OSDCapGrant(const OSDCapProfile& profile,
boost::optional<string> n = {})
: profile(profile) {
if (n) {
- network = *n;
+ set_network(*n);
}
expand_profile();
}
+ void set_network(const string& n);
+
bool allow_all() const;
bool is_capable(const string& pool_name, const string& ns, int64_t pool_auid,
const OSDCapPoolTag::app_map_t& application_metadata,
{{"rbd", "other function", true, true, true}}, addr));
}
+TEST(OSDCap, network) {
+ entity_addr_t a, b, c;
+ a.parse("10.1.2.3");
+ b.parse("192.168.2.3");
+ c.parse("192.167.2.3");
+
+ OSDCap cap;
+ ASSERT_TRUE(cap.parse("allow * network 192.168.0.0/16, allow * network 10.0.0.0/8", NULL));
+
+ ASSERT_TRUE(cap.is_capable("foo", "", 0, {}, "asdf", true, true, {{"cls", "", true, true, true}}, a));
+ ASSERT_TRUE(cap.is_capable("foo", "", 0, {}, "asdf", true, true, {{"cls", "", true, true, true}}, b));
+ ASSERT_FALSE(cap.is_capable("foo", "", 0, {}, "asdf", true, true, {{"cls", "", true, true, true}}, c));
+}