#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix.hpp>
+#include <boost/algorithm/string/predicate.hpp>
#include "OSDCap.h"
#include "common/config.h"
}
}
if (nspace) {
+ if ((*nspace)[nspace->length() - 1] == '*' &&
+ boost::starts_with(ns, nspace->substr(0, nspace->length() - 1))) {
+ return true;
+ }
+
if (*nspace != ns) {
return false;
}
spaces = +ascii::space;
pool_name %= -(spaces >> lit("pool") >> (lit('=') | spaces) >> str);
- nspace %= (spaces >> lit("namespace") >> (lit('=') | spaces) >> estr);
+ nspace %= (spaces >> lit("namespace")
+ >> (lit('=') | spaces)
+ >> estr >> -char_('*'));
// match := [pool[=]<poolname> [namespace[=]<namespace>] | auid <123>] [object_prefix <prefix>]
auid %= (spaces >> lit("auid") >> spaces >> int_);
"allow pool foo namespace=nfoo rwx ; allow pool bar namespace=nbar r",
"allow pool foo namespace nfoo rwx ;allow pool bar namespace nbar r",
"allow pool foo namespace=nfoo rwx; allow pool bar namespace nbar object_prefix rbd r",
+ "allow pool foo namespace=nfoo* rwx",
"allow pool foo namespace=\"\" rwx; allow pool bar namespace='' object_prefix rbd r",
"allow pool foo namespace \"\" rwx; allow pool bar namespace '' object_prefix rbd r",
"profile abc, profile abc pool=bar, profile abc pool=bar namespace=foo",
"allow rwx namespace",
"allow namespace",
"allow namespace=foo",
+ "allow namespace=f*oo",
"allow rwx auid 123 namespace asdf",
"allow wwx pool ''",
"allow rwx tag application key value",
ASSERT_FALSE(cap.is_capable("baz", "", 0, {}, "fo", true, true, {{"cls", true, true, true}}));
}
+TEST(OSDCap, Namespace) {
+ OSDCap cap;
+ ASSERT_TRUE(cap.parse("allow rw namespace=nfoo"));
+
+ ASSERT_TRUE(cap.is_capable("bar", "nfoo", 0, {}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("bar", "", 0, {}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("bar", "nfoobar", 0, {}, "foo", true, true, {}));
+}
+
+TEST(OSDCap, NamespaceGlob) {
+ OSDCap cap;
+ ASSERT_TRUE(cap.parse("allow rw namespace=nfoo*"));
+
+ ASSERT_TRUE(cap.is_capable("bar", "nfoo", 0, {}, "foo", true, true, {}));
+ ASSERT_TRUE(cap.is_capable("bar", "nfoobar", 0, {}, "foo", true, true, {}));
+
+ ASSERT_FALSE(cap.is_capable("bar", "", 0, {}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("bar", "nfo", 0, {}, "foo", true, true, {}));
+}
+
TEST(OSDCap, BasicR) {
OSDCap cap;
ASSERT_TRUE(cap.parse("allow r", NULL));