Skip to contentSkip to conversation

Initial policyrep patch v2

PATCH In review Karl MacMillan 2 participants 3 messages Jun 28, 2007 – Jun 29, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Initial policyrep patch v2

Initial patch to create a new policyrep branch using C++. This patch includes basic classes for representing policy (Node and Parent), a few policy objects, a bison parser, a boost::python binding, and basic test infrastructure.

Includes updates based on comments from James Antill.

* * *

---

Makefile +1 -1
diff -r f7c0c0ec9d61 -r f71c0f396608 Makefile
@@ -1,4 +1,4 @@ SUBDIRS=libsepol libselinux libsemanage 
-SUBDIRS=libsepol libselinux libsemanage sepolgen checkpolicy policycoreutils # policy
+SUBDIRS=libsepol libselinux libsemanage libpolicyrep sepolgen checkpolicy policycoreutils # policy
 PYSUBDIRS=libselinux libsemanage
 
 ifeq ($(DEBUG),1)
libpolicyrep/Makefile +22 -0
diff -r f7c0c0ec9d61 -r f71c0f396608 libpolicyrep/Makefile
@@ -0,0 +1,22 @@
+all: 
+	$(MAKE) -C src 
+
+install: 
+	$(MAKE) -C include install
+	$(MAKE) -C src install
+
+relabel:
+	$(MAKE) -C src relabel
+
+clean:
+	$(MAKE) -C src clean
+	$(MAKE) -C tests clean
+
+indent:
+	$(MAKE) -C src $@
+	$(MAKE) -C include $@
+	$(MAKE) -C utils $@
+
+test: all
+	$(MAKE) -C tests test
+
libpolicyrep/include/Makefile +10 -0
diff -r f7c0c0ec9d61 -r f71c0f396608 libpolicyrep/include/Makefile
@@ -0,0 +1,10 @@
+# Installation directories.
+PREFIX ?= $(DESTDIR)/usr
+INCDIR ?= $(PREFIX)/include/policyrep
+
+install:
+	test -d $(INCDIR) || install -m 755 -d $(INCDIR)
+	install -m 644 $(wildcard policyrep/*.hpp) $(INCDIR)
+
+indent:
+	../../scripts/Lindent $(wildcard policyrep/*.hpp)
libpolicyrep/include/policyrep/idset.hpp +33 -0
diff -r f7c0c0ec9d61 -r f71c0f396608 libpolicyrep/include/policyrep/idset.hpp
@@ -0,0 +1,33 @@
+/* Author: Karl MacMillan <[email protected]> */
+
+#ifndef __idset_hpp__
+#define __idset_hpp__
+
+#include <policyrep/policy_base.hpp>
+
+#include <set>
+
+namespace policyrep
+{
+	struct IdSetImpl;
+	class IdSet
+	{
+	public:
+		IdSet();
+		IdSet(const IdSet& other);
+		~IdSet();
+		void operator=(const IdSet& other);
+
+		void set_compl(bool val);
+		bool get_compl() const;
+
+		StringSet& ids();
+	protected:
+		void init();
+		IdSetImpl* impl;
+	};
+
+
+} // namespace policyrep
+
+#endif
libpolicyrep/include/policyrep/object_class.hpp +83 -0

83 lines not on this page · raw message

libpolicyrep/include/policyrep/parse.hpp +47 -0

47 lines not on this page · raw message

libpolicyrep/include/policyrep/policy.hpp +85 -0

85 lines not on this page · raw message

libpolicyrep/include/policyrep/policy_base.hpp +135 -0

135 lines not on this page · raw message

libpolicyrep/include/policyrep/rule.hpp +42 -0

42 lines not on this page · raw message

libpolicyrep/include/policyrep/te_decl.hpp +144 -0

144 lines not on this page · raw message

libpolicyrep/src/Makefile +76 -0

76 lines not on this page · raw message

libpolicyrep/src/idset.cpp +67 -0

67 lines not on this page · raw message

libpolicyrep/src/object_class.cpp +157 -0

157 lines not on this page · raw message

libpolicyrep/src/parse.cpp +107 -0

107 lines not on this page · raw message

libpolicyrep/src/policy.cpp +178 -0

178 lines not on this page · raw message

libpolicyrep/src/policy_base.cpp +365 -0

365 lines not on this page · raw message

libpolicyrep/src/policy_internal.hpp new file +1 -0
diff -r f7c0c0ec9d61 -r f71c0f396608 libpolicyrep/src/policy_internal.hpp
@@ -0,0 +1,1 @@
+
libpolicyrep/src/policy_parse.y +708 -0

708 lines not on this page · raw message

libpolicyrep/src/policy_scan.l +275 -0

275 lines not on this page · raw message

libpolicyrep/src/policyrep_python.cpp +250 -0

250 lines not on this page · raw message

libpolicyrep/src/rule.cpp +131 -0

131 lines not on this page · raw message

libpolicyrep/src/te_decl.cpp +255 -0

79 lines not on this page · raw message

libpolicyrep/tests/Makefile +24 -0
diff -r f7c0c0ec9d61 -r f71c0f396608 libpolicyrep/tests/Makefile

Lines of this file are not shown. View the raw message.

libpolicyrep/tests/example.te +24 -0
diff -r f7c0c0ec9d61 -r f71c0f396608 libpolicyrep/tests/example.te

Lines of this file are not shown. View the raw message.

libpolicyrep/tests/libpolicyrep-test.cpp +59 -0

59 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

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

Part of the diff is not shown here. View the raw message.

#1 lore raw

libpolicyrep/src/policy_parse.y line 687

Quoted 12 lines · Karl MacMillan
libpolicyrep/src/policy_parse.y +11 -0
+	
+	AVRule* define_avrule(AVRule::Type type, IdSet* src_types,
+			      IdSet* tgt_types, IdSet* classes,
+			      IdSet* perms, Parser& driver)
+	{
+		AVRule* x = new AVRule(type);
+		
+		x->src_types().ids().insert(src_types->ids().begin(), src_types->ids().end());
+		x->src_types().set_compl(src_types->get_compl());
+		delete src_types;
+

I don't see - (subtraction) handling here, also compliments are not allowed in type sets for any rules except neverallows (which also allows *), also how do you handle * in permissions?

--
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
Quoted 14 lines · Joshua Brindle

libpolicyrep/src/policy_parse.y line 687

Quoted 12 lines · Karl MacMillan
libpolicyrep/src/policy_parse.y +11 -0
+	
+	AVRule* define_avrule(AVRule::Type type, IdSet* src_types,
+			      IdSet* tgt_types, IdSet* classes,
+			      IdSet* perms, Parser& driver)
+	{
+		AVRule* x = new AVRule(type);
+		
+		x->src_types().ids().insert(src_types->ids().begin(), src_types->ids().end());
+		x->src_types().set_compl(src_types->get_compl());
+		delete src_types;
+

I don't see - (subtraction) handling here,

The ids are inserted with the "-" - e.g., "-foo_t".

Quoted 3 lines

also compliments are not
allowed in type sets for any rules except neverallows (which also allows *),

Oh yeah - totally forgot.

Quoted 2 lines

also how do you handle * in permissions?

They just show up as the string "*". Both * and - are simply deferred for later processing. We can certainly discuss leaving these strings in
- it is simply how I did it in sepolgen. FWIW it worked pretty well there and makes policy generation a bit easier. It makes this representation almost purely syntactic.

The reason I pull out complement is because it is global to the set, but I would be fine with sticking in "~" if people think that is more consistent. Alternatively I could pull out * for the perms. Handling subtraction specially requires that id's be something other than std::string. That ends up being a real PITA because the stl doesn't support inheritance (don't ask - it's better just to accept and move on however irritating that is).

Karl

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