#include <errno.h>
#include "common/config.h"
#include "common/debug.h"
+#include "common/Formatter.h"
#include "MonCaps.h"
#include "mon_types.h"
return false;
return true;
}
+
+// ----
+
+string rwx_to_string(rwx_t r)
+{
+ string s;
+ if (r & MON_CAP_R)
+ s += "r";
+ else
+ s += "-";
+ if (r & MON_CAP_W)
+ s += "w";
+ else
+ s += "-";
+ if (r & MON_CAP_X)
+ s += "x";
+ else
+ s += "-";
+ return s;
+}
+
+// ----
+
+void MonCap::dump(Formatter *f) const
+{
+ f->dump_string("allow", rwx_to_string(allow));
+ f->dump_string("deny", rwx_to_string(deny));
+}
+
+void MonCap::generate_test_instances(list<MonCap*>& o)
+{
+ o.push_back(new MonCap);
+ o.push_back(new MonCap(MON_CAP_R, MON_CAP_W));
+ o.push_back(new MonCap(MON_CAP_RW, MON_CAP_ALL));
+}
+
+// ----
+
+void MonCaps::encode(bufferlist& bl) const
+{
+ __u8 v = 2;
+ ::encode(v, bl);
+ ::encode(text, bl);
+ ::encode(default_action, bl);
+ ::encode(services_map, bl);
+ ::encode(pool_auid_map, bl);
+ ::encode(allow_all, bl);
+ ::encode(auid, bl);
+ ::encode(cmd_allow, bl);
+}
+
+void MonCaps::decode(bufferlist::iterator& bl)
+{
+ __u8 v;
+ ::decode(v, bl);
+ ::decode(text, bl);
+ ::decode(default_action, bl);
+ ::decode(services_map, bl);
+ ::decode(pool_auid_map, bl);
+ ::decode(allow_all, bl);
+ ::decode(auid, bl);
+ ::decode(cmd_allow, bl);
+}
+
+void MonCaps::dump(Formatter *f) const
+{
+ f->dump_string("text", text);
+ f->dump_string("default_action", rwx_to_string(default_action));
+ f->dump_int("allow_all", allow_all);
+ f->dump_unsigned("auid", auid);
+ f->open_object_section("services_map");
+ for (map<int,MonCap>::const_iterator p = services_map.begin(); p != services_map.end(); ++p) {
+ f->open_object_section("moncap");
+ p->second.dump(f);
+ f->close_section();
+ }
+ f->close_section();
+ f->open_object_section("pool_auid_map");
+ for (map<int,MonCap>::const_iterator p = pool_auid_map.begin(); p != pool_auid_map.end(); ++p) {
+ f->open_object_section("moncap");
+ p->second.dump(f);
+ f->close_section();
+ }
+ f->close_section();
+}
+
+void MonCaps::generate_test_instances(list<MonCaps*>& o)
+{
+ o.push_back(new MonCaps);
+ // FIXME.
+}
#define CEPH_MONCAPS_H
#include "include/types.h"
-//#include ""
#define MON_CAP_R 0x1
#define MON_CAP_W 0x2
struct MonCap {
rwx_t allow;
rwx_t deny;
+
MonCap() : allow(0), deny(0) {}
+ MonCap(rwx_t a, rwx_t d) : allow(a), deny(d) {}
void encode(bufferlist& bl) const {
::encode(allow, bl);
::decode(allow, bl);
::decode(deny, bl);
}
+ void dump(Formatter *f) const;
+ static void generate_test_instances(list<MonCap*>& o);
};
WRITE_RAW_ENCODER(MonCap);
rwx_t default_action;
map<int, MonCap> services_map;
map<int, MonCap> pool_auid_map;
- bool get_next_token(string s, size_t& pos, string& token);
- bool is_rwx(string& token, rwx_t& cap_val);
- int get_service_id(string& token);
bool allow_all;
uint64_t auid;
// command whitelist
list<list<string> > cmd_allow;
+ bool get_next_token(string s, size_t& pos, string& token);
+ bool is_rwx(string& token, rwx_t& cap_val);
+ int get_service_id(string& token);
+
public:
MonCaps()
: text(), default_action(0),
allow_all(false), auid(CEPH_AUTH_UID_DEFAULT)
{}
+
const string& get_str() const { return text; }
+
bool parse(bufferlist::iterator& iter);
rwx_t get_caps(int service) const;
bool check_privileges(int service, int req_perm,
void set_allow_all(bool allow) { allow_all = allow; }
void set_auid(uint64_t uid) { auid = uid; }
- void encode(bufferlist& bl) const {
- __u8 v = 2;
- ::encode(v, bl);
- ::encode(text, bl);
- ::encode(default_action, bl);
- ::encode(services_map, bl);
- ::encode(pool_auid_map, bl);
- ::encode(allow_all, bl);
- ::encode(auid, bl);
- ::encode(cmd_allow, bl);
- }
-
- void decode(bufferlist::iterator& bl) {
- __u8 v;
- ::decode(v, bl);
- ::decode(text, bl);
- ::decode(default_action, bl);
- ::decode(services_map, bl);
- ::decode(pool_auid_map, bl);
- ::decode(allow_all, bl);
- ::decode(auid, bl);
- ::decode(cmd_allow, bl);
- }
+ void encode(bufferlist& bl) const;
+ void decode(bufferlist::iterator& bl);
+ void dump(Formatter *f) const;
+ static void generate_test_instances(list<MonCaps*>& o);
};
WRITE_CLASS_ENCODER(MonCaps);
inline ostream& operator<<(ostream& out, const MonCaps& m) {
return out << m.get_str();
}
+
#endif