You can subscribe to this list here.
| 2006 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug (24) | Sep (38) | Oct (29) | Nov (40) | Dec (4) | 
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 | Jan (88) | Feb (66) | Mar (44) | Apr (104) | May (35) | Jun (34) | Jul (12) | Aug (42) | Sep (84) | Oct (34) | Nov (30) | Dec (22) | 
| 2008 | Jan (60) | Feb (54) | Mar (32) | Apr (14) | May (16) | Jun (26) | Jul (22) | Aug (12) | Sep | Oct | Nov | Dec | 
| 
      
      
      From: <ssm...@us...> - 2007-09-10 19:20:35
      
     | 
| Revision: 2550
          http://selinux.svn.sourceforge.net/selinux/?rev=2550&view=rev
Author:   ssmalley
Date:     2007-09-10 12:20:32 -0700 (Mon, 10 Sep 2007)
Log Message:
-----------
Author: Karl MacMillan
Email: kma...@me...
Subject: Suppress rule generation for dontaudit rules
Date: Mon, 03 Sep 2007 12:18:11 -0400
Suppress rule generation for dontaudit rules.
The current policy generation code incorrectly generates allow rules for dontaudit messages. This patch fixes that.
Modified Paths:
--------------
    trunk/sepolgen/src/sepolgen/audit.py
    trunk/sepolgen/tests/test_audit.py
Modified: trunk/sepolgen/src/sepolgen/audit.py
===================================================================
--- trunk/sepolgen/src/sepolgen/audit.py	2007-09-05 16:32:27 UTC (rev 2549)
+++ trunk/sepolgen/src/sepolgen/audit.py	2007-09-10 19:20:32 UTC (rev 2550)
@@ -402,7 +402,7 @@
             self.__parse(l)
         self.__post_process()
 
-    def to_access(self, avc_filter=None):
+    def to_access(self, avc_filter=None, only_denials=True):
         """Convert the audit logs access into a an access vector set.
 
         Convert the audit logs into an access vector set, optionally
@@ -421,6 +421,8 @@
         """
         av_set = access.AccessVectorSet()
         for avc in self.avc_msgs:
+            if avc.denial != True and only_denials:
+                continue
             if avc_filter:
                 if avc_filter.filter(avc):
                     av_set.add(avc.scontext.type, avc.tcontext.type, avc.tclass,
Modified: trunk/sepolgen/tests/test_audit.py
===================================================================
--- trunk/sepolgen/tests/test_audit.py	2007-09-05 16:32:27 UTC (rev 2549)
+++ trunk/sepolgen/tests/test_audit.py	2007-09-10 19:20:32 UTC (rev 2550)
@@ -46,6 +46,8 @@
 type=AVC_PATH msg=audit(1162850461.778:1113):  path="/etc/rc.d/init.d/innd"
 """
 
+granted1 = """type=AVC msg=audit(1188833848.190:34): avc:  granted  { getattr } for  pid=4310 comm="ls" name="foo.pp" dev=sda5 ino=295171 scontext=user_u:system_r:unconfined_t:s0 tcontext=user_u:object_r:user_home_t:s0 tclass=file"""
+
 path1 = """type=AVC_PATH msg=audit(1162852201.019:1225):  path="/usr/lib/sa/sa1"
 """
 
@@ -63,6 +65,26 @@
         self.assertEquals(avc.tclass, "")
         self.assertEquals(avc.accesses, [])
 
+    def test_granted(self):
+        avc = sepolgen.audit.AVCMessage(granted1)
+        avc.from_split_string(granted1.split())
+
+        self.assertEquals(avc.scontext.user, "user_u")
+        self.assertEquals(avc.scontext.role, "system_r")
+        self.assertEquals(avc.scontext.type, "unconfined_t")
+        self.assertEquals(avc.scontext.level, "s0")
+
+        self.assertEquals(avc.tcontext.user, "user_u")
+        self.assertEquals(avc.tcontext.role, "object_r")
+        self.assertEquals(avc.tcontext.type, "user_home_t")
+        self.assertEquals(avc.tcontext.level, "s0")
+        
+        self.assertEquals(avc.tclass, "file")
+        self.assertEquals(avc.accesses, ["getattr"])
+
+        self.assertEquals(avc.denial, False)
+
+
     def test_from_split_string(self):
         # syslog message
         avc = sepolgen.audit.AVCMessage(audit1)
@@ -148,4 +170,23 @@
         self.assertEquals(len(a.compute_sid_msgs), 0)
         self.assertEquals(len(a.invalid_msgs), 0)
         self.assertEquals(len(a.policy_load_msgs), 0)
+
+class TestGeneration(unittest.TestCase):
+    def test_generation(self):
+        parser = sepolgen.audit.AuditParser()
+        parser.parse_string(log1)
+        avs = parser.to_access()
+
+        self.assertEqual(len(avs), 1)
+
+    def test_genaration_granted(self):
+        parser = sepolgen.audit.AuditParser()
+        parser.parse_string(granted1)
+        avs = parser.to_access()
+
+        self.assertEqual(len(avs), 0)
         
+        avs = parser.to_access(only_denials=False)
+        
+        self.assertEqual(len(avs), 1)
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <mad...@us...> - 2007-09-05 16:32:30
      
     | 
| Revision: 2549
          http://selinux.svn.sourceforge.net/selinux/?rev=2549&view=rev
Author:   madmethod
Date:     2007-09-05 09:32:27 -0700 (Wed, 05 Sep 2007)
Log Message:
-----------
add mls.cpp which was mistakenly left out
Added Paths:
-----------
    branches/policyrep/libpolicyrep/src/mls.cpp
Added: branches/policyrep/libpolicyrep/src/mls.cpp
===================================================================
--- branches/policyrep/libpolicyrep/src/mls.cpp	                        (rev 0)
+++ branches/policyrep/libpolicyrep/src/mls.cpp	2007-09-05 16:32:27 UTC (rev 2549)
@@ -0,0 +1,348 @@
+/*
+ * Author : Mark Goldman <mgo...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
+02110-1301  USA  */
+
+#include <policyrep/mls.hpp>
+
+namespace policyrep
+{
+
+	//
+	// Sensitivity
+	//
+
+	struct SensitivityImpl
+	{
+		std::string name;
+		StringSet aliases;
+	};
+
+	void Sensitivity::init()
+	{
+		impl = new SensitivityImpl;
+	}
+
+	Sensitivity::Sensitivity() { init(); }
+
+	Sensitivity::Sensitivity(const std::string& name)
+	{
+		init();
+		impl->name = name;
+	}
+
+	Sensitivity::Sensitivity(const Sensitivity& other)
+		: Node()
+	{
+		init();
+		*impl = *other.impl;
+	}
+
+	Sensitivity::~Sensitivity() { delete impl; }
+
+	void Sensitivity::operator=(const Sensitivity& other)
+	{
+		*impl = *other.impl;
+	}
+
+	const std::string& Sensitivity::get_name() const
+	{
+		return impl->name;
+	}
+
+	void Sensitivity::set_name(const std::string& name)
+	{
+		impl->name = name;
+	}
+
+	StringSet& Sensitivity::aliases()
+	{
+		return impl->aliases;
+	}
+
+	void Sensitivity::do_output(std::ostream& o, const OutputFormatter& op) const
+	{
+		o << "sensitivity " << impl->name;
+		if (!impl->aliases.empty()) {
+			o << " alias ";
+			bracket_output_container(o, impl->aliases.begin(),
+					impl->aliases.end(), " ", "{ ", " }");
+		}
+		o << ";";
+	}
+
+	//
+	// Dominance
+	//
+
+	struct DominanceImpl
+	{
+		StringVector ordering;
+	};
+
+	void Dominance::init()
+	{
+		impl = new DominanceImpl;
+	}
+
+	Dominance::Dominance() { init(); }
+
+	Dominance::Dominance(const Dominance& other)
+		: Node()
+	{
+		init();
+		*impl = *other.impl;
+	}
+
+	Dominance::~Dominance() { delete impl; }
+
+	void Dominance::operator=(const Dominance& other)
+	{
+		*impl = *other.impl;
+	}
+
+	StringVector& Dominance::ordering()
+	{
+		return impl->ordering;
+	}
+
+	void Dominance::do_output(std::ostream& o, const OutputFormatter& op) const
+	{
+		o << "dominance ";
+		if (!impl->ordering.empty()) {
+			bracket_output_container(o, impl->ordering.begin(),
+					impl->ordering.end(), " ", "{ ", " }");
+		}
+		o << ";";
+	}
+
+	//
+	// Category
+	//
+
+	struct CategoryImpl
+	{
+		std::string name;
+		StringSet aliases;
+	};
+
+	void Category::init()
+	{
+		impl = new CategoryImpl;
+	}
+
+	Category::Category() { init(); }
+
+	Category::Category(const std::string& name)
+	{
+		init();
+		impl->name = name;
+	}
+
+	Category::Category(const Category& other)
+		: Node()
+	{
+		init();
+		*impl = *other.impl;
+	}
+
+	Category::~Category() { delete impl; }
+
+	void Category::operator=(const Category& other)
+	{
+		*impl = *other.impl;
+	}
+
+	const std::string& Category::get_name() const
+	{
+		return impl->name;
+	}
+
+	void Category::set_name(const std::string& name)
+	{
+		impl->name = name;
+	}
+
+	StringSet& Category::aliases()
+	{
+		return impl->aliases;
+	}
+
+	void Category::do_output(std::ostream& o, const OutputFormatter& op) const
+	{
+		o << "category " << impl->name;
+		if (!impl->aliases.empty()) {
+			o << " alias ";
+			bracket_output_container(o, impl->aliases.begin(),
+					impl->aliases.end(), " ", "{ ", " }");
+		}
+		o << ";";
+	}
+
+	//
+	// Level
+	//
+
+	struct LevelImpl
+	{
+		std::string name;
+		StringSet categories;
+	};
+
+	void Level::init()
+	{
+		impl = new LevelImpl;
+	}
+
+	Level::Level() { init(); }
+
+	Level::Level(const std::string& name)
+	{
+		init();
+		impl->name = name;
+	}
+
+	Level::Level(const Level& other)
+		: Node()
+	{
+		init();
+		*impl = *other.impl;
+	}
+
+	Level::~Level() {
+		delete impl;
+	}
+
+	void Level::operator=(const Level& other)
+	{
+		*impl = *other.impl;
+	}
+
+	const std::string& Level::get_name() const
+	{
+		return impl->name;
+	}
+
+	void Level::set_name(const std::string& name)
+	{
+		impl->name = name;
+	}
+
+	StringSet& Level::categories()
+	{
+		return impl->categories;
+	}
+
+	void Level::do_output_brief(std::ostream& o, const OutputFormatter& op) const
+	{
+		o << impl->name;
+		if (!impl->categories.empty()) {
+			o << ":";
+			bracket_output_container(o, impl->categories.begin(),
+					impl->categories.end(), ", ", "", "");
+		}
+	}
+
+	void Level::do_output(std::ostream& o, const OutputFormatter& op) const
+	{
+		o << "level ";
+		do_output_brief(o, op);
+		o << ";";
+	}
+
+	//
+	// Range
+	//
+
+	struct RangeImpl
+	{
+		LevelPtr low;
+		LevelPtr high;
+	};
+
+	Range::Range()
+	{
+		init();
+	}
+
+	Range::Range(LevelPtr low)
+	{
+		init();
+		impl->low = low;
+	}
+
+	Range::Range(LevelPtr low, LevelPtr high)
+	{
+		init();
+		impl->low = low;
+		impl->high = high;
+	}
+
+	Range::Range(const Range& other)
+		: Node()
+	{
+		init();
+		*impl = *(other.impl);
+	}
+
+	Range::~Range()
+	{
+		delete impl;
+	}
+
+	void Range::operator=(const Range& other)
+	{
+		*impl = *(other.impl);
+	}
+
+	const LevelPtr& Range::get_low(void) const
+	{
+		return impl->low;
+	}
+
+	const LevelPtr& Range::get_high(void) const
+	{
+		return impl->high;
+	}
+
+	LevelPtr& Range::get_low(void)
+	{
+		return impl->low;
+	}
+
+	LevelPtr& Range::get_high(void)
+	{
+		return impl->high;
+	}
+
+	void Range::do_output(std::ostream& o, const OutputFormatter& op) const
+	{
+		get_low()->do_output_brief(o,op);
+		if(get_high()){
+			o << " - ";
+			get_high()->do_output_brief(o,op);
+		}
+	}
+
+	void Range::init()
+	{
+		impl = new RangeImpl;
+	}
+
+
+} // namespace policyrep
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <mad...@us...> - 2007-09-04 18:59:45
      
     | 
| Revision: 2548
          http://selinux.svn.sourceforge.net/selinux/?rev=2548&view=rev
Author:   madmethod
Date:     2007-09-04 11:59:43 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
add missing mls.hpp
Added Paths:
-----------
    branches/policyrep/libpolicyrep/include/policyrep/mls.hpp
Added: branches/policyrep/libpolicyrep/include/policyrep/mls.hpp
===================================================================
--- branches/policyrep/libpolicyrep/include/policyrep/mls.hpp	                        (rev 0)
+++ branches/policyrep/libpolicyrep/include/policyrep/mls.hpp	2007-09-04 18:59:43 UTC (rev 2548)
@@ -0,0 +1,166 @@
+/* Author: Mark Goldman <mgo...@tr...> */
+
+#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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <mad...@us...> - 2007-09-04 18:54:27
      
     | 
| Revision: 2547
          http://selinux.svn.sourceforge.net/selinux/?rev=2547&view=rev
Author:   madmethod
Date:     2007-09-04 11:54:25 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
Author: Mark Goldman
Email: mgo...@tr...
Subject: Add mls to the policy representation.
Date: Thu, 16 Aug 2007 14:28:56 -0400
Adds objects to represent sensitivity, dominance, category and level
statements.
Add mls additions to the object representing user statements.
Signed-off-by: Joshua Brindle <jbr...@tr...>
Modified Paths:
--------------
    branches/policyrep/libpolicyrep/include/policyrep/policy.hpp
    branches/policyrep/libpolicyrep/include/policyrep/user.hpp
    branches/policyrep/libpolicyrep/src/policy_parse.y
    branches/policyrep/libpolicyrep/src/user.cpp
    branches/policyrep/libpolicyrep/tests/example.te
    branches/policyrep/libpolicyrep/tests/libpolicyrep-test.cpp
Modified: branches/policyrep/libpolicyrep/include/policyrep/policy.hpp
===================================================================
--- branches/policyrep/libpolicyrep/include/policyrep/policy.hpp	2007-09-04 18:53:38 UTC (rev 2546)
+++ branches/policyrep/libpolicyrep/include/policyrep/policy.hpp	2007-09-04 18:54:25 UTC (rev 2547)
@@ -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
Modified: branches/policyrep/libpolicyrep/include/policyrep/user.hpp
===================================================================
--- branches/policyrep/libpolicyrep/include/policyrep/user.hpp	2007-09-04 18:53:38 UTC (rev 2546)
+++ branches/policyrep/libpolicyrep/include/policyrep/user.hpp	2007-09-04 18:54:25 UTC (rev 2547)
@@ -4,6 +4,7 @@
 #define __user_hpp__
 
 #include <policyrep/policy_base.hpp>
+#include <policyrep/mls.hpp>
 
 namespace policyrep
 {
@@ -30,8 +31,25 @@
 					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:
Modified: branches/policyrep/libpolicyrep/src/policy_parse.y
===================================================================
--- branches/policyrep/libpolicyrep/src/policy_parse.y	2007-09-04 18:53:38 UTC (rev 2546)
+++ branches/policyrep/libpolicyrep/src/policy_parse.y	2007-09-04 18:54:25 UTC (rev 2547)
@@ -119,6 +119,13 @@
 %type <pnode> type_def
 %type <pnode> role_type_def
 %type <pnode> user_role_def
+%type <pnode> raw_level
+%type <pnode> mls_range
+%type <pnode> sensitivity_def
+%type <pnode> dominance_def
+%type <pnode> category_def
+%type <pnode> level_def
+
 %type <pnode> typealias_def
 %type <pnode> typeattribute_def
 %type <pnode> allow_def
@@ -253,6 +260,11 @@
 			| role_type_def
 			/* Users */
 			| user_role_def
+			/* MLS */
+			| sensitivity_def
+			| dominance_def
+			| category_def
+			| level_def
 			/* rules */
 			| allow_def
 			| auditallow_def
@@ -284,27 +296,42 @@
                         | CLASS IDENTIFIER INHERITS IDENTIFIER LBRACE identifier_list RBRACE
                           { $$ = new ObjectClass(*$2, *$4, $6->begin(), $6->end()); delete $2; delete $4; delete $6; }
 			;
-/*
 sensitivity_def		: SENSITIVITY IDENTIFIER alias_def SEMI
-			{ $$ = define_sens($2, $3); check($$); }
+			{ $$ = new Sensitivity(*$2, $3->begin(), $3->end());
+			  delete $2;
+			  delete $3;  }
 			| SENSITIVITY IDENTIFIER SEMI
-			{ $$ = define_sens($2, NULL); check($$); }
+			{ $$ = new Sensitivity(*$2);
+			  delete $2; }
 	                ;
-dominance		: DOMINANCE IDENTIFIER
-			{ NodeVector tmp = tolist($2); check(tmp); $$ = define_dominance(tmp); check($$); }
-                        | DOMINANCE LBRACE IDENTIFIER_list RBRACE
-			{ $$ = define_dominance($3); check($$); }
+dominance_def		: DOMINANCE IDENTIFIER
+			{ Dominance *d = new Dominance();
+			  d->ordering().push_back(*$2);
+			  $$ = d;
+			  delete $2; }
+                        | DOMINANCE LBRACE identifier_list RBRACE
+			{ $$ = new Dominance($3->begin(), $3->end());
+			  delete $3; }
 			;
 category_def		: CATEGORY IDENTIFIER alias_def SEMI
-			{ $$ = define_category($2, $3); check($$); }
+			{ $$ = new Category(*$2, $3->begin(), $3->end());
+			  delete $2;
+			  delete $3;  }
 			| CATEGORY IDENTIFIER SEMI
-			{ $$ = define_category($2, NULL); check($$); }
+			{ $$ = new Category(*$2);
+			  delete $2; }
 			;
 level_def		: LEVEL IDENTIFIER COLON id_comma_list SEMI
-			{ $$ = define_level(); check($$); }
+			{ 
+			  $$ = new Level(*$2, $4->begin(), $4->end());
+			  delete $2;
+			  delete $4;  }
 			| LEVEL IDENTIFIER SEMI
-			{ $$ = define_level(); check($$); }
+			{ 
+			  $$ = new Level(*$2);
+			  delete $2; }
 			;
+/*
 mlsconstraint_def	: MLSCONSTRAIN names names cexpr SEMI
 			{ $$ = define_constraint($4); check($$); }
 			;
@@ -476,11 +503,42 @@
  			| 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_role_def		: USER IDENTIFIER ROLES id_comma_list LEVEL raw_level RANGE mls_range SEMI
+			  { $$ = new User(*$2, $4->begin(), $4->end());
+			    delete $2;
+			    delete $4;
+			    ((User*)$$)->set_level(LevelPtr((Level*)$6));
+			    ((User*)$$)->set_range(RangePtr((Range*)$8));
+			    // $6 and $8 are now managed by a shared ptr
+			    // don't delete them.  They will be free'd
+			    // when the final ptr is destroyed.
+			  }
+			| 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; }
                         ;
+raw_level		: IDENTIFIER COLON id_comma_list
+			  { $$ = new Level(*$1, $3->begin(), $3->end());
+			    delete $1;
+			    delete $3;
+			  }
+			| IDENTIFIER
+			  { $$ = new Level(*$1);
+			    delete $1;
+			  }
+			;
+mls_range		: raw_level DASH raw_level
+			  { $$ = new Range(LevelPtr((Level*)$1), LevelPtr((Level*)$3));
+			    // $1 and $2 become owned by Range, do not delete
+			  }
+			| raw_level
+			  { $$ = new Range(LevelPtr((Level*)$1));
+			    // $1 becomes owned by Range do not delete.
+			  }
+			;
 /*
 role_dominance		: DOMINANCE LBRACE roles RBRACE { $$ = $3; check($$); }
 			;
@@ -812,4 +870,5 @@
 
 /* FLASK */
 
-
+/* vi:ts=8: 
+*/
Modified: branches/policyrep/libpolicyrep/src/user.cpp
===================================================================
--- branches/policyrep/libpolicyrep/src/user.cpp	2007-09-04 18:53:38 UTC (rev 2546)
+++ branches/policyrep/libpolicyrep/src/user.cpp	2007-09-04 18:54:25 UTC (rev 2547)
@@ -19,6 +19,7 @@
  */
 
 #include <policyrep/user.hpp>
+#include <policyrep/mls.hpp>
 
 namespace policyrep
 {
@@ -30,6 +31,8 @@
 	struct UserImpl
 	{
 		std::string name;
+		LevelPtr level;
+		RangePtr range;
 		StringSet roles;
 	};
 
@@ -53,7 +56,9 @@
 		*impl = *other.impl;
 	}
 
-	User::~User() { delete impl; }
+	User::~User() { 
+		delete impl;
+	}
 
 	void User::operator=(const User& other)
 	{
@@ -75,6 +80,23 @@
 		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 @@
 			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 << ";";
 	}
 
Modified: branches/policyrep/libpolicyrep/tests/example.te
===================================================================
--- branches/policyrep/libpolicyrep/tests/example.te	2007-09-04 18:53:38 UTC (rev 2546)
+++ branches/policyrep/libpolicyrep/tests/example.te	2007-09-04 18:54:25 UTC (rev 2547)
@@ -34,9 +34,26 @@
 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;
 }
Modified: branches/policyrep/libpolicyrep/tests/libpolicyrep-test.cpp
===================================================================
--- branches/policyrep/libpolicyrep/tests/libpolicyrep-test.cpp	2007-09-04 18:53:38 UTC (rev 2546)
+++ branches/policyrep/libpolicyrep/tests/libpolicyrep-test.cpp	2007-09-04 18:54:25 UTC (rev 2547)
@@ -47,7 +47,21 @@
 	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);
         
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <mad...@us...> - 2007-09-04 18:53:42
      
     | 
| Revision: 2546
          http://selinux.svn.sourceforge.net/selinux/?rev=2546&view=rev
Author:   madmethod
Date:     2007-09-04 11:53:38 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
Author: Mark Goldman
Email: mgo...@tr...
Subject: Generalize an output function to make display easier.
Date: Thu, 16 Aug 2007 14:28:55 -0400
Generalize an output function to make display easier.
Signed-off-by: Joshua Brindle <jbr...@tr...>
Modified Paths:
--------------
    branches/policyrep/libpolicyrep/include/policyrep/policy_base.hpp
    branches/policyrep/libpolicyrep/src/policy_base.cpp
Modified: branches/policyrep/libpolicyrep/include/policyrep/policy_base.hpp
===================================================================
--- branches/policyrep/libpolicyrep/include/policyrep/policy_base.hpp	2007-09-04 18:22:54 UTC (rev 2545)
+++ branches/policyrep/libpolicyrep/include/policyrep/policy_base.hpp	2007-09-04 18:53:38 UTC (rev 2546)
@@ -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 @@
         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 @@
 		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();
Modified: branches/policyrep/libpolicyrep/src/policy_base.cpp
===================================================================
--- branches/policyrep/libpolicyrep/src/policy_base.cpp	2007-09-04 18:22:54 UTC (rev 2545)
+++ branches/policyrep/libpolicyrep/src/policy_base.cpp	2007-09-04 18:53:38 UTC (rev 2546)
@@ -37,30 +37,16 @@
 	{
 		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)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <mad...@us...> - 2007-09-04 18:22:57
      
     | 
| Revision: 2545
          http://selinux.svn.sourceforge.net/selinux/?rev=2545&view=rev
Author:   madmethod
Date:     2007-09-04 11:22:54 -0700 (Tue, 04 Sep 2007)
Log Message:
-----------
merge from trunk r2494:HEAD
Modified Paths:
--------------
    branches/policyrep/libselinux/ChangeLog
    branches/policyrep/libselinux/Makefile
    branches/policyrep/libselinux/VERSION
    branches/policyrep/libselinux/include/selinux/av_permissions.h
    branches/policyrep/libselinux/include/selinux/flask.h
    branches/policyrep/libselinux/include/selinux/selinux.h
    branches/policyrep/libselinux/man/man3/avc_add_callback.3
    branches/policyrep/libselinux/man/man3/avc_cache_stats.3
    branches/policyrep/libselinux/man/man3/avc_compute_create.3
    branches/policyrep/libselinux/man/man3/avc_context_to_sid.3
    branches/policyrep/libselinux/man/man3/avc_has_perm.3
    branches/policyrep/libselinux/man/man3/avc_init.3
    branches/policyrep/libselinux/man/man3/context_new.3
    branches/policyrep/libselinux/man/man3/freecon.3
    branches/policyrep/libselinux/man/man3/get_ordered_context_list.3
    branches/policyrep/libselinux/man/man3/getcon.3
    branches/policyrep/libselinux/man/man3/getexeccon.3
    branches/policyrep/libselinux/man/man3/getfilecon.3
    branches/policyrep/libselinux/man/man3/getfscreatecon.3
    branches/policyrep/libselinux/man/man3/getseuserbyname.3
    branches/policyrep/libselinux/man/man3/is_context_customizable.3
    branches/policyrep/libselinux/man/man3/matchmediacon.3
    branches/policyrep/libselinux/man/man3/matchpathcon.3
    branches/policyrep/libselinux/man/man3/security_class_to_string.3
    branches/policyrep/libselinux/man/man3/security_compute_av.3
    branches/policyrep/libselinux/man/man3/security_getenforce.3
    branches/policyrep/libselinux/man/man3/security_load_booleans.3
    branches/policyrep/libselinux/man/man3/selabel_lookup.3
    branches/policyrep/libselinux/man/man3/selabel_open.3
    branches/policyrep/libselinux/man/man3/selabel_stats.3
    branches/policyrep/libselinux/man/man3/selinux_binary_policy_path.3
    branches/policyrep/libselinux/man/man3/selinux_getenforcemode.3
    branches/policyrep/libselinux/man/man3/selinux_policy_root.3
    branches/policyrep/libselinux/man/man3/selinux_set_callback.3
    branches/policyrep/libselinux/man/man3/setfilecon.3
    branches/policyrep/libselinux/man/man5/selabel_file.5
    branches/policyrep/libselinux/man/man5/selabel_media.5
    branches/policyrep/libselinux/man/man5/selabel_x.5
    branches/policyrep/libselinux/man/man8/matchpathcon.8
    branches/policyrep/libselinux/man/man8/selinux.8
    branches/policyrep/libselinux/src/Makefile
    branches/policyrep/libselinux/src/file_path_suffixes.h
    branches/policyrep/libselinux/src/label_internal.h
    branches/policyrep/libselinux/src/label_x.c
    branches/policyrep/libselinux/src/mapping.h
    branches/policyrep/libselinux/src/matchpathcon.c
    branches/policyrep/libselinux/src/selinux_config.c
    branches/policyrep/libselinux/src/selinux_internal.h
    branches/policyrep/libselinux/src/stringrep.c
    branches/policyrep/libsemanage/ChangeLog
    branches/policyrep/libsemanage/VERSION
    branches/policyrep/libsemanage/include/semanage/handle.h
    branches/policyrep/libsemanage/src/Makefile
    branches/policyrep/libsemanage/src/conf-parse.y
    branches/policyrep/libsemanage/src/conf-scan.l
    branches/policyrep/libsemanage/src/handle.c
    branches/policyrep/libsemanage/src/libsemanage.map
    branches/policyrep/libsemanage/src/semanage_conf.h
    branches/policyrep/libsemanage/src/semanage_store.c
    branches/policyrep/libsemanage/src/semanage_store.h
    branches/policyrep/libsemanage/tests/Makefile
    branches/policyrep/libsemanage/tests/libsemanage-tests.c
    branches/policyrep/libsepol/ChangeLog
    branches/policyrep/libsepol/VERSION
    branches/policyrep/libsepol/include/sepol/handle.h
    branches/policyrep/libsepol/src/avtab.c
    branches/policyrep/libsepol/src/conditional.c
    branches/policyrep/libsepol/src/context_record.c
    branches/policyrep/libsepol/src/ebitmap.c
    branches/policyrep/libsepol/src/expand.c
    branches/policyrep/libsepol/src/handle.c
    branches/policyrep/libsepol/src/handle.h
    branches/policyrep/libsepol/src/libsepol.map
    branches/policyrep/libsepol/src/module.c
    branches/policyrep/libsepol/src/policydb.c
    branches/policyrep/libsepol/src/private.h
    branches/policyrep/libsepol/src/services.c
    branches/policyrep/policycoreutils/ChangeLog
    branches/policyrep/policycoreutils/VERSION
    branches/policyrep/policycoreutils/newrole/Makefile
    branches/policyrep/policycoreutils/run_init/Makefile
    branches/policyrep/policycoreutils/scripts/Makefile
    branches/policyrep/policycoreutils/scripts/chcat
    branches/policyrep/policycoreutils/scripts/fixfiles
    branches/policyrep/policycoreutils/semanage/semanage
    branches/policyrep/policycoreutils/semodule/semodule.c
    branches/policyrep/sepolgen/ChangeLog
    branches/policyrep/sepolgen/VERSION
Added Paths:
-----------
    branches/policyrep/libsemanage/src/genhomedircon.c
    branches/policyrep/libsemanage/src/genhomedircon.h
    branches/policyrep/libsemanage/src/utilities.c
    branches/policyrep/libsemanage/src/utilities.h
    branches/policyrep/libsemanage/tests/test_utilities.c
    branches/policyrep/libsemanage/tests/test_utilities.h
Removed Paths:
-------------
    branches/policyrep/policycoreutils/restorecon/
    branches/policyrep/policycoreutils/scripts/genhomedircon
    branches/policyrep/policycoreutils/scripts/genhomedircon.8
Modified: branches/policyrep/libselinux/ChangeLog
===================================================================
--- branches/policyrep/libselinux/ChangeLog	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/ChangeLog	2007-09-04 18:22:54 UTC (rev 2545)
@@ -1,3 +1,26 @@
+2.0.31 2007-08-23
+	* Fix file_contexts.homedirs path from Todd Miller.
+
+2.0.30 2007-08-06
+	* Fix segfault resulting from uninitialized print-callback pointer.
+
+2.0.29 2007-08-02
+	* Added x_contexts path function patch from Eamon Walsh.
+
+2.0.28 2007-08-01
+	* Fix build for EMBEDDED=y from Yuichi Nakamura.
+
+2.0.27 2007-07-25
+	* Fix markup problems in selinux man pages from Dan Walsh.
+
+2.0.26 2007-07-23
+	* Updated av_permissions.h and flask.h to include new nscd permissions from Dan Walsh.
+	* Added swigify to top-level Makefile from Dan Walsh.
+
+2.0.25 2007-07-23
+	* Fix for string_to_security_class segfault on x86_64 from Stephen
+	  Smalley.
+
 2.0.24 2007-09-07
 	* Fix for getfilecon() for zero-length contexts from Stephen Smalley.
 
Modified: branches/policyrep/libselinux/Makefile
===================================================================
--- branches/policyrep/libselinux/Makefile	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/Makefile	2007-09-04 18:22:54 UTC (rev 2545)
@@ -8,6 +8,9 @@
 	override DISABLE_RPM=y
 	override DISABLE_BOOL=y
 endif
+ifeq ($(DISABLE_AVC),y)
+	EMFLAGS+= -DDISABLE_AVC
+endif
 ifeq ($(DISABLE_BOOL),y)
 	EMFLAGS+= -DDISABLE_BOOL
 endif
@@ -20,6 +23,9 @@
 	$(MAKE) -C src 
 	$(MAKE) -C utils
 
+swigify: all
+	$(MAKE) -C src swigify
+
 pywrap: 
 	$(MAKE) -C src pywrap
 
Modified: branches/policyrep/libselinux/VERSION
===================================================================
--- branches/policyrep/libselinux/VERSION	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/VERSION	2007-09-04 18:22:54 UTC (rev 2545)
@@ -1 +1 @@
-2.0.24
+2.0.31
Modified: branches/policyrep/libselinux/include/selinux/av_permissions.h
===================================================================
--- branches/policyrep/libselinux/include/selinux/av_permissions.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/include/selinux/av_permissions.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -290,12 +290,16 @@
 #define NODE__RAWIP_RECV                          0x00000010UL
 #define NODE__RAWIP_SEND                          0x00000020UL
 #define NODE__ENFORCE_DEST                        0x00000040UL
+#define NODE__DCCP_RECV                           0x00000080UL
+#define NODE__DCCP_SEND                           0x00000100UL
 #define NETIF__TCP_RECV                           0x00000001UL
 #define NETIF__TCP_SEND                           0x00000002UL
 #define NETIF__UDP_RECV                           0x00000004UL
 #define NETIF__UDP_SEND                           0x00000008UL
 #define NETIF__RAWIP_RECV                         0x00000010UL
 #define NETIF__RAWIP_SEND                         0x00000020UL
+#define NETIF__DCCP_RECV                          0x00000040UL
+#define NETIF__DCCP_SEND                          0x00000080UL
 #define NETLINK_SOCKET__IOCTL                     0x00000001UL
 #define NETLINK_SOCKET__READ                      0x00000002UL
 #define NETLINK_SOCKET__WRITE                     0x00000004UL
@@ -837,6 +841,8 @@
 #define NSCD__SHMEMPWD                            0x00000020UL
 #define NSCD__SHMEMGRP                            0x00000040UL
 #define NSCD__SHMEMHOST                           0x00000080UL
+#define NSCD__GETSERV                             0x00000100UL
+#define NSCD__SHMEMSERV                           0x00000200UL
 #define ASSOCIATION__SENDTO                       0x00000001UL
 #define ASSOCIATION__RECVFROM                     0x00000002UL
 #define ASSOCIATION__SETCONTEXT                   0x00000004UL
@@ -897,3 +903,28 @@
 #define KEY__CREATE                               0x00000040UL
 #define CONTEXT__TRANSLATE                        0x00000001UL
 #define CONTEXT__CONTAINS                         0x00000002UL
+#define DCCP_SOCKET__IOCTL                        0x00000001UL
+#define DCCP_SOCKET__READ                         0x00000002UL
+#define DCCP_SOCKET__WRITE                        0x00000004UL
+#define DCCP_SOCKET__CREATE                       0x00000008UL
+#define DCCP_SOCKET__GETATTR                      0x00000010UL
+#define DCCP_SOCKET__SETATTR                      0x00000020UL
+#define DCCP_SOCKET__LOCK                         0x00000040UL
+#define DCCP_SOCKET__RELABELFROM                  0x00000080UL
+#define DCCP_SOCKET__RELABELTO                    0x00000100UL
+#define DCCP_SOCKET__APPEND                       0x00000200UL
+#define DCCP_SOCKET__BIND                         0x00000400UL
+#define DCCP_SOCKET__CONNECT                      0x00000800UL
+#define DCCP_SOCKET__LISTEN                       0x00001000UL
+#define DCCP_SOCKET__ACCEPT                       0x00002000UL
+#define DCCP_SOCKET__GETOPT                       0x00004000UL
+#define DCCP_SOCKET__SETOPT                       0x00008000UL
+#define DCCP_SOCKET__SHUTDOWN                     0x00010000UL
+#define DCCP_SOCKET__RECVFROM                     0x00020000UL
+#define DCCP_SOCKET__SENDTO                       0x00040000UL
+#define DCCP_SOCKET__RECV_MSG                     0x00080000UL
+#define DCCP_SOCKET__SEND_MSG                     0x00100000UL
+#define DCCP_SOCKET__NAME_BIND                    0x00200000UL
+#define DCCP_SOCKET__NODE_BIND                    0x00400000UL
+#define DCCP_SOCKET__NAME_CONNECT                 0x00800000UL
+#define MEMPROTECT__MMAP_ZERO                     0x00000001UL
Modified: branches/policyrep/libselinux/include/selinux/flask.h
===================================================================
--- branches/policyrep/libselinux/include/selinux/flask.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/include/selinux/flask.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -64,6 +64,8 @@
 #define SECCLASS_PACKET                                  57
 #define SECCLASS_KEY                                     58
 #define SECCLASS_CONTEXT                                 59
+#define SECCLASS_DCCP_SOCKET                             60
+#define SECCLASS_MEMPROTECT                              61
 
 /*
  * Security identifier indices for initial entities
Modified: branches/policyrep/libselinux/include/selinux/selinux.h
===================================================================
--- branches/policyrep/libselinux/include/selinux/selinux.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/include/selinux/selinux.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -454,6 +454,7 @@
 extern const char *selinux_file_context_local_path(void);
 extern const char *selinux_homedir_context_path(void);
 extern const char *selinux_media_context_path(void);
+extern const char *selinux_x_context_path(void);
 extern const char *selinux_contexts_path(void);
 extern const char *selinux_securetty_types_path(void);
 extern const char *selinux_booleans_path(void);
Modified: branches/policyrep/libselinux/man/man3/avc_add_callback.3
===================================================================
--- branches/policyrep/libselinux/man/man3/avc_add_callback.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/avc_add_callback.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,26 +6,26 @@
 avc_add_callback \- additional event notification for SELinux userspace object managers.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_add_callback(int (*" callback ")(uint32_t " event , 
 .in +\w'int avc_add_callback(int (*callback)('u
 .BI "security_id_t " ssid ,
-.br
+
 .BI "security_id_t " tsid ,
-.br
+
 .BI "security_class_t " tclass ,
-.br
+
 .BI "access_vector_t " perms ,
-.br
+
 .BI "access_vector_t *" out_retained "),"
 .in
 .in +\w'int avc_add_callback('u
 .BI "uint32_t " events ", security_id_t " ssid , 
-.br
+
 .BI "security_id_t " tsid ", security_class_t " tclass ,
-.br
+
 .BI "access_vector_t " perms ");"
 .in
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/avc_cache_stats.3
===================================================================
--- branches/policyrep/libselinux/man/man3/avc_cache_stats.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/avc_cache_stats.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 avc_cache_stats, avc_av_stats, avc_sid_stats \- obtain userspace SELinux AVC statistics.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/avc.h>
 .sp
 .BI "void avc_av_stats(void);"
Modified: branches/policyrep/libselinux/man/man3/avc_compute_create.3
===================================================================
--- branches/policyrep/libselinux/man/man3/avc_compute_create.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/avc_compute_create.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 avc_compute_create \- obtain SELinux label for new object.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_compute_create(security_id_t " ssid ", security_id_t " tsid ,
Modified: branches/policyrep/libselinux/man/man3/avc_context_to_sid.3
===================================================================
--- branches/policyrep/libselinux/man/man3/avc_context_to_sid.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/avc_context_to_sid.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 avc_context_to_sid, avc_sid_to_context, sidput, sidget, avc_get_initial_sid \- obtain and manipulate SELinux security ID's.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_context_to_sid(security_context_t " ctx ", security_id_t *" sid ");"
Modified: branches/policyrep/libselinux/man/man3/avc_has_perm.3
===================================================================
--- branches/policyrep/libselinux/man/man3/avc_has_perm.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/avc_has_perm.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \- obtain and audit SELinux access decisions.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/avc.h>
 .sp
 .BI "void avc_entry_ref_init(struct avc_entry_ref *" aeref ");"
@@ -14,21 +14,21 @@
 .BI "int avc_has_perm(security_id_t " ssid ", security_id_t " tsid ,
 .in +\w'int avc_has_perm('u
 .BI "security_class_t " tclass ", access_vector_t " requested ,
-.br
+
 .BI "struct avc_entry_ref *" aeref ", void *" auditdata ");"
 .in
 .sp
 .BI "int avc_has_perm_noaudit(security_id_t " ssid ", security_id_t " tsid ,
 .in +\w'int avc_has_perm('u
 .BI "security_class_t " tclass ", access_vector_t " requested ,
-.br
+
 .BI "struct avc_entry_ref *" aeref ", struct av_decision *" avd ");"
 .in
 .sp
 .BI "void avc_audit(security_id_t " ssid ", security_id_t " tsid ,
 .in +\w'void avc_audit('u
 .BI "security_class_t " tclass ", access_vector_t " requested ,
-.br
+
 .BI "struct av_decision *" avd ", int " result ", void *" auditdata ");"
 .in
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/avc_init.3
===================================================================
--- branches/policyrep/libselinux/man/man3/avc_init.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/avc_init.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,17 +6,17 @@
 avc_init, avc_destroy, avc_reset, avc_cleanup \- userspace SELinux AVC setup and teardown.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_init(const char *" msgprefix , 
 .in +\w'int avc_init('u
 .BI "const struct avc_memory_callback *" mem_callbacks ,
-.br
+
 .BI "const struct avc_log_callback *" log_callbacks ,
-.br
+
 .BI "const struct avc_thread_callback *" thread_callbacks ,
-.br
+
 .BI "const struct avc_lock_callback *" lock_callbacks ");"
 .in
 .sp
Modified: branches/policyrep/libselinux/man/man3/context_new.3
===================================================================
--- branches/policyrep/libselinux/man/man3/context_new.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/context_new.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -4,27 +4,27 @@
 
 .SH "SYNOPSIS"
 .B #include <selinux/context.h>
-.br 
+
 .B "context_t context_new(const char *" context_str );
-.br 
+
 .B "const char * context_str(context_t " con );
-.br 
+
 .B "void context_free(context_t " con );
-.br 
+
 .B "const char * context_type_get(context_t " con );
-.br 
+
 .B "const char * context_range_get(context_t " con );
-.br 
+
 .B "const char * context_role_get(context_t " con );
-.br 
+
 .B "const char * context_user_get(context_t " con );
-.br 
+
 .B "const char * context_type_set(context_t " con ", const char* " type);
-.br 
+
 .B "const char * context_range_set(context_t " con ", const char* " range);
-.br 
+
 .B "const char * context_role_set(context_t " con ", const char* " role );
-.br 
+
 .B "const char * context_user_set(context_t " con ", const char* " user );
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/freecon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/freecon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/freecon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -5,7 +5,7 @@
 .B #include <selinux/selinux.h>
 .sp
 .BI "void freecon(security_context_t "con );
-.br 
+
 .BI "void freeconary(security_context_t *" con );
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/get_ordered_context_list.3
===================================================================
--- branches/policyrep/libselinux/man/man3/get_ordered_context_list.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/get_ordered_context_list.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -4,7 +4,7 @@
 
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/get_context_list.h>
 .sp
 .BI "int get_ordered_context_list(const char *" user ", security_context_t "fromcon ", security_context_t **" list );
Modified: branches/policyrep/libselinux/man/man3/getcon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/getcon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/getcon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -1,21 +1,21 @@
 .TH "getcon" "3" "1 January 2004" "ru...@co..." "SELinux API documentation"
 .SH "NAME"
 getcon, getprevcon, getpidcon \- get SELinux security context of a process.
-.br
+
 getpeercon - get security context of a peer socket.
-.br
+
 setcon - set current security context of a process.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getcon(security_context_t *" context );
-.br 
+
 .BI "int getprevcon(security_context_t *" context );
-.br
+
 .BI "int getpidcon(pid_t " pid ", security_context_t *" context );
-.br
+
 .BI "int getpeercon(int " fd ", security_context_t *" context);
-.br
+
 .BI "int setcon(security_context_t " context);
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/getexeccon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/getexeccon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/getexeccon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -1,16 +1,16 @@
 .TH "getexeccon" "3" "1 January 2004" "ru...@co..." "SELinux API documentation"
 .SH "NAME"
 getexeccon, setexeccon \- get or set the SELinux security context used for executing a new process.
-.br
+
 rpm_execcon \- run a helper for rpm in an appropriate security context
 
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getexeccon(security_context_t *" context );
-.br 
+
 .BI "int setexeccon(security_context_t "context );
-.br 
+
 .BI "int rpm_execcon(unsigned int " verified ", const char *" filename ", char *const " argv "[] , char *const " envp "[]);
 
 .SH "DESCRIPTION"
@@ -26,17 +26,17 @@
 setexeccon to reset to the default policy behavior.  
 The exec context is automatically reset after the next execve, so a
 program doesn't need to explicitly sanitize it upon startup.  
-.br
 
+
 setexeccon can be applied prior to library
 functions that internally perform an execve, e.g. execl*, execv*, popen,
 in order to set an exec context for that operation.  
-.br
 
+
 Note: Signal handlers that perform an execve must take care to
 save, reset, and restore the exec context to avoid unexpected behaviors.
-.br
 
+
 .B rpm_execcon
 runs a helper for rpm in an appropriate security context.  The
 verified parameter should contain the return code from the signature
Modified: branches/policyrep/libselinux/man/man3/getfilecon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/getfilecon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/getfilecon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -5,9 +5,9 @@
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getfilecon(const char *" path ", security_context_t *" con );
-.br 
+
 .BI "int lgetfilecon(const char *" path ", security_context_t *" con );
-.br 
+
 .BI "int fgetfilecon(int "fd ", security_context_t *" con );
 .SH "DESCRIPTION"
 .B getfilecon
@@ -22,7 +22,6 @@
 is identical to getfilecon, only the open file pointed to by filedes (as
 returned by open(2)) is interrogated in place of path.
 
-.br
 
 The returned context should be freed with freecon if non-NULL.  
 .SH "RETURN VALUE"
Modified: branches/policyrep/libselinux/man/man3/getfscreatecon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/getfscreatecon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/getfscreatecon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getfscreatecon(security_context_t *" con );
-.br 
+
 .BI "int setfscreatecon(security_context_t "context );
 
 .SH "DESCRIPTION"
@@ -22,12 +22,12 @@
 setfscreatecon to reset to the default policy behavior.  
 The fscreate context is automatically reset after the next execve, so a
 program doesn't need to explicitly sanitize it upon startup.  
-.br
+
 setfscreatecon can be applied prior to library
 functions that internally perform an file creation,
 in order to set an file context on the objects.
-.br
 
+
 Note: Signal handlers that perform an setfscreate must take care to
 save, reset, and restore the fscreate context to avoid unexpected behaviors.
 .SH "RETURN VALUE"
Modified: branches/policyrep/libselinux/man/man3/getseuserbyname.3
===================================================================
--- branches/policyrep/libselinux/man/man3/getseuserbyname.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/getseuserbyname.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -12,8 +12,8 @@
 then be passed to other libselinux functions such as 
 get_ordered_context_list_with_level and get_default_context_with_level.
 
-.br
 
+
 The returned SELinux username and level should be freed by the caller
 using free.  
 .SH "RETURN VALUE"
Modified: branches/policyrep/libselinux/man/man3/is_context_customizable.3
===================================================================
--- branches/policyrep/libselinux/man/man3/is_context_customizable.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/is_context_customizable.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -8,7 +8,7 @@
 
 .SH "DESCRIPTION"
 .B is_context_customizable
-.br
+
 This function checks whether the type of scon is in the /etc/selinux/SELINUXTYPE/context/customizable_types file.  A customizable type is a file context type that
 administrators set on files, usually to allow certain domains to share the file content. restorecon and setfiles, by default, leave these context in place.
 
Modified: branches/policyrep/libselinux/man/man3/matchmediacon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/matchmediacon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/matchmediacon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,14 +6,14 @@
 .B #include <selinux/selinux.h>
 .sp
 .BI "int matchmediacon(const char *" media ", security_context_t *" con);"
-.br 
 
+
 .SH "DESCRIPTION"
-.br
+
 .B matchmediacon 
 matches the specified media type with the media contexts configuration and sets the security context "con" to refer to the resulting context. 
 .sp
-.br
+
 .B Note: 
    Caller must free returned security context "con" using freecon.
 .SH "RETURN VALUE"
Modified: branches/policyrep/libselinux/man/man3/matchpathcon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/matchpathcon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/matchpathcon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,18 +6,18 @@
 .B #include <selinux/selinux.h>
 .sp
 .BI "int matchpathcon_init(const char *" path ");"
-.br
+
 .BI "int matchpathcon_fini(void);"
-.br
+
 .BI "int matchpathcon(const char *" path ", mode_t " mode ", security_context_t *" con);
 .sp
-.br 
+
 .BI "void set_matchpathcon_printf(void (*" f ")(const char *" fmt ", ...));"
-.br
+
 .BI "void set_matchpathcon_invalidcon(int (*" f ")(const char *"path ", unsigned " lineno ", char * " context "));"
-.br
+
 .BI "void set_matchpathcon_flags(unsigned int " flags ");"
-.br
+
 .SH "DESCRIPTION"
 .B matchpathcon_init
 loads the file contexts configuration specified by
@@ -40,7 +40,7 @@
 suffix are also looked up and loaded if present.  These files provide
 dynamically generated entries for user home directories and for local
 customizations.
-.br 
+
 .sp
 .B matchpathcon_fini
 frees the memory allocated by a prior call to
@@ -49,7 +49,7 @@
 .B matchpathcon_init 
 calls, or to free memory when finished using 
 .B matchpathcon.
-.br
+
 .sp
 .B matchpathcon 
 matches the specified pathname and mode against the file contexts
@@ -72,14 +72,14 @@
 .I path,
 defaulting to the active file contexts configuration.
 .sp
-.br
+
 .B set_matchpathcon_printf
 sets the function used by 
 .B matchpathcon_init
 when displaying errors about the file contexts configuration.  If not set, 
 then this defaults to fprintf(stderr, fmt, ...).  This can be set to redirect
 error reporting to a different destination.
-.br
+
 .sp
 .B set_matchpathcon_invalidcon
 sets the function used by 
@@ -100,7 +100,7 @@
 and
 .I lineno
 in such error messages.
-.br
+
 .sp
 .B set_matchpathcon_flags
 sets flags controlling the operation of 
@@ -111,7 +111,7 @@
 .B MATCHPATHCON_BASEONLY
 flag is set, then only the base file contexts configuration file
 will be processed, not any dynamically generated entries or local customizations.
-.br
+
 .sp
 .SH "RETURN VALUE"
 Returns 0 on success or -1 otherwise.
Modified: branches/policyrep/libselinux/man/man3/security_class_to_string.3
===================================================================
--- branches/policyrep/libselinux/man/man3/security_class_to_string.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/security_class_to_string.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -8,7 +8,7 @@
 
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/flask.h>
 .sp
 .BI "const char * security_class_to_string(security_class_t " tclass ");"
Modified: branches/policyrep/libselinux/man/man3/security_compute_av.3
===================================================================
--- branches/policyrep/libselinux/man/man3/security_compute_av.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/security_compute_av.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/flask.h>
 .sp
 .BI "int security_compute_av(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
Modified: branches/policyrep/libselinux/man/man3/security_getenforce.3
===================================================================
--- branches/policyrep/libselinux/man/man3/security_getenforce.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/security_getenforce.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -5,7 +5,7 @@
 .B #include <selinux/selinux.h>
 .sp
 .B int security_getenforce();
-.br
+
 .BI "int security_setenforce(int "value );
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/security_load_booleans.3
===================================================================
--- branches/policyrep/libselinux/man/man3/security_load_booleans.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/security_load_booleans.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -7,15 +7,15 @@
 .B #include <selinux/selinux.h>
 .sp
 extern int security_load_booleans(char *path);
-.br
+
 extern int security_get_boolean_names(char ***names, int *len);
-.br
+
 extern int security_get_boolean_pending(const char *name);
-.br
+
 extern int security_get_boolean_active(const char *name);
-.br
+
 extern int security_set_boolean(const char *name, int value);
-.br
+
 extern int security_commit_booleans(void);
 
 
@@ -29,27 +29,27 @@
 The SELinux API allows for a transaction based update.  So you can set several boolean values and the commit them all at once.
 
 security_load_booleans
-.br
+
 Load policy boolean settings. Path may be NULL, in which case the booleans are loaded from the active policy boolean configuration file.
 
 security_get_boolean_names
-.br
+
 Returns a list of boolean names, currently supported by the loaded policy.
 
 security_set_boolean 
-.br
+
 Sets the pending value for boolean 
 
 security_get_boolean_pending
-.br
+
 Return pending value for boolean
 
 security_get_boolean_active
-.br
+
 Return active value for boolean
 
 security_commit_booleans
-.br
+
 Commit all pending values for the booleans.
 
 .SH AUTHOR	
Modified: branches/policyrep/libselinux/man/man3/selabel_lookup.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selabel_lookup.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selabel_lookup.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,20 +6,20 @@
 selabel_lookup \- obtain SELinux security context from a string label.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/label.h>
 .sp
 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup('u
 .BI "security_context_t *" context ,
-.br
+
 .BI "const char *" key ", int " type ");"
 .in
 .sp
 .BI "int selabel_lookup_raw(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup_raw('u
 .BI "security_context_t *" context ,
-.br
+
 .BI "const char *" key ", int " type ");"
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man3/selabel_open.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selabel_open.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selabel_open.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,13 +6,13 @@
 selabel_open, selabel_close \- userspace SELinux labeling interface.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/label.h>
 .sp
 .BI "struct selabel_handle *selabel_open(int " backend , 
 .in +\w'struct selabel_handle *selabel_open('u
 .BI "struct selinux_opt *" options ,
-.br
+
 .BI "unsigned " nopt ");"
 .in
 .sp
Modified: branches/policyrep/libselinux/man/man3/selabel_stats.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selabel_stats.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selabel_stats.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,7 +6,7 @@
 selabel_stats \- obtain SELinux labeling statistics.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/label.h>
 .sp
 .BI "void selabel_lookup(struct selabel_handle *" hnd ");"
Modified: branches/policyrep/libselinux/man/man3/selinux_binary_policy_path.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selinux_binary_policy_path.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selinux_binary_policy_path.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -10,27 +10,27 @@
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.br
+
 extern const char *selinux_policy_root(void);
-.br
+
 extern const char *selinux_binary_policy_path(void);
-.br
+
 extern const char *selinux_failsafe_context_path(void);
-.br
+
 extern const char *selinux_removable_context_path(void);
-.br
+
 extern const char *selinux_default_context_path(void);
-.br
+
 extern const char *selinux_user_contexts_path(void);
-.br
+
 extern const char *selinux_file_context_path(void);
-.br
+
 extern const char *selinux_media_context_path(void);
-.br
+
 extern const char *selinux_securetty_types_path(void);
-.br
+
 extern const char *selinux_contexts_path(void);
-.br
+
 extern const char *selinux_booleans_path(void);
 
 
Modified: branches/policyrep/libselinux/man/man3/selinux_getenforcemode.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selinux_getenforcemode.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selinux_getenforcemode.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -5,13 +5,13 @@
 .B #include <selinux/selinux.h>
 .sp
 .B int selinux_getenforcemode(int *enforce);
-.br
 
+
 .SH "DESCRIPTION"
 .B selinux_getenforcemode
 Reads the contents of the /etc/selinux/config file to determine how the 
 system was setup to run SELinux.
-.br
+
 Sets the value of enforce to 1 if SELinux should be run in enforcing mode.
 Sets the value of enforce to 0 if SELinux should be run in permissive mode.
 Sets the value of enforce to -1 if SELinux should be disabled.
Modified: branches/policyrep/libselinux/man/man3/selinux_policy_root.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selinux_policy_root.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selinux_policy_root.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -5,8 +5,8 @@
 .B #include <selinux/selinux.h>
 .sp
 .B char *selinux_policy_root();
-.br
 
+
 .SH "DESCRIPTION"
 .B selinux_policy_root
 Reads the contents of the /etc/selinux/config file to determine which policy files should be used for this machine.
Modified: branches/policyrep/libselinux/man/man3/selinux_set_callback.3
===================================================================
--- branches/policyrep/libselinux/man/man3/selinux_set_callback.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/selinux_set_callback.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -39,11 +39,11 @@
 argument indicates the type of message and will be set to one of the following:
 
 .B SELINUX_ERROR
-.br
+
 .B SELINUX_WARNING
-.br
+
 .B SELINUX_INFO
-.br
+
 .B SELINUX_AVC
 
 .TP
Modified: branches/policyrep/libselinux/man/man3/setfilecon.3
===================================================================
--- branches/policyrep/libselinux/man/man3/setfilecon.3	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man3/setfilecon.3	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,9 +6,9 @@
 .B #include <selinux/selinux.h>
 .sp
 .BI "int setfilecon(const char *" path ", security_context_t "con );
-.br 
+
 .BI "int lsetfilecon(const char *" path ", security_context_t "con );
-.br 
+
 .BI "int fsetfilecon(int "fd ", security_context_t "con );
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man5/selabel_file.5
===================================================================
--- branches/policyrep/libselinux/man/man5/selabel_file.5	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man5/selabel_file.5	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,13 +6,13 @@
 selabel_file \- userspace SELinux labeling interface: file contexts backend.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/label.h>
 .sp
 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup('u
 .BI "security_context_t *" context ,
-.br
+
 .BI "const char *" path ", int " mode ");"
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man5/selabel_media.5
===================================================================
--- branches/policyrep/libselinux/man/man5/selabel_media.5	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man5/selabel_media.5	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,13 +6,13 @@
 selabel_media \- userspace SELinux labeling interface: media contexts backend.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/label.h>
 .sp
 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup('u
 .BI "security_context_t *" context ,
-.br
+
 .BI "const char *" device_name ", int " unused ");"
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man5/selabel_x.5
===================================================================
--- branches/policyrep/libselinux/man/man5/selabel_x.5	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man5/selabel_x.5	2007-09-04 18:22:54 UTC (rev 2545)
@@ -6,13 +6,13 @@
 selabel_x \- userspace SELinux labeling interface: X Window System contexts backend.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-.br
+
 .B #include <selinux/label.h>
 .sp
 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup('u
 .BI "security_context_t *" context ,
-.br
+
 .BI "const char *" object_name ", int " object_type ");"
 
 .SH "DESCRIPTION"
Modified: branches/policyrep/libselinux/man/man8/matchpathcon.8
===================================================================
--- branches/policyrep/libselinux/man/man8/matchpathcon.8	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man8/matchpathcon.8	2007-09-04 18:22:54 UTC (rev 2545)
@@ -10,16 +10,16 @@
 .SH OPTIONS
 .B \-n
 Do not display path.
-.br
+
 .B \-N
 Do not use translations.
-.br
+
 .B \-f file_context_file
 Use alternate file_context file
-.br
+
 .B \-p prefix
 Use prefix to speed translations
-.br
+
 .B \-V
 Verify file context on disk matches defaults
 
Modified: branches/policyrep/libselinux/man/man8/selinux.8
===================================================================
--- branches/policyrep/libselinux/man/man8/selinux.8	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/man/man8/selinux.8	2007-09-04 18:22:54 UTC (rev 2545)
@@ -62,14 +62,13 @@
 .B system-config-securitylevel
 allows customization of these booleans and tunables.
 
-.br
 Many domains that are protected by SELinux also include selinux man pages explainging how to customize their policy.  
 
 .SH FILE LABELING
 
 All files, directories, devices ... have a security context/label associated with them.  These context are stored in the extended attributes of the file system.
 Problems with SELinux often arise from the file system being mislabeled. This can be caused by booting the machine with a non selinux kernel.  If you see an error message containing file_t, that is usually a good indicator that you have a serious problem with file system labeling.  
-.br 
+
 The best way to relabel the file system is to create the flag file /.autorelabel and reboot.  system-config-securitylevel, also has this capability.  The restorcon/fixfiles commands are also available for relabeling files. 
   
 .SH AUTHOR	
Modified: branches/policyrep/libselinux/src/Makefile
===================================================================
--- branches/policyrep/libselinux/src/Makefile	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/Makefile	2007-09-04 18:22:54 UTC (rev 2545)
@@ -20,7 +20,7 @@
 LIBSO=$(TARGET).$(LIBVERSION)
 
 ifeq ($(DISABLE_AVC),y)
-	UNUSED_SRCS+=avc.c avc_internal.c avc_sidtab.c 
+	UNUSED_SRCS+=avc.c avc_internal.c avc_sidtab.c mapping.c stringrep.c checkAccess.c
 endif
 ifeq ($(DISABLE_BOOL),y)
 	UNUSED_SRCS+=booleans.c
Modified: branches/policyrep/libselinux/src/file_path_suffixes.h
===================================================================
--- branches/policyrep/libselinux/src/file_path_suffixes.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/file_path_suffixes.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -16,5 +16,6 @@
     S_(SEUSERS, "/seusers")
     S_(TRANSLATIONS, "/setrans.conf")
     S_(NETFILTER_CONTEXTS, "/contexts/netfilter_contexts")
-    S_(FILE_CONTEXTS_HOMEDIR, "/contexts/files/file_contexts.homedir")
+    S_(FILE_CONTEXTS_HOMEDIR, "/contexts/files/file_contexts.homedirs")
     S_(FILE_CONTEXTS_LOCAL, "/contexts/files/file_contexts.local")
+    S_(X_CONTEXTS, "/contexts/x_contexts")
Modified: branches/policyrep/libselinux/src/label_internal.h
===================================================================
--- branches/policyrep/libselinux/src/label_internal.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/label_internal.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -58,10 +58,11 @@
 /*
  * Compatibility support
  */
+extern int myprintf_compat;
 extern void __attribute__ ((format(printf, 1, 2)))
 (*myprintf) (const char *fmt,...);
 
-#define COMPAT_LOG(type, fmt...) if (myprintf)		  \
+#define COMPAT_LOG(type, fmt...) if (myprintf_compat)	  \
 		myprintf(fmt);				  \
 	else						  \
 		selinux_log(type, fmt);
Modified: branches/policyrep/libselinux/src/label_x.c
===================================================================
--- branches/policyrep/libselinux/src/label_x.c	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/label_x.c	2007-09-04 18:22:54 UTC (rev 2545)
@@ -107,7 +107,7 @@
 
 	/* Open the specification file. */
 	if (!path)
-		path = "/etc/selinux/refpolicy/contexts/x_contexts";
+		path = selinux_x_context_path();
 	if ((fp = fopen(path, "r")) == NULL)
 		return -1;
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
Modified: branches/policyrep/libselinux/src/mapping.h
===================================================================
--- branches/policyrep/libselinux/src/mapping.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/mapping.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -31,4 +31,11 @@
 extern void
 map_decision(security_class_t tclass, struct av_decision *avd);
 
+/*mapping is not used for embedded build*/
+#ifdef DISABLE_AVC 
+#define unmap_perm(x,y) y
+#define unmap_class(x) x
+#define map_decision(x,y) 
+#endif
+
 #endif				/* _SELINUX_MAPPING_H_ */
Modified: branches/policyrep/libselinux/src/matchpathcon.c
===================================================================
--- branches/policyrep/libselinux/src/matchpathcon.c	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/matchpathcon.c	2007-09-04 18:22:54 UTC (rev 2545)
@@ -65,14 +65,13 @@
 #ifdef __GNUC__
     __attribute__ ((format(printf, 1, 2)))
 #endif
-    (*myprintf) (const char *fmt,...);
+    (*myprintf) (const char *fmt,...) = &default_printf;
+int myprintf_compat = 0;
 
 void set_matchpathcon_printf(void (*f) (const char *fmt, ...))
 {
-	if (f)
-		myprintf = f;
-	else
-		myprintf = &default_printf;
+	myprintf = f ? f : &default_printf;
+	myprintf_compat = 1;
 }
 
 static int (*myinvalidcon) (const char *p, unsigned l, char *c) = NULL;
Modified: branches/policyrep/libselinux/src/selinux_config.c
===================================================================
--- branches/policyrep/libselinux/src/selinux_config.c	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/selinux_config.c	2007-09-04 18:22:54 UTC (rev 2545)
@@ -38,7 +38,8 @@
 #define FILE_CONTEXTS_HOMEDIR 16
 #define FILE_CONTEXTS_LOCAL 17
 #define SECURETTY_TYPES   18
-#define NEL               19
+#define X_CONTEXTS        19
+#define NEL               20
 
 /* New layout is relative to SELINUXDIR/policytype. */
 static char *file_paths[NEL];
@@ -369,3 +370,10 @@
 }
 
 hidden_def(selinux_file_context_local_path)
+
+const char *selinux_x_context_path()
+{
+	return get_path(X_CONTEXTS);
+}
+
+hidden_def(selinux_x_context_path)
Modified: branches/policyrep/libselinux/src/selinux_internal.h
===================================================================
--- branches/policyrep/libselinux/src/selinux_internal.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/selinux_internal.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -65,6 +65,7 @@
     hidden_proto(selinux_booleans_path)
     hidden_proto(selinux_customizable_types_path)
     hidden_proto(selinux_media_context_path)
+    hidden_proto(selinux_x_context_path)
     hidden_proto(selinux_path)
     hidden_proto(selinux_check_passwd_access)
     hidden_proto(selinux_check_securetty_context)
Modified: branches/policyrep/libselinux/src/stringrep.c
===================================================================
--- branches/policyrep/libselinux/src/stringrep.c	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libselinux/src/stringrep.c	2007-09-04 18:22:54 UTC (rev 2545)
@@ -236,7 +236,7 @@
 
 	dentry = readdir(dir);
 	while (dentry != NULL) {
-		size_t value;
+		unsigned int value;
 		struct stat m;
 
 		snprintf(path, sizeof path, "%s/class/%s/perms/%s", selinux_mnt,s,dentry->d_name);
@@ -258,7 +258,7 @@
 		if (ret < 0)
 			goto err4;
 
-		if (sscanf(buf, "%u", (unsigned int *)&value) != 1)
+		if (sscanf(buf, "%u", &value) != 1)
 			goto err4;
 
 		node->perms[value-1] = strdup(dentry->d_name);
Modified: branches/policyrep/libsemanage/ChangeLog
===================================================================
--- branches/policyrep/libsemanage/ChangeLog	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libsemanage/ChangeLog	2007-09-04 18:22:54 UTC (rev 2545)
@@ -1,3 +1,13 @@
+2.0.5 2007-08-23
+	* Replace genhomedircon script with equivalent functionality within
+	  libsemanage and introduce disable-genhomedircon option in
+	  semanage.conf from Todd Miller.
+	  Note:  Depends on ustr.
+
+2.0.4 2007-08-16
+	* Allow dontaudits to be turned off via semanage interface when
+	  updating policy from Joshua Brindle.
+
 2.0.3 2007-04-25
 	* Fix to libsemanage man patches so whatis will work better from Dan Walsh
 
Modified: branches/policyrep/libsemanage/VERSION
===================================================================
--- branches/policyrep/libsemanage/VERSION	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libsemanage/VERSION	2007-09-04 18:22:54 UTC (rev 2545)
@@ -1 +1 @@
-2.0.3
+2.0.5
Modified: branches/policyrep/libsemanage/include/semanage/handle.h
===================================================================
--- branches/policyrep/libsemanage/include/semanage/handle.h	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libsemanage/include/semanage/handle.h	2007-09-04 18:22:54 UTC (rev 2545)
@@ -69,6 +69,9 @@
  * 1 for yes, 0 for no (default) */
 void semanage_set_create_store(semanage_handle_t * handle, int create_store);
 
+/* Set whether or not to disable dontaudits upon commit */
+void semanage_set_disable_dontaudit(semanage_handle_t * handle, int disable_dontaudit);
+
 /* Check whether policy is managed via libsemanage on this system.
  * Must be called prior to trying to connect.
  * Return 1 if policy is managed via libsemanage on this system,
Modified: branches/policyrep/libsemanage/src/Makefile
===================================================================
--- branches/policyrep/libsemanage/src/Makefile	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libsemanage/src/Makefile	2007-09-04 18:22:54 UTC (rev 2545)
@@ -54,7 +54,7 @@
 	ranlib $@
 
 $(LIBSO): $(LOBJS)
-	$(CC) $(LDFLAGS) -shared -o $@ $^ -lsepol -lselinux -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
+	$(CC) $(LDFLAGS) -shared -o $@ $^ -lsepol -lselinux -lustr -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
 	ln -sf $@ $(TARGET)
 
 conf-scan.c: conf-scan.l conf-parse.h
Modified: branches/policyrep/libsemanage/src/conf-parse.y
===================================================================
--- branches/policyrep/libsemanage/src/conf-parse.y	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libsemanage/src/conf-parse.y	2007-09-04 18:22:54 UTC (rev 2545)
@@ -57,7 +57,7 @@
 }
 
 %token MODULE_STORE VERSION EXPAND_CHECK FILE_MODE SAVE_PREVIOUS SAVE_LINKED
-%token LOAD_POLICY_START SETFILES_START GENHOMEDIRCON_START
+%token LOAD_POLICY_START SETFILES_START DISABLE_GENHOMEDIRCON
 %token VERIFY_MOD_START VERIFY_LINKED_START VERIFY_KERNEL_START BLOCK_END
 %token PROG_PATH PROG_ARGS
 %token <s> ARG
@@ -80,6 +80,7 @@
         |       file_mode
         |       save_previous
         |       save_linked
+        |       disable_genhomedircon
         ;
 
 module_store:   MODULE_STORE '=' ARG {
@@ -137,6 +138,16 @@
                 }
         ;
 
+disable_genhomedircon: DISABLE_GENHOMEDIRCON '=' ARG {
+								if (strcasecmp($3, "false") == 0) {
+										current_conf->disable_genhomedircon = 0;
+									} else if (strcasecmp($3, "true") == 0) {
+										current_conf->disable_genhomedircon = 1;
+									} else {
+										yyerror("disable-genhomedircon can only be 'true' or 'false'");
+									}
+									free($3);
+					  }
 
 command_block: 
                 command_start external_opts BLOCK_END  {
@@ -164,14 +175,6 @@
                                 YYABORT;
                         }
                 }
-        |       GENHOMEDIRCON_START {
-                        semanage_conf_external_prog_destroy(current_conf->genhomedircon);
-                        current_conf->genhomedircon = NULL;
-                        if (new_external_prog(¤t_conf->genhomedircon) == -1) {
-                                parse_errors++;
-                                YYABORT;
-                        }
-                }
         ;
 
 verify_block:   verify_start external_opts BLOCK_END  {
@@ -239,16 +242,6 @@
 		return -1;
 	}
 
-	if ((conf->genhomedircon =
-	     calloc(1, sizeof(*(current_conf->genhomedircon)))) == NULL) {
-		return -1;
-	}
-	if ((conf->genhomedircon->path =
-	     strdup("/usr/sbin/genhomedircon")) == NULL
-	    || (conf->genhomedircon->args = strdup("-t $@")) == NULL) {
-		return -1;
-	}
-
 	return 0;
 }
 
@@ -303,7 +296,6 @@
 		free(conf->store_path);
 		semanage_conf_external_prog_destroy(conf->load_policy);
 		semanage_conf_external_prog_destroy(conf->setfiles);
-		semanage_conf_external_prog_destroy(conf->genhomedircon);
 		semanage_conf_external_prog_destroy(conf->mod_prog);
 		semanage_conf_external_prog_destroy(conf->linked_prog);
 		semanage_conf_external_prog_destroy(conf->kernel_prog);
Modified: branches/policyrep/libsemanage/src/conf-scan.l
===================================================================
--- branches/policyrep/libsemanage/src/conf-scan.l	2007-08-29 13:03:18 UTC (rev 2544)
+++ branches/policyrep/libsemanage/src/conf-scan.l	2007-09-04 18:22:54 UTC (rev 2545)
@@ -44,9 +44,9 @@
 file-mode         return FILE_MODE;
 save-previous     return SAVE_PREVIOUS;
 save-linked       return SAVE_LINKED;
+disable-genhomedircon return DISABLE_GENHOMEDIRCON;
 "[load_policy]"   return LOAD_POLICY_START;
 "[setfiles]"      return SETFILES_START;
-"[genhomedircon]" return GENHOMEDIRCON_START;
 "[verify module]" return VERIFY_MOD_START;
 "[verify linked]" return VERIFY_LINKED_START;
 "[verify kernel]" return VERIFY_KERNEL_START;
Copied: branches/policyrep/libsemanage/src/genhomedircon.c (from rev 2544, trunk/libsemanage/src/genhomedircon.c)
===================================================================
--- branches/policyrep/libsemanage/src/genhomedircon.c	                        (rev 0)
+++ branches/policyrep/libsemanage/src/genhomedircon.c	2007-09-04 18:22:54 UTC (rev 2545)
@@ -0,0 +1,717 @@
+/* Author: Mark Goldman   <mgo...@tr...>
+ * 			Paul Rosenfeld	<pro...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as
+ *  published by the Free Software Foundation; either version 2.1 of the
+ *  License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ *  02110-1301  USA
+ */
+
+#include <semanage/handle.h>
+#include <semanage/seusers_policy.h>
+#include <semanage/users_policy.h>
+#include <semanage/user_record.h>
+#include "semanage_store.h"
+#include "seuser_internal.h"
+#include "debug.h"
+
+#include "utilities.h"
+#include "genhomedircon.h"
+#include <ustr.h>
+
+#include <assert.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <errno.h>
+
+/* paths used in get_home_dirs() */
+#define PATH_ETC_USERADD "/etc/default/useradd"
+#define PATH_ETC_LIBUSER "/etc/libuser.conf"
+#define PATH_DEFAULT_HOME "/home"
+#define PATH_EXPORT_HOME "/export/home"
+#define PATH_ETC_LOGIN_DEFS "/etc/login.defs"
+
+/* other paths */
+#define PATH_SHELLS_FILE "/etc/shells"
+#define PATH_NOLOGIN_SHELL "/sbin/nologin"
+
+/* comments written to context file */
+#define COMMENT_FILE_CONTEXT_HEADER "#\n#\n# " \
+			"User-specific file contexts, generated via libsemanage\n" \
+			"# use semanage command to manage system users to change" \
+			" the file_context\n#\n#\n"
+
+#define COMMENT_USER_HOME_CONTEXT "\n\n#\n# Home Context for user %s" \
+			"\n#\n\n"
+
+/* placeholders used in the template file
+   which are searched for and replaced */
+#define TEMPLATE_HOME_ROOT "HOME_ROOT"
+#define TEMPLATE_HOME_DIR "HOME_DIR"
+#define TEMPLATE_USER "USER"
+#define TEMPLATE_ROLE "ROLE"
+#define TEMPLATE_SEUSER "system_u"
+
+#define FALLBACK_USER "user_u"
+#define FALLBACK_USER_PREFIX "user"
+#define DEFAULT_LOGIN "__default__"
+
+typedef struct {
+	const char *fcfilepath;
+	int usepasswd;
+	const char *homedir_template_path;
+	semanage_handle_t *h_semanage;
+} genhomedircon_settings_t;
+
+typedef struct user_entry {
+	char *name;
+	char *sename;
+	char *prefix;
+	char *home;
+	struct user_entry *next;
+} genhomedircon_user_entry_t;
+
+typedef struct {
+	const char *search_for;
+	const char *replace_with;
+} replacement_pair_t;
+
+static semanage_list_t *default_shell_list(void)
+{
+	semanage_list_t *list = NULL;
+
+	if (semanage_list_push(&list, "/bin/csh")
+	    || semanage_list_push(&list, "/bin/tcsh")
+	    || semanage_list_push(&list, "/bin/ksh")
+	    || semanage_list_push(&list, "/bin/bsh")
+	    || semanage_list_push(&list, "/bin/ash")
+	    || semanage_list_push(&list, "/usr/bin/ksh")
+	    || semanage_list_push(&list, "/usr/bin/pdksh")
+	    || semanage_list_push(&list, "/bin/zsh")
+	    || semanage_list_push(&list, "/bin/sh")
+	    || semanage_list_push(&list, "/bin/bash"))
+		goto fail;
+
+	return list;
+
+      fail:
+	semanage_list_destroy(&list);
+	return NULL;
+}
+
+static semanage_list_t *get_shell_list(void)
+{
+	FILE *shells;
+	char *temp = NULL;
+	semanage_list_t *list = NULL;
+	size_t buff_len = 0;
+
+	shells = fopen(PATH_SHELLS_FILE, "r");
+	if (!shells)
+		return default_shell_list();
+	while (getline(&temp, &buff_len, shells) >= 0) {
+		if (strcmp(temp, PATH_NOLOGIN_SHELL)) {
+			if (semanage_list_push(&list, temp)) {
+				free(temp);
+				semanage_list_destroy(&list);
+				return default_shell_list();
+			}
+		}
+	}
+	free(temp);
+
+	return list;
+}
+
+static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s)
+{
+	semanage_list_t *homedir_list = NULL;
+	semanage_list_t *shells = NULL;
+	char *path = NULL;
+	size_t minuid = 0;
+	size_t minuid_set = 0;
+	size_t temp;
+	struct passwd *pwbuf;
+	struct stat buf;
+
+	shells = get_shell_list();
+	assert(shells);
+
+	path = semanage_findval(PATH_ETC_USERADD, "HOME", "=");
+	if (path && *path) {
+		if (semanage_list_push(&homedir_list, path)) {
+			free(path);
+			goto fail;
+		}
+	}
+	free(path);
+
+	path = semanage_findval(PATH_ETC_LIBUSER, "LU_HOMEDIRECTORY", "=");
+	if (path && *path) {
+		if (semanage_list_push(&homedir_list, path)) {
+			free(path);
+			goto fail;
+		}
+	}
+	free(path);
+
+	if (!homedir_list) {
+		if (semanage_list_push(&homedir_list, PATH_DEFAULT_HOME)) {
+			goto fail;
+		}
+	}
+
+	if (!stat(PATH_EXPORT_HOME, &buf)) {
+		if (S_ISDIR(buf.st_mode)) {
+			if (semanage_list_push(&homedir_list, PATH_EXPORT_HOME)) {
+				goto fail;
+			}
+		}
+	}
+
+	if (!(s->usepasswd))
+		return homedir_list;
+
+	path = semanage_findval(PATH_ETC_LOGIN_DEFS, "UID_MIN", NULL);
+	if (path && *path) {
+		temp = atoi(path);
+		if (!minuid_set || temp < minuid) {
+			minuid = temp;
+			minuid_set = 1;
+		}
+	}
+	free(path);
+
+	path = semanage_findval(PATH_ETC_LIBUSER, "LU_UIDNUMBER", "=");
+	if (path && *path) {
+		temp = atoi(path);
+		if (!minuid_set || temp < minuid) {
+			minuid = temp;
+			minuid_set = 1;
+		}
+	}
+	free(path);
+
+	if (!minuid_set) {
+		minuid = 500;
+		minuid_set = 1;
+	}
+
+	setpwent();
+	for (errno = 0; (pwbuf = getpwent()); errno = 0) {
+		if (pwbuf->pw_uid < minuid)
+			continue;
+		if (!semanage_list_find(shells, pwbuf->pw_shell))
+			continue;
+		if (strcmp(pwbuf->pw_dir, "/") == 0)
+			continue;
+		if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)
+			continue;
+		if (!(path = strdup(pwbuf->pw_dir))) {
+			break;
+		}
+
+		semanage_rtrim(path, '/');
+		if (!semanage_list_find(homedir_list, path)) {
+			if (semanage_list_push(&homedir_list, path)) {
+				free(path);
+				goto fail;
+			}
+		}
+		free(path);
+	}
+
+	if (errno) {
+		WARN(s->h_semanage, "Error while fetching users.  "
+		     "Returning list so far.");
+	}
+	endpwent();
+	semanage_list_destroy(&shells);
+	if (semanage_list_sort(&homedir_list))
+		goto fail;
+
+	...
 
[truncated message content] | 
| 
      
      
      From: <ssm...@us...> - 2007-08-29 13:03:22
      
     | 
| Revision: 2544
          http://selinux.svn.sourceforge.net/selinux/?rev=2544&view=rev
Author:   ssmalley
Date:     2007-08-29 06:03:18 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
updated libsepol to version 2.0.9
Modified Paths:
--------------
    trunk/libsepol/ChangeLog
    trunk/libsepol/VERSION
Modified: trunk/libsepol/ChangeLog
===================================================================
--- trunk/libsepol/ChangeLog	2007-08-29 13:02:10 UTC (rev 2543)
+++ trunk/libsepol/ChangeLog	2007-08-29 13:03:18 UTC (rev 2544)
@@ -1,3 +1,6 @@
+2.0.9 2007-08-29
+	* Moved next_entry and put_entry out-of-line to reduce code size from Ulrich Drepper.
+
 2.0.8 2007-08-28
 	* Fixed module_package_read_offsets bug introduced by the prior patch.
 
Modified: trunk/libsepol/VERSION
===================================================================
--- trunk/libsepol/VERSION	2007-08-29 13:02:10 UTC (rev 2543)
+++ trunk/libsepol/VERSION	2007-08-29 13:03:18 UTC (rev 2544)
@@ -1 +1 @@
-2.0.8
+2.0.9
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-29 13:02:13
      
     | 
| Revision: 2543
          http://selinux.svn.sourceforge.net/selinux/?rev=2543&view=rev
Author:   ssmalley
Date:     2007-08-29 06:02:10 -0700 (Wed, 29 Aug 2007)
Log Message:
-----------
Author: Ulrich Drepper
Email: dr...@re...
Subject: libsepol optimization
Date: Tue, 28 Aug 2007 12:53:23 -0700
First in a series of changes proposed for libsepol.
The first is a little patch which shrinks the DSO by 4.3%.  The
next_entry and put_entry functions are marked inline.  These are not
good candidates, the code is too big.  I bet without inlining them the
code actually runs faster because the i-cache isn't so polluted.  Plus
the savings in memory of course.
Modified Paths:
--------------
    trunk/libsepol/src/private.h
    trunk/libsepol/src/services.c
Modified: trunk/libsepol/src/private.h
===================================================================
--- trunk/libsepol/src/private.h	2007-08-28 17:42:07 UTC (rev 2542)
+++ trunk/libsepol/src/private.h	2007-08-29 13:02:10 UTC (rev 2543)
@@ -7,6 +7,7 @@
 #include <byteswap.h>
 #include <endian.h>
 #include <errno.h>
+#include <dso.h>
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define cpu_to_le16(x) (x)
@@ -41,52 +42,6 @@
 							   unsigned int type);
 
 /* Reading from a policy "file". */
-static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes)
-{
-	size_t nread;
-
-	switch (fp->type) {
-	case PF_USE_STDIO:
-		nread = fread(buf, bytes, 1, fp->fp);
-		if (nread != 1)
-			return -1;
-		break;
-	case PF_USE_MEMORY:
-		if (bytes > fp->len)
-			return -1;
-		memcpy(buf, fp->data, bytes);
-		fp->data += bytes;
-		fp->len -= bytes;
-		break;
-	default:
-		return -1;
-	}
-	return 0;
-}
-
-static inline size_t put_entry(const void *ptr, size_t size, size_t n,
-			       struct policy_file *fp)
-{
-	size_t bytes = size * n;
-
-	switch (fp->type) {
-	case PF_USE_STDIO:
-		return fwrite(ptr, size, n, fp->fp);
-	case PF_USE_MEMORY:
-		if (bytes > fp->len) {
-			errno = ENOSPC;
-			return 0;
-		}
-
-		memcpy(fp->data, ptr, bytes);
-		fp->data += bytes;
-		fp->len -= bytes;
-		return n;
-	case PF_LEN:
-		fp->len += bytes;
-		return n;
-	default:
-		return 0;
-	}
-	return 0;
-}
+extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden;
+extern size_t put_entry(const void *ptr, size_t size, size_t n,
+		        struct policy_file *fp) hidden;
Modified: trunk/libsepol/src/services.c
===================================================================
--- trunk/libsepol/src/services.c	2007-08-28 17:42:07 UTC (rev 2542)
+++ trunk/libsepol/src/services.c	2007-08-29 13:02:10 UTC (rev 2543)
@@ -927,6 +927,58 @@
 	return rc;
 }
 
+/* Reading from a policy "file". */
+int hidden next_entry(void *buf, struct policy_file *fp, size_t bytes)
+{
+	size_t nread;
+
+	switch (fp->type) {
+	case PF_USE_STDIO:
+		nread = fread(buf, bytes, 1, fp->fp);
+
+		if (nread != 1)
+			return -1;
+		break;
+	case PF_USE_MEMORY:
+		if (bytes > fp->len)
+			return -1;
+		memcpy(buf, fp->data, bytes);
+		fp->data += bytes;
+		fp->len -= bytes;
+		break;
+	default:
+		return -1;
+	}
+	return 0;
+}
+
+size_t hidden put_entry(const void *ptr, size_t size, size_t n,
+			struct policy_file *fp)
+{
+	size_t bytes = size * n;
+
+	switch (fp->type) {
+	case PF_USE_STDIO:
+		return fwrite(ptr, size, n, fp->fp);
+	case PF_USE_MEMORY:
+		if (bytes > fp->len) {
+			errno = ENOSPC;
+			return 0;
+		}
+
+		memcpy(fp->data, ptr, bytes);
+		fp->data += bytes;
+		fp->len -= bytes;
+		return n;
+	case PF_LEN:
+		fp->len += bytes;
+		return n;
+	default:
+		return 0;
+	}
+	return 0;
+}
+
 /*
  * Read a new set of configuration data from 
  * a policy database binary representation file.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-28 17:42:11
      
     | 
| Revision: 2542
          http://selinux.svn.sourceforge.net/selinux/?rev=2542&view=rev
Author:   ssmalley
Date:     2007-08-28 10:42:07 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
updated libsepol to version 1.16.5
Modified Paths:
--------------
    branches/stable/1_0/libsepol/ChangeLog
    branches/stable/1_0/libsepol/VERSION
Modified: branches/stable/1_0/libsepol/ChangeLog
===================================================================
--- branches/stable/1_0/libsepol/ChangeLog	2007-08-28 17:40:41 UTC (rev 2541)
+++ branches/stable/1_0/libsepol/ChangeLog	2007-08-28 17:42:07 UTC (rev 2542)
@@ -1,3 +1,6 @@
+1.16.5 2007-08-28
+	* Fixed module_package_read_offsets bug introduced by the prior patch.
+
 1.16.4 2007-08-23
 	* Eliminate unaligned accesses from policy reading code from Stephen Smalley.
 
Modified: branches/stable/1_0/libsepol/VERSION
===================================================================
--- branches/stable/1_0/libsepol/VERSION	2007-08-28 17:40:41 UTC (rev 2541)
+++ branches/stable/1_0/libsepol/VERSION	2007-08-28 17:42:07 UTC (rev 2542)
@@ -1 +1 @@
-1.16.4
+1.16.5
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-28 17:40:48
      
     | 
| Revision: 2541
          http://selinux.svn.sourceforge.net/selinux/?rev=2541&view=rev
Author:   ssmalley
Date:     2007-08-28 10:40:41 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
Fix size bug in module_package_read_offsets introduced by my prior change
Modified Paths:
--------------
    branches/stable/1_0/libsepol/src/module.c
Modified: branches/stable/1_0/libsepol/src/module.c
===================================================================
--- branches/stable/1_0/libsepol/src/module.c	2007-08-28 17:40:17 UTC (rev 2540)
+++ branches/stable/1_0/libsepol/src/module.c	2007-08-28 17:40:41 UTC (rev 2541)
@@ -353,21 +353,27 @@
 				       struct policy_file *file,
 				       size_t ** offsets, uint32_t * sections)
 {
-	uint32_t buf[3], nsec;
+	uint32_t *buf = NULL, nsec;
 	unsigned i;
-	size_t *off;
+	size_t *off = NULL;
 	int rc;
 
+	buf = malloc(sizeof(uint32_t)*3);
+	if (!buf) {
+		ERR(file->handle, "out of memory");
+		goto err;
+	}
+	  
 	rc = next_entry(buf, file, sizeof(uint32_t) * 3);
 	if (rc < 0) {
 		ERR(file->handle, "module package header truncated");
-		return -1;
+		goto err;
 	}
 	if (le32_to_cpu(buf[0]) != SEPOL_MODULE_PACKAGE_MAGIC) {
 		ERR(file->handle,
 		    "wrong magic number for module package:  expected %u, got %u",
 		    SEPOL_MODULE_PACKAGE_MAGIC, le32_to_cpu(buf[0]));
-		return -1;
+		goto err;
 	}
 
 	mod->version = le32_to_cpu(buf[1]);
@@ -376,23 +382,29 @@
 	if (nsec > MAXSECTIONS) {
 		ERR(file->handle, "too many sections (%u) in module package",
 		    nsec);
-		return -1;
+		goto err;
 	}
 
 	off = (size_t *) malloc((nsec + 1) * sizeof(size_t));
 	if (!off) {
 		ERR(file->handle, "out of memory");
-		return -1;
+		goto err;
 	}
 
-	rc = next_entry(off, file, sizeof(uint32_t) * nsec);
+	free(buf);
+	buf = malloc(sizeof(uint32_t) * nsec);
+	if (!buf) {
+		ERR(file->handle, "out of memory");
+		goto err;
+	}
+	rc = next_entry(buf, file, sizeof(uint32_t) * nsec);
 	if (rc < 0) {
 		ERR(file->handle, "module package offset array truncated");
-		return -1;
+		goto err;
 	}
 
 	for (i = 0; i < nsec; i++) {
-		off[i] = le32_to_cpu(off[i]);
+		off[i] = le32_to_cpu(buf[i]);
 		if (i && off[i] < off[i - 1]) {
 			ERR(file->handle, "offsets are not increasing (at %u, "
 			    "offset %zu -> %zu", i, off[i - 1],
@@ -401,10 +413,15 @@
 		}
 	}
 
-	
+	free(buf); 	
 	off[nsec] = policy_file_length(file);
 	*offsets = off;
 	return 0;
+
+err:
+	free(buf);
+	free(off);
+	return -1;
 }
 
 /* Flags for which sections have been seen during parsing of module package. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-28 17:40:28
      
     | 
| Revision: 2540
          http://selinux.svn.sourceforge.net/selinux/?rev=2540&view=rev
Author:   ssmalley
Date:     2007-08-28 10:40:17 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
updated libsepol to version 2.0.8
Modified Paths:
--------------
    trunk/libsepol/ChangeLog
    trunk/libsepol/VERSION
Modified: trunk/libsepol/ChangeLog
===================================================================
--- trunk/libsepol/ChangeLog	2007-08-28 17:39:25 UTC (rev 2539)
+++ trunk/libsepol/ChangeLog	2007-08-28 17:40:17 UTC (rev 2540)
@@ -1,3 +1,6 @@
+2.0.8 2007-08-28
+	* Fixed module_package_read_offsets bug introduced by the prior patch.
+
 2.0.7 2007-08-23
 	* Eliminate unaligned accesses from policy reading code from Stephen Smalley.
 
Modified: trunk/libsepol/VERSION
===================================================================
--- trunk/libsepol/VERSION	2007-08-28 17:39:25 UTC (rev 2539)
+++ trunk/libsepol/VERSION	2007-08-28 17:40:17 UTC (rev 2540)
@@ -1 +1 @@
-2.0.7
+2.0.8
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-28 17:40:10
      
     | 
| Revision: 2539
          http://selinux.svn.sourceforge.net/selinux/?rev=2539&view=rev
Author:   ssmalley
Date:     2007-08-28 10:39:25 -0700 (Tue, 28 Aug 2007)
Log Message:
-----------
Fix size bug in module_package_read_offsets introduced by my prior change
Modified Paths:
--------------
    trunk/libsepol/src/module.c
Modified: trunk/libsepol/src/module.c
===================================================================
--- trunk/libsepol/src/module.c	2007-08-23 15:01:52 UTC (rev 2538)
+++ trunk/libsepol/src/module.c	2007-08-28 17:39:25 UTC (rev 2539)
@@ -353,21 +353,27 @@
 				       struct policy_file *file,
 				       size_t ** offsets, uint32_t * sections)
 {
-	uint32_t buf[3], nsec;
+	uint32_t *buf = NULL, nsec;
 	unsigned i;
-	size_t *off;
+	size_t *off = NULL;
 	int rc;
 
+	buf = malloc(sizeof(uint32_t)*3);
+	if (!buf) {
+		ERR(file->handle, "out of memory");
+		goto err;
+	}
+	  
 	rc = next_entry(buf, file, sizeof(uint32_t) * 3);
 	if (rc < 0) {
 		ERR(file->handle, "module package header truncated");
-		return -1;
+		goto err;
 	}
 	if (le32_to_cpu(buf[0]) != SEPOL_MODULE_PACKAGE_MAGIC) {
 		ERR(file->handle,
 		    "wrong magic number for module package:  expected %u, got %u",
 		    SEPOL_MODULE_PACKAGE_MAGIC, le32_to_cpu(buf[0]));
-		return -1;
+		goto err;
 	}
 
 	mod->version = le32_to_cpu(buf[1]);
@@ -376,23 +382,29 @@
 	if (nsec > MAXSECTIONS) {
 		ERR(file->handle, "too many sections (%u) in module package",
 		    nsec);
-		return -1;
+		goto err;
 	}
 
 	off = (size_t *) malloc((nsec + 1) * sizeof(size_t));
 	if (!off) {
 		ERR(file->handle, "out of memory");
-		return -1;
+		goto err;
 	}
 
-	rc = next_entry(off, file, sizeof(uint32_t) * nsec);
+	free(buf);
+	buf = malloc(sizeof(uint32_t) * nsec);
+	if (!buf) {
+		ERR(file->handle, "out of memory");
+		goto err;
+	}
+	rc = next_entry(buf, file, sizeof(uint32_t) * nsec);
 	if (rc < 0) {
 		ERR(file->handle, "module package offset array truncated");
-		return -1;
+		goto err;
 	}
 
 	for (i = 0; i < nsec; i++) {
-		off[i] = le32_to_cpu(off[i]);
+		off[i] = le32_to_cpu(buf[i]);
 		if (i && off[i] < off[i - 1]) {
 			ERR(file->handle, "offsets are not increasing (at %u, "
 			    "offset %zu -> %zu", i, off[i - 1],
@@ -401,10 +413,15 @@
 		}
 	}
 
-	
+	free(buf); 	
 	off[nsec] = policy_file_length(file);
 	*offsets = off;
 	return 0;
+
+err:
+	free(buf);
+	free(off);
+	return -1;
 }
 
 /* Flags for which sections have been seen during parsing of module package. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 15:01:54
      
     | 
| Revision: 2538
          http://selinux.svn.sourceforge.net/selinux/?rev=2538&view=rev
Author:   ssmalley
Date:     2007-08-23 08:01:52 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
updated libsepol to version 1.16.4
Modified Paths:
--------------
    branches/stable/1_0/libsepol/ChangeLog
    branches/stable/1_0/libsepol/VERSION
Modified: branches/stable/1_0/libsepol/ChangeLog
===================================================================
--- branches/stable/1_0/libsepol/ChangeLog	2007-08-23 15:00:43 UTC (rev 2537)
+++ branches/stable/1_0/libsepol/ChangeLog	2007-08-23 15:01:52 UTC (rev 2538)
@@ -1,3 +1,6 @@
+1.16.4 2007-08-23
+	* Eliminate unaligned accesses from policy reading code from Stephen Smalley.
+
 1.16.3 2007-04-13
 	* Merged add boolmap argument to expand_module_avrules() from Chris PeBenito.
 
Modified: branches/stable/1_0/libsepol/VERSION
===================================================================
--- branches/stable/1_0/libsepol/VERSION	2007-08-23 15:00:43 UTC (rev 2537)
+++ branches/stable/1_0/libsepol/VERSION	2007-08-23 15:01:52 UTC (rev 2538)
@@ -1 +1 @@
-1.16.3
+1.16.4
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 15:00:47
      
     | 
| Revision: 2537
          http://selinux.svn.sourceforge.net/selinux/?rev=2537&view=rev
Author:   ssmalley
Date:     2007-08-23 08:00:43 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
applied r2534:2535 from trunk
Modified Paths:
--------------
    branches/stable/1_0/libsepol/src/avtab.c
    branches/stable/1_0/libsepol/src/conditional.c
    branches/stable/1_0/libsepol/src/ebitmap.c
    branches/stable/1_0/libsepol/src/module.c
    branches/stable/1_0/libsepol/src/policydb.c
    branches/stable/1_0/libsepol/src/private.h
Modified: branches/stable/1_0/libsepol/src/avtab.c
===================================================================
--- branches/stable/1_0/libsepol/src/avtab.c	2007-08-23 14:59:08 UTC (rev 2536)
+++ branches/stable/1_0/libsepol/src/avtab.c	2007-08-23 15:00:43 UTC (rev 2537)
@@ -333,8 +333,8 @@
 		    int (*insertf) (avtab_t * a, avtab_key_t * k,
 				    avtab_datum_t * d, void *p), void *p)
 {
-	uint16_t *buf16, enabled;
-	uint32_t *buf32, items, items2, val;
+	uint16_t buf16[4], enabled;
+	uint32_t buf32[7], items, items2, val;
 	avtab_key_t key;
 	avtab_datum_t datum;
 	unsigned set;
@@ -345,20 +345,20 @@
 	memset(&datum, 0, sizeof(avtab_datum_t));
 
 	if (vers < POLICYDB_VERSION_AVTAB) {
-		buf32 = next_entry(fp, sizeof(uint32_t));
-		if (!buf32) {
+		rc = next_entry(buf32, fp, sizeof(uint32_t));
+		if (rc < 0) {
 			ERR(fp->handle, "truncated entry");
 			return -1;
 		}
 		items2 = le32_to_cpu(buf32[0]);
 
-		if (items2 < 5 || items2 > 8) {
+		if (items2 < 5 || items2 > ARRAY_SIZE(buf32)) {
 			ERR(fp->handle, "invalid item count");
 			return -1;
 		}
 
-		buf32 = next_entry(fp, sizeof(uint32_t) * items2);
-		if (!buf32) {
+		rc = next_entry(buf32, fp, sizeof(uint32_t) * items2);
+		if (rc < 0) {
 			ERR(fp->handle, "truncated entry");
 			return -1;
 		}
@@ -396,7 +396,7 @@
 			return -1;
 		}
 
-		for (i = 0; i < sizeof(spec_order) / sizeof(uint16_t); i++) {
+		for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
 			if (val & spec_order[i]) {
 				key.specified = spec_order[i] | enabled;
 				datum.data = le32_to_cpu(buf32[items++]);
@@ -414,8 +414,8 @@
 		return 0;
 	}
 
-	buf16 = next_entry(fp, sizeof(uint16_t) * 4);
-	if (!buf16) {
+	rc = next_entry(buf16, fp, sizeof(uint16_t) * 4);
+	if (rc < 0) {
 		ERR(fp->handle, "truncated entry");
 		return -1;
 	}
@@ -426,7 +426,7 @@
 	key.specified = le16_to_cpu(buf16[items++]);
 
 	set = 0;
-	for (i = 0; i < sizeof(spec_order) / sizeof(uint16_t); i++) {
+	for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
 		if (key.specified & spec_order[i])
 			set++;
 	}
@@ -435,8 +435,8 @@
 		return -1;
 	}
 
-	buf32 = next_entry(fp, sizeof(uint32_t));
-	if (!buf32) {
+	rc = next_entry(buf32, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		ERR(fp->handle, "truncated entry");
 		return -1;
 	}
@@ -454,11 +454,11 @@
 {
 	unsigned int i;
 	int rc;
-	uint32_t *buf;
+	uint32_t buf[1];
 	uint32_t nel;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		ERR(fp->handle, "truncated table");
 		goto bad;
 	}
Modified: branches/stable/1_0/libsepol/src/conditional.c
===================================================================
--- branches/stable/1_0/libsepol/src/conditional.c	2007-08-23 14:59:08 UTC (rev 2536)
+++ branches/stable/1_0/libsepol/src/conditional.c	2007-08-23 15:00:43 UTC (rev 2537)
@@ -569,15 +569,16 @@
 {
 	char *key = 0;
 	cond_bool_datum_t *booldatum;
-	uint32_t *buf, len;
+	uint32_t buf[3], len;
+	int rc;
 
 	booldatum = malloc(sizeof(cond_bool_datum_t));
 	if (!booldatum)
 		return -1;
 	memset(booldatum, 0, sizeof(cond_bool_datum_t));
 
-	buf = next_entry(fp, sizeof(uint32_t) * 3);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+	if (rc < 0)
 		goto err;
 
 	booldatum->s.value = le32_to_cpu(buf[0]);
@@ -588,13 +589,12 @@
 
 	len = le32_to_cpu(buf[2]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto err;
 	key = malloc(len + 1);
 	if (!key)
 		goto err;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto err;
 	key[len] = 0;
 	if (hashtab_insert(h, key, booldatum))
 		goto err;
@@ -703,14 +703,14 @@
 {
 	unsigned int i;
 	int rc;
-	uint32_t *buf, len;
+	uint32_t buf[1], len;
 	struct cond_insertf_data data;
 
 	*ret_list = NULL;
 
 	len = 0;
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 
 	len = le32_to_cpu(buf[0]);
@@ -752,27 +752,27 @@
 
 static int cond_read_node(policydb_t * p, cond_node_t * node, void *fp)
 {
-	uint32_t *buf;
-	int len, i;
+	uint32_t buf[2];
+	int len, i, rc;
 	cond_expr_t *expr = NULL, *last = NULL;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto err;
 
 	node->cur_state = le32_to_cpu(buf[0]);
 
 	len = 0;
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto err;
 
 	/* expr */
 	len = le32_to_cpu(buf[0]);
 
 	for (i = 0; i < len; i++) {
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0)
 			goto err;
 
 		expr = malloc(sizeof(cond_expr_t));
@@ -820,11 +820,11 @@
 int cond_read_list(policydb_t * p, cond_list_t ** list, void *fp)
 {
 	cond_node_t *node, *last = NULL;
-	uint32_t *buf;
-	int i, len;
+	uint32_t buf[1];
+	int i, len, rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 
 	len = le32_to_cpu(buf[0]);
Modified: branches/stable/1_0/libsepol/src/ebitmap.c
===================================================================
--- branches/stable/1_0/libsepol/src/ebitmap.c	2007-08-23 14:59:08 UTC (rev 2536)
+++ branches/stable/1_0/libsepol/src/ebitmap.c	2007-08-23 15:00:43 UTC (rev 2537)
@@ -265,16 +265,16 @@
 
 int ebitmap_read(ebitmap_t * e, void *fp)
 {
-	int rc = -EINVAL;
+	int rc;
 	ebitmap_node_t *n, *l;
-	uint32_t *buf, mapsize, count, i;
+	uint32_t buf[3], mapsize, count, i;
 	uint64_t map;
 
 	ebitmap_init(e);
 
-	buf = next_entry(fp, sizeof(uint32_t) * 3);
-	if (!buf)
-		goto out;
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+	if (rc < 0)
+		goto bad;
 
 	mapsize = le32_to_cpu(buf[0]);
 	e->highbit = le32_to_cpu(buf[1]);
@@ -284,7 +284,7 @@
 		printf
 		    ("security: ebitmap: map size %d does not match my size %zu (high bit was %d)\n",
 		     mapsize, MAPSIZE, e->highbit);
-		goto out;
+		goto bad;
 	}
 	if (!e->highbit) {
 		e->node = NULL;
@@ -298,8 +298,8 @@
 	}
 	l = NULL;
 	for (i = 0; i < count; i++) {
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf) {
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0) {
 			printf("security: ebitmap: truncated map\n");
 			goto bad;
 		}
@@ -325,12 +325,11 @@
 			     n->startbit, (e->highbit - MAPSIZE));
 			goto bad_free;
 		}
-		buf = next_entry(fp, sizeof(uint64_t));
-		if (!buf) {
+		rc = next_entry(&map, fp, sizeof(uint64_t));
+		if (rc < 0) {
 			printf("security: ebitmap: truncated map\n");
 			goto bad_free;
 		}
-		memcpy(&map, buf, sizeof(uint64_t));
 		n->map = le64_to_cpu(map);
 
 		if (!n->map) {
@@ -360,6 +359,8 @@
       bad_free:
 	free(n);
       bad:
+	if (!rc)
+		rc = -EINVAL;
 	ebitmap_destroy(e);
 	goto out;
 }
Modified: branches/stable/1_0/libsepol/src/module.c
===================================================================
--- branches/stable/1_0/libsepol/src/module.c	2007-08-23 14:59:08 UTC (rev 2536)
+++ branches/stable/1_0/libsepol/src/module.c	2007-08-23 15:00:43 UTC (rev 2537)
@@ -326,7 +326,7 @@
 static int read_helper(char *buf, struct policy_file *file, uint32_t bytes)
 {
 	uint32_t offset, nel, read_len;
-	void *tmp;
+	int rc;
 
 	offset = 0;
 	nel = bytes;
@@ -336,10 +336,9 @@
 			read_len = nel;
 		else
 			read_len = _read_helper_bufsize;
-		tmp = next_entry(file, read_len);
-		if (!tmp)
+		rc = next_entry(&buf[offset], file, read_len);
+		if (rc < 0)
 			return -1;
-		memcpy(&buf[offset], tmp, read_len);
 		offset += read_len;
 		nel -= read_len;
 	}
@@ -354,11 +353,13 @@
 				       struct policy_file *file,
 				       size_t ** offsets, uint32_t * sections)
 {
-	uint32_t *buf, nsec;
+	uint32_t buf[3], nsec;
 	unsigned i;
+	size_t *off;
+	int rc;
 
-	buf = next_entry(file, sizeof(uint32_t) * 3);
-	if (!buf) {
+	rc = next_entry(buf, file, sizeof(uint32_t) * 3);
+	if (rc < 0) {
 		ERR(file->handle, "module package header truncated");
 		return -1;
 	}
@@ -378,29 +379,31 @@
 		return -1;
 	}
 
-	*offsets = (size_t *) malloc((nsec + 1) * sizeof(size_t));
-	if (!*offsets) {
+	off = (size_t *) malloc((nsec + 1) * sizeof(size_t));
+	if (!off) {
 		ERR(file->handle, "out of memory");
 		return -1;
 	}
 
-	buf = next_entry(file, sizeof(uint32_t) * nsec);
-	if (!buf) {
+	rc = next_entry(off, file, sizeof(uint32_t) * nsec);
+	if (rc < 0) {
 		ERR(file->handle, "module package offset array truncated");
 		return -1;
 	}
 
 	for (i = 0; i < nsec; i++) {
-		(*offsets)[i] = le32_to_cpu(buf[i]);
-		if (i && (*offsets)[i] < (*offsets)[i - 1]) {
+		off[i] = le32_to_cpu(off[i]);
+		if (i && off[i] < off[i - 1]) {
 			ERR(file->handle, "offsets are not increasing (at %u, "
-			    "offset %zu -> %zu", i, (*offsets)[i - 1],
-			    (*offsets)[i]);
+			    "offset %zu -> %zu", i, off[i - 1],
+			    off[i]);
 			return -1;
 		}
 	}
 
-	(*offsets)[nsec] = policy_file_length(file);
+	
+	off[nsec] = policy_file_length(file);
+	*offsets = off;
 	return 0;
 }
 
@@ -415,9 +418,9 @@
 			      struct sepol_policy_file *spf, int verbose)
 {
 	struct policy_file *file = &spf->pf;
-	uint32_t *buf, nsec;
+	uint32_t buf[1], nsec;
 	size_t *offsets, len;
-	int retval = -1;
+	int rc;
 	unsigned i, seen = 0;
 
 	if (module_package_read_offsets(mod, file, &offsets, &nsec))
@@ -442,8 +445,8 @@
 		}
 
 		/* read the magic number, so that we know which function to call */
-		buf = next_entry(file, sizeof(uint32_t));
-		if (!buf) {
+		rc = next_entry(buf, file, sizeof(uint32_t));
+		if (rc < 0) {
 			ERR(file->handle,
 			    "module package section %u truncated, lacks magic number",
 			    i);
@@ -565,8 +568,8 @@
 			if (policy_file_seek(file, offsets[i]))
 				goto cleanup;
 
-			retval = policydb_read(&mod->policy->p, file, verbose);
-			if (retval < 0) {
+			rc = policydb_read(&mod->policy->p, file, verbose);
+			if (rc < 0) {
 				ERR(file->handle,
 				    "invalid module in module package (at section %u)",
 				    i);
@@ -593,7 +596,7 @@
 
       cleanup:
 	free(offsets);
-	return retval;
+	return -1;
 }
 
 int sepol_module_package_info(struct sepol_policy_file *spf, int *type,
@@ -601,9 +604,11 @@
 {
 	struct policy_file *file = &spf->pf;
 	sepol_module_package_t *mod = NULL;
-	uint32_t *buf, len, nsec;
+	uint32_t buf[5], len, nsec;
 	size_t *offsets = NULL;
 	unsigned i, seen = 0;
+	char *id;
+	int rc;
 
 	if (sepol_module_package_create(&mod))
 		return -1;
@@ -630,8 +635,8 @@
 		}
 
 		/* read the magic number, so that we know which function to call */
-		buf = next_entry(file, sizeof(uint32_t) * 2);
-		if (!buf) {
+		rc = next_entry(buf, file, sizeof(uint32_t) * 2);
+		if (rc < 0) {
 			ERR(file->handle,
 			    "module package section %u truncated, lacks magic number",
 			    i);
@@ -695,16 +700,24 @@
 			}
 
 			/* skip id */
-			buf = next_entry(file, len);
-			if (!buf) {
+			id = malloc(len + 1);
+			if (!id) {
 				ERR(file->handle,
+				    "out of memory (at section %u)",
+				    i);
+				goto cleanup;				
+			}
+			rc = next_entry(id, file, len);
+			free(id);
+			if (rc < 0) {
+				ERR(file->handle,
 				    "cannot get module string (at section %u)",
 				    i);
 				goto cleanup;
 			}
-
-			buf = next_entry(file, sizeof(uint32_t) * 5);
-			if (!buf) {
+			
+			rc = next_entry(buf, file, sizeof(uint32_t) * 5);
+			if (rc < 0) {
 				ERR(file->handle,
 				    "cannot get module header (at section %u)",
 				    i);
@@ -726,49 +739,47 @@
 			}
 
 			/* read the name and version */
-			buf = next_entry(file, sizeof(uint32_t));
-			if (!buf) {
+			rc = next_entry(buf, file, sizeof(uint32_t));
+			if (rc < 0) {
 				ERR(file->handle,
 				    "cannot get module name len (at section %u)",
 				    i);
 				goto cleanup;
 			}
 			len = le32_to_cpu(buf[0]);
-			buf = next_entry(file, len);
-			if (!buf) {
-				ERR(file->handle,
-				    "cannot get module name string (at section %u)",
-				    i);
-				goto cleanup;
-			}
 			*name = malloc(len + 1);
 			if (!*name) {
 				ERR(file->handle, "out of memory");
 				goto cleanup;
 			}
-			memcpy(*name, buf, len);
-			(*name)[len] = '\0';
-			buf = next_entry(file, sizeof(uint32_t));
-			if (!buf) {
+			rc = next_entry(*name, file, len);
+			if (rc < 0) {
 				ERR(file->handle,
-				    "cannot get module version len (at section %u)",
+				    "cannot get module name string (at section %u)",
 				    i);
 				goto cleanup;
 			}
-			len = le32_to_cpu(buf[0]);
-			buf = next_entry(file, len);
-			if (!buf) {
+			(*name)[len] = '\0';
+			rc = next_entry(buf, file, sizeof(uint32_t));
+			if (rc < 0) {
 				ERR(file->handle,
-				    "cannot get module version string (at section %u)",
+				    "cannot get module version len (at section %u)",
 				    i);
 				goto cleanup;
 			}
+			len = le32_to_cpu(buf[0]);
 			*version = malloc(len + 1);
 			if (!*version) {
 				ERR(file->handle, "out of memory");
 				goto cleanup;
 			}
-			memcpy(*version, buf, len);
+			rc = next_entry(*version, file, len);
+			if (rc < 0) {
+				ERR(file->handle,
+				    "cannot get module version string (at section %u)",
+				    i);
+				goto cleanup;
+			}
 			(*version)[len] = '\0';
 			seen |= SEEN_MOD;
 			break;
Modified: branches/stable/1_0/libsepol/src/policydb.c
===================================================================
--- branches/stable/1_0/libsepol/src/policydb.c	2007-08-23 14:59:08 UTC (rev 2536)
+++ branches/stable/1_0/libsepol/src/policydb.c	2007-08-23 15:00:43 UTC (rev 2537)
@@ -1316,11 +1316,13 @@
 
 static int role_set_read(role_set_t * r, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
+
 	if (ebitmap_read(&r->roles, fp))
 		return -1;
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	r->flags = le32_to_cpu(buf[0]);
 
@@ -1329,15 +1331,16 @@
 
 static int type_set_read(type_set_t * t, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
 
 	if (ebitmap_read(&t->types, fp))
 		return -1;
 	if (ebitmap_read(&t->negset, fp))
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	t->flags = le32_to_cpu(buf[0]);
 
@@ -1350,16 +1353,21 @@
  */
 static int mls_read_range_helper(mls_range_t * r, struct policy_file *fp)
 {
-	uint32_t *buf;
-	int items, rc = -EINVAL;
+	uint32_t buf[2], items;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto out;
 
 	items = le32_to_cpu(buf[0]);
-	buf = next_entry(fp, sizeof(uint32_t) * items);
-	if (!buf) {
+	if (items > ARRAY_SIZE(buf)) {
+		ERR(fp->handle, "range overflow");
+		rc = -EINVAL;
+		goto out;
+	}
+	rc = next_entry(buf, fp, sizeof(uint32_t) * items);
+	if (rc < 0) {
 		ERR(fp->handle, "truncated range");
 		goto out;
 	}
@@ -1403,14 +1411,15 @@
 static int mls_read_semantic_level_helper(mls_semantic_level_t * l,
 					  struct policy_file *fp)
 {
-	uint32_t *buf, ncat;
+	uint32_t buf[2], ncat;
 	unsigned int i;
 	mls_semantic_cat_t *cat;
+	int rc;
 
 	mls_semantic_level_init(l);
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0) {
 		ERR(fp->handle, "truncated level");
 		goto bad;
 	}
@@ -1428,8 +1437,8 @@
 		cat->next = l->cat;
 		l->cat = cat;
 
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf) {
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0) {
 			ERR(fp->handle, "error reading level categories");
 			goto bad;
 		}
@@ -1513,10 +1522,11 @@
 static int context_read_and_validate(context_struct_t * c,
 				     policydb_t * p, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[3];
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 3);
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+	if (rc < 0) {
 		ERR(fp->handle, "context truncated");
 		return -1;
 	}
@@ -1554,27 +1564,27 @@
 {
 	char *key = 0;
 	perm_datum_t *perdatum;
-	uint32_t *buf;
+	uint32_t buf[2];
 	size_t len;
+	int rc;
 
 	perdatum = calloc(1, sizeof(perm_datum_t));
 	if (!perdatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	perdatum->s.value = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (hashtab_insert(h, key, perdatum))
@@ -1591,16 +1601,17 @@
 {
 	char *key = 0;
 	common_datum_t *comdatum;
-	uint32_t *buf;
+	uint32_t buf[4];
 	size_t len, nel;
 	unsigned int i;
+	int rc;
 
 	comdatum = calloc(1, sizeof(common_datum_t));
 	if (!comdatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 4);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 4);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
@@ -1611,13 +1622,12 @@
 	comdatum->permissions.nprim = le32_to_cpu(buf[2]);
 	nel = le32_to_cpu(buf[3]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	for (i = 0; i < nel; i++) {
@@ -1641,10 +1651,10 @@
 {
 	constraint_node_t *c, *lc;
 	constraint_expr_t *e, *le;
-	uint32_t *buf;
+	uint32_t buf[3];
 	size_t nexpr;
 	unsigned int i, j;
-	int depth;
+	int rc, depth;
 
 	lc = NULL;
 	for (i = 0; i < ncons; i++) {
@@ -1657,8 +1667,8 @@
 		else
 			*nodep = c;
 
-		buf = next_entry(fp, (sizeof(uint32_t) * 2));
-		if (!buf)
+		rc = next_entry(buf, fp, (sizeof(uint32_t) * 2));
+		if (rc < 0)
 			return -1;
 		c->permissions = le32_to_cpu(buf[0]);
 		nexpr = le32_to_cpu(buf[1]);
@@ -1678,8 +1688,8 @@
 				c->expr = e;
 			}
 
-			buf = next_entry(fp, (sizeof(uint32_t) * 3));
-			if (!buf)
+			rc = next_entry(buf, fp, (sizeof(uint32_t) * 3));
+			if (rc < 0)
 				return -1;
 			e->expr_type = le32_to_cpu(buf[0]);
 			e->attr = le32_to_cpu(buf[1]);
@@ -1730,16 +1740,17 @@
 {
 	char *key = 0;
 	class_datum_t *cladatum;
-	uint32_t *buf;
+	uint32_t buf[6];
 	size_t len, len2, ncons, nel;
 	unsigned int i;
+	int rc;
 
 	cladatum = (class_datum_t *) calloc(1, sizeof(class_datum_t));
 	if (!cladatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 6);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 6);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
@@ -1753,23 +1764,21 @@
 
 	ncons = le32_to_cpu(buf[5]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (len2) {
 		cladatum->comkey = malloc(len2 + 1);
 		if (!cladatum->comkey)
 			goto bad;
-		buf = next_entry(fp, len2);
-		if (!buf)
+		rc = next_entry(cladatum->comkey, fp, len2);
+		if (rc < 0)
 			goto bad;
-		memcpy(cladatum->comkey, buf, len2);
 		cladatum->comkey[len2] = 0;
 
 		cladatum->comdatum = hashtab_search(p->p_commons.table,
@@ -1792,8 +1801,8 @@
 	    || (p->policy_type == POLICY_BASE
 		&& p->policyvers >= MOD_POLICYDB_VERSION_VALIDATETRANS)) {
 		/* grab the validatetrans rules */
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			goto bad;
 		ncons = le32_to_cpu(buf[0]);
 		if (read_cons_helper(p, &cladatum->validatetrans, ncons, 1, fp))
@@ -1816,27 +1825,27 @@
 {
 	char *key = 0;
 	role_datum_t *role;
-	uint32_t *buf;
+	uint32_t buf[2];
 	size_t len;
+	int rc;
 
 	role = calloc(1, sizeof(role_datum_t));
 	if (!role)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	role->s.value = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (ebitmap_read(&role->dominates, fp))
@@ -1877,19 +1886,20 @@
 {
 	char *key = 0;
 	type_datum_t *typdatum;
-	uint32_t *buf;
+	uint32_t buf[4];
 	size_t len;
+	int rc;
 
 	typdatum = calloc(1, sizeof(type_datum_t));
 	if (!typdatum)
 		return -1;
 
 	if (p->policy_type == POLICY_KERN) {
-		buf = next_entry(fp, sizeof(uint32_t) * 3);
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
 	} else {
-		buf = next_entry(fp, sizeof(uint32_t) * 4);
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 4);
 	}
-	if (!buf)
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
@@ -1901,13 +1911,12 @@
 			goto bad;
 	}
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (hashtab_insert(h, key, typdatum))
@@ -1923,11 +1932,12 @@
 int role_trans_read(role_trans_t ** t, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, nel;
+	uint32_t buf[3], nel;
 	role_trans_t *tr, *ltr;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	ltr = NULL;
@@ -1941,8 +1951,8 @@
 		} else {
 			*t = tr;
 		}
-		buf = next_entry(fp, sizeof(uint32_t) * 3);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+		if (rc < 0)
 			return -1;
 		tr->role = le32_to_cpu(buf[0]);
 		tr->type = le32_to_cpu(buf[1]);
@@ -1955,11 +1965,12 @@
 int role_allow_read(role_allow_t ** r, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, nel;
+	uint32_t buf[2], nel;
 	role_allow_t *ra, *lra;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	lra = NULL;
@@ -1973,8 +1984,8 @@
 		} else {
 			*r = ra;
 		}
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0)
 			return -1;
 		ra->role = le32_to_cpu(buf[0]);
 		ra->new_role = le32_to_cpu(buf[1]);
@@ -1989,10 +2000,12 @@
 	unsigned int i, j;
 	size_t nel, len;
 	ocontext_t *l, *c;
-	uint32_t *buf;
+	uint32_t buf[8];
+	int rc;
+
 	for (i = 0; i < info->ocon_num; i++) {
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			return -1;
 		nel = le32_to_cpu(buf[0]);
 		l = NULL;
@@ -2009,8 +2022,8 @@
 			l = c;
 			switch (i) {
 			case OCON_ISID:
-				buf = next_entry(fp, sizeof(uint32_t));
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t));
+				if (rc < 0)
 					return -1;
 				c->sid[0] = le32_to_cpu(buf[0]);
 				if (context_read_and_validate
@@ -2019,18 +2032,16 @@
 				break;
 			case OCON_FS:
 			case OCON_NETIF:
-				buf = next_entry(fp, sizeof(uint32_t));
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t));
+				if (rc < 0)
 					return -1;
 				len = le32_to_cpu(buf[0]);
-				buf = next_entry(fp, len);
-				if (!buf)
-					return -1;
 				c->u.name = malloc(len + 1);
-				if (!c->u.name) {
+				if (!c->u.name)
 					return -1;
-				}
-				memcpy(c->u.name, buf, len);
+				rc = next_entry(c->u.name, fp, len);
+				if (rc < 0)
+					return -1;
 				c->u.name[len] = 0;
 				if (context_read_and_validate
 				    (&c->context[0], p, fp))
@@ -2040,8 +2051,8 @@
 					return -1;
 				break;
 			case OCON_PORT:
-				buf = next_entry(fp, sizeof(uint32_t) * 3);
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+				if (rc < 0)
 					return -1;
 				c->u.port.protocol = le32_to_cpu(buf[0]);
 				c->u.port.low_port = le32_to_cpu(buf[1]);
@@ -2051,8 +2062,8 @@
 					return -1;
 				break;
 			case OCON_NODE:
-				buf = next_entry(fp, sizeof(uint32_t) * 2);
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+				if (rc < 0)
 					return -1;
 				c->u.node.addr = le32_to_cpu(buf[0]);
 				c->u.node.mask = le32_to_cpu(buf[1]);
@@ -2061,19 +2072,17 @@
 					return -1;
 				break;
 			case OCON_FSUSE:
-				buf = next_entry(fp, sizeof(uint32_t) * 2);
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+				if (rc < 0)
 					return -1;
 				c->v.behavior = le32_to_cpu(buf[0]);
 				len = le32_to_cpu(buf[1]);
-				buf = next_entry(fp, len);
-				if (!buf)
-					return -1;
 				c->u.name = malloc(len + 1);
-				if (!c->u.name) {
+				if (!c->u.name)
 					return -1;
-				}
-				memcpy(c->u.name, buf, len);
+				rc = next_entry(c->u.name, fp, len);
+				if (rc < 0)
+					return -1;
 				c->u.name[len] = 0;
 				if (context_read_and_validate
 				    (&c->context[0], p, fp))
@@ -2082,10 +2091,9 @@
 			case OCON_NODE6:{
 					int k;
 
-					buf =
-					    next_entry(fp,
-						       sizeof(uint32_t) * 8);
-					if (!buf)
+					rc = next_entry(buf, fp,
+							sizeof(uint32_t) * 8);
+					if (rc < 0)
 						return -1;
 					for (k = 0; k < 4; k++)
 						c->u.node6.addr[k] =
@@ -2109,36 +2117,37 @@
 
 static int genfs_read(policydb_t * p, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
 	size_t nel, nel2, len, len2;
 	genfs_t *genfs_p, *newgenfs, *genfs;
 	unsigned int i, j;
 	ocontext_t *l, *c, *newc = NULL;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto bad;
 	nel = le32_to_cpu(buf[0]);
 	genfs_p = NULL;
 	for (i = 0; i < nel; i++) {
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			goto bad;
 		len = le32_to_cpu(buf[0]);
 		newgenfs = calloc(1, sizeof(genfs_t));
 		if (!newgenfs)
 			goto bad;
-		buf = next_entry(fp, len);
-		if (!buf) {
+		newgenfs->fstype = malloc(len + 1);
+		if (!newgenfs->fstype) {
 			free(newgenfs);
 			goto bad;
 		}
-		newgenfs->fstype = malloc(len + 1);
-		if (!newgenfs->fstype) {
+		rc = next_entry(newgenfs->fstype, fp, len);
+		if (rc < 0) {
+			free(newgenfs->fstype);
 			free(newgenfs);
 			goto bad;
 		}
-		memcpy(newgenfs->fstype, buf, len);
 		newgenfs->fstype[len] = 0;
 		for (genfs_p = NULL, genfs = p->genfs; genfs;
 		     genfs_p = genfs, genfs = genfs->next) {
@@ -2157,8 +2166,8 @@
 			genfs_p->next = newgenfs;
 		else
 			p->genfs = newgenfs;
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			goto bad;
 		nel2 = le32_to_cpu(buf[0]);
 		for (j = 0; j < nel2; j++) {
@@ -2166,21 +2175,20 @@
 			if (!newc) {
 				goto bad;
 			}
-			buf = next_entry(fp, sizeof(uint32_t));
-			if (!buf)
+			rc = next_entry(buf, fp, sizeof(uint32_t));
+			if (rc < 0)
 				goto bad;
 			len = le32_to_cpu(buf[0]);
-			buf = next_entry(fp, len);
-			if (!buf)
-				goto bad;
 			newc->u.name = malloc(len + 1);
 			if (!newc->u.name) {
 				goto bad;
 			}
-			memcpy(newc->u.name, buf, len);
+			rc = next_entry(newc->u.name, fp, len);
+			if (rc < 0)
+				goto bad;
 			newc->u.name[len] = 0;
-			buf = next_entry(fp, sizeof(uint32_t));
-			if (!buf)
+			rc = next_entry(buf, fp, sizeof(uint32_t));
+			if (rc < 0)
 				goto bad;
 			newc->v.sclass = le32_to_cpu(buf[0]);
 			if (context_read_and_validate(&newc->context[0], p, fp))
@@ -2226,12 +2234,13 @@
  */
 static int mls_read_level(mls_level_t * lp, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
 
 	mls_level_init(lp);
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		ERR(fp->handle, "truncated level");
 		goto bad;
 	}
@@ -2251,27 +2260,27 @@
 {
 	char *key = 0;
 	user_datum_t *usrdatum;
-	uint32_t *buf;
+	uint32_t buf[2];
 	size_t len;
+	int rc;
 
 	usrdatum = calloc(1, sizeof(user_datum_t));
 	if (!usrdatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	usrdatum->s.value = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (p->policy_type == POLICY_KERN) {
@@ -2332,27 +2341,27 @@
 {
 	char *key = 0;
 	level_datum_t *levdatum;
-	uint32_t *buf, len;
+	uint32_t buf[2], len;
+	int rc;
 
 	levdatum = malloc(sizeof(level_datum_t));
 	if (!levdatum)
 		return -1;
 	level_datum_init(levdatum);
 
-	buf = next_entry(fp, (sizeof(uint32_t) * 2));
-	if (!buf)
+	rc = next_entry(buf, fp, (sizeof(uint32_t) * 2));
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	levdatum->isalias = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	levdatum->level = malloc(sizeof(mls_level_t));
@@ -2375,28 +2384,28 @@
 {
 	char *key = 0;
 	cat_datum_t *catdatum;
-	uint32_t *buf, len;
+	uint32_t buf[3], len;
+	int rc;
 
 	catdatum = malloc(sizeof(cat_datum_t));
 	if (!catdatum)
 		return -1;
 	cat_datum_init(catdatum);
 
-	buf = next_entry(fp, (sizeof(uint32_t) * 3));
-	if (!buf)
+	rc = next_entry(buf, fp, (sizeof(uint32_t) * 3));
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	catdatum->s.value = le32_to_cpu(buf[1]);
 	catdatum->isalias = le32_to_cpu(buf[2]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (hashtab_insert(h, key, catdatum))
@@ -2420,9 +2429,10 @@
 			     __attribute__ ((unused)), struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, len;
+	uint32_t buf[2], len;
 	class_perm_node_t *cur, *tail = NULL;
 	avrule_t *avrule;
+	int rc;
 
 	avrule = (avrule_t *) malloc(sizeof(avrule_t));
 	if (!avrule)
@@ -2430,8 +2440,8 @@
 
 	avrule_init(avrule);
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	(avrule)->specified = le32_to_cpu(buf[0]);
@@ -2443,8 +2453,8 @@
 	if (type_set_read(&avrule->ttypes, fp))
 		goto bad;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto bad;
 	len = le32_to_cpu(buf[0]);
 
@@ -2454,8 +2464,8 @@
 			goto bad;
 		class_perm_node_init(cur);
 
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf) {
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0) {
 			free(cur);
 			goto bad;
 		}
@@ -2482,15 +2492,16 @@
 
 static int range_read(policydb_t * p, struct policy_file *fp)
 {
-	uint32_t *buf, nel;
+	uint32_t buf[2], nel;
 	range_trans_t *rt, *lrt;
 	range_trans_rule_t *rtr, *lrtr = NULL;
 	unsigned int i;
 	int new_rangetr = (p->policy_type == POLICY_KERN &&
 			   p->policyvers >= POLICYDB_VERSION_RANGETRANS);
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	lrt = NULL;
@@ -2502,14 +2513,14 @@
 			lrt->next = rt;
 		else
 			p->range_tr = rt;
-		buf = next_entry(fp, (sizeof(uint32_t) * 2));
-		if (!buf)
+		rc = next_entry(buf, fp, (sizeof(uint32_t) * 2));
+		if (rc < 0)
 			return -1;
 		rt->source_type = le32_to_cpu(buf[0]);
 		rt->target_type = le32_to_cpu(buf[1]);
 		if (new_rangetr) {
-			buf = next_entry(fp, (sizeof(uint32_t)));
-			if (!buf)
+			rc = next_entry(buf, fp, (sizeof(uint32_t)));
+			if (rc < 0)
 				return -1;
 			rt->target_class = le32_to_cpu(buf[0]);
 		} else
@@ -2578,12 +2589,13 @@
 {
 	unsigned int i;
 	avrule_t *cur, *tail;
-	uint32_t *buf, len;
+	uint32_t buf[1], len;
+	int rc;
 
 	*avrules = tail = NULL;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		return -1;
 	}
 	len = le32_to_cpu(buf[0]);
@@ -2607,12 +2619,13 @@
 
 static int role_trans_rule_read(role_trans_rule_t ** r, struct policy_file *fp)
 {
-	uint32_t *buf, nel;
+	uint32_t buf[1], nel;
 	unsigned int i;
 	role_trans_rule_t *tr, *ltr;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	ltr = NULL;
@@ -2635,8 +2648,8 @@
 		if (type_set_read(&tr->types, fp))
 			return -1;
 
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			return -1;
 		tr->new_role = le32_to_cpu(buf[0]);
 		ltr = tr;
@@ -2648,11 +2661,12 @@
 static int role_allow_rule_read(role_allow_rule_t ** r, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, nel;
+	uint32_t buf[1], nel;
 	role_allow_rule_t *ra, *lra;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	lra = NULL;
@@ -2683,12 +2697,13 @@
 static int range_trans_rule_read(range_trans_rule_t ** r,
 				 struct policy_file *fp)
 {
-	uint32_t *buf, nel;
+	uint32_t buf[1], nel;
 	unsigned int i;
 	range_trans_rule_t *rt, *lrt = NULL;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	for (i = 0; i < nel; i++) {
@@ -2725,15 +2740,17 @@
 			    unsigned int num_scope_syms, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
+
 	for (i = 0; i < num_scope_syms; i++) {
 		if (ebitmap_read(scope_index->scope + i, fp) == -1) {
 			return -1;
 		}
 	}
-	if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
-	}
 	scope_index->class_perms_len = le32_to_cpu(buf[0]);
 	if (scope_index->class_perms_len == 0) {
 		scope_index->class_perms_map = NULL;
@@ -2755,11 +2772,13 @@
 static int avrule_decl_read(policydb_t * p, avrule_decl_t * decl,
 			    unsigned int num_scope_syms, struct policy_file *fp)
 {
-	uint32_t *buf, nprim, nel;
+	uint32_t buf[2], nprim, nel;
 	unsigned int i, j;
-	if ((buf = next_entry(fp, sizeof(uint32_t) * 2)) == NULL) {
+	int rc;
+
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		return -1;
-	}
 	decl->decl_id = le32_to_cpu(buf[0]);
 	decl->enabled = le32_to_cpu(buf[1]);
 	if (cond_read_list(p, &decl->cond_list, fp) == -1 ||
@@ -2778,9 +2797,9 @@
 	}
 
 	for (i = 0; i < num_scope_syms; i++) {
-		if ((buf = next_entry(fp, sizeof(uint32_t) * 2)) == NULL) {
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0) 
 			return -1;
-		}
 		nprim = le32_to_cpu(buf[0]);
 		nel = le32_to_cpu(buf[1]);
 		for (j = 0; j < nel; j++) {
@@ -2799,11 +2818,12 @@
 			     struct policy_file *fp)
 {
 	avrule_block_t *last_block = NULL, *curblock;
-	uint32_t *buf, num_blocks, nel;
+	uint32_t buf[1], num_blocks, nel;
+	int rc;
 
-	if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
-	}
 	num_blocks = le32_to_cpu(buf[0]);
 	nel = num_blocks;
 	while (num_blocks > 0) {
@@ -2812,8 +2832,8 @@
 		if ((curblock = calloc(1, sizeof(*curblock))) == NULL) {
 			return -1;
 		}
-
-		if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0) {
 			free(curblock);
 			return -1;
 		}
@@ -2869,23 +2889,23 @@
 static int scope_read(policydb_t * p, int symnum, struct policy_file *fp)
 {
 	scope_datum_t *scope = NULL;
-	uint32_t *buf;
+	uint32_t buf[2];
 	char *key = NULL;
 	size_t key_len;
 	unsigned int i;
 	hashtab_t h = p->scope[symnum].table;
+	int rc;
 
-	if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto cleanup;
-	}
 	key_len = le32_to_cpu(buf[0]);
-	if ((buf = next_entry(fp, key_len)) == NULL) {
+	key = malloc(key_len + 1);
+	if (!key)
 		goto cleanup;
-	}
-	if ((key = malloc(key_len + 1)) == NULL) {
+	rc = next_entry(key, fp, key_len);
+	if (rc < 0)
 		goto cleanup;
-	}
-	memcpy(key, buf, key_len);
 	key[key_len] = '\0';
 
 	/* ensure that there already exists a symbol with this key */
@@ -2896,9 +2916,9 @@
 	if ((scope = calloc(1, sizeof(*scope))) == NULL) {
 		goto cleanup;
 	}
-	if ((buf = next_entry(fp, sizeof(uint32_t) * 2)) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto cleanup;
-	}
 	scope->scope = le32_to_cpu(buf[0]);
 	scope->decl_ids_len = le32_to_cpu(buf[1]);
 	assert(scope->decl_ids_len > 0);
@@ -2906,12 +2926,11 @@
 	     malloc(scope->decl_ids_len * sizeof(uint32_t))) == NULL) {
 		goto cleanup;
 	}
-	if ((buf =
-	     next_entry(fp, sizeof(uint32_t) * scope->decl_ids_len)) == NULL) {
+	rc = next_entry(scope->decl_ids, fp, sizeof(uint32_t) * scope->decl_ids_len);
+	if (rc < 0)
 		goto cleanup;
-	}
 	for (i = 0; i < scope->decl_ids_len; i++) {
-		scope->decl_ids[i] = le32_to_cpu(buf[i]);
+		scope->decl_ids[i] = le32_to_cpu(scope->decl_ids[i]);
 	}
 
 	if (strcmp(key, "object_r") == 0 && h == p->p_roles_scope.table) {
@@ -2938,18 +2957,19 @@
 {
 
 	unsigned int i, j, r_policyvers;
-	uint32_t *buf, config;
+	uint32_t buf[5], config;
 	size_t len, nprim, nel;
 	char *policydb_str, *target_str = NULL;
 	struct policydb_compat_info *info;
 	unsigned int policy_type, bufindex;
 	ebitmap_node_t *tnode;
+	int rc;
 
 	config = 0;
 
 	/* Read the magic number and string length. */
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		return POLICYDB_ERROR;
 	for (i = 0; i < 2; i++)
 		buf[i] = le32_to_cpu(buf[i]);
@@ -2974,18 +2994,18 @@
 		return POLICYDB_ERROR;
 	}
 
-	buf = next_entry(fp, len);
-	if (!buf) {
-		ERR(fp->handle, "truncated policydb string identifier");
-		return POLICYDB_ERROR;
-	}
 	policydb_str = malloc(len + 1);
 	if (!policydb_str) {
 		ERR(fp->handle, "unable to allocate memory for policydb "
 		    "string of length %zu", len);
 		return POLICYDB_ERROR;
 	}
-	memcpy(policydb_str, buf, len);
+	rc = next_entry(policydb_str, fp, len);
+	if (rc < 0) {
+		ERR(fp->handle, "truncated policydb string identifier");
+		free(policydb_str);
+		return POLICYDB_ERROR;
+	}
 	policydb_str[len] = 0;
 	if (strcmp(policydb_str, target_str)) {
 		ERR(fp->handle, "policydb string %s does not match "
@@ -3003,8 +3023,8 @@
 	else
 		nel = 5;
 
-	buf = next_entry(fp, sizeof(uint32_t) * nel);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * nel);
+	if (rc < 0)
 		return POLICYDB_ERROR;
 	for (i = 0; i < nel; i++)
 		buf[i] = le32_to_cpu(buf[i]);
@@ -3077,35 +3097,33 @@
 
 	if (p->policy_type == POLICY_MOD) {
 		/* Get the module name and version */
-		if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+		if ((rc = next_entry(buf, fp, sizeof(uint32_t))) < 0) {
 			goto bad;
 		}
 		len = le32_to_cpu(buf[0]);
-		if ((buf = next_entry(fp, len)) == NULL) {
+		if ((p->name = malloc(len + 1)) == NULL) {
 			goto bad;
 		}
-		if ((p->name = malloc(len + 1)) == NULL) {
+		if ((rc = next_entry(p->name, fp, len)) < 0) {
 			goto bad;
 		}
-		memcpy(p->name, buf, len);
 		p->name[len] = '\0';
-		if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+		if ((rc = next_entry(buf, fp, sizeof(uint32_t))) < 0) {
 			goto bad;
 		}
 		len = le32_to_cpu(buf[0]);
-		if ((buf = next_entry(fp, len)) == NULL) {
+		if ((p->version = malloc(len + 1)) == NULL) {
 			goto bad;
 		}
-		if ((p->version = malloc(len + 1)) == NULL) {
+		if ((rc = next_entry(p->version, fp, len)) < 0) {
 			goto bad;
 		}
-		memcpy(p->version, buf, len);
 		p->version[len] = '\0';
 	}
 
 	for (i = 0; i < info->sym_num; i++) {
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0)
 			goto bad;
 		nprim = le32_to_cpu(buf[0]);
 		nel = le32_to_cpu(buf[1]);
@@ -3135,7 +3153,7 @@
 			goto bad;
 		}
 		for (i = 0; i < info->sym_num; i++) {
-			if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+			if ((rc = next_entry(buf, fp, sizeof(uint32_t))) < 0) {
 				goto bad;
 			}
 			nel = le32_to_cpu(buf[0]);
Modified: branches/stable/1_0/libsepol/src/private.h
===================================================================
--- branches/stable/1_0/libsepol/src/private.h	2007-08-23 14:59:08 UTC (rev 2536)
+++ branches/stable/1_0/libsepol/src/private.h	2007-08-23 15:00:43 UTC (rev 2537)
@@ -25,6 +25,8 @@
 #undef min
 #define min(a,b) (((a) < (b)) ? (a) : (b))
 
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+
 /* Policy compatibility information. */
 struct policydb_compat_info {
 	unsigned int type;
@@ -37,31 +39,27 @@
 							   unsigned int type);
 
 /* Reading from a policy "file". */
-static inline void *next_entry(struct policy_file *fp, size_t bytes)
+static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes)
 {
-	static unsigned char buffer[BUFSIZ];
 	size_t nread;
 
-	if (bytes > sizeof buffer)
-		return NULL;
-
 	switch (fp->type) {
 	case PF_USE_STDIO:
-		nread = fread(buffer, bytes, 1, fp->fp);
+		nread = fread(buf, bytes, 1, fp->fp);
 		if (nread != 1)
-			return NULL;
+			return -1;
 		break;
 	case PF_USE_MEMORY:
 		if (bytes > fp->len)
-			return NULL;
-		memcpy(buffer, fp->data, bytes);
+			return -1;
+		memcpy(buf, fp->data, bytes);
 		fp->data += bytes;
 		fp->len -= bytes;
 		break;
 	default:
-		return NULL;
+		return -1;
 	}
-	return buffer;
+	return 0;
 }
 
 static inline size_t put_entry(const void *ptr, size_t size, size_t n,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:59:33
      
     | 
| Revision: 2536
          http://selinux.svn.sourceforge.net/selinux/?rev=2536&view=rev
Author:   ssmalley
Date:     2007-08-23 07:59:08 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
updated libsepol to version 2.0.7
Modified Paths:
--------------
    trunk/libsepol/ChangeLog
    trunk/libsepol/VERSION
Modified: trunk/libsepol/ChangeLog
===================================================================
--- trunk/libsepol/ChangeLog	2007-08-23 14:56:56 UTC (rev 2535)
+++ trunk/libsepol/ChangeLog	2007-08-23 14:59:08 UTC (rev 2536)
@@ -1,5 +1,9 @@
+2.0.7 2007-08-23
+	* Eliminate unaligned accesses from policy reading code from Stephen Smalley.
+
 2.0.6 2007-08-16
-	* Allow dontaudits to be turned off during policy expansion
+	* Allow dontaudits to be turned off during policy expansion from
+	  Joshua Brindle.
 
 2.0.5 2007-08-01
 	* Fix sepol_context_clone to handle a NULL context correctly.
Modified: trunk/libsepol/VERSION
===================================================================
--- trunk/libsepol/VERSION	2007-08-23 14:56:56 UTC (rev 2535)
+++ trunk/libsepol/VERSION	2007-08-23 14:59:08 UTC (rev 2536)
@@ -1 +1 @@
-2.0.6
+2.0.7
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:57:00
      
     | 
| Revision: 2535
          http://selinux.svn.sourceforge.net/selinux/?rev=2535&view=rev
Author:   ssmalley
Date:     2007-08-23 07:56:56 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Author: Stephen Smalley
Email: sd...@ty...
Subject: libsepol: eliminate unaligned accesses (Was: Re: wrong magic number (using old sources))
Date: Tue, 21 Aug 2007 13:05:23 -0400
Rewrite libsepol next_entry function and all callers to copy entry data
from the binary policy into properly aligned buffers, eliminating
unaligned accesses, just as I did for the kernel back in 2004,
http://marc.info/?l=selinux&m=110252376515271&w=2
Signed-off-by:  Stephen Smalley <sd...@ty...>
[adjusted for comments from Eric Paris]
Modified Paths:
--------------
    trunk/libsepol/src/avtab.c
    trunk/libsepol/src/conditional.c
    trunk/libsepol/src/ebitmap.c
    trunk/libsepol/src/module.c
    trunk/libsepol/src/policydb.c
    trunk/libsepol/src/private.h
Modified: trunk/libsepol/src/avtab.c
===================================================================
--- trunk/libsepol/src/avtab.c	2007-08-23 14:54:42 UTC (rev 2534)
+++ trunk/libsepol/src/avtab.c	2007-08-23 14:56:56 UTC (rev 2535)
@@ -337,8 +337,8 @@
 		    int (*insertf) (avtab_t * a, avtab_key_t * k,
 				    avtab_datum_t * d, void *p), void *p)
 {
-	uint16_t *buf16, enabled;
-	uint32_t *buf32, items, items2, val;
+	uint16_t buf16[4], enabled;
+	uint32_t buf32[7], items, items2, val;
 	avtab_key_t key;
 	avtab_datum_t datum;
 	unsigned set;
@@ -349,20 +349,20 @@
 	memset(&datum, 0, sizeof(avtab_datum_t));
 
 	if (vers < POLICYDB_VERSION_AVTAB) {
-		buf32 = next_entry(fp, sizeof(uint32_t));
-		if (!buf32) {
+		rc = next_entry(buf32, fp, sizeof(uint32_t));
+		if (rc < 0) {
 			ERR(fp->handle, "truncated entry");
 			return -1;
 		}
 		items2 = le32_to_cpu(buf32[0]);
 
-		if (items2 < 5 || items2 > 8) {
+		if (items2 < 5 || items2 > ARRAY_SIZE(buf32)) {
 			ERR(fp->handle, "invalid item count");
 			return -1;
 		}
 
-		buf32 = next_entry(fp, sizeof(uint32_t) * items2);
-		if (!buf32) {
+		rc = next_entry(buf32, fp, sizeof(uint32_t) * items2);
+		if (rc < 0) {
 			ERR(fp->handle, "truncated entry");
 			return -1;
 		}
@@ -400,7 +400,7 @@
 			return -1;
 		}
 
-		for (i = 0; i < sizeof(spec_order) / sizeof(uint16_t); i++) {
+		for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
 			if (val & spec_order[i]) {
 				key.specified = spec_order[i] | enabled;
 				datum.data = le32_to_cpu(buf32[items++]);
@@ -418,8 +418,8 @@
 		return 0;
 	}
 
-	buf16 = next_entry(fp, sizeof(uint16_t) * 4);
-	if (!buf16) {
+	rc = next_entry(buf16, fp, sizeof(uint16_t) * 4);
+	if (rc < 0) {
 		ERR(fp->handle, "truncated entry");
 		return -1;
 	}
@@ -430,7 +430,7 @@
 	key.specified = le16_to_cpu(buf16[items++]);
 
 	set = 0;
-	for (i = 0; i < sizeof(spec_order) / sizeof(uint16_t); i++) {
+	for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
 		if (key.specified & spec_order[i])
 			set++;
 	}
@@ -439,8 +439,8 @@
 		return -1;
 	}
 
-	buf32 = next_entry(fp, sizeof(uint32_t));
-	if (!buf32) {
+	rc = next_entry(buf32, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		ERR(fp->handle, "truncated entry");
 		return -1;
 	}
@@ -458,11 +458,11 @@
 {
 	unsigned int i;
 	int rc;
-	uint32_t *buf;
+	uint32_t buf[1];
 	uint32_t nel;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		ERR(fp->handle, "truncated table");
 		goto bad;
 	}
Modified: trunk/libsepol/src/conditional.c
===================================================================
--- trunk/libsepol/src/conditional.c	2007-08-23 14:54:42 UTC (rev 2534)
+++ trunk/libsepol/src/conditional.c	2007-08-23 14:56:56 UTC (rev 2535)
@@ -569,15 +569,16 @@
 {
 	char *key = 0;
 	cond_bool_datum_t *booldatum;
-	uint32_t *buf, len;
+	uint32_t buf[3], len;
+	int rc;
 
 	booldatum = malloc(sizeof(cond_bool_datum_t));
 	if (!booldatum)
 		return -1;
 	memset(booldatum, 0, sizeof(cond_bool_datum_t));
 
-	buf = next_entry(fp, sizeof(uint32_t) * 3);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+	if (rc < 0)
 		goto err;
 
 	booldatum->s.value = le32_to_cpu(buf[0]);
@@ -588,13 +589,12 @@
 
 	len = le32_to_cpu(buf[2]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto err;
 	key = malloc(len + 1);
 	if (!key)
 		goto err;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto err;
 	key[len] = 0;
 	if (hashtab_insert(h, key, booldatum))
 		goto err;
@@ -703,14 +703,14 @@
 {
 	unsigned int i;
 	int rc;
-	uint32_t *buf, len;
+	uint32_t buf[1], len;
 	struct cond_insertf_data data;
 
 	*ret_list = NULL;
 
 	len = 0;
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 
 	len = le32_to_cpu(buf[0]);
@@ -752,27 +752,27 @@
 
 static int cond_read_node(policydb_t * p, cond_node_t * node, void *fp)
 {
-	uint32_t *buf;
-	int len, i;
+	uint32_t buf[2];
+	int len, i, rc;
 	cond_expr_t *expr = NULL, *last = NULL;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto err;
 
 	node->cur_state = le32_to_cpu(buf[0]);
 
 	len = 0;
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto err;
 
 	/* expr */
 	len = le32_to_cpu(buf[0]);
 
 	for (i = 0; i < len; i++) {
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0)
 			goto err;
 
 		expr = malloc(sizeof(cond_expr_t));
@@ -820,11 +820,11 @@
 int cond_read_list(policydb_t * p, cond_list_t ** list, void *fp)
 {
 	cond_node_t *node, *last = NULL;
-	uint32_t *buf;
-	int i, len;
+	uint32_t buf[1];
+	int i, len, rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 
 	len = le32_to_cpu(buf[0]);
Modified: trunk/libsepol/src/ebitmap.c
===================================================================
--- trunk/libsepol/src/ebitmap.c	2007-08-23 14:54:42 UTC (rev 2534)
+++ trunk/libsepol/src/ebitmap.c	2007-08-23 14:56:56 UTC (rev 2535)
@@ -265,16 +265,16 @@
 
 int ebitmap_read(ebitmap_t * e, void *fp)
 {
-	int rc = -EINVAL;
+	int rc;
 	ebitmap_node_t *n, *l;
-	uint32_t *buf, mapsize, count, i;
+	uint32_t buf[3], mapsize, count, i;
 	uint64_t map;
 
 	ebitmap_init(e);
 
-	buf = next_entry(fp, sizeof(uint32_t) * 3);
-	if (!buf)
-		goto out;
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+	if (rc < 0)
+		goto bad;
 
 	mapsize = le32_to_cpu(buf[0]);
 	e->highbit = le32_to_cpu(buf[1]);
@@ -284,7 +284,7 @@
 		printf
 		    ("security: ebitmap: map size %d does not match my size %zu (high bit was %d)\n",
 		     mapsize, MAPSIZE, e->highbit);
-		goto out;
+		goto bad;
 	}
 	if (!e->highbit) {
 		e->node = NULL;
@@ -298,8 +298,8 @@
 	}
 	l = NULL;
 	for (i = 0; i < count; i++) {
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf) {
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0) {
 			printf("security: ebitmap: truncated map\n");
 			goto bad;
 		}
@@ -325,12 +325,11 @@
 			     n->startbit, (e->highbit - MAPSIZE));
 			goto bad_free;
 		}
-		buf = next_entry(fp, sizeof(uint64_t));
-		if (!buf) {
+		rc = next_entry(&map, fp, sizeof(uint64_t));
+		if (rc < 0) {
 			printf("security: ebitmap: truncated map\n");
 			goto bad_free;
 		}
-		memcpy(&map, buf, sizeof(uint64_t));
 		n->map = le64_to_cpu(map);
 
 		if (!n->map) {
@@ -360,6 +359,8 @@
       bad_free:
 	free(n);
       bad:
+	if (!rc)
+		rc = -EINVAL;
 	ebitmap_destroy(e);
 	goto out;
 }
Modified: trunk/libsepol/src/module.c
===================================================================
--- trunk/libsepol/src/module.c	2007-08-23 14:54:42 UTC (rev 2534)
+++ trunk/libsepol/src/module.c	2007-08-23 14:56:56 UTC (rev 2535)
@@ -326,7 +326,7 @@
 static int read_helper(char *buf, struct policy_file *file, uint32_t bytes)
 {
 	uint32_t offset, nel, read_len;
-	void *tmp;
+	int rc;
 
 	offset = 0;
 	nel = bytes;
@@ -336,10 +336,9 @@
 			read_len = nel;
 		else
 			read_len = _read_helper_bufsize;
-		tmp = next_entry(file, read_len);
-		if (!tmp)
+		rc = next_entry(&buf[offset], file, read_len);
+		if (rc < 0)
 			return -1;
-		memcpy(&buf[offset], tmp, read_len);
 		offset += read_len;
 		nel -= read_len;
 	}
@@ -354,11 +353,13 @@
 				       struct policy_file *file,
 				       size_t ** offsets, uint32_t * sections)
 {
-	uint32_t *buf, nsec;
+	uint32_t buf[3], nsec;
 	unsigned i;
+	size_t *off;
+	int rc;
 
-	buf = next_entry(file, sizeof(uint32_t) * 3);
-	if (!buf) {
+	rc = next_entry(buf, file, sizeof(uint32_t) * 3);
+	if (rc < 0) {
 		ERR(file->handle, "module package header truncated");
 		return -1;
 	}
@@ -378,29 +379,31 @@
 		return -1;
 	}
 
-	*offsets = (size_t *) malloc((nsec + 1) * sizeof(size_t));
-	if (!*offsets) {
+	off = (size_t *) malloc((nsec + 1) * sizeof(size_t));
+	if (!off) {
 		ERR(file->handle, "out of memory");
 		return -1;
 	}
 
-	buf = next_entry(file, sizeof(uint32_t) * nsec);
-	if (!buf) {
+	rc = next_entry(off, file, sizeof(uint32_t) * nsec);
+	if (rc < 0) {
 		ERR(file->handle, "module package offset array truncated");
 		return -1;
 	}
 
 	for (i = 0; i < nsec; i++) {
-		(*offsets)[i] = le32_to_cpu(buf[i]);
-		if (i && (*offsets)[i] < (*offsets)[i - 1]) {
+		off[i] = le32_to_cpu(off[i]);
+		if (i && off[i] < off[i - 1]) {
 			ERR(file->handle, "offsets are not increasing (at %u, "
-			    "offset %zu -> %zu", i, (*offsets)[i - 1],
-			    (*offsets)[i]);
+			    "offset %zu -> %zu", i, off[i - 1],
+			    off[i]);
 			return -1;
 		}
 	}
 
-	(*offsets)[nsec] = policy_file_length(file);
+	
+	off[nsec] = policy_file_length(file);
+	*offsets = off;
 	return 0;
 }
 
@@ -415,9 +418,9 @@
 			      struct sepol_policy_file *spf, int verbose)
 {
 	struct policy_file *file = &spf->pf;
-	uint32_t *buf, nsec;
+	uint32_t buf[1], nsec;
 	size_t *offsets, len;
-	int retval = -1;
+	int rc;
 	unsigned i, seen = 0;
 
 	if (module_package_read_offsets(mod, file, &offsets, &nsec))
@@ -442,8 +445,8 @@
 		}
 
 		/* read the magic number, so that we know which function to call */
-		buf = next_entry(file, sizeof(uint32_t));
-		if (!buf) {
+		rc = next_entry(buf, file, sizeof(uint32_t));
+		if (rc < 0) {
 			ERR(file->handle,
 			    "module package section %u truncated, lacks magic number",
 			    i);
@@ -565,8 +568,8 @@
 			if (policy_file_seek(file, offsets[i]))
 				goto cleanup;
 
-			retval = policydb_read(&mod->policy->p, file, verbose);
-			if (retval < 0) {
+			rc = policydb_read(&mod->policy->p, file, verbose);
+			if (rc < 0) {
 				ERR(file->handle,
 				    "invalid module in module package (at section %u)",
 				    i);
@@ -593,7 +596,7 @@
 
       cleanup:
 	free(offsets);
-	return retval;
+	return -1;
 }
 
 int sepol_module_package_info(struct sepol_policy_file *spf, int *type,
@@ -601,9 +604,11 @@
 {
 	struct policy_file *file = &spf->pf;
 	sepol_module_package_t *mod = NULL;
-	uint32_t *buf, len, nsec;
+	uint32_t buf[5], len, nsec;
 	size_t *offsets = NULL;
 	unsigned i, seen = 0;
+	char *id;
+	int rc;
 
 	if (sepol_module_package_create(&mod))
 		return -1;
@@ -630,8 +635,8 @@
 		}
 
 		/* read the magic number, so that we know which function to call */
-		buf = next_entry(file, sizeof(uint32_t) * 2);
-		if (!buf) {
+		rc = next_entry(buf, file, sizeof(uint32_t) * 2);
+		if (rc < 0) {
 			ERR(file->handle,
 			    "module package section %u truncated, lacks magic number",
 			    i);
@@ -695,16 +700,24 @@
 			}
 
 			/* skip id */
-			buf = next_entry(file, len);
-			if (!buf) {
+			id = malloc(len + 1);
+			if (!id) {
 				ERR(file->handle,
+				    "out of memory (at section %u)",
+				    i);
+				goto cleanup;				
+			}
+			rc = next_entry(id, file, len);
+			free(id);
+			if (rc < 0) {
+				ERR(file->handle,
 				    "cannot get module string (at section %u)",
 				    i);
 				goto cleanup;
 			}
-
-			buf = next_entry(file, sizeof(uint32_t) * 5);
-			if (!buf) {
+			
+			rc = next_entry(buf, file, sizeof(uint32_t) * 5);
+			if (rc < 0) {
 				ERR(file->handle,
 				    "cannot get module header (at section %u)",
 				    i);
@@ -726,49 +739,47 @@
 			}
 
 			/* read the name and version */
-			buf = next_entry(file, sizeof(uint32_t));
-			if (!buf) {
+			rc = next_entry(buf, file, sizeof(uint32_t));
+			if (rc < 0) {
 				ERR(file->handle,
 				    "cannot get module name len (at section %u)",
 				    i);
 				goto cleanup;
 			}
 			len = le32_to_cpu(buf[0]);
-			buf = next_entry(file, len);
-			if (!buf) {
-				ERR(file->handle,
-				    "cannot get module name string (at section %u)",
-				    i);
-				goto cleanup;
-			}
 			*name = malloc(len + 1);
 			if (!*name) {
 				ERR(file->handle, "out of memory");
 				goto cleanup;
 			}
-			memcpy(*name, buf, len);
-			(*name)[len] = '\0';
-			buf = next_entry(file, sizeof(uint32_t));
-			if (!buf) {
+			rc = next_entry(*name, file, len);
+			if (rc < 0) {
 				ERR(file->handle,
-				    "cannot get module version len (at section %u)",
+				    "cannot get module name string (at section %u)",
 				    i);
 				goto cleanup;
 			}
-			len = le32_to_cpu(buf[0]);
-			buf = next_entry(file, len);
-			if (!buf) {
+			(*name)[len] = '\0';
+			rc = next_entry(buf, file, sizeof(uint32_t));
+			if (rc < 0) {
 				ERR(file->handle,
-				    "cannot get module version string (at section %u)",
+				    "cannot get module version len (at section %u)",
 				    i);
 				goto cleanup;
 			}
+			len = le32_to_cpu(buf[0]);
 			*version = malloc(len + 1);
 			if (!*version) {
 				ERR(file->handle, "out of memory");
 				goto cleanup;
 			}
-			memcpy(*version, buf, len);
+			rc = next_entry(*version, file, len);
+			if (rc < 0) {
+				ERR(file->handle,
+				    "cannot get module version string (at section %u)",
+				    i);
+				goto cleanup;
+			}
 			(*version)[len] = '\0';
 			seen |= SEEN_MOD;
 			break;
Modified: trunk/libsepol/src/policydb.c
===================================================================
--- trunk/libsepol/src/policydb.c	2007-08-23 14:54:42 UTC (rev 2534)
+++ trunk/libsepol/src/policydb.c	2007-08-23 14:56:56 UTC (rev 2535)
@@ -1316,11 +1316,13 @@
 
 static int role_set_read(role_set_t * r, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
+
 	if (ebitmap_read(&r->roles, fp))
 		return -1;
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	r->flags = le32_to_cpu(buf[0]);
 
@@ -1329,15 +1331,16 @@
 
 static int type_set_read(type_set_t * t, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
 
 	if (ebitmap_read(&t->types, fp))
 		return -1;
 	if (ebitmap_read(&t->negset, fp))
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	t->flags = le32_to_cpu(buf[0]);
 
@@ -1350,16 +1353,21 @@
  */
 static int mls_read_range_helper(mls_range_t * r, struct policy_file *fp)
 {
-	uint32_t *buf;
-	int items, rc = -EINVAL;
+	uint32_t buf[2], items;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto out;
 
 	items = le32_to_cpu(buf[0]);
-	buf = next_entry(fp, sizeof(uint32_t) * items);
-	if (!buf) {
+	if (items > ARRAY_SIZE(buf)) {
+		ERR(fp->handle, "range overflow");
+		rc = -EINVAL;
+		goto out;
+	}
+	rc = next_entry(buf, fp, sizeof(uint32_t) * items);
+	if (rc < 0) {
 		ERR(fp->handle, "truncated range");
 		goto out;
 	}
@@ -1403,14 +1411,15 @@
 static int mls_read_semantic_level_helper(mls_semantic_level_t * l,
 					  struct policy_file *fp)
 {
-	uint32_t *buf, ncat;
+	uint32_t buf[2], ncat;
 	unsigned int i;
 	mls_semantic_cat_t *cat;
+	int rc;
 
 	mls_semantic_level_init(l);
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0) {
 		ERR(fp->handle, "truncated level");
 		goto bad;
 	}
@@ -1428,8 +1437,8 @@
 		cat->next = l->cat;
 		l->cat = cat;
 
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf) {
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0) {
 			ERR(fp->handle, "error reading level categories");
 			goto bad;
 		}
@@ -1513,10 +1522,11 @@
 static int context_read_and_validate(context_struct_t * c,
 				     policydb_t * p, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[3];
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 3);
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+	if (rc < 0) {
 		ERR(fp->handle, "context truncated");
 		return -1;
 	}
@@ -1554,27 +1564,27 @@
 {
 	char *key = 0;
 	perm_datum_t *perdatum;
-	uint32_t *buf;
+	uint32_t buf[2];
 	size_t len;
+	int rc;
 
 	perdatum = calloc(1, sizeof(perm_datum_t));
 	if (!perdatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	perdatum->s.value = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (hashtab_insert(h, key, perdatum))
@@ -1591,16 +1601,17 @@
 {
 	char *key = 0;
 	common_datum_t *comdatum;
-	uint32_t *buf;
+	uint32_t buf[4];
 	size_t len, nel;
 	unsigned int i;
+	int rc;
 
 	comdatum = calloc(1, sizeof(common_datum_t));
 	if (!comdatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 4);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 4);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
@@ -1611,13 +1622,12 @@
 	comdatum->permissions.nprim = le32_to_cpu(buf[2]);
 	nel = le32_to_cpu(buf[3]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	for (i = 0; i < nel; i++) {
@@ -1641,10 +1651,10 @@
 {
 	constraint_node_t *c, *lc;
 	constraint_expr_t *e, *le;
-	uint32_t *buf;
+	uint32_t buf[3];
 	size_t nexpr;
 	unsigned int i, j;
-	int depth;
+	int rc, depth;
 
 	lc = NULL;
 	for (i = 0; i < ncons; i++) {
@@ -1657,8 +1667,8 @@
 		else
 			*nodep = c;
 
-		buf = next_entry(fp, (sizeof(uint32_t) * 2));
-		if (!buf)
+		rc = next_entry(buf, fp, (sizeof(uint32_t) * 2));
+		if (rc < 0)
 			return -1;
 		c->permissions = le32_to_cpu(buf[0]);
 		nexpr = le32_to_cpu(buf[1]);
@@ -1678,8 +1688,8 @@
 				c->expr = e;
 			}
 
-			buf = next_entry(fp, (sizeof(uint32_t) * 3));
-			if (!buf)
+			rc = next_entry(buf, fp, (sizeof(uint32_t) * 3));
+			if (rc < 0)
 				return -1;
 			e->expr_type = le32_to_cpu(buf[0]);
 			e->attr = le32_to_cpu(buf[1]);
@@ -1730,16 +1740,17 @@
 {
 	char *key = 0;
 	class_datum_t *cladatum;
-	uint32_t *buf;
+	uint32_t buf[6];
 	size_t len, len2, ncons, nel;
 	unsigned int i;
+	int rc;
 
 	cladatum = (class_datum_t *) calloc(1, sizeof(class_datum_t));
 	if (!cladatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 6);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 6);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
@@ -1753,23 +1764,21 @@
 
 	ncons = le32_to_cpu(buf[5]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (len2) {
 		cladatum->comkey = malloc(len2 + 1);
 		if (!cladatum->comkey)
 			goto bad;
-		buf = next_entry(fp, len2);
-		if (!buf)
+		rc = next_entry(cladatum->comkey, fp, len2);
+		if (rc < 0)
 			goto bad;
-		memcpy(cladatum->comkey, buf, len2);
 		cladatum->comkey[len2] = 0;
 
 		cladatum->comdatum = hashtab_search(p->p_commons.table,
@@ -1792,8 +1801,8 @@
 	    || (p->policy_type == POLICY_BASE
 		&& p->policyvers >= MOD_POLICYDB_VERSION_VALIDATETRANS)) {
 		/* grab the validatetrans rules */
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			goto bad;
 		ncons = le32_to_cpu(buf[0]);
 		if (read_cons_helper(p, &cladatum->validatetrans, ncons, 1, fp))
@@ -1816,27 +1825,27 @@
 {
 	char *key = 0;
 	role_datum_t *role;
-	uint32_t *buf;
+	uint32_t buf[2];
 	size_t len;
+	int rc;
 
 	role = calloc(1, sizeof(role_datum_t));
 	if (!role)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	role->s.value = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (ebitmap_read(&role->dominates, fp))
@@ -1877,19 +1886,20 @@
 {
 	char *key = 0;
 	type_datum_t *typdatum;
-	uint32_t *buf;
+	uint32_t buf[4];
 	size_t len;
+	int rc;
 
 	typdatum = calloc(1, sizeof(type_datum_t));
 	if (!typdatum)
 		return -1;
 
 	if (p->policy_type == POLICY_KERN) {
-		buf = next_entry(fp, sizeof(uint32_t) * 3);
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
 	} else {
-		buf = next_entry(fp, sizeof(uint32_t) * 4);
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 4);
 	}
-	if (!buf)
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
@@ -1901,13 +1911,12 @@
 			goto bad;
 	}
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (hashtab_insert(h, key, typdatum))
@@ -1923,11 +1932,12 @@
 int role_trans_read(role_trans_t ** t, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, nel;
+	uint32_t buf[3], nel;
 	role_trans_t *tr, *ltr;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	ltr = NULL;
@@ -1941,8 +1951,8 @@
 		} else {
 			*t = tr;
 		}
-		buf = next_entry(fp, sizeof(uint32_t) * 3);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+		if (rc < 0)
 			return -1;
 		tr->role = le32_to_cpu(buf[0]);
 		tr->type = le32_to_cpu(buf[1]);
@@ -1955,11 +1965,12 @@
 int role_allow_read(role_allow_t ** r, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, nel;
+	uint32_t buf[2], nel;
 	role_allow_t *ra, *lra;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	lra = NULL;
@@ -1973,8 +1984,8 @@
 		} else {
 			*r = ra;
 		}
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0)
 			return -1;
 		ra->role = le32_to_cpu(buf[0]);
 		ra->new_role = le32_to_cpu(buf[1]);
@@ -1989,10 +2000,12 @@
 	unsigned int i, j;
 	size_t nel, len;
 	ocontext_t *l, *c;
-	uint32_t *buf;
+	uint32_t buf[8];
+	int rc;
+
 	for (i = 0; i < info->ocon_num; i++) {
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			return -1;
 		nel = le32_to_cpu(buf[0]);
 		l = NULL;
@@ -2009,8 +2022,8 @@
 			l = c;
 			switch (i) {
 			case OCON_ISID:
-				buf = next_entry(fp, sizeof(uint32_t));
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t));
+				if (rc < 0)
 					return -1;
 				c->sid[0] = le32_to_cpu(buf[0]);
 				if (context_read_and_validate
@@ -2019,18 +2032,16 @@
 				break;
 			case OCON_FS:
 			case OCON_NETIF:
-				buf = next_entry(fp, sizeof(uint32_t));
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t));
+				if (rc < 0)
 					return -1;
 				len = le32_to_cpu(buf[0]);
-				buf = next_entry(fp, len);
-				if (!buf)
-					return -1;
 				c->u.name = malloc(len + 1);
-				if (!c->u.name) {
+				if (!c->u.name)
 					return -1;
-				}
-				memcpy(c->u.name, buf, len);
+				rc = next_entry(c->u.name, fp, len);
+				if (rc < 0)
+					return -1;
 				c->u.name[len] = 0;
 				if (context_read_and_validate
 				    (&c->context[0], p, fp))
@@ -2040,8 +2051,8 @@
 					return -1;
 				break;
 			case OCON_PORT:
-				buf = next_entry(fp, sizeof(uint32_t) * 3);
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 3);
+				if (rc < 0)
 					return -1;
 				c->u.port.protocol = le32_to_cpu(buf[0]);
 				c->u.port.low_port = le32_to_cpu(buf[1]);
@@ -2051,8 +2062,8 @@
 					return -1;
 				break;
 			case OCON_NODE:
-				buf = next_entry(fp, sizeof(uint32_t) * 2);
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+				if (rc < 0)
 					return -1;
 				c->u.node.addr = le32_to_cpu(buf[0]);
 				c->u.node.mask = le32_to_cpu(buf[1]);
@@ -2061,19 +2072,17 @@
 					return -1;
 				break;
 			case OCON_FSUSE:
-				buf = next_entry(fp, sizeof(uint32_t) * 2);
-				if (!buf)
+				rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+				if (rc < 0)
 					return -1;
 				c->v.behavior = le32_to_cpu(buf[0]);
 				len = le32_to_cpu(buf[1]);
-				buf = next_entry(fp, len);
-				if (!buf)
-					return -1;
 				c->u.name = malloc(len + 1);
-				if (!c->u.name) {
+				if (!c->u.name)
 					return -1;
-				}
-				memcpy(c->u.name, buf, len);
+				rc = next_entry(c->u.name, fp, len);
+				if (rc < 0)
+					return -1;
 				c->u.name[len] = 0;
 				if (context_read_and_validate
 				    (&c->context[0], p, fp))
@@ -2082,10 +2091,9 @@
 			case OCON_NODE6:{
 					int k;
 
-					buf =
-					    next_entry(fp,
-						       sizeof(uint32_t) * 8);
-					if (!buf)
+					rc = next_entry(buf, fp,
+							sizeof(uint32_t) * 8);
+					if (rc < 0)
 						return -1;
 					for (k = 0; k < 4; k++)
 						c->u.node6.addr[k] =
@@ -2109,36 +2117,37 @@
 
 static int genfs_read(policydb_t * p, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
 	size_t nel, nel2, len, len2;
 	genfs_t *genfs_p, *newgenfs, *genfs;
 	unsigned int i, j;
 	ocontext_t *l, *c, *newc = NULL;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto bad;
 	nel = le32_to_cpu(buf[0]);
 	genfs_p = NULL;
 	for (i = 0; i < nel; i++) {
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			goto bad;
 		len = le32_to_cpu(buf[0]);
 		newgenfs = calloc(1, sizeof(genfs_t));
 		if (!newgenfs)
 			goto bad;
-		buf = next_entry(fp, len);
-		if (!buf) {
+		newgenfs->fstype = malloc(len + 1);
+		if (!newgenfs->fstype) {
 			free(newgenfs);
 			goto bad;
 		}
-		newgenfs->fstype = malloc(len + 1);
-		if (!newgenfs->fstype) {
+		rc = next_entry(newgenfs->fstype, fp, len);
+		if (rc < 0) {
+			free(newgenfs->fstype);
 			free(newgenfs);
 			goto bad;
 		}
-		memcpy(newgenfs->fstype, buf, len);
 		newgenfs->fstype[len] = 0;
 		for (genfs_p = NULL, genfs = p->genfs; genfs;
 		     genfs_p = genfs, genfs = genfs->next) {
@@ -2157,8 +2166,8 @@
 			genfs_p->next = newgenfs;
 		else
 			p->genfs = newgenfs;
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			goto bad;
 		nel2 = le32_to_cpu(buf[0]);
 		for (j = 0; j < nel2; j++) {
@@ -2166,21 +2175,20 @@
 			if (!newc) {
 				goto bad;
 			}
-			buf = next_entry(fp, sizeof(uint32_t));
-			if (!buf)
+			rc = next_entry(buf, fp, sizeof(uint32_t));
+			if (rc < 0)
 				goto bad;
 			len = le32_to_cpu(buf[0]);
-			buf = next_entry(fp, len);
-			if (!buf)
-				goto bad;
 			newc->u.name = malloc(len + 1);
 			if (!newc->u.name) {
 				goto bad;
 			}
-			memcpy(newc->u.name, buf, len);
+			rc = next_entry(newc->u.name, fp, len);
+			if (rc < 0)
+				goto bad;
 			newc->u.name[len] = 0;
-			buf = next_entry(fp, sizeof(uint32_t));
-			if (!buf)
+			rc = next_entry(buf, fp, sizeof(uint32_t));
+			if (rc < 0)
 				goto bad;
 			newc->v.sclass = le32_to_cpu(buf[0]);
 			if (context_read_and_validate(&newc->context[0], p, fp))
@@ -2226,12 +2234,13 @@
  */
 static int mls_read_level(mls_level_t * lp, struct policy_file *fp)
 {
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
 
 	mls_level_init(lp);
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		ERR(fp->handle, "truncated level");
 		goto bad;
 	}
@@ -2251,27 +2260,27 @@
 {
 	char *key = 0;
 	user_datum_t *usrdatum;
-	uint32_t *buf;
+	uint32_t buf[2];
 	size_t len;
+	int rc;
 
 	usrdatum = calloc(1, sizeof(user_datum_t));
 	if (!usrdatum)
 		return -1;
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	usrdatum->s.value = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (p->policy_type == POLICY_KERN) {
@@ -2332,27 +2341,27 @@
 {
 	char *key = 0;
 	level_datum_t *levdatum;
-	uint32_t *buf, len;
+	uint32_t buf[2], len;
+	int rc;
 
 	levdatum = malloc(sizeof(level_datum_t));
 	if (!levdatum)
 		return -1;
 	level_datum_init(levdatum);
 
-	buf = next_entry(fp, (sizeof(uint32_t) * 2));
-	if (!buf)
+	rc = next_entry(buf, fp, (sizeof(uint32_t) * 2));
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	levdatum->isalias = le32_to_cpu(buf[1]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	levdatum->level = malloc(sizeof(mls_level_t));
@@ -2375,28 +2384,28 @@
 {
 	char *key = 0;
 	cat_datum_t *catdatum;
-	uint32_t *buf, len;
+	uint32_t buf[3], len;
+	int rc;
 
 	catdatum = malloc(sizeof(cat_datum_t));
 	if (!catdatum)
 		return -1;
 	cat_datum_init(catdatum);
 
-	buf = next_entry(fp, (sizeof(uint32_t) * 3));
-	if (!buf)
+	rc = next_entry(buf, fp, (sizeof(uint32_t) * 3));
+	if (rc < 0)
 		goto bad;
 
 	len = le32_to_cpu(buf[0]);
 	catdatum->s.value = le32_to_cpu(buf[1]);
 	catdatum->isalias = le32_to_cpu(buf[2]);
 
-	buf = next_entry(fp, len);
-	if (!buf)
-		goto bad;
 	key = malloc(len + 1);
 	if (!key)
 		goto bad;
-	memcpy(key, buf, len);
+	rc = next_entry(key, fp, len);
+	if (rc < 0)
+		goto bad;
 	key[len] = 0;
 
 	if (hashtab_insert(h, key, catdatum))
@@ -2420,9 +2429,10 @@
 			     __attribute__ ((unused)), struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, len;
+	uint32_t buf[2], len;
 	class_perm_node_t *cur, *tail = NULL;
 	avrule_t *avrule;
+	int rc;
 
 	avrule = (avrule_t *) malloc(sizeof(avrule_t));
 	if (!avrule)
@@ -2430,8 +2440,8 @@
 
 	avrule_init(avrule);
 
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto bad;
 
 	(avrule)->specified = le32_to_cpu(buf[0]);
@@ -2443,8 +2453,8 @@
 	if (type_set_read(&avrule->ttypes, fp))
 		goto bad;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto bad;
 	len = le32_to_cpu(buf[0]);
 
@@ -2454,8 +2464,8 @@
 			goto bad;
 		class_perm_node_init(cur);
 
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf) {
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0) {
 			free(cur);
 			goto bad;
 		}
@@ -2482,15 +2492,16 @@
 
 static int range_read(policydb_t * p, struct policy_file *fp)
 {
-	uint32_t *buf, nel;
+	uint32_t buf[2], nel;
 	range_trans_t *rt, *lrt;
 	range_trans_rule_t *rtr, *lrtr = NULL;
 	unsigned int i;
 	int new_rangetr = (p->policy_type == POLICY_KERN &&
 			   p->policyvers >= POLICYDB_VERSION_RANGETRANS);
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	lrt = NULL;
@@ -2502,14 +2513,14 @@
 			lrt->next = rt;
 		else
 			p->range_tr = rt;
-		buf = next_entry(fp, (sizeof(uint32_t) * 2));
-		if (!buf)
+		rc = next_entry(buf, fp, (sizeof(uint32_t) * 2));
+		if (rc < 0)
 			return -1;
 		rt->source_type = le32_to_cpu(buf[0]);
 		rt->target_type = le32_to_cpu(buf[1]);
 		if (new_rangetr) {
-			buf = next_entry(fp, (sizeof(uint32_t)));
-			if (!buf)
+			rc = next_entry(buf, fp, (sizeof(uint32_t)));
+			if (rc < 0)
 				return -1;
 			rt->target_class = le32_to_cpu(buf[0]);
 		} else
@@ -2578,12 +2589,13 @@
 {
 	unsigned int i;
 	avrule_t *cur, *tail;
-	uint32_t *buf, len;
+	uint32_t buf[1], len;
+	int rc;
 
 	*avrules = tail = NULL;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0) {
 		return -1;
 	}
 	len = le32_to_cpu(buf[0]);
@@ -2607,12 +2619,13 @@
 
 static int role_trans_rule_read(role_trans_rule_t ** r, struct policy_file *fp)
 {
-	uint32_t *buf, nel;
+	uint32_t buf[1], nel;
 	unsigned int i;
 	role_trans_rule_t *tr, *ltr;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	ltr = NULL;
@@ -2635,8 +2648,8 @@
 		if (type_set_read(&tr->types, fp))
 			return -1;
 
-		buf = next_entry(fp, sizeof(uint32_t));
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0)
 			return -1;
 		tr->new_role = le32_to_cpu(buf[0]);
 		ltr = tr;
@@ -2648,11 +2661,12 @@
 static int role_allow_rule_read(role_allow_rule_t ** r, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf, nel;
+	uint32_t buf[1], nel;
 	role_allow_rule_t *ra, *lra;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	lra = NULL;
@@ -2683,12 +2697,13 @@
 static int range_trans_rule_read(range_trans_rule_t ** r,
 				 struct policy_file *fp)
 {
-	uint32_t *buf, nel;
+	uint32_t buf[1], nel;
 	unsigned int i;
 	range_trans_rule_t *rt, *lrt = NULL;
+	int rc;
 
-	buf = next_entry(fp, sizeof(uint32_t));
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
 	nel = le32_to_cpu(buf[0]);
 	for (i = 0; i < nel; i++) {
@@ -2725,15 +2740,17 @@
 			    unsigned int num_scope_syms, struct policy_file *fp)
 {
 	unsigned int i;
-	uint32_t *buf;
+	uint32_t buf[1];
+	int rc;
+
 	for (i = 0; i < num_scope_syms; i++) {
 		if (ebitmap_read(scope_index->scope + i, fp) == -1) {
 			return -1;
 		}
 	}
-	if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
-	}
 	scope_index->class_perms_len = le32_to_cpu(buf[0]);
 	if (scope_index->class_perms_len == 0) {
 		scope_index->class_perms_map = NULL;
@@ -2755,11 +2772,13 @@
 static int avrule_decl_read(policydb_t * p, avrule_decl_t * decl,
 			    unsigned int num_scope_syms, struct policy_file *fp)
 {
-	uint32_t *buf, nprim, nel;
+	uint32_t buf[2], nprim, nel;
 	unsigned int i, j;
-	if ((buf = next_entry(fp, sizeof(uint32_t) * 2)) == NULL) {
+	int rc;
+
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		return -1;
-	}
 	decl->decl_id = le32_to_cpu(buf[0]);
 	decl->enabled = le32_to_cpu(buf[1]);
 	if (cond_read_list(p, &decl->cond_list, fp) == -1 ||
@@ -2778,9 +2797,9 @@
 	}
 
 	for (i = 0; i < num_scope_syms; i++) {
-		if ((buf = next_entry(fp, sizeof(uint32_t) * 2)) == NULL) {
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0) 
 			return -1;
-		}
 		nprim = le32_to_cpu(buf[0]);
 		nel = le32_to_cpu(buf[1]);
 		for (j = 0; j < nel; j++) {
@@ -2799,11 +2818,12 @@
 			     struct policy_file *fp)
 {
 	avrule_block_t *last_block = NULL, *curblock;
-	uint32_t *buf, num_blocks, nel;
+	uint32_t buf[1], num_blocks, nel;
+	int rc;
 
-	if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		return -1;
-	}
 	num_blocks = le32_to_cpu(buf[0]);
 	nel = num_blocks;
 	while (num_blocks > 0) {
@@ -2812,8 +2832,8 @@
 		if ((curblock = calloc(1, sizeof(*curblock))) == NULL) {
 			return -1;
 		}
-
-		if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+		rc = next_entry(buf, fp, sizeof(uint32_t));
+		if (rc < 0) {
 			free(curblock);
 			return -1;
 		}
@@ -2869,23 +2889,23 @@
 static int scope_read(policydb_t * p, int symnum, struct policy_file *fp)
 {
 	scope_datum_t *scope = NULL;
-	uint32_t *buf;
+	uint32_t buf[2];
 	char *key = NULL;
 	size_t key_len;
 	unsigned int i;
 	hashtab_t h = p->scope[symnum].table;
+	int rc;
 
-	if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t));
+	if (rc < 0)
 		goto cleanup;
-	}
 	key_len = le32_to_cpu(buf[0]);
-	if ((buf = next_entry(fp, key_len)) == NULL) {
+	key = malloc(key_len + 1);
+	if (!key)
 		goto cleanup;
-	}
-	if ((key = malloc(key_len + 1)) == NULL) {
+	rc = next_entry(key, fp, key_len);
+	if (rc < 0)
 		goto cleanup;
-	}
-	memcpy(key, buf, key_len);
 	key[key_len] = '\0';
 
 	/* ensure that there already exists a symbol with this key */
@@ -2896,9 +2916,9 @@
 	if ((scope = calloc(1, sizeof(*scope))) == NULL) {
 		goto cleanup;
 	}
-	if ((buf = next_entry(fp, sizeof(uint32_t) * 2)) == NULL) {
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		goto cleanup;
-	}
 	scope->scope = le32_to_cpu(buf[0]);
 	scope->decl_ids_len = le32_to_cpu(buf[1]);
 	assert(scope->decl_ids_len > 0);
@@ -2906,12 +2926,11 @@
 	     malloc(scope->decl_ids_len * sizeof(uint32_t))) == NULL) {
 		goto cleanup;
 	}
-	if ((buf =
-	     next_entry(fp, sizeof(uint32_t) * scope->decl_ids_len)) == NULL) {
+	rc = next_entry(scope->decl_ids, fp, sizeof(uint32_t) * scope->decl_ids_len);
+	if (rc < 0)
 		goto cleanup;
-	}
 	for (i = 0; i < scope->decl_ids_len; i++) {
-		scope->decl_ids[i] = le32_to_cpu(buf[i]);
+		scope->decl_ids[i] = le32_to_cpu(scope->decl_ids[i]);
 	}
 
 	if (strcmp(key, "object_r") == 0 && h == p->p_roles_scope.table) {
@@ -2938,18 +2957,19 @@
 {
 
 	unsigned int i, j, r_policyvers;
-	uint32_t *buf, config;
+	uint32_t buf[5], config;
 	size_t len, nprim, nel;
 	char *policydb_str, *target_str = NULL;
 	struct policydb_compat_info *info;
 	unsigned int policy_type, bufindex;
 	ebitmap_node_t *tnode;
+	int rc;
 
 	config = 0;
 
 	/* Read the magic number and string length. */
-	buf = next_entry(fp, sizeof(uint32_t) * 2);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+	if (rc < 0)
 		return POLICYDB_ERROR;
 	for (i = 0; i < 2; i++)
 		buf[i] = le32_to_cpu(buf[i]);
@@ -2974,18 +2994,18 @@
 		return POLICYDB_ERROR;
 	}
 
-	buf = next_entry(fp, len);
-	if (!buf) {
-		ERR(fp->handle, "truncated policydb string identifier");
-		return POLICYDB_ERROR;
-	}
 	policydb_str = malloc(len + 1);
 	if (!policydb_str) {
 		ERR(fp->handle, "unable to allocate memory for policydb "
 		    "string of length %zu", len);
 		return POLICYDB_ERROR;
 	}
-	memcpy(policydb_str, buf, len);
+	rc = next_entry(policydb_str, fp, len);
+	if (rc < 0) {
+		ERR(fp->handle, "truncated policydb string identifier");
+		free(policydb_str);
+		return POLICYDB_ERROR;
+	}
 	policydb_str[len] = 0;
 	if (strcmp(policydb_str, target_str)) {
 		ERR(fp->handle, "policydb string %s does not match "
@@ -3003,8 +3023,8 @@
 	else
 		nel = 5;
 
-	buf = next_entry(fp, sizeof(uint32_t) * nel);
-	if (!buf)
+	rc = next_entry(buf, fp, sizeof(uint32_t) * nel);
+	if (rc < 0)
 		return POLICYDB_ERROR;
 	for (i = 0; i < nel; i++)
 		buf[i] = le32_to_cpu(buf[i]);
@@ -3077,35 +3097,33 @@
 
 	if (p->policy_type == POLICY_MOD) {
 		/* Get the module name and version */
-		if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+		if ((rc = next_entry(buf, fp, sizeof(uint32_t))) < 0) {
 			goto bad;
 		}
 		len = le32_to_cpu(buf[0]);
-		if ((buf = next_entry(fp, len)) == NULL) {
+		if ((p->name = malloc(len + 1)) == NULL) {
 			goto bad;
 		}
-		if ((p->name = malloc(len + 1)) == NULL) {
+		if ((rc = next_entry(p->name, fp, len)) < 0) {
 			goto bad;
 		}
-		memcpy(p->name, buf, len);
 		p->name[len] = '\0';
-		if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+		if ((rc = next_entry(buf, fp, sizeof(uint32_t))) < 0) {
 			goto bad;
 		}
 		len = le32_to_cpu(buf[0]);
-		if ((buf = next_entry(fp, len)) == NULL) {
+		if ((p->version = malloc(len + 1)) == NULL) {
 			goto bad;
 		}
-		if ((p->version = malloc(len + 1)) == NULL) {
+		if ((rc = next_entry(p->version, fp, len)) < 0) {
 			goto bad;
 		}
-		memcpy(p->version, buf, len);
 		p->version[len] = '\0';
 	}
 
 	for (i = 0; i < info->sym_num; i++) {
-		buf = next_entry(fp, sizeof(uint32_t) * 2);
-		if (!buf)
+		rc = next_entry(buf, fp, sizeof(uint32_t) * 2);
+		if (rc < 0)
 			goto bad;
 		nprim = le32_to_cpu(buf[0]);
 		nel = le32_to_cpu(buf[1]);
@@ -3135,7 +3153,7 @@
 			goto bad;
 		}
 		for (i = 0; i < info->sym_num; i++) {
-			if ((buf = next_entry(fp, sizeof(uint32_t))) == NULL) {
+			if ((rc = next_entry(buf, fp, sizeof(uint32_t))) < 0) {
 				goto bad;
 			}
 			nel = le32_to_cpu(buf[0]);
Modified: trunk/libsepol/src/private.h
===================================================================
--- trunk/libsepol/src/private.h	2007-08-23 14:54:42 UTC (rev 2534)
+++ trunk/libsepol/src/private.h	2007-08-23 14:56:56 UTC (rev 2535)
@@ -27,6 +27,8 @@
 #undef min
 #define min(a,b) (((a) < (b)) ? (a) : (b))
 
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+
 /* Policy compatibility information. */
 struct policydb_compat_info {
 	unsigned int type;
@@ -39,31 +41,27 @@
 							   unsigned int type);
 
 /* Reading from a policy "file". */
-static inline void *next_entry(struct policy_file *fp, size_t bytes)
+static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes)
 {
-	static unsigned char buffer[BUFSIZ];
 	size_t nread;
 
-	if (bytes > sizeof buffer)
-		return NULL;
-
 	switch (fp->type) {
 	case PF_USE_STDIO:
-		nread = fread(buffer, bytes, 1, fp->fp);
+		nread = fread(buf, bytes, 1, fp->fp);
 		if (nread != 1)
-			return NULL;
+			return -1;
 		break;
 	case PF_USE_MEMORY:
 		if (bytes > fp->len)
-			return NULL;
-		memcpy(buffer, fp->data, bytes);
+			return -1;
+		memcpy(buf, fp->data, bytes);
 		fp->data += bytes;
 		fp->len -= bytes;
 		break;
 	default:
-		return NULL;
+		return -1;
 	}
-	return buffer;
+	return 0;
 }
 
 static inline size_t put_entry(const void *ptr, size_t size, size_t n,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:54:44
      
     | 
| Revision: 2534
          http://selinux.svn.sourceforge.net/selinux/?rev=2534&view=rev
Author:   ssmalley
Date:     2007-08-23 07:54:42 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Fix genhomedircon matching of USER template from Todd Miller.
Fix chcat from Dan Walsh.
Modified Paths:
--------------
    branches/stable/1_0/policycoreutils/ChangeLog
    branches/stable/1_0/policycoreutils/VERSION
    branches/stable/1_0/policycoreutils/scripts/chcat
    branches/stable/1_0/policycoreutils/scripts/genhomedircon
Modified: branches/stable/1_0/policycoreutils/ChangeLog
===================================================================
--- branches/stable/1_0/policycoreutils/ChangeLog	2007-08-23 14:50:08 UTC (rev 2533)
+++ branches/stable/1_0/policycoreutils/ChangeLog	2007-08-23 14:54:42 UTC (rev 2534)
@@ -1,3 +1,7 @@
+1.34.11 2007-08-23
+	* Fix genhomedircon matching of the USER template from Todd Miller.
+	* Fix chcat from Dan Walsh.
+
 1.34.10 2007-05-09
 	* Merged genhomedircon fix to find conflicting directories correctly from Dan Walsh.
 
Modified: branches/stable/1_0/policycoreutils/VERSION
===================================================================
--- branches/stable/1_0/policycoreutils/VERSION	2007-08-23 14:50:08 UTC (rev 2533)
+++ branches/stable/1_0/policycoreutils/VERSION	2007-08-23 14:54:42 UTC (rev 2534)
@@ -1 +1 @@
-1.34.10
+1.34.11
Modified: branches/stable/1_0/policycoreutils/scripts/chcat
===================================================================
--- branches/stable/1_0/policycoreutils/scripts/chcat	2007-08-23 14:50:08 UTC (rev 2533)
+++ branches/stable/1_0/policycoreutils/scripts/chcat	2007-08-23 14:54:42 UTC (rev 2534)
@@ -77,7 +77,7 @@
             
         if len(cats) > 0:
             new_serange = "%s-%s:%s" % (serange[0], top[0], ",".join(cats))
-        else
+        else:
             new_serange = "%s-%s" % (serange[0], top[0])
             
         if add_ind:
@@ -155,7 +155,7 @@
 
         if len(cats) > 0:
             new_serange = "%s-%s:%s" % (serange[0], top[0], ",".join(cats))
-        else
+        else:
             new_serange = "%s-%s" % (serange[0], top[0])
             
         if add_ind:
Modified: branches/stable/1_0/policycoreutils/scripts/genhomedircon
===================================================================
--- branches/stable/1_0/policycoreutils/scripts/genhomedircon	2007-08-23 14:50:08 UTC (rev 2533)
+++ branches/stable/1_0/policycoreutils/scripts/genhomedircon	2007-08-23 14:54:42 UTC (rev 2534)
@@ -272,7 +272,7 @@
 		ret = ""
 		fd = open(self.getHomeDirTemplate(), 'r')
 		for i in  fd.readlines():
-			if i.find("USER") == 1:
+			if i.find("USER") >= 0:
 				i = i.replace("USER", user)
 				i = i.replace("ROLE", prefix)
 				i = i.replace("system_u", sel_user)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:50:13
      
     | 
| Revision: 2533
          http://selinux.svn.sourceforge.net/selinux/?rev=2533&view=rev
Author:   ssmalley
Date:     2007-08-23 07:50:08 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
updated policycoreutils to version 2.0.25
Modified Paths:
--------------
    trunk/policycoreutils/ChangeLog
    trunk/policycoreutils/VERSION
Modified: trunk/policycoreutils/ChangeLog
===================================================================
--- trunk/policycoreutils/ChangeLog	2007-08-23 14:48:58 UTC (rev 2532)
+++ trunk/policycoreutils/ChangeLog	2007-08-23 14:50:08 UTC (rev 2533)
@@ -1,3 +1,7 @@
+2.0.25 2007-08-23
+	* Remove genhomedircon script (functionality is now provided
+	  within libsemanage) from Todd Miller.
+
 2.0.24 2007-08-23
 	* Fix genhomedircon searching for USER from Todd Miller
 	* Install run_init with mode 0755 from Dan Walsh.
Modified: trunk/policycoreutils/VERSION
===================================================================
--- trunk/policycoreutils/VERSION	2007-08-23 14:48:58 UTC (rev 2532)
+++ trunk/policycoreutils/VERSION	2007-08-23 14:50:08 UTC (rev 2533)
@@ -1 +1 @@
-2.0.24
+2.0.25
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:48:59
      
     | 
| Revision: 2532
          http://selinux.svn.sourceforge.net/selinux/?rev=2532&view=rev
Author:   ssmalley
Date:     2007-08-23 07:48:58 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
updated libsemanage to version 2.0.5
Modified Paths:
--------------
    trunk/libsemanage/ChangeLog
    trunk/libsemanage/VERSION
Modified: trunk/libsemanage/ChangeLog
===================================================================
--- trunk/libsemanage/ChangeLog	2007-08-23 14:46:08 UTC (rev 2531)
+++ trunk/libsemanage/ChangeLog	2007-08-23 14:48:58 UTC (rev 2532)
@@ -1,6 +1,12 @@
+2.0.5 2007-08-23
+	* Replace genhomedircon script with equivalent functionality within
+	  libsemanage and introduce disable-genhomedircon option in
+	  semanage.conf from Todd Miller.
+	  Note:  Depends on ustr.
+
 2.0.4 2007-08-16
 	* Allow dontaudits to be turned off via semanage interface when
-	  updating policy
+	  updating policy from Joshua Brindle.
 
 2.0.3 2007-04-25
 	* Fix to libsemanage man patches so whatis will work better from Dan Walsh
Modified: trunk/libsemanage/VERSION
===================================================================
--- trunk/libsemanage/VERSION	2007-08-23 14:46:08 UTC (rev 2531)
+++ trunk/libsemanage/VERSION	2007-08-23 14:48:58 UTC (rev 2532)
@@ -1 +1 @@
-2.0.4
+2.0.5
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:46:09
      
     | 
| Revision: 2531
          http://selinux.svn.sourceforge.net/selinux/?rev=2531&view=rev
Author:   ssmalley
Date:     2007-08-23 07:46:08 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
updated libselinux to version 2.0.31
Modified Paths:
--------------
    trunk/libselinux/ChangeLog
    trunk/libselinux/VERSION
Modified: trunk/libselinux/ChangeLog
===================================================================
--- trunk/libselinux/ChangeLog	2007-08-23 14:43:35 UTC (rev 2530)
+++ trunk/libselinux/ChangeLog	2007-08-23 14:46:08 UTC (rev 2531)
@@ -1,3 +1,6 @@
+2.0.31 2007-08-23
+	* Fix file_contexts.homedirs path from Todd Miller.
+
 2.0.30 2007-08-06
 	* Fix segfault resulting from uninitialized print-callback pointer.
 
Modified: trunk/libselinux/VERSION
===================================================================
--- trunk/libselinux/VERSION	2007-08-23 14:43:35 UTC (rev 2530)
+++ trunk/libselinux/VERSION	2007-08-23 14:46:08 UTC (rev 2531)
@@ -1 +1 @@
-2.0.30
+2.0.31
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:43:36
      
     | 
| Revision: 2530
          http://selinux.svn.sourceforge.net/selinux/?rev=2530&view=rev
Author:   ssmalley
Date:     2007-08-23 07:43:35 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Author: tm...@tr...
Email: tm...@tr...
Subject: libsemanage: genhomedircon enable/disable GHDC
Date: Tue, 21 Aug 2007 15:10:47 -0400
This patch allows the user to disable genhomedircon by adding
"disable-genhomedircon = true" to /etc/selinux/semanage.conf
It also eliminates the [genhomedircon] section from semanage.conf
Modified Paths:
--------------
    trunk/libsemanage/src/conf-parse.y
    trunk/libsemanage/src/conf-scan.l
    trunk/libsemanage/src/semanage_conf.h
    trunk/libsemanage/src/semanage_store.c
Modified: trunk/libsemanage/src/conf-parse.y
===================================================================
--- trunk/libsemanage/src/conf-parse.y	2007-08-23 14:43:09 UTC (rev 2529)
+++ trunk/libsemanage/src/conf-parse.y	2007-08-23 14:43:35 UTC (rev 2530)
@@ -57,7 +57,7 @@
 }
 
 %token MODULE_STORE VERSION EXPAND_CHECK FILE_MODE SAVE_PREVIOUS SAVE_LINKED
-%token LOAD_POLICY_START SETFILES_START GENHOMEDIRCON_START
+%token LOAD_POLICY_START SETFILES_START DISABLE_GENHOMEDIRCON
 %token VERIFY_MOD_START VERIFY_LINKED_START VERIFY_KERNEL_START BLOCK_END
 %token PROG_PATH PROG_ARGS
 %token <s> ARG
@@ -80,6 +80,7 @@
         |       file_mode
         |       save_previous
         |       save_linked
+        |       disable_genhomedircon
         ;
 
 module_store:   MODULE_STORE '=' ARG {
@@ -137,6 +138,16 @@
                 }
         ;
 
+disable_genhomedircon: DISABLE_GENHOMEDIRCON '=' ARG {
+								if (strcasecmp($3, "false") == 0) {
+										current_conf->disable_genhomedircon = 0;
+									} else if (strcasecmp($3, "true") == 0) {
+										current_conf->disable_genhomedircon = 1;
+									} else {
+										yyerror("disable-genhomedircon can only be 'true' or 'false'");
+									}
+									free($3);
+					  }
 
 command_block: 
                 command_start external_opts BLOCK_END  {
@@ -164,14 +175,6 @@
                                 YYABORT;
                         }
                 }
-        |       GENHOMEDIRCON_START {
-                        semanage_conf_external_prog_destroy(current_conf->genhomedircon);
-                        current_conf->genhomedircon = NULL;
-                        if (new_external_prog(¤t_conf->genhomedircon) == -1) {
-                                parse_errors++;
-                                YYABORT;
-                        }
-                }
         ;
 
 verify_block:   verify_start external_opts BLOCK_END  {
@@ -239,16 +242,6 @@
 		return -1;
 	}
 
-	if ((conf->genhomedircon =
-	     calloc(1, sizeof(*(current_conf->genhomedircon)))) == NULL) {
-		return -1;
-	}
-	if ((conf->genhomedircon->path =
-	     strdup("/usr/sbin/genhomedircon")) == NULL
-	    || (conf->genhomedircon->args = strdup("-t $@")) == NULL) {
-		return -1;
-	}
-
 	return 0;
 }
 
@@ -303,7 +296,6 @@
 		free(conf->store_path);
 		semanage_conf_external_prog_destroy(conf->load_policy);
 		semanage_conf_external_prog_destroy(conf->setfiles);
-		semanage_conf_external_prog_destroy(conf->genhomedircon);
 		semanage_conf_external_prog_destroy(conf->mod_prog);
 		semanage_conf_external_prog_destroy(conf->linked_prog);
 		semanage_conf_external_prog_destroy(conf->kernel_prog);
Modified: trunk/libsemanage/src/conf-scan.l
===================================================================
--- trunk/libsemanage/src/conf-scan.l	2007-08-23 14:43:09 UTC (rev 2529)
+++ trunk/libsemanage/src/conf-scan.l	2007-08-23 14:43:35 UTC (rev 2530)
@@ -44,9 +44,9 @@
 file-mode         return FILE_MODE;
 save-previous     return SAVE_PREVIOUS;
 save-linked       return SAVE_LINKED;
+disable-genhomedircon return DISABLE_GENHOMEDIRCON;
 "[load_policy]"   return LOAD_POLICY_START;
 "[setfiles]"      return SETFILES_START;
-"[genhomedircon]" return GENHOMEDIRCON_START;
 "[verify module]" return VERIFY_MOD_START;
 "[verify linked]" return VERIFY_LINKED_START;
 "[verify kernel]" return VERIFY_KERNEL_START;
Modified: trunk/libsemanage/src/semanage_conf.h
===================================================================
--- trunk/libsemanage/src/semanage_conf.h	2007-08-23 14:43:09 UTC (rev 2529)
+++ trunk/libsemanage/src/semanage_conf.h	2007-08-23 14:43:35 UTC (rev 2530)
@@ -37,10 +37,10 @@
 	int expand_check;
 	int save_previous;
 	int save_linked;
+	int disable_genhomedircon;
 	mode_t file_mode;
 	struct external_prog *load_policy;
 	struct external_prog *setfiles;
-	struct external_prog *genhomedircon;
 	struct external_prog *mod_prog, *linked_prog, *kernel_prog;
 } semanage_conf_t;
 
Modified: trunk/libsemanage/src/semanage_store.c
===================================================================
--- trunk/libsemanage/src/semanage_store.c	2007-08-23 14:43:09 UTC (rev 2529)
+++ trunk/libsemanage/src/semanage_store.c	2007-08-23 14:43:35 UTC (rev 2530)
@@ -1062,11 +1062,13 @@
 		goto cleanup;
 	}
 
-	snprintf(store_fc_hd, PATH_MAX, "%s%s", storepath, running_fc_hd);
-	if (semanage_copy_file(active_fc_hd, store_fc_hd, sh->conf->file_mode)
-	    == -1) {
-		ERR(sh, "Could not copy %s to %s.", active_fc_hd, store_fc_hd);
-		goto cleanup;
+	if (!sh->conf->disable_genhomedircon) {
+		snprintf(store_fc_hd, PATH_MAX, "%s%s", storepath, running_fc_hd);
+		if (semanage_copy_file(active_fc_hd, store_fc_hd, sh->conf->file_mode)
+			== -1) {
+			ERR(sh, "Could not copy %s to %s.", active_fc_hd, store_fc_hd);
+			goto cleanup;
+		}
 	}
 
 	snprintf(store_fc, PATH_MAX, "%s%s", storepath, running_fc);
@@ -1268,12 +1270,16 @@
 		ERR(sh, "No setfiles program specified in configuration file.");
 		goto cleanup;
 	}
-
-	if ((retval =
-	     semanage_genhomedircon(sh, TRUE)) != 0) {
-		ERR(sh, "semanage_genhomedircon returned error code %d.",
-		    retval);
-		goto cleanup;
+	if (!sh->conf->disable_genhomedircon) {
+		if ((retval =
+		     semanage_genhomedircon(sh, TRUE)) != 0) {
+			ERR(sh, "semanage_genhomedircon returned error code %d.",
+			    retval);
+			goto cleanup;
+		}
+	} else {
+		WARN(sh, "WARNING: genhomedircon is disabled. \
+See /etc/selinux/semanage.conf if you need to enable it.");
 	}
 
 	if ((commit_num = semanage_commit_sandbox(sh)) < 0) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:43:15
      
     | 
| Revision: 2529
          http://selinux.svn.sourceforge.net/selinux/?rev=2529&view=rev
Author:   ssmalley
Date:     2007-08-23 07:43:09 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Author: tm...@tr...
Email: tm...@tr...
Subject: libsemanage: remove genhomedircon python script
Date: Tue, 21 Aug 2007 15:10:46 -0400
remove legacy genhomedircon python script
Modified Paths:
--------------
    trunk/policycoreutils/scripts/Makefile
Removed Paths:
-------------
    trunk/policycoreutils/scripts/genhomedircon
    trunk/policycoreutils/scripts/genhomedircon.8
Modified: trunk/policycoreutils/scripts/Makefile
===================================================================
--- trunk/policycoreutils/scripts/Makefile	2007-08-23 14:42:14 UTC (rev 2528)
+++ trunk/policycoreutils/scripts/Makefile	2007-08-23 14:43:09 UTC (rev 2529)
@@ -5,18 +5,14 @@
 MANDIR ?= $(PREFIX)/share/man
 LOCALEDIR ?= /usr/share/locale
 
-TARGETS=genhomedircon 
+all: fixfiles
 
-all: $(TARGETS) fixfiles
-
 install: all
 	-mkdir -p $(BINDIR)
-	install -m 755 $(TARGETS) $(SBINDIR)
 	install -m 755 chcat $(BINDIR)
 	install -m 755 fixfiles $(DESTDIR)/sbin
 	-mkdir -p $(MANDIR)/man8
 	install -m 644 fixfiles.8 $(MANDIR)/man8/
-	install -m 644 genhomedircon.8 $(MANDIR)/man8/
 	install -m 644 chcat.8 $(MANDIR)/man8/
 
 clean:
Deleted: trunk/policycoreutils/scripts/genhomedircon
===================================================================
--- trunk/policycoreutils/scripts/genhomedircon	2007-08-23 14:42:14 UTC (rev 2528)
+++ trunk/policycoreutils/scripts/genhomedircon	2007-08-23 14:43:09 UTC (rev 2529)
@@ -1,404 +0,0 @@
-#! /usr/bin/python -E
-# Copyright (C) 2004 Tresys Technology, LLC
-# see file 'COPYING' for use and warranty information
-#
-# genhomedircon - this script is used to generate file context
-# configuration entries for user home directories based on their
-# default prefixes and is run when building the policy. Specifically, we
-# replace HOME_ROOT, HOME_DIR, and ROLE macros in .fc files with
-# generic and user-specific values.
-#
-# Based off original script by Dan Walsh, <dw...@re...>
-#
-# ASSUMPTIONS:
-#
-# The file CONTEXTDIR/files/homedir_template exists.  This file is used to
-# set up the home directory context for each real user.
-# 
-# If a user is not listed in CONTEXTDIR/seusers, he will default to user_u, prefix user
-#
-# "Real" users (as opposed to system users) are those whose UID is greater than
-#  or equal STARTING_UID (usually 500) and whose login is not a member of
-#  EXCLUDE_LOGINS.  Users who are explicitly defined in CONTEXTDIR/seusers
-#  are always "real" (including root, in the default configuration).
-#
-#  
-
-import sys, os, pwd, string, getopt, re
-from semanage import *;
-import selinux
-import gettext
-gettext.install('policycoreutils')
-
-def grep(file, var):
-	ret = ""
-	fd = open(file, 'r')
-
-	for i in  fd.readlines():
-	    if re.search(var, i, 0) != None:
-	        ret = i
-                break
-	fd.close()
-	return ret
-
-def findval(file, var, delim = ""):
-	val = ""
-	try:
-		fd = open(file, 'r')
-		for i in  fd.readlines():
-			if i.startswith(var) == 1:
-				if delim == "":
-					val = i.split()[1]
-				else:
-					val = i.split(delim)[1]
-				val = val.split("#")[0]
-				val = val.strip()
-		fd.close()
-	except:
-		val = ""
-	return val
-
-def getStartingUID():
-	starting_uid = sys.maxint
-	uid_min =  findval("/etc/login.defs", "UID_MIN")
-	if uid_min != "":
-		uid_min = uid_min.split("#")[0]
-		uid_min = uid_min.strip()
-		if int(uid_min) < starting_uid:
-			starting_uid = int(uid_min)
-
-	uid_min =  findval("/etc/libuser.conf", "LU_UIDNUMBER", "=")
-	if uid_min != "":
-		uid_min = uid_min.split("#")[0]
-		uid_min = uid_min.strip()
-		if int(uid_min) < starting_uid:
-			starting_uid = int(uid_min)
-
-	if starting_uid == sys.maxint:
-		starting_uid = 500
-	return starting_uid
-
-def getDefaultHomeDir():
-	ret = []
-	homedir = findval("/etc/default/useradd", "HOME", "=")
-	if homedir != "" and not homedir in ret:
-		ret.append(homedir)
-	
-	homedir = findval("/etc/libuser.conf", "LU_HOMEDIRECTORY", "=")
-	if homedir != "" and not homedir in ret:
-		ret.append(homedir)
-	
-	if ret == []:
-		ret.append("/home")
-
-	# Add /export/home if it exists
-	# Some customers use this for automounted homedirs
-	if os.path.exists("/export/home"):
-		ret.append("/export/home")
-
-	return ret
-
-def getSELinuxType(directory):
-	val = findval(directory+"/config", "SELINUXTYPE", "=")
-	if val != "":
-		return val
-	return "targeted"
-
-def usage(rc=0, error = ""):
-	if error != "":
-		sys.stderr.write("%s\n" % error)
-		rc = 1
-	sys.stderr.write("Usage: %s [ -d selinuxdir ] [-n | --nopasswd] [-t selinuxtype ]\n" % sys.argv[0])
-	sys.stderr.flush()
-	sys.exit(rc)
-
-def warning(warning = ""):
-	sys.stderr.write("%s\n" % warning)
-	sys.stderr.flush()
-	
-def errorExit(error):
-	sys.stderr.write("%s exiting for: " % sys.argv[0])
-	sys.stderr.write("%s\n" % error)
-	sys.stderr.flush()
-	sys.exit(1)
-
-class selinuxConfig:
-	def __init__(self, selinuxdir = "/etc/selinux", type = "targeted", usepwd = 1):
-		self.semanageHandle = semanage_handle_create()
-		self.semanaged = semanage_is_managed(self.semanageHandle)
-		if self.semanaged:
-			rc = semanage_connect(self.semanageHandle)
-			if rc:
-				errorExit("Unable to connect to semanage")
-			(status, self.ulist) = semanage_user_list(self.semanageHandle)
-		self.type = type
-		self.selinuxdir = selinuxdir +"/"
-		self.contextdir = "/contexts"
-		self.filecontextdir = self.contextdir+"/files"
-		self.usepwd = usepwd
-		self.default_user = "user_u"
-		self.default_prefix = "user"
-		self.users = self.getUsers()
-		fd = open(self.getFileContextFile())
-		self.fclines=[]
-		for i in fd.readlines():
-		    try:
-			    regex = i.split()[0]
-			    #match a trailing .+
-			    regex = re.sub("\.+$", "", regex)
-			    regex = re.sub("\.\*$", "", regex)
-			    regex = re.sub("\(\/\.\*\)\?", "", regex)
-			    regex = regex + "/*$"
-			    self.fclines.append(re.compile(regex))
-		    except:
-			    continue
-
-		fd.close()
-		
-	def getFileContextDir(self):
-		return self.selinuxdir+self.type+self.filecontextdir
-
-	def getFileContextFile(self):
-		return self.getFileContextDir()+"/file_contexts"
-	
-	def getContextDir(self):
-		return self.selinuxdir+self.type+self.contextdir
-
-	def getHomeDirTemplate(self):
-		return self.getFileContextDir()+"/homedir_template"
-
-	def getHomeRootContext(self, homedir):
-		ret = ""
-		fd = open(self.getHomeDirTemplate(), 'r')
-
-		for i in  fd.readlines():
-			if i.find("HOME_ROOT") == 0:
-				i = i.replace("HOME_ROOT", homedir)
-				ret += i
-		fd.close()
-		if ret == "":
-			errorExit("No Home Root Context Found")
-		return ret
-
-	def heading(self):
-		ret = "\n#\n#\n# User-specific file contexts, generated via %s\n" % sys.argv[0]
-		if self.semanaged:
-			ret += "# use semanage command to manage system users in order to change the file_context\n#\n#\n"
-		else:
-			ret += "# edit %s to change file_context\n#\n#\n" % (self.selinuxdir+self.type+"/seusers")
-		return ret
-
-	def get_default_prefix(self, name):
-		for user in self.ulist:
-			if semanage_user_get_name(user) == name:
-				return semanage_user_get_prefix(user)
-		return name
-
-	def get_old_prefix(self, user):
-		rc = grep(self.selinuxdir+self.type+"/users/system.users", "^user %s" % user)
-		if rc == "":					    
-			rc = grep(self.selinuxdir+self.type+"/users/local.users", "^user %s" % user)
-		if rc != "":
-			user = rc.split()
-			prefix  =  user[3]
-			if prefix == "{":
-				prefix = user[4]
-		if len(prefix) > 2 and (prefix[-2:] == "_r" or prefix[-2:] == "_u"):
-			prefix = prefix[:-2]
-		return prefix
-		
-	def adduser(self, udict, user, seuser, prefix):
-		if seuser == self.default_user or user == "__default__" or user == "system_u":
-			return
-		# !!! chooses first prefix in the list to use in the file context !!!
-		try:
-			home = pwd.getpwnam(user)[5]
-			if home == "/":
-				# Probably install so hard code to /root
-				if user == "root":
-					home = "/root"
-				else:
-					return
-		except KeyError:
-			if user == "root":
-				home = "/root"
-			else:
-				sys.stderr.write("The user \"%s\" is not present in the passwd file, skipping...\n" % user)
-				return
-		prefs = {}
-		prefs["seuser"] = seuser
-		prefs["prefix"] = prefix
-		prefs["home"] = home
-		udict[user] = prefs
-			
-	def setDefaultUser(self, user, prefix):
-		self.default_user = user
-		self.default_prefix = prefix
-		
-	def getUsers(self):
-		udict = {}
-		if self.semanaged:
-			(status, list) = semanage_seuser_list(self.semanageHandle)
-			for seuser in list:
-				user = []
-				seusername = semanage_seuser_get_sename(seuser)
-				prefix = self.get_default_prefix(seusername)
-				if semanage_seuser_get_name(seuser) == "__default__":
-					self.setDefaultUser(seusername, prefix)
-
-				self.adduser(udict, semanage_seuser_get_name(seuser), seusername, prefix)
-				
-		else:
-			try:
-				fd = open(self.selinuxdir+self.type+"/seusers")
-				for u in  fd.readlines():
-					u = u.strip()
-					if len(u) == 0 or u[0] == "#":
-						continue
-					user = u.split(":")
-					if len(user) < 2:
-						continue
-					
-					prefix = self.get_old_prefix(user[1])
-					self.adduser(udict, user[0], user[1], prefix)
-				fd.close()
-			except IOError, error:
-				# Must be install so force add of root
-				self.adduser(udict, "root", "root", "root")
-
-		return udict
-
-	def getHomeDirContext(self, user, seuser, home, prefix):
-		ret = "\n\n#\n# Home Context for user %s\n#\n\n" % user
-		fd = open(self.getHomeDirTemplate(), 'r')
-		for i in  fd.readlines():
-			if i.startswith("HOME_DIR") == 1:
-				i = i.replace("HOME_DIR", home)
-				i = i.replace("ROLE", prefix)
-				i = i.replace("system_u", seuser)
-				# Validate if the generated context exists.  Some user types may not exist
-				scon = i.split()[-1]
-				if selinux.is_selinux_enabled() < 1 or selinux.security_check_context(scon) == 0:
-					ret = ret+i
-		fd.close()
-		return ret
-
-	def getUserContext(self, user, sel_user, prefix):
-		ret = ""
-		fd = open(self.getHomeDirTemplate(), 'r')
-		for i in  fd.readlines():
-			if i.find("USER") >= 0:
-				i = i.replace("USER", user)
-				i = i.replace("ROLE", prefix)
-				i = i.replace("system_u", sel_user)
-				ret = ret+i
-		fd.close()
-		return ret
-
-	def genHomeDirContext(self):
-		ret = ""
-		# Fill in HOME and prefix for users that are defined
-		for u in self.users.keys():
-			ret += self.getHomeDirContext (u, self.users[u]["seuser"], self.users[u]["home"], self.users[u]["prefix"])
-			ret += self.getUserContext (u, self.users[u]["seuser"], self.users[u]["prefix"])
-		return ret+"\n"
-
-	def checkExists(self, home):
-		for i in self.fclines:
-		    try:
-			    if i.match(home):
-				    return 1
-		    except:
-			    continue
-		return 0
-
-	def getHomeDirs(self):
-		homedirs = getDefaultHomeDir()
-		starting_uid = getStartingUID()
-		if self.usepwd == 0:
-			return homedirs
-		ulist = pwd.getpwall()
-		for u in ulist:
-			if u[2] >= starting_uid and \
-					u[6] in VALID_SHELLS and \
-					u[5] != "/" and \
-					string.count(u[5], "/") > 1:
-				homedir = u[5][:string.rfind(u[5], "/")]
-				if not homedir in homedirs:
-					if self.checkExists(homedir) == 1:
-						warning("%s homedir %s or its parent directory conflicts with a\ndefined context in %s,\n%s will not create a new context. This usually indicates an incorrectly defined system account.  If it is a system account please make sure its login shell is /sbin/nologin." % (u[0], u[5], self.getFileContextFile(), sys.argv[0]))
-					else:
-						homedirs.append(homedir)
-
-		homedirs.sort()
-		return homedirs
- 
-	def genoutput(self):
-		ret = self.heading()
-		for h in self.getHomeDirs():
-			ret += self.getHomeDirContext (self.default_user, self.default_user, h+'/[^/]*', self.default_prefix)
-			ret += self.getHomeRootContext(h)
-		ret += self.getUserContext(".*", self.default_user, self.default_prefix) + "\n"
-		ret += self.genHomeDirContext()
-		return ret
-
-	def printout(self):
-		print self.genoutput()
-
-	def write(self):
-		fd = open(self.getFileContextDir()+"/file_contexts.homedirs", "w")
-		fd.write(self.genoutput())
-		fd.close()
-
-if os.getuid() > 0 or os.geteuid() > 0:
-	print _("You must be root to run %s.") % sys.argv[0]
-	sys.exit(1)
-
-try:
-	fd = open("/etc/shells", 'r')
-	VALID_SHELLS = fd.read().split("\n")
-	fd.close()
-	if "/sbin/nologin" in VALID_SHELLS:
-		VALID_SHELLS.remove("/sbin/nologin")
-	if "" in VALID_SHELLS:
-		VALID_SHELLS.remove("")
-except:
-	VALID_SHELLS = ['/bin/sh', '/bin/bash', '/bin/ash', '/bin/bsh', '/bin/ksh', '/usr/bin/ksh', '/usr/bin/pdksh', '/bin/tcsh', '/bin/csh', '/bin/zsh']
-
-#
-# This script will generate home dir file context
-# based off the homedir_template file, entries in the password file, and
-#
-try:
-	usepwd = 1
-	directory = "/etc/selinux"
-	type = None
-	gopts, cmds = getopt.getopt(sys.argv[1:], 'hnd:t:', ['help',
-						'type=',
-						'nopasswd',
-						'dir='])
-	for o,a in gopts:
-		if o == '--type' or o == "-t":
-			type = a
-		if o == '--nopasswd'  or o == "-n":
-			usepwd = 0
-		if o == '--dir'  or o == "-d":
-			directory = a
-		if o == '--help'  or o == "-h":
-			usage()
-except getopt.error, error:
-	errorExit(_("Options Error %s ") % error)
-
-if type == None:
-	type = getSELinuxType(directory)
-
-if len(cmds) != 0:
-	usage(1)
-
-selconf = selinuxConfig(directory, type, usepwd)
-try:
-	selconf.write()
-except IOError, error:
-	sys.stderr.write("%s: %s\n" % ( sys.argv[0], error ))
-	sys.exit(1)
-
Deleted: trunk/policycoreutils/scripts/genhomedircon.8
===================================================================
--- trunk/policycoreutils/scripts/genhomedircon.8	2007-08-23 14:42:14 UTC (rev 2528)
+++ trunk/policycoreutils/scripts/genhomedircon.8	2007-08-23 14:43:09 UTC (rev 2529)
@@ -1,82 +0,0 @@
-.\" Hey, Emacs! This is an -*- nroff -*- source file.
-.\" Copyright (c) 2005 Manoj Srivastava <sri...@de...>
-.\"
-.\" This is free documentation; you can redistribute it and/or
-.\" modify it under the terms of the GNU General Public License as
-.\" published by the Free Software Foundation; either version 2 of
-.\" the License, or (at your option) any later version.
-.\"
-.\" The GNU General Public License's references to "object code"
-.\" and "executables" are to be interpreted as the output of any
-.\" document formatting or typesetting system, including
-.\" intermediate and printed output.
-.\"
-.\" This manual is distributed in the hope that it will be useful,
-.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
-.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-.\" GNU General Public License for more details.
-.\"
-.\" You should have received a copy of the GNU General Public
-.\" License along with this manual; if not, write to the Free
-.\" Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
-.\" USA.
-.\"
-.\"
-.TH GENHOMEDIRCON "8" "January 2005" "Security Enhanced Linux" ""
-.SH NAME
-genhomedircon \- generate SELinux file context configuration entries for user home directories 
-.SH SYNOPSIS
-.B genhomedircon [ -d selinuxdir ] [-n | --nopasswd] [-t selinuxtype ] [-h]
-
-.SH OPTIONS
-.TP
-.B "\-h"
-Print a short usage message
-.TP
-.B "\-d selinuxdir (\-\-directory)"
-Directory where selinux files are installed defaults to /etc/selinux
-.TP
-.B 
-\-n \-\-nopasswd
-Indicates to the utility not to read homedirectories out of the password database.  
-.TP
-\-t selinuxtype (\-\-type)
-Indicates the selinux type of this install.  Defaults to "targeted".
-.SH DESCRIPTION
-.PP
-This utility is used to generate file context configuration entries for 
-user home directories based on their 
-.B prefix 
-entry in the the 
-.B semanage user record.  
-genhomedircon is run when building 
-the policy. It is also run automaticaly when ever the 
-.B semanage 
-utility modifies 
-.B user
-or
-.B login
-records.
-Specifically, we replace HOME_ROOT, HOME_DIR, and ROLE macros in the 
-.I /etc/selinux/<<SELINUXTYPE>>/contexts/files/homedir_template 
-file with generic and user-specific values.  HOME_ROOT and HOME_DIR is replaced with each distinct location where login users homedirectories are located.  Defaults to /home. ROLE is replaced based on the prefix entry in the 
-.B user
-record.
-.PP 
-genhomedircon searches through all password entires for all "login" user home directories, (as opposed
-to system users).  Login users are those whose UID is greater than or equal 
-.I STARTING_UID
-(default 500) and whose login shell is not "/sbin/nologin", or
-"/bin/false". 
-.PP 
-.SH AUTHOR
-This manual page was originally written by 
-.I Manoj Srivastava <sri...@de...>,
-for the Debian GNU/Linux system, based on the comments and the code
-in the utility, and then updated by Dan Walsh of Red Hat. The 
-.B genhomedircon
-utility was originally written by 
-.I Dan Walsh of Red Hat 
-with some modifications by 
-.I Tresys Technology, LLC.
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:42:22
      
     | 
| Revision: 2528
          http://selinux.svn.sourceforge.net/selinux/?rev=2528&view=rev
Author:   ssmalley
Date:     2007-08-23 07:42:14 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Author: tm...@tr...
Email: tm...@tr...
Subject: libsemanage: test functions
Date: Tue, 21 Aug 2007 15:10:45 -0400
Test functions for libsemanage/src/utilities.c and
libsemanage/src/utilities.h
Modified Paths:
--------------
    trunk/libsemanage/tests/Makefile
    trunk/libsemanage/tests/libsemanage-tests.c
Added Paths:
-----------
    trunk/libsemanage/tests/test_utilities.c
    trunk/libsemanage/tests/test_utilities.h
Modified: trunk/libsemanage/tests/Makefile
===================================================================
--- trunk/libsemanage/tests/Makefile	2007-08-23 14:41:50 UTC (rev 2527)
+++ trunk/libsemanage/tests/Makefile	2007-08-23 14:42:14 UTC (rev 2528)
@@ -13,7 +13,7 @@
 CC = gcc
 CFLAGS = -c -g -o0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter
 INCLUDE = -I$(TESTSRC) -I$(TESTSRC)/../include/semanage
-LDFLAGS = -lcunit
+LDFLAGS = -lcunit -lustr
 OBJECTS = $(SOURCES:.c=.o) 
 
 all: $(EXECUTABLE) 
Modified: trunk/libsemanage/tests/libsemanage-tests.c
===================================================================
--- trunk/libsemanage/tests/libsemanage-tests.c	2007-08-23 14:41:50 UTC (rev 2527)
+++ trunk/libsemanage/tests/libsemanage-tests.c	2007-08-23 14:42:14 UTC (rev 2528)
@@ -20,6 +20,7 @@
  */
 
 #include "test_semanage_store.h"
+#include "test_utilities.h"
 
 #include <CUnit/Basic.h>
 #include <CUnit/Console.h>
@@ -55,6 +56,7 @@
 		return CU_get_error();
 
 	DECLARE_SUITE(semanage_store);
+	DECLARE_SUITE(semanage_utilities);
 
 	if (verbose)
 		CU_basic_set_mode(CU_BRM_VERBOSE);
Added: trunk/libsemanage/tests/test_utilities.c
===================================================================
--- trunk/libsemanage/tests/test_utilities.c	                        (rev 0)
+++ trunk/libsemanage/tests/test_utilities.c	2007-08-23 14:42:14 UTC (rev 2528)
@@ -0,0 +1,285 @@
+/* Authors: Mark Goldman <mgo...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/*  The purpose of this file is to provide unit tests of the functions in:
+ *
+ *  libsemanage/src/utilities.c
+ *
+ */
+
+#include <CUnit/Basic.h>
+#include <CUnit/Console.h>
+#include <CUnit/TestDB.h>
+
+#include <utilities.h>
+#include <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+void test_semanage_is_prefix(void);
+void test_semanage_split_on_space(void);
+void test_semanage_split(void);
+void test_semanage_list(void);
+void test_semanage_str_count(void);
+void test_semanage_rtrim(void);
+void test_semanage_findval(void);
+void test_slurp_file_filter(void);
+
+char fname[] = {
+	'T', 'E', 'S', 'T', '_', 'T', 'E', 'M', 'P', '_', 'X', 'X', 'X', 'X',
+	'X', 'X'
+};
+int fd;
+FILE *fptr;
+
+int semanage_utilities_test_init(void)
+{
+	fd = mkstemp(fname);
+
+	if (fd < 0) {
+		perror("test_semanage_findval: ");
+		CU_FAIL_FATAL
+		    ("Error opening temporary file, test cannot start.");
+	}
+
+	fptr = fdopen(fd, "w+");
+	if (!fptr) {
+		perror("test_semanage_findval file: ");
+		CU_FAIL_FATAL("Error opening file stream, test cannot start.");
+	}
+
+	fprintf(fptr, "one\ntwo\nthree\nsigma=foo\n#boo\n#bar\n");
+
+	rewind(fptr);
+	return 0;
+}
+
+int semanage_utilities_test_cleanup(void)
+{
+	unlink(fname);
+	return 0;
+}
+
+int semanage_utilities_add_tests(CU_pSuite suite)
+{
+	if (NULL == CU_add_test(suite, "semanage_is_prefix",
+				test_semanage_is_prefix)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "semanage_split_on_space",
+				test_semanage_split_on_space)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "semanage_split", test_semanage_split)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "semanage_list", test_semanage_list)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "semanage_str_count",
+				test_semanage_str_count)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "semanage_rtrim", test_semanage_rtrim)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "semanage_findval",
+				test_semanage_findval)) {
+		goto err;
+	}
+	if (NULL == CU_add_test(suite, "slurp_file_filter",
+				test_slurp_file_filter)) {
+		goto err;
+	}
+	return 0;
+      err:
+	CU_cleanup_registry();
+	return CU_get_error();
+}
+
+void test_semanage_is_prefix(void)
+{
+	char *str = "some string";
+	char *pre = "some";
+	char *not_pre = "not this";
+
+	CU_ASSERT_TRUE(semanage_is_prefix(str, pre));
+	CU_ASSERT_TRUE(semanage_is_prefix(str, ""));
+	CU_ASSERT_TRUE(semanage_is_prefix(str, NULL));
+	CU_ASSERT_FALSE(semanage_is_prefix(str, not_pre));
+}
+
+void test_semanage_split_on_space(void)
+{
+	char *str = strdup("foo bar baz");
+	char *temp;
+
+	if (!str) {
+		CU_FAIL
+		    ("semanage_split_on_space: unable to perform test, no memory");
+	}
+	temp = semanage_split_on_space(str);
+	if (strncmp(temp, "bar", 3)) {
+		CU_FAIL("semanage_split_on_space: token did not match");
+	}
+	temp = semanage_split_on_space(temp);
+	if (strncmp(temp, "baz", 3)) {
+		CU_FAIL("semanage_split_on_space: token did not match");
+	}
+	temp = semanage_split_on_space(temp);
+	if (strcmp(temp, "")) {
+		CU_FAIL("semanage_split_on_space: token did not match");
+	}
+
+	free(str);
+}
+
+void test_semanage_split(void)
+{
+	char *str = strdup("foo1 foo2 foo:bar");
+	char *temp;
+
+	if (!str) {
+		CU_FAIL
+		    ("semanage_split_on_space: unable to perform test, no memory");
+		return;
+	}
+	temp = semanage_split(str, NULL);
+	CU_ASSERT_NSTRING_EQUAL(temp, "foo2", 4);
+	temp = semanage_split(temp, "");
+	CU_ASSERT_NSTRING_EQUAL(temp, "foo", 3);
+	temp = semanage_split(temp, ":");
+	CU_ASSERT_NSTRING_EQUAL(temp, "bar", 3);
+
+	free(str);
+}
+
+void test_semanage_list(void)
+{
+	semanage_list_t *list = NULL;
+	semanage_list_t *ptr = NULL;
+	char *temp = NULL;
+	int retval = 0;
+
+	CU_ASSERT_FALSE(semanage_list_push(&list, "foo"));
+	CU_ASSERT_PTR_NOT_NULL(list);
+	CU_ASSERT_FALSE(semanage_list_push(&list, "bar"));
+	CU_ASSERT_FALSE(semanage_list_push(&list, "gonk"));
+	CU_ASSERT_FALSE(semanage_list_push(&list, "zebra"));
+
+	for (ptr = list; ptr; ptr = ptr->next)
+		retval++;
+	CU_ASSERT_EQUAL(retval, 4);
+
+	temp = semanage_list_pop(&list);
+	CU_ASSERT_STRING_EQUAL(temp, "zebra");
+	CU_ASSERT_FALSE(semanage_list_push(&list, temp));
+	free(temp);
+	temp = NULL;
+
+	retval = 0;
+	for (ptr = list; ptr; ptr = ptr->next)
+		retval++;
+	CU_ASSERT_EQUAL(retval, 4);
+
+	retval = semanage_list_sort(&list);
+	if (retval) {
+		CU_FAIL
+		    ("semanage_list_sort: error unrelated to sort (memory?)");
+		goto past_sort;
+	}
+	CU_ASSERT_STRING_EQUAL(list->data, "bar");
+	CU_ASSERT_STRING_EQUAL(list->next->data, "foo");
+	CU_ASSERT_STRING_EQUAL(list->next->next->data, "gonk");
+	CU_ASSERT_STRING_EQUAL(list->next->next->next->data, "zebra");
+
+      past_sort:
+	ptr = semanage_list_find(list, "zebra");
+	CU_ASSERT_PTR_NOT_NULL(ptr);
+	ptr = semanage_list_find(list, "bogus");
+	CU_ASSERT_PTR_NULL(ptr);
+
+	semanage_list_destroy(&list);
+	CU_ASSERT_PTR_NULL(list);
+}
+
+void test_semanage_str_count(void)
+{
+	char *test_string = "abaababbaaaba";
+
+	CU_ASSERT_EQUAL(semanage_str_count(test_string, 'z'), 0);
+	CU_ASSERT_EQUAL(semanage_str_count(test_string, 'a'), 8);
+	CU_ASSERT_EQUAL(semanage_str_count(test_string, 'b'), 5);
+}
+
+void test_semanage_rtrim(void)
+{
+	char *str = strdup("/blah/foo/bar/baz/");
+
+	CU_ASSERT_PTR_NOT_NULL_FATAL(str);
+
+	semanage_rtrim(str, 'Q');
+	CU_ASSERT_STRING_EQUAL(str, "/blah/foo/bar/baz/");
+	semanage_rtrim(str, 'a');
+	CU_ASSERT_STRING_EQUAL(str, "/blah/foo/bar/b");
+	semanage_rtrim(str, '/');
+	CU_ASSERT_STRING_EQUAL(str, "/blah/foo/bar");
+}
+
+void test_semanage_findval(void)
+{
+	char *tok;
+	if (!fptr) {
+		CU_FAIL_FATAL("Temporary file was not created, aborting test.");
+	}
+	tok = semanage_findval(fname, "one", NULL);
+	CU_ASSERT_STRING_EQUAL(tok, "");
+	rewind(fptr);
+	tok = semanage_findval(fname, "one", "");
+	CU_ASSERT_STRING_EQUAL(tok, "");
+	free(tok);
+	rewind(fptr);
+	tok = semanage_findval(fname, "sigma", "=");
+	CU_ASSERT_STRING_EQUAL(tok, "foo");
+}
+
+int PREDICATE(const char *str)
+{
+	return semanage_is_prefix(str, "#");
+}
+
+void test_slurp_file_filter(void)
+{
+	semanage_list_t *data, *tmp;
+	int cnt = 0;
+
+	if (!fptr) {
+		CU_FAIL_FATAL("Temporary file was not created, aborting test.");
+	}
+	rewind(fptr);
+	data = semanage_slurp_file_filter(fptr, PREDICATE);
+	CU_ASSERT_PTR_NOT_NULL_FATAL(data);
+	for (tmp = data; tmp; tmp = tmp->next)
+		cnt++;
+	CU_ASSERT_EQUAL(cnt, 2);
+
+	semanage_list_destroy(&data);
+}
Added: trunk/libsemanage/tests/test_utilities.h
===================================================================
--- trunk/libsemanage/tests/test_utilities.h	                        (rev 0)
+++ trunk/libsemanage/tests/test_utilities.h	2007-08-23 14:42:14 UTC (rev 2528)
@@ -0,0 +1,5 @@
+#include <CUnit/Basic.h>
+
+int semanage_utilities_test_init(void);
+int semanage_utilities_test_cleanup(void);
+int semanage_utilities_add_tests(CU_pSuite suite);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:41:52
      
     | 
| Revision: 2527
          http://selinux.svn.sourceforge.net/selinux/?rev=2527&view=rev
Author:   ssmalley
Date:     2007-08-23 07:41:50 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Author: tm...@tr...
Email: tm...@tr...
Subject: libsemanage: genhomedircon replacement
Date: Tue, 21 Aug 2007 15:10:44 -0400
Remove python script genhomedircon from libsemanage and replace
with C functionality.
Note: This code fixes a bug in the orignal genhomedircon python script; the
following two lines are added to the file contexts whereas the old
genhomedircon would not add them: 
/tmp/\.exchange-.*(/.*)?      user_u:object_r:user_evolution_exchange_tmp_t:s0
/tmp/\.exchange-root(/.*)?    root:object_r:user_evolution_exchange_tmp_t:s0
Modified Paths:
--------------
    trunk/libselinux/src/file_path_suffixes.h
    trunk/libsemanage/src/Makefile
    trunk/libsemanage/src/semanage_store.c
    trunk/libsemanage/src/semanage_store.h
Added Paths:
-----------
    trunk/libsemanage/src/genhomedircon.c
    trunk/libsemanage/src/genhomedircon.h
    trunk/libsemanage/src/utilities.c
    trunk/libsemanage/src/utilities.h
Modified: trunk/libselinux/src/file_path_suffixes.h
===================================================================
--- trunk/libselinux/src/file_path_suffixes.h	2007-08-23 14:39:48 UTC (rev 2526)
+++ trunk/libselinux/src/file_path_suffixes.h	2007-08-23 14:41:50 UTC (rev 2527)
@@ -16,6 +16,6 @@
     S_(SEUSERS, "/seusers")
     S_(TRANSLATIONS, "/setrans.conf")
     S_(NETFILTER_CONTEXTS, "/contexts/netfilter_contexts")
-    S_(FILE_CONTEXTS_HOMEDIR, "/contexts/files/file_contexts.homedir")
+    S_(FILE_CONTEXTS_HOMEDIR, "/contexts/files/file_contexts.homedirs")
     S_(FILE_CONTEXTS_LOCAL, "/contexts/files/file_contexts.local")
     S_(X_CONTEXTS, "/contexts/x_contexts")
Modified: trunk/libsemanage/src/Makefile
===================================================================
--- trunk/libsemanage/src/Makefile	2007-08-23 14:39:48 UTC (rev 2526)
+++ trunk/libsemanage/src/Makefile	2007-08-23 14:41:50 UTC (rev 2527)
@@ -54,7 +54,7 @@
 	ranlib $@
 
 $(LIBSO): $(LOBJS)
-	$(CC) $(LDFLAGS) -shared -o $@ $^ -lsepol -lselinux -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
+	$(CC) $(LDFLAGS) -shared -o $@ $^ -lsepol -lselinux -lustr -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
 	ln -sf $@ $(TARGET)
 
 conf-scan.c: conf-scan.l conf-parse.h
Added: trunk/libsemanage/src/genhomedircon.c
===================================================================
--- trunk/libsemanage/src/genhomedircon.c	                        (rev 0)
+++ trunk/libsemanage/src/genhomedircon.c	2007-08-23 14:41:50 UTC (rev 2527)
@@ -0,0 +1,717 @@
+/* Author: Mark Goldman   <mgo...@tr...>
+ * 			Paul Rosenfeld	<pro...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as
+ *  published by the Free Software Foundation; either version 2.1 of the
+ *  License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ *  02110-1301  USA
+ */
+
+#include <semanage/handle.h>
+#include <semanage/seusers_policy.h>
+#include <semanage/users_policy.h>
+#include <semanage/user_record.h>
+#include "semanage_store.h"
+#include "seuser_internal.h"
+#include "debug.h"
+
+#include "utilities.h"
+#include "genhomedircon.h"
+#include <ustr.h>
+
+#include <assert.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <pwd.h>
+#include <errno.h>
+
+/* paths used in get_home_dirs() */
+#define PATH_ETC_USERADD "/etc/default/useradd"
+#define PATH_ETC_LIBUSER "/etc/libuser.conf"
+#define PATH_DEFAULT_HOME "/home"
+#define PATH_EXPORT_HOME "/export/home"
+#define PATH_ETC_LOGIN_DEFS "/etc/login.defs"
+
+/* other paths */
+#define PATH_SHELLS_FILE "/etc/shells"
+#define PATH_NOLOGIN_SHELL "/sbin/nologin"
+
+/* comments written to context file */
+#define COMMENT_FILE_CONTEXT_HEADER "#\n#\n# " \
+			"User-specific file contexts, generated via libsemanage\n" \
+			"# use semanage command to manage system users to change" \
+			" the file_context\n#\n#\n"
+
+#define COMMENT_USER_HOME_CONTEXT "\n\n#\n# Home Context for user %s" \
+			"\n#\n\n"
+
+/* placeholders used in the template file
+   which are searched for and replaced */
+#define TEMPLATE_HOME_ROOT "HOME_ROOT"
+#define TEMPLATE_HOME_DIR "HOME_DIR"
+#define TEMPLATE_USER "USER"
+#define TEMPLATE_ROLE "ROLE"
+#define TEMPLATE_SEUSER "system_u"
+
+#define FALLBACK_USER "user_u"
+#define FALLBACK_USER_PREFIX "user"
+#define DEFAULT_LOGIN "__default__"
+
+typedef struct {
+	const char *fcfilepath;
+	int usepasswd;
+	const char *homedir_template_path;
+	semanage_handle_t *h_semanage;
+} genhomedircon_settings_t;
+
+typedef struct user_entry {
+	char *name;
+	char *sename;
+	char *prefix;
+	char *home;
+	struct user_entry *next;
+} genhomedircon_user_entry_t;
+
+typedef struct {
+	const char *search_for;
+	const char *replace_with;
+} replacement_pair_t;
+
+static semanage_list_t *default_shell_list(void)
+{
+	semanage_list_t *list = NULL;
+
+	if (semanage_list_push(&list, "/bin/csh")
+	    || semanage_list_push(&list, "/bin/tcsh")
+	    || semanage_list_push(&list, "/bin/ksh")
+	    || semanage_list_push(&list, "/bin/bsh")
+	    || semanage_list_push(&list, "/bin/ash")
+	    || semanage_list_push(&list, "/usr/bin/ksh")
+	    || semanage_list_push(&list, "/usr/bin/pdksh")
+	    || semanage_list_push(&list, "/bin/zsh")
+	    || semanage_list_push(&list, "/bin/sh")
+	    || semanage_list_push(&list, "/bin/bash"))
+		goto fail;
+
+	return list;
+
+      fail:
+	semanage_list_destroy(&list);
+	return NULL;
+}
+
+static semanage_list_t *get_shell_list(void)
+{
+	FILE *shells;
+	char *temp = NULL;
+	semanage_list_t *list = NULL;
+	size_t buff_len = 0;
+
+	shells = fopen(PATH_SHELLS_FILE, "r");
+	if (!shells)
+		return default_shell_list();
+	while (getline(&temp, &buff_len, shells) >= 0) {
+		if (strcmp(temp, PATH_NOLOGIN_SHELL)) {
+			if (semanage_list_push(&list, temp)) {
+				free(temp);
+				semanage_list_destroy(&list);
+				return default_shell_list();
+			}
+		}
+	}
+	free(temp);
+
+	return list;
+}
+
+static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s)
+{
+	semanage_list_t *homedir_list = NULL;
+	semanage_list_t *shells = NULL;
+	char *path = NULL;
+	size_t minuid = 0;
+	size_t minuid_set = 0;
+	size_t temp;
+	struct passwd *pwbuf;
+	struct stat buf;
+
+	shells = get_shell_list();
+	assert(shells);
+
+	path = semanage_findval(PATH_ETC_USERADD, "HOME", "=");
+	if (path && *path) {
+		if (semanage_list_push(&homedir_list, path)) {
+			free(path);
+			goto fail;
+		}
+	}
+	free(path);
+
+	path = semanage_findval(PATH_ETC_LIBUSER, "LU_HOMEDIRECTORY", "=");
+	if (path && *path) {
+		if (semanage_list_push(&homedir_list, path)) {
+			free(path);
+			goto fail;
+		}
+	}
+	free(path);
+
+	if (!homedir_list) {
+		if (semanage_list_push(&homedir_list, PATH_DEFAULT_HOME)) {
+			goto fail;
+		}
+	}
+
+	if (!stat(PATH_EXPORT_HOME, &buf)) {
+		if (S_ISDIR(buf.st_mode)) {
+			if (semanage_list_push(&homedir_list, PATH_EXPORT_HOME)) {
+				goto fail;
+			}
+		}
+	}
+
+	if (!(s->usepasswd))
+		return homedir_list;
+
+	path = semanage_findval(PATH_ETC_LOGIN_DEFS, "UID_MIN", NULL);
+	if (path && *path) {
+		temp = atoi(path);
+		if (!minuid_set || temp < minuid) {
+			minuid = temp;
+			minuid_set = 1;
+		}
+	}
+	free(path);
+
+	path = semanage_findval(PATH_ETC_LIBUSER, "LU_UIDNUMBER", "=");
+	if (path && *path) {
+		temp = atoi(path);
+		if (!minuid_set || temp < minuid) {
+			minuid = temp;
+			minuid_set = 1;
+		}
+	}
+	free(path);
+
+	if (!minuid_set) {
+		minuid = 500;
+		minuid_set = 1;
+	}
+
+	setpwent();
+	for (errno = 0; (pwbuf = getpwent()); errno = 0) {
+		if (pwbuf->pw_uid < minuid)
+			continue;
+		if (!semanage_list_find(shells, pwbuf->pw_shell))
+			continue;
+		if (strcmp(pwbuf->pw_dir, "/") == 0)
+			continue;
+		if (semanage_str_count(pwbuf->pw_dir, '/') <= 1)
+			continue;
+		if (!(path = strdup(pwbuf->pw_dir))) {
+			break;
+		}
+
+		semanage_rtrim(path, '/');
+		if (!semanage_list_find(homedir_list, path)) {
+			if (semanage_list_push(&homedir_list, path)) {
+				free(path);
+				goto fail;
+			}
+		}
+		free(path);
+	}
+
+	if (errno) {
+		WARN(s->h_semanage, "Error while fetching users.  "
+		     "Returning list so far.");
+	}
+	endpwent();
+	semanage_list_destroy(&shells);
+	if (semanage_list_sort(&homedir_list))
+		goto fail;
+
+	return homedir_list;
+
+      fail:
+	semanage_list_destroy(&homedir_list);
+	semanage_list_destroy(&shells);
+	return NULL;
+}
+
+/**
+ * @param	s	settings structure, stores various paths etc. Must never be NULL
+ * @param	out	the FILE to put all the output in.
+ * @return	0 on success
+ */
+static int write_file_context_header(genhomedircon_settings_t * s, FILE * out)
+{
+	if (fprintf(out, COMMENT_FILE_CONTEXT_HEADER) < 0) {
+		return STATUS_ERR;
+	}
+
+	return STATUS_SUCCESS;
+}
+
+/* Predicates for use with semanage_slurp_file_filter() the homedir_template
+ * file currently contains lines that serve as the template for a user's
+ * homedir.
+ *
+ * It also contains lines that are the template for the parent of a
+ * user's home directory.
+ *
+ * Currently, the only lines that apply to the the root of a user's home
+ * directory are all prefixed with the string "HOME_ROOT".  All other
+ * lines apply to a user's home directory.  If this changes the
+ * following predicates need to change to reflect that.
+ */
+static int HOME_ROOT_PRED(const char *string)
+{
+	return semanage_is_prefix(string, TEMPLATE_HOME_ROOT);
+}
+
+static int HOME_DIR_PRED(const char *string)
+{
+	return semanage_is_prefix(string, TEMPLATE_HOME_DIR);
+}
+
+static int USER_CONTEXT_PRED(const char *string)
+{
+	return (int)(strstr(string, TEMPLATE_USER) != NULL);
+}
+
+/* make_tempate
+ * @param	s	  the settings holding the paths to various files
+ * @param	pred	function pointer to function to use as filter for slurp
+ * 					file filter
+ * @return   a list of lines from the template file with inappropriate
+ *	    lines filtered out.
+ */
+static semanage_list_t *make_template(genhomedircon_settings_t * s,
+				      int (*pred) (const char *))
+{
+	FILE *template_file = NULL;
+	semanage_list_t *template_data = NULL;
+
+	template_file = fopen(s->homedir_template_path, "r");
+	if (!template_file)
+		return NULL;
+	template_data = semanage_slurp_file_filter(template_file, pred);
+	fclose(template_file);
+
+	return template_data;
+}
+
+static Ustr *replace_all(const char *str, const replacement_pair_t * repl)
+{
+	Ustr *retval = USTR_NULL;
+	int i, num_replaced = 0;
+
+	if (!str || !repl)
+		goto done;
+	if (!(retval = ustr_dup_cstr(str)))
+		goto done;
+
+	for (i = 0; repl[i].search_for; i++) {
+		num_replaced += ustr_replace_cstr(&retval, repl[i].search_for,
+						  repl[i].replace_with, 0);
+	}
+	if (!num_replaced)
+		ustr_sc_free(&retval);
+
+      done:
+	return retval;
+}
+
+static int write_home_dir_context(FILE * out, semanage_list_t * tpl,
+				  const char *user, const char *seuser,
+				  const char *home, const char *role_prefix)
+{
+	replacement_pair_t repl[] = {
+		{.search_for = TEMPLATE_SEUSER,.replace_with = seuser},
+		{.search_for = TEMPLATE_HOME_DIR,.replace_with = home},
+		{.search_for = TEMPLATE_ROLE,.replace_with = role_prefix},
+		{NULL, NULL}
+	};
+	Ustr *line = USTR_NULL;
+
+	if (fprintf(out, COMMENT_USER_HOME_CONTEXT, user) < 0)
+		return STATUS_ERR;
+
+	for (; tpl; tpl = tpl->next) {
+		line = replace_all(tpl->data, repl);
+		if (!line || !ustr_io_putfileline(&line, out))
+			goto fail;
+		ustr_sc_free(&line);
+	}
+	return STATUS_SUCCESS;
+
+      fail:
+	ustr_sc_free(&line);
+	return STATUS_ERR;
+}
+
+static int write_home_root_context(FILE * out, semanage_list_t * tpl,
+				   char *homedir)
+{
+	replacement_pair_t repl[] = {
+		{.search_for = TEMPLATE_HOME_ROOT,.replace_with = homedir},
+		{NULL, NULL}
+	};
+	Ustr *line = USTR_NULL;
+
+	for (; tpl; tpl = tpl->next) {
+		line = replace_all(tpl->data, repl);
+		if (!line || !ustr_io_putfileline(&line, out))
+			goto fail;
+		ustr_sc_free(&line);
+	}
+	return STATUS_SUCCESS;
+
+      fail:
+	ustr_sc_free(&line);
+	return STATUS_ERR;
+}
+
+static int write_user_context(FILE * out, semanage_list_t * tpl, char *user,
+			      char *seuser, char *role_prefix)
+{
+	replacement_pair_t repl[] = {
+		{.search_for = TEMPLATE_USER,.replace_with = user},
+		{.search_for = TEMPLATE_ROLE,.replace_with = role_prefix},
+		{.search_for = TEMPLATE_SEUSER,.replace_with = seuser},
+		{NULL, NULL}
+	};
+	Ustr *line = USTR_NULL;
+
+	for (; tpl; tpl = tpl->next) {
+		line = replace_all(tpl->data, repl);
+		if (!line || !ustr_io_putfileline(&line, out))
+			goto fail;
+		ustr_sc_free(&line);
+	}
+	return STATUS_SUCCESS;
+
+      fail:
+	ustr_sc_free(&line);
+	return STATUS_ERR;
+}
+
+static int user_sort_func(semanage_user_t ** arg1, semanage_user_t ** arg2)
+{
+	return strcmp(semanage_user_get_name(*arg1),
+		      semanage_user_get_name(*arg2));
+}
+
+static int name_user_cmp(char *key, semanage_user_t ** val)
+{
+	return strcmp(key, semanage_user_get_name(*val));
+}
+
+static int push_user_entry(genhomedircon_user_entry_t ** list, const char *n,
+			   const char *sen, const char *pre, const char *h)
+{
+	genhomedircon_user_entry_t *temp = NULL;
+	char *name = NULL;
+	char *sename = NULL;
+	char *prefix = NULL;
+	char *home = NULL;
+
+	temp = malloc(sizeof(genhomedircon_user_entry_t));
+	if (!temp)
+		goto cleanup;
+	name = strdup(n);
+	if (!name)
+		goto cleanup;
+	sename = strdup(sen);
+	if (!sename)
+		goto cleanup;
+	prefix = strdup(pre);
+	if (!prefix)
+		goto cleanup;
+	home = strdup(h);
+	if (!home)
+		goto cleanup;
+
+	temp->name = name;
+	temp->sename = sename;
+	temp->prefix = prefix;
+	temp->home = home;
+	temp->next = (*list);
+	(*list) = temp;
+
+	return STATUS_SUCCESS;
+
+      cleanup:
+	free(name);
+	free(sename);
+	free(prefix);
+	free(home);
+	free(temp);
+	return STATUS_ERR;
+}
+
+static void pop_user_entry(genhomedircon_user_entry_t ** list)
+{
+	genhomedircon_user_entry_t *temp;
+
+	if (!list || !(*list))
+		return;
+
+	temp = *list;
+	*list = temp->next;
+	free(temp->name);
+	free(temp->sename);
+	free(temp->prefix);
+	free(temp->home);
+	free(temp);
+}
+
+static genhomedircon_user_entry_t *get_users(genhomedircon_settings_t * s,
+					     int *errors)
+{
+	genhomedircon_user_entry_t *head = NULL;
+	semanage_seuser_t **seuser_list = NULL;
+	unsigned int nseusers = 0;
+	semanage_user_t **user_list = NULL;
+	unsigned int nusers = 0;
+	semanage_user_t **u = NULL;
+	const char *name = NULL;
+	const char *seuname = NULL;
+	const char *prefix = NULL;
+	struct passwd *pwent = NULL;
+	unsigned int i;
+	int retval;
+
+	*errors = 0;
+	retval = semanage_seuser_list(s->h_semanage, &seuser_list, &nseusers);
+	if (retval < 0 || (nseusers < 1)) {
+		/* if there are no users, this function can't do any other work */
+		return NULL;
+	}
+
+	if (semanage_user_list(s->h_semanage, &user_list, &nusers) < 0) {
+		nusers = 0;
+	}
+
+	qsort(user_list, nusers, sizeof(semanage_user_t *),
+	      (int (*)(const void *, const void *))&user_sort_func);
+
+	for (i = 0; i < nseusers; i++) {
+		name = semanage_seuser_get_name(seuser_list[i]);
+		seuname = semanage_seuser_get_sename(seuser_list[i]);
+
+		if (strcmp(seuname, FALLBACK_USER) == 0)
+			continue;
+		if (strcmp(seuname, DEFAULT_LOGIN) == 0)
+			continue;
+		if (strcmp(seuname, TEMPLATE_SEUSER) == 0)
+			continue;
+
+		/* find the user structure given the name */
+		u = bsearch(seuname, user_list, nusers, sizeof(semanage_user_t *),
+			    (int (*)(const void *, const void *))
+			    &name_user_cmp);
+		if (u) {
+			prefix = semanage_user_get_prefix(*u);
+		} else {
+			prefix = name;
+		}
+
+		errno = 0;
+		pwent = getpwnam(name);
+		if (!pwent) {
+			if (errno != 0) {
+				*errors = STATUS_ERR;
+				goto cleanup;
+			}
+			WARN(s->h_semanage,
+			     "user %s not in password file", name);
+			continue;
+		}
+
+		if (strcmp(pwent->pw_dir, "/") == 0) {
+			/* don't relabel / genhomdircon checked to see if root
+			 * was the user and if so, set his home directory to
+			 * /root */
+			continue;
+		}
+		if (push_user_entry(&head, name, seuname,
+				    prefix, pwent->pw_dir) != STATUS_SUCCESS) {
+			*errors = STATUS_ERR;
+			break;
+		}
+	}
+
+      cleanup:
+	if (*errors) {
+		for (; head; pop_user_entry(&head)) {
+			/* the pop function takes care of all the cleanup
+			   so the loop body is just empty */
+		}
+	}
+	for (i = 0; i < nseusers; i++) {
+		semanage_seuser_free(seuser_list[i]);
+	}
+	free(seuser_list);
+
+	for (i = 0; i < nusers; i++) {
+		semanage_user_free(user_list[i]);
+	}
+	free(user_list);
+
+	return head;
+}
+
+static int write_gen_home_dir_context(FILE * out, genhomedircon_settings_t * s,
+				      semanage_list_t * user_context_tpl,
+				      semanage_list_t * homedir_context_tpl)
+{
+	genhomedircon_user_entry_t *users;
+	int errors = 0;
+
+	users = get_users(s, &errors);
+	if (!users && errors) {
+		return STATUS_ERR;
+	}
+
+	for (; users; pop_user_entry(&users)) {
+		if (write_home_dir_context(out, homedir_context_tpl,
+					   users->name,
+					   users->sename, users->home,
+					   users->prefix)) {
+			return STATUS_ERR;
+		}
+		if (write_user_context(out, user_context_tpl, users->name,
+				       users->sename, users->prefix)) {
+			return STATUS_ERR;
+		}
+	}
+
+	return STATUS_SUCCESS;
+}
+
+/**
+ * @param	s	settings structure, stores various paths etc. Must never be NULL
+ * @param	out	the FILE to put all the output in.
+ * @return	0 on success
+ */
+static int write_context_file(genhomedircon_settings_t * s, FILE * out)
+{
+	semanage_list_t *homedirs = NULL;
+	semanage_list_t *h = NULL;
+	semanage_list_t *user_context_tpl = NULL;
+	semanage_list_t *homedir_context_tpl = NULL;
+	semanage_list_t *homeroot_context_tpl = NULL;
+	int retval = STATUS_SUCCESS;
+
+	homedirs = get_home_dirs(s);
+	if (!homedirs) {
+		WARN(s->h_semanage,
+		     "no home directories were available, exiting without writing");
+		return STATUS_ERR;	/* No homedirs so no output */
+	}
+
+	if (write_file_context_header(s, out) != STATUS_SUCCESS)
+		return STATUS_ERR;
+
+	homedir_context_tpl = make_template(s, &HOME_DIR_PRED);
+	homeroot_context_tpl = make_template(s, &HOME_ROOT_PRED);
+	user_context_tpl = make_template(s, &USER_CONTEXT_PRED);
+	if (!homedir_context_tpl || !homeroot_context_tpl || !user_context_tpl) {
+		retval = STATUS_ERR;
+		goto done;
+	}
+
+	for (h = homedirs; h; h = h->next) {
+		Ustr *temp = ustr_dup_cstr(h->data);
+
+		if (!temp || !ustr_add_cstr(&temp, "/[^/]*")) {
+			ustr_sc_free(&temp);
+			retval = STATUS_ERR;
+			goto done;
+		}
+
+		if (write_home_dir_context(out,
+					   homedir_context_tpl, FALLBACK_USER,
+					   FALLBACK_USER, ustr_cstr(temp),
+					   FALLBACK_USER_PREFIX) !=
+		    STATUS_SUCCESS) {
+			ustr_sc_free(&temp);
+			retval = STATUS_ERR;
+			goto done;
+		}
+		if (write_home_root_context(out,
+					    homeroot_context_tpl,
+					    h->data) != STATUS_SUCCESS) {
+			ustr_sc_free(&temp);
+			retval = STATUS_ERR;
+			goto done;
+		}
+
+		ustr_sc_free(&temp);
+	}
+	if (write_user_context(out, user_context_tpl,
+			       ".*", FALLBACK_USER,
+			       FALLBACK_USER_PREFIX) != STATUS_SUCCESS) {
+		retval = STATUS_ERR;
+		goto done;
+	}
+	if (write_gen_home_dir_context(out, s, user_context_tpl,
+				       homedir_context_tpl) != STATUS_SUCCESS) {
+		retval = STATUS_ERR;
+	}
+
+      done:
+	/* Cleanup */
+	semanage_list_destroy(&homedirs);
+	semanage_list_destroy(&user_context_tpl);
+	semanage_list_destroy(&homedir_context_tpl);
+	semanage_list_destroy(&homeroot_context_tpl);
+
+	return retval;
+}
+
+int semanage_genhomedircon(semanage_handle_t * sh, int usepasswd)
+{
+	genhomedircon_settings_t s;
+	FILE *out = NULL;
+	int retval = 0;
+
+	assert(sh);
+
+	s.homedir_template_path =
+	    semanage_path(SEMANAGE_TMP, SEMANAGE_HOMEDIR_TMPL);
+	s.fcfilepath = semanage_path(SEMANAGE_TMP, SEMANAGE_FC_HOMEDIRS);
+
+	s.usepasswd = usepasswd;
+	s.h_semanage = sh;
+
+	if (!(out = fopen(s.fcfilepath, "w"))) {
+		/* couldn't open output file */
+		ERR(sh, "Could not open the file_context file for writing");
+		return STATUS_ERR;
+	}
+
+	retval = write_context_file(&s, out);
+
+	fclose(out);
+	return retval;
+}
Added: trunk/libsemanage/src/genhomedircon.h
===================================================================
--- trunk/libsemanage/src/genhomedircon.h	                        (rev 0)
+++ trunk/libsemanage/src/genhomedircon.h	2007-08-23 14:41:50 UTC (rev 2527)
@@ -0,0 +1,27 @@
+/* Author: Mark Goldman   <mgo...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _SEMANAGE_GENHOMEDIRCON_H_
+#define _SEMANAGE_GENHOMEDIRCON_H_
+
+#include "utilities.h"
+
+int semanage_genhomedircon(semanage_handle_t * sh, int usepasswd);
+
+#endif
Modified: trunk/libsemanage/src/semanage_store.c
===================================================================
--- trunk/libsemanage/src/semanage_store.c	2007-08-23 14:39:48 UTC (rev 2526)
+++ trunk/libsemanage/src/semanage_store.c	2007-08-23 14:41:50 UTC (rev 2527)
@@ -34,6 +34,7 @@
 #include "semanage_store.h"
 #include "database_policydb.h"
 #include "handle.h"
+#include "genhomedircon.h"
 
 #include <selinux/selinux.h>
 #include <sepol/policydb.h>
@@ -60,6 +61,9 @@
 #define SEMANAGE_CONF_FILE "semanage.conf"
 /* relative path names to enum semanage_paths to special files and
  * directories for the module store */
+
+#define TRUE 1
+
 enum semanage_file_defs {
 	SEMANAGE_ROOT,
 	SEMANAGE_TRANS_LOCK,
@@ -110,6 +114,7 @@
 	"/seusers.final",
 	"/users_extra",
 	"/netfilter_contexts",
+	"/file_contexts.homedirs",
 };
 
 /* A node used in a linked list of file contexts; used for sorting.
@@ -1264,15 +1269,15 @@
 		goto cleanup;
 	}
 
-	if ((commit_num = semanage_commit_sandbox(sh)) < 0) {
-		retval = commit_num;
+	if ((retval =
+	     semanage_genhomedircon(sh, TRUE)) != 0) {
+		ERR(sh, "semanage_genhomedircon returned error code %d.",
+		    retval);
 		goto cleanup;
 	}
 
-	if ((retval =
-	     semanage_exec_prog(sh, sh->conf->genhomedircon,
-				sh->conf->store_path, "")) != 0) {
-		ERR(sh, "genhomedircon returned error code %d.", retval);
+	if ((commit_num = semanage_commit_sandbox(sh)) < 0) {
+		retval = commit_num;
 		goto cleanup;
 	}
 
Modified: trunk/libsemanage/src/semanage_store.h
===================================================================
--- trunk/libsemanage/src/semanage_store.h	2007-08-23 14:39:48 UTC (rev 2526)
+++ trunk/libsemanage/src/semanage_store.h	2007-08-23 14:41:50 UTC (rev 2527)
@@ -57,6 +57,7 @@
 	SEMANAGE_SEUSERS,
 	SEMANAGE_USERS_EXTRA,
 	SEMANAGE_NC,
+	SEMANAGE_FC_HOMEDIRS,
 	SEMANAGE_STORE_NUM_PATHS
 };
 
Added: trunk/libsemanage/src/utilities.c
===================================================================
--- trunk/libsemanage/src/utilities.c	                        (rev 0)
+++ trunk/libsemanage/src/utilities.c	2007-08-23 14:41:50 UTC (rev 2527)
@@ -0,0 +1,312 @@
+/* Author: Mark Goldman   <mgo...@tr...>
+ *			Paul Rosenfeld	<pro...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include "utilities.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/types.h>
+#include <assert.h>
+#include <ustr.h>
+
+#define TRUE 1
+#define FALSE 0
+
+char *semanage_findval(char *file, char *var, char *delim)
+{
+	FILE *fd;
+	char *buff = NULL;
+	char *retval = NULL;
+	size_t buff_len = 0;
+
+	assert(file);
+	assert(var);
+
+	if ((fd = fopen(file, "r")) == NULL)
+		return NULL;
+
+	while (getline(&buff, &buff_len, fd) > 0) {
+		if (semanage_is_prefix(buff, var)) {
+			retval = semanage_split(buff, delim);
+			if (retval)
+				semanage_rtrim(retval, '\n');
+			break;
+		}
+	}
+	free(buff);
+	fclose(fd);
+
+	return retval;
+}
+
+int semanage_is_prefix(const char *str, const char *prefix)
+{
+	int retval;
+	Ustr *ustr = USTR_NULL;
+
+	if (!str) {
+		return FALSE;
+	}
+	if (!prefix) {
+		return TRUE;
+	}
+	if (!(ustr = ustr_dup_cstr(str))) {
+		return FALSE;
+	}
+	retval = (ustr_srch_cstr_fwd(ustr, 0, prefix) == 1);
+	ustr_sc_free(&ustr);
+
+	return retval;
+}
+
+char *semanage_split_on_space(const char *str)
+{
+	/* as per the man page, these are the isspace() chars */
+	const char *seps = "\f\n\r\t\v ";
+	size_t slen = strlen(seps);
+	size_t off = 0, rside_len = 0;
+	char *retval = NULL;
+	Ustr *ustr = USTR_NULL, *temp = USTR_NULL;
+
+	if (!str)
+		goto done;
+	if (!(ustr = ustr_dup_cstr(str)))
+		goto done;
+	temp =
+	    ustr_split_spn_chrs(ustr, &off, seps, slen, USTR_NULL,
+				USTR_FLAG_SPLIT_DEF);
+	if (!temp)
+		goto done;
+	/* throw away the left hand side */
+	ustr_sc_free(&temp);
+
+	rside_len = ustr_len(ustr) - off;
+	temp = ustr_dup_subustr(ustr, off + 1, rside_len);
+	if (!temp)
+		goto done;
+	retval = strdup(ustr_cstr(temp));
+	ustr_sc_free(&temp);
+
+      done:
+	ustr_sc_free(&ustr);
+	return retval;
+}
+
+char *semanage_split(const char *str, const char *delim)
+{
+	Ustr *ustr = USTR_NULL, *temp = USTR_NULL;
+	size_t off = 0, rside_len = 0;
+	char *retval = NULL;
+
+	if (!str)
+		goto done;
+	if (!delim || !(*delim))
+		return semanage_split_on_space(str);
+	ustr = ustr_dup_cstr(str);
+	temp =
+	    ustr_split_cstr(ustr, &off, delim, USTR_NULL, USTR_FLAG_SPLIT_DEF);
+	if (!temp)
+		goto done;
+	/* throw away the left hand side */
+	ustr_sc_free(&temp);
+
+	rside_len = ustr_len(ustr) - off;
+
+	temp = ustr_dup_subustr(ustr, off + 1, rside_len);
+	if (!temp)
+		goto done;
+	retval = strdup(ustr_cstr(temp));
+	ustr_sc_free(&temp);
+
+      done:
+	ustr_sc_free(&ustr);
+	return retval;
+}
+
+int semanage_list_push(semanage_list_t ** list, char *data)
+{
+	semanage_list_t *temp = NULL;
+
+	if (!data)
+		return EINVAL;
+	if (!(temp = malloc(sizeof(semanage_list_t))))
+		return ENOMEM;
+
+	if (!(temp->data = strdup(data))) {
+		free(temp);
+		return ENOMEM;
+	}
+	temp->next = *list;
+	*list = temp;
+
+	return 0;
+}
+
+char *semanage_list_pop(semanage_list_t ** list)
+{
+	semanage_list_t *node = NULL;
+	char *data = NULL;
+
+	if (!list || !(*list))
+		return NULL;
+
+	node = (*list);
+	data = node->data;
+
+	(*list) = node->next;
+	free(node);
+
+	return data;
+}
+
+void semanage_list_destroy(semanage_list_t ** list)
+{
+	semanage_list_t *temp;
+
+	while ((temp = (*list))) {
+		free(temp->data);
+		(*list) = temp->next;
+		free(temp);
+	}
+}
+
+semanage_list_t *semanage_list_find(semanage_list_t * l, char *data)
+{
+	if (!data)
+		return NULL;
+	while (l && strcmp(l->data, data))
+		l = l->next;
+
+	return l;
+}
+
+int semanage_list_sort(semanage_list_t ** l)
+{
+	semanage_list_t **array = NULL;
+	semanage_list_t *temp = NULL;
+	size_t count = 0;
+	size_t i = 0;
+
+	if (!l)
+		return 0;
+
+	for (temp = *l; temp; temp = temp->next)
+		++count;
+
+	array = malloc(sizeof(semanage_list_t *) * count);
+	if (!array)
+		return ENOMEM;	/* couldn't allocate memory for sort */
+	for (temp = *l; temp; temp = temp->next) {
+		array[i++] = temp;
+	}
+
+	qsort(array, count, sizeof(semanage_list_t *),
+	      (int (*)(const void *, const void *))&semanage_cmp_plist_t);
+	for (i = 0; i < (count - 1); ++i) {
+		array[i]->next = array[i + 1];
+	}
+	array[i]->next = NULL;
+	(*l) = array[0];
+	free(array);
+
+	return 0;
+}
+
+int semanage_cmp_plist_t(const semanage_list_t ** x, const semanage_list_t ** y)
+{
+	return strcmp((*x)->data, (*y)->data);
+}
+
+int semanage_str_count(char *data, char what)
+{
+	int count = 0;
+
+	if (!data)
+		return 0;
+	while (*data) {
+		if (*data == what)
+			++count;
+		++data;
+	}
+
+	return count;
+}
+
+void semanage_rtrim(char *str, char trim_to)
+{
+	int len = 0;
+
+	if (!str)
+		return;
+	len = strlen(str);
+
+	while (len > 0) {
+		if (str[--len] == trim_to) {
+			str[len] = '\0';
+			return;
+		}
+	}
+}
+
+/* list_addafter_controlmem does *NOT* duplicate the data argument
+ * use at your own risk, I am building a list out of malloc'd memory and
+ * it is only going to get stored into this list, thus when I destroy it
+ * later I won't free a ptr twice.
+ *
+ * returns the newly created node or NULL on error
+ */
+semanage_list_t *list_addafter_controlmem(semanage_list_t * item, char *data)
+{
+	semanage_list_t *temp = malloc(sizeof(semanage_list_t));
+
+	if (!temp)
+		return NULL;
+	temp->data = data;
+	temp->next = item->next;
+	item->next = temp;
+
+	return temp;
+}
+
+semanage_list_t *semanage_slurp_file_filter(FILE * file,
+					    int (*pred) (const char *))
+{
+	semanage_list_t head;
+	semanage_list_t *current = &head;
+	char *line = NULL;
+	size_t buff_len = 0;
+
+	head.next = NULL;	/* initialize head, we aren't going to use the data */
+	while (getline(&line, &buff_len, file) >= 0) {
+		if (pred(line)) {
+			semanage_rtrim(line, '\n');
+			current = list_addafter_controlmem(current, line);
+			if (!current) 
+				break;
+			line = NULL;
+			buff_len = 0;
+		}
+	}
+	free(line);
+
+	return head.next;
+}
Added: trunk/libsemanage/src/utilities.h
===================================================================
--- trunk/libsemanage/src/utilities.h	                        (rev 0)
+++ trunk/libsemanage/src/utilities.h	2007-08-23 14:41:50 UTC (rev 2527)
@@ -0,0 +1,137 @@
+/* Author: Mark Goldman   <mgo...@tr...>
+ *
+ * Copyright (C) 2007 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/* This file contains helper functions that are loosely based off of what is
+ * available from the python script genhomedircon.  Also this file contains
+ * c implementations of a couple of python functions so that genhomedircon will
+ * look/act like the python script.
+ */
+#ifndef _SEMANAGE_UTILITIES_H_
+#define _SEMANAGE_UTILITIES_H_
+
+#include <stdio.h>
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#define WARN_UNUSED \
+	__attribute__ ((__warn_unused_result__))
+#else
+# define WARN_UNUSED		/* nothing */
+#endif
+
+typedef struct list {
+	char *data;
+	struct list *next;
+} semanage_list_t;
+
+/**
+ * @param file  the path to the file to look for a variable in
+ * @param var   the variable that you want the value of
+ * @param delim the value that separates the part you care about from the part
+ *	       that you don't.
+ * @return for the first instance of var in the file, returns everything after
+ *	   delim.
+ *	   returns "" if not found IE if(*(semanage_findval(f,v,d)) == '\0'){
+ *					  printf("%s not found in file", v);
+ *				       }
+ *
+ *	   NULL for error (out of memory, etc)
+ */
+char *semanage_findval(char *file, char *var, char *delim) WARN_UNUSED;
+
+/**
+ * @param str   string to test
+ * @param	 val   prefix
+ * @return  1 if val is the prefix of str
+ *	    0 if val is not the prefix of str
+ *
+ * note: if str == NULL, returns false
+ *	 if val == NULL, returns true --nothing can always be the prefix of
+ *				        something
+ *	 if (*val) == "" returns true same as above.
+ */
+int semanage_is_prefix(const char *str, const char *val) WARN_UNUSED;
+
+/**
+ * @param str   the string to semanage_split
+ * @return     malloc'd string after the first run of charachters that aren't whitespace
+ */
+char *semanage_split_on_space(const char *str) WARN_UNUSED;
+
+/**
+ * @param	 str   the string to semanage_split
+ * @param	 delim the string delimiter.  NOT a set of charachters that can be
+ *	       a delimiter.
+ *	       if *delim == '\0' behaves as semanage_splitOnSpace()
+ * @return   a ptr to the first charachter past the delimiter.
+ *	    if delim doesn't appear in the string, returns a ptr to the
+ *	    trailing null in the string
+ */
+char *semanage_split(const char *str, const char *delim) WARN_UNUSED;
+
+/* linked list string functions
+ * Functions allocate memory.  Must be free'd with
+ * either semanage_list_pop until list == NULL or semanage_list_destroy()
+ */
+int semanage_list_push(semanage_list_t ** list, char *data) WARN_UNUSED;
+char *semanage_list_pop(semanage_list_t ** list);
+void semanage_list_destroy(semanage_list_t ** list);
+semanage_list_t *semanage_list_find(semanage_list_t * l,
+				    char *data) WARN_UNUSED;
+int semanage_list_sort(semanage_list_t ** l) WARN_UNUSED;
+/* function to compare 2 semanage_list_t nodes,
+ * returns strcmp(x->data, y->data)
+ * used internally by semanage_list_sort()
+ */
+int semanage_cmp_plist_t(const semanage_list_t ** x,
+			 const semanage_list_t ** y);
+/**
+ * @param      data a target string
+ * @param      what  a charachter
+ * @returns    the number of times the char appears in the string
+ */
+int semanage_str_count(char *data, char what);
+/**
+ * @param      - a string
+ * @param            the charachter to trim to
+ * @return   - mangles the string, converting the first
+ *             occurrance of the charachter to a '\0' from
+ *             the end of the string.
+ */
+void semanage_rtrim(char *str, char trim_to);
+
+/**
+ * @param data    some string
+ * @return  modifies the string such that the first whitespace char becomes
+ *	    '\0', ending the string.
+ */
+void semanage_keep_until_space(char *data);
+
+/**
+ * @param    file    - an open FILE to read from
+ * @param    pred    - a function taking a string that
+ *                    returns 1 if the string should be
+ *                    kept and 0 otherwise
+ * @return  a list of lines from the file (empty lines become
+ *          empty strings) in the file order where pred(line)
+ *          returns > 0
+ */
+semanage_list_t *semanage_slurp_file_filter(FILE * file,
+					    int (*pred) (const char *))
+    WARN_UNUSED;
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <ssm...@us...> - 2007-08-23 14:40:02
      
     | 
| Revision: 2526
          http://selinux.svn.sourceforge.net/selinux/?rev=2526&view=rev
Author:   ssmalley
Date:     2007-08-23 07:39:48 -0700 (Thu, 23 Aug 2007)
Log Message:
-----------
Author: tm...@tr...
Email: tm...@tr...
Subject: libsemanage: genhomedircon initial cleanup
Date: Tue, 21 Aug 2007 15:10:43 -0400
Does a series of simple cleanups to make way for the new
genhomedircon.
 
Modified Paths:
--------------
    trunk/libsemanage/src/semanage_store.c
Modified: trunk/libsemanage/src/semanage_store.c
===================================================================
--- trunk/libsemanage/src/semanage_store.c	2007-08-23 14:38:08 UTC (rev 2525)
+++ trunk/libsemanage/src/semanage_store.c	2007-08-23 14:39:48 UTC (rev 2526)
@@ -1008,14 +1008,15 @@
 	const char *active_fc = semanage_path(SEMANAGE_ACTIVE, SEMANAGE_FC);
 	const char *active_fc_loc =
 	    semanage_path(SEMANAGE_ACTIVE, SEMANAGE_FC_LOCAL);
-	const char *active_hd =
-	    semanage_path(SEMANAGE_ACTIVE, SEMANAGE_HOMEDIR_TMPL);
 	const char *active_seusers =
 	    semanage_path(SEMANAGE_ACTIVE, SEMANAGE_SEUSERS);
 	const char *active_nc = semanage_path(SEMANAGE_ACTIVE, SEMANAGE_NC);
+	const char *active_fc_hd =
+	    semanage_path(SEMANAGE_ACTIVE, SEMANAGE_FC_HOMEDIRS);
 
 	const char *running_fc = selinux_file_context_path();
 	const char *running_fc_loc = selinux_file_context_local_path();
+	const char *running_fc_hd = selinux_file_context_homedir_path();
 	const char *running_hd = selinux_homedir_context_path();
 	const char *running_policy = selinux_binary_policy_path();
 	const char *running_seusers = selinux_usersconf_path();
@@ -1027,14 +1028,15 @@
 	 * POLICYTYPE and should probably be done in the future. */
 	char store_fc[PATH_MAX];
 	char store_fc_loc[PATH_MAX];
-	char store_hd[PATH_MAX];
 	char store_pol[PATH_MAX];
 	char store_seusers[PATH_MAX];
 	char store_nc[PATH_MAX];
+	char store_fc_hd[PATH_MAX];
 
 	len = strlen(really_active_store);
 	running_fc += len;
 	running_fc_loc += len;
+	running_fc_hd += len;
 	running_hd += len;
 	running_policy += len;
 	running_seusers += len;
@@ -1055,9 +1057,10 @@
 		goto cleanup;
 	}
 
-	snprintf(store_hd, PATH_MAX, "%s%s", storepath, running_hd);
-	if (semanage_copy_file(active_hd, store_hd, sh->conf->file_mode) == -1) {
-		ERR(sh, "Could not copy %s to %s.", active_hd, store_hd);
+	snprintf(store_fc_hd, PATH_MAX, "%s%s", storepath, running_fc_hd);
+	if (semanage_copy_file(active_fc_hd, store_fc_hd, sh->conf->file_mode)
+	    == -1) {
+		ERR(sh, "Could not copy %s to %s.", active_fc_hd, store_fc_hd);
 		goto cleanup;
 	}
 
@@ -1197,6 +1200,10 @@
 		retval = -1;
 		goto cleanup;
 	}
+
+	/* clean up some files from the sandbox before install */
+	/* remove homedir_template from sandbox */
+
 	if (rename(sandbox, active) == -1) {
 		ERR(sh, "Error while renaming %s to %s.", sandbox, active);
 		/* note that if an error occurs during the next
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |