Skip to contentSkip to conversation

Add user object to libpolicyrep

PATCH In review [email protected] 1 participant 3 messages Jul 23, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover Add user object to libpolicyrep

Added User object to libpolicyrep.

Signed-off-by Joshua Brindle
 include/policyrep/policy.hpp |    1 
 include/policyrep/user.hpp   |   46 ++++++++++++++++++++++
 src/policy_parse.y           |    8 +++
 src/user.cpp                 |   89 +++++++++++++++++++++++++++++++++++++++++++
 tests/example.te             |    4 +
 tests/libpolicyrep-test.cpp  |    4 +
 6 files changed, 152 insertions(+)
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.
#1 lore raw

PATCH 1/1 Add users to libpolicyrep

 include/policyrep/policy.hpp |    1 
 include/policyrep/user.hpp   |   46 ++++++++++++++++++++++
 src/policy_parse.y           |    8 +++
 src/user.cpp                 |   89 +++++++++++++++++++++++++++++++++++++++++++
 tests/example.te             |    4 +
 tests/libpolicyrep-test.cpp  |    4 +
 6 files changed, 152 insertions(+)
libpolicyrep/include/policyrep/user.hpp new file +46 -0
Index: cpp-policyrep/libpolicyrep/include/policyrep/user.hpp
===================================================================
@@ -0,0 +1,46 @@
+/* Author: Mark Goldman <[email protected]> */
+
+#ifndef __user_hpp__
+#define __user_hpp__
+
+#include <policyrep/policy_base.hpp>
+
+namespace policyrep
+{
+
+	//
+	// User
+	//
+
+	struct UserImpl;
+	class User : public Node
+	{
+		public:
+			User();
+			User(const std::string& name);
+			User(const User& other);
+			virtual ~User();
+			virtual void operator=(const User& other);
+
+			template<class T>
+				User(const std::string& name, T roles_begin, T end)
+				{
+					init();
+					set_name(name);
+					roles().insert(roles_begin, end);
+				}
+
+			virtual const std::string& get_name() const;
+			virtual void set_name(const std::string& name);
+
+			virtual StringSet& roles();
+		protected:
+			virtual void do_output(std::ostream& o, const OutputFormatter& op) const;
+			void init();
+			UserImpl* impl;
+	};
+	typedef boost::shared_ptr<User> UserPtr;
+
+} // namespace policyrep
+
+#endif
libpolicyrep/src/policy_parse.y +8 -0
Index: cpp-policyrep/libpolicyrep/src/policy_parse.y
===================================================================
@@ -117,6 +117,7 @@ policyrep::policy_parser::token_type
 %type <pnode> attribute_def
 %type <pnode> type_def
 %type <pnode> role_type_def
+%type <pnode> user_role_def
 %type <pnode> typealias_def
 %type <pnode> typeattribute_def
 %type <pnode> allow_def
@@ -240,6 +241,8 @@ policy_statement        : class_def
                         | typeattribute_def
 			/* Roles */
 			| role_type_def
+			/* Users */
+			| user_role_def
 			/* rules */
 			| allow_def
 			| auditallow_def
@@ -435,6 +438,11 @@ role_type_def		: ROLE IDENTIFIER TYPES i
  			| ROLE IDENTIFIER SEMI
 			  { $$ = new Role(*$2); delete $2; }
                         ;
+user_role_def		: USER IDENTIFIER ROLES id_comma_list SEMI
+                          { $$ = new User(*$2, $4->begin(), $4->end()); delete $2; delete $4; }
+ 			| USER IDENTIFIER SEMI
+			  { $$ = new User(*$2); delete $2; }
+                        ;
 /*
 role_dominance		: DOMINANCE LBRACE roles RBRACE { $$ = $3; check($$); }
 			;
libpolicyrep/src/user.cpp new file +89 -0

89 lines not on this page · raw message

libpolicyrep/tests/example.te +4 -0
Index: cpp-policyrep/libpolicyrep/tests/example.te
===================================================================
@@ -27,6 +27,10 @@ role foo_r types user_t;
 
 role bar_r;
 
+user foo_u roles bar_r;
+
+user unfoo_u;
+
 if (foo) {
    allow foo bar : file read;
 }
libpolicyrep/tests/libpolicyrep-test.cpp +4 -0
Index: cpp-policyrep/libpolicyrep/tests/libpolicyrep-test.cpp
===================================================================
@@ -43,6 +43,10 @@ void test()
 	RolePtr r(new Role("foo"));
 	r->types().insert("foo");
 	mod->append_child(r);       
+
+	UserPtr u(new User("bang"));
+	u->roles().insert("bust");
+	mod->append_child(u);
  
 	std::cout << "============ basic test ============" << std::endl;
         output_tree(std::cout, pol);
libpolicyrep/include/policyrep/policy.hpp +1 -0
Index: cpp-policyrep/libpolicyrep/include/policyrep/policy.hpp
===================================================================
@@ -9,6 +9,7 @@
 #include <policyrep/rule.hpp>
 #include <policyrep/conditional.hpp>
 #include <policyrep/rbac.hpp>
+#include <policyrep/user.hpp>
 
 namespace policyrep
 {
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.
#2 lore raw
In reply to [email protected]
Quoted 11 lines · On Mon, 2007-07-23 at 13:34 -0400, [email protected] wrote:

Added User object to libpolicyrep.

Signed-off-by Joshua Brindle
 include/policyrep/policy.hpp |    1 
 include/policyrep/user.hpp   |   46 ++++++++++++++++++++++
 src/policy_parse.y           |    8 +++
 src/user.cpp                 |   89 +++++++++++++++++++++++++++++++++++++++++++
 tests/example.te             |    4 +
 tests/libpolicyrep-test.cpp  |    4 +
 6 files changed, 152 insertions(+)

Note: This patch does not contain MLS support for users. This support will be in a forthcoming MLS patch.

-Mark Goldman

--
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.