Add MLS support to policy rep branch
cover Add MLS support to policy rep branch
The first patch generalizes an output function.
The second patch adds MLS support to the policy representation. The object representing user statements now supports MLS as well.
-mdg
Signature · 4 lines
-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/2 Generalize an output function to make display easier.
Generalize an output function to make display easier.
---
libpolicyrep/include/policyrep/policy_base.hpp | 39 36 + 3 - 0 ! libpolicyrep/src/policy_base.cpp | 22 4 + 18 - 0 ! 2 files changed, 40 insertions(+), 21 deletions(-)
libpolicyrep/src/policy_base.cpp +4 -18
@@ -37,30 +37,16 @@ namespace policyrep { if (set.size() > 1) o << "{ "; - StringSet::const_iterator i; - bool first = true; - for (i = set.begin(); i != set.end(); ++i) { - if (first) - first = false; - else - o << " "; - o << *i; - } + + output_container(o, set.begin(), set.end(), " "); + if (set.size() > 1) o << " }"; } void output_set_comma(std::ostream& o, const StringSet& set) { - StringSet::const_iterator i; - bool first = true; - for (i = set.begin(); i != set.end(); ++i) { - if (first) - first = false; - else - o << ", "; - o << *i; - } + output_container(o, set.begin(), set.end(), ", "); } std::ostream& operator<<(std::ostream& o, const Node& n)
libpolicyrep/include/policyrep/policy_base.hpp +36 -3
@@ -8,11 +8,13 @@ #include <string> #include <functional> #include <ostream> +#include <iterator> #include <boost/shared_ptr.hpp> #include <boost/iterator/iterator_facade.hpp> namespace policyrep { + using std::string; // Forward declarations class Node;
@@ -34,6 +36,37 @@ namespace policyrep { typedef boost::shared_ptr<StringVector> StringVectorPtr; // Output (string output) + template<class iter> + void output_container(std::ostream& o, const iter& beg, const iter& end, + const string sep) + { + bool first = true; + for(iter i = beg; i != end; i++) + { + if(!first){ + o << sep; + } + o << *i; + first = false; + } + } + + template<class iter> + void bracket_output_container(std::ostream& o, const iter& beg, + const iter& end, const string sep, + const string pre, const string post) + { + iter temp = beg; + ++temp; + if(temp != end){ + o << pre; + } + output_container(o, beg, end, sep); + if(temp != end){ + o << post; + } + } + std::ostream& operator<<(std::ostream& o, const Node& n); void output_set_space(std::ostream& o, const StringSet& set);
@@ -149,10 +182,10 @@ namespace policyrep { virtual void make_child(NodePtr node); template<class T> - void append_children(T begin, T end) + void append_children(T start, T finish) { - for (; begin != end; ++begin) - append_child(*begin); + for (; start != finish; ++start) + append_child(*start); } virtual NodeVector& children();
Signature · 4 lines
-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/2 Add mls to the policy representation.
In reply to Mark GoldmanAdds objects to represent sensitivity, dominance, category and level statements.
Add mls additions to the object representing user statements.
---
libpolicyrep/include/policyrep/mls.hpp | 166 166 + 0 - 0 ! libpolicyrep/include/policyrep/policy.hpp | 1 1 + 0 - 0 ! libpolicyrep/include/policyrep/user.hpp | 18 18 + 0 - 0 ! libpolicyrep/src/policy_parse.y | 87 73 + 14 - 0 ! libpolicyrep/src/user.cpp | 32 31 + 1 - 0 ! libpolicyrep/tests/example.te | 17 17 + 0 - 0 ! libpolicyrep/tests/libpolicyrep-test.cpp | 14 14 + 0 - 0 ! 7 files changed, 320 insertions(+), 15 deletions(-)
libpolicyrep/include/policyrep/mls.hpp new file +166 -0
@@ -0,0 +1,166 @@ +/* Author: Mark Goldman <[email protected]> */ + +#ifndef __mls_hpp__ +#define __mls_hpp__ + +#include <policyrep/policy_base.hpp> + +namespace policyrep +{ + + // + // Sensitivity + // + + struct SensitivityImpl; + class Sensitivity : public Node + { + public: + Sensitivity(); + Sensitivity(const std::string& name); + Sensitivity(const Sensitivity& other); + virtual ~Sensitivity(); + virtual void operator=(const Sensitivity& other); + + template<class T> + Sensitivity(const std::string& name, T begin, T end) + { + init(); + set_name(name); + aliases().insert(begin, end); + } + + virtual const std::string& get_name() const; + virtual void set_name(const std::string& name); + + virtual StringSet& aliases(); + protected: + virtual void do_output(std::ostream& o, const OutputFormatter& op) const; + void init(); + SensitivityImpl* impl; + }; + typedef boost::shared_ptr<Sensitivity> SensitivityPtr; + + // + // Dominance + // + + struct DominanceImpl; + class Dominance : public Node + { + public: + Dominance(); + Dominance(const Dominance& other); + virtual ~Dominance(); + virtual void operator=(const Dominance& other); + + template<class T> + Dominance(T begin, T end) + { + init(); + ordering().insert(ordering().begin(), begin, end); + } + + virtual StringVector& ordering(); + protected: + virtual void do_output(std::ostream& o, const OutputFormatter& op) const; + void init(); + DominanceImpl* impl; + }; + typedef boost::shared_ptr<Dominance> DominancePtr; + + // + // Category + // + + struct CategoryImpl; + class Category : public Node + { + public: + Category(); + Category(const std::string& name); + Category(const Category& other); + virtual ~Category(); + virtual void operator=(const Category& other); + + template<class T> + Category(const std::string& name, T begin, T end) + { + init(); + set_name(name); + aliases().insert(begin, end); + } + + virtual const std::string& get_name() const; + virtual void set_name(const std::string& name); + + virtual StringSet& aliases(); + protected: + virtual void do_output(std::ostream& o, const OutputFormatter& op) const; + void init(); + CategoryImpl* impl; + }; + typedef boost::shared_ptr<Category> CategoryPtr; + + // + // Level + // + + struct LevelImpl; + class Level : public Node + { + public: + Level(); + Level(const std::string& name); + Level(const Level& other); + virtual ~Level(); + virtual void operator=(const Level& other); + + template<class T> + Level(const std::string& name, T begin, T end) + { + init(); + set_name(name); + categories().insert(begin, end); + } + + virtual const std::string& get_name() const; + virtual void set_name(const std::string& name); + + virtual StringSet& categories(); + virtual void do_output_brief(std::ostream& o, const OutputFormatter& op) const; + protected: + virtual void do_output(std::ostream& o, const OutputFormatter& op) const; + void init(); + LevelImpl* impl; + }; + typedef boost::shared_ptr<Level> LevelPtr; + + // + // Range + // + + struct RangeImpl; + class Range : public Node + { + public: + Range(); + Range(LevelPtr low); + Range(LevelPtr low, LevelPtr high); + Range(const Range& other); + virtual ~Range(); + virtual const LevelPtr& get_low() const; + virtual const LevelPtr& get_high() const; + virtual LevelPtr& get_low(); + virtual LevelPtr& get_high(); + virtual void operator=(const Range& other); + virtual void do_output(std::ostream& o, const OutputFormatter& op) const; + protected: + void init(); + RangeImpl* impl; + }; + typedef boost::shared_ptr<Range> RangePtr; + +} // namespace policyrep + +#endif
libpolicyrep/include/policyrep/policy.hpp +1 -0
@@ -10,6 +10,7 @@ #include <policyrep/conditional.hpp> #include <policyrep/rbac.hpp> #include <policyrep/user.hpp> +#include <policyrep/mls.hpp> #include <policyrep/optional.hpp> namespace policyrep
libpolicyrep/src/policy_parse.y +73 -14
127 lines not on this page · raw message
libpolicyrep/tests/example.te +17 -0
@@ -34,9 +34,26 @@ role bar_r; bool foo true; user foo_u roles bar_r; +user fooyou_u roles bar_r level s1 range s1:c2 - s12:c3; +user fubu_u roles bar_r level s1 range s3 - s13:c3,c5,c12.c34; +user footoo_u roles bar_r level s1:c3,c12.c20 range s1; user unfoo_u; +sensitivity s1; +sensitivity s2 alias whiskey; +sensitivity s3 alias {tango foxtrot}; + +category c1; +category c2 alias alpha; +category c3 alias { bravo delta }; + +level s1 ; +level s2:c1.c3; +level s3:c1, c2,c3; + +dominance { s1 s2 s3 } + if (foo) { allow foo bar : file read; }
libpolicyrep/tests/libpolicyrep-test.cpp +14 -0
@@ -47,7 +47,21 @@ void test() UserPtr u(new User("bang")); u->roles().insert("bust"); mod->append_child(u); + + SensitivityPtr sen(new Sensitivity("s1")); + sen->aliases().insert("whiskey"); + sen->aliases().insert("tango"); + mod->append_child(sen); + CategoryPtr cat(new Category("c1")); + cat->aliases().insert("alpha"); + cat->aliases().insert("delta"); + mod->append_child(cat); + + LevelPtr lev(new Level("l1")); + lev->categories().insert("c1"); + mod->append_child(lev); + std::cout << "============ basic test ============" << std::endl; output_tree(std::cout, pol);
libpolicyrep/src/user.cpp +31 -1
@@ -19,6 +19,7 @@ */ #include <policyrep/user.hpp> +#include <policyrep/mls.hpp> namespace policyrep {
@@ -30,6 +31,8 @@ namespace policyrep struct UserImpl { std::string name; + LevelPtr level; + RangePtr range; StringSet roles; };
@@ -53,7 +56,9 @@ namespace policyrep *impl = *other.impl; } - User::~User() { delete impl; } + User::~User() { + delete impl; + } void User::operator=(const User& other) {
@@ -75,6 +80,23 @@ namespace policyrep return impl->roles; } + void User::set_level(LevelPtr level){ + impl->level = level; + } + + void User::set_range_low(LevelPtr low){ + impl->range->get_low() = low; + } + + void User::set_range_high(LevelPtr high){ + impl->range->get_high() = high; + } + + void User::set_range(RangePtr r) + { + impl->range = r; + } + void User::do_output(std::ostream& o, const OutputFormatter& op) const { o << "user " << impl->name;
@@ -82,6 +104,14 @@ namespace policyrep o << " roles "; output_set_comma(o, impl->roles); } + if(impl->level){ + o << " level "; + impl->level->do_output_brief(o, op); + } + if(impl->range){ + o << " range "; + impl->range->do_output(o, op); + } o << ";"; }
libpolicyrep/include/policyrep/user.hpp +18 -0
@@ -4,6 +4,7 @@ #define __user_hpp__ #include <policyrep/policy_base.hpp> +#include <policyrep/mls.hpp> namespace policyrep {
@@ -30,8 +31,25 @@ namespace policyrep roles().insert(roles_begin, end); } + template<class T> + User(const std::string& name, T roles_begin, T end, + LevelPtr& level, LevelPtr& low, LevelPtr& high) + { + init(); + set_name(name); + roles().insert(roles_begin, end); + set_level(level); + set_range_low(low); + set_range_high(high); + } + + virtual const std::string& get_name() const; virtual void set_name(const std::string& name); + virtual void set_level(LevelPtr level); + virtual void set_range_low(LevelPtr low); + virtual void set_range_high(LevelPtr high); + virtual void set_range(RangePtr r); virtual StringSet& roles(); protected:
Signature · 4 lines
-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 7 lines · Mark Goldman
The first patch generalizes an output function.
The second patch adds MLS support to the policy representation. The object representing user statements now supports MLS as well.
-mdg
Both merged, r2546 and r2547 respectively.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.