Skip to contentSkip to conversation

seobject_fcontext patch allows you to modify a preexisting file context.

PATCH Daniel J Walsh 2 participants 2 messages Nov 7, 2008 – Nov 10, 2008 SELinux security module

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Currently semanage is not allowed to change a file context mapping if it matches exactly, this patch allows you to modify the file context. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iEYEARECAAYFAkkUVMwACgkQrlYvE4MpobONMgCgi6UbaQXR2yK+tXzh6ouLNtfY PFQAn38zI31rZtdBqKTS34SaEfQ5K4VG
=6jM8
-----END PGP SIGNATURE-----

semanage/seobject.py +27 -14
@@ -1433,8 +1433,14 @@
 		(rc,exists) = semanage_fcontext_exists(self.sh, k)
 		if rc < 0:
 			raise ValueError(_("Could not check if file context for %s is defined") % target)
-		if exists:
-			raise ValueError(_("File context for %s already defined") % target)
+
+		if not exists:
+                       (rc,exists) = semanage_fcontext_exists_local(self.sh, k)
+                       if rc < 0:
+                              raise ValueError(_("Could not check if file context for %s is defined") % target)
+
+                if exists:
+                       raise ValueError(_("File context for %s already defined") % target)
 
 		(rc,fcontext) = semanage_fcontext_create(self.sh)
 		if rc < 0:
@@ -1481,15 +1487,19 @@
 		if rc < 0:
 			raise ValueError(_("Could not create a key for %s") % target)
 
-		(rc,exists) = semanage_fcontext_exists_local(self.sh, k)
+		(rc,exists) = semanage_fcontext_exists(self.sh, k)
 		if rc < 0:
 			raise ValueError(_("Could not check if file context for %s is defined") % target)
 		if not exists:
-			raise ValueError(_("File context for %s is not defined") % target)
+                       (rc,exists) = semanage_fcontext_exists_local(self.sh, k)
+                       if not exists:
+                              raise ValueError(_("File context for %s is not defined") % target)
 		
 		(rc,fcontext) = semanage_fcontext_query_local(self.sh, k)
 		if rc < 0:
-			raise ValueError(_("Could not query file context for %s") % target)
+                       (rc,fcontext) = semanage_fcontext_query(self.sh, k)
+                       if rc < 0:
+                              raise ValueError(_("Could not query file context for %s") % target)
 
                 if setype != "<<none>>":
                        con = semanage_fcontext_get_con(fcontext)
@@ -1591,30 +1601,33 @@
 
                        self.flist += fclocal
 
+                ddict = {}
 		for fcontext in self.flist:
 			expr = semanage_fcontext_get_expr(fcontext)
 			ftype = semanage_fcontext_get_type(fcontext)
 			ftype_str = semanage_fcontext_get_type_str(ftype)
 			con = semanage_fcontext_get_con(fcontext)
 			if con:
-				l.append((expr, ftype_str, semanage_context_get_user(con), semanage_context_get_role(con), semanage_context_get_type(con), semanage_context_get_mls(con)))
+                               ddict[(expr, ftype_str)] = (semanage_context_get_user(con), semanage_context_get_role(con), semanage_context_get_type(con), semanage_context_get_mls(con))
 			else:
-				l.append((expr, ftype_str, con))
+				ddict[(expr, ftype_str)] = con
 
-		return l
+		return ddict
 			
 	def list(self, heading = 1, locallist = 0 ):
 		if heading:
 			print "%-50s %-18s %s\n" % (_("SELinux fcontext"), _("type"), _("Context"))
-		fcon_list = self.get_all(locallist)
-		for fcon in fcon_list:
-			if len(fcon) > 3:
+		fcon_dict = self.get_all(locallist)
+                keys = fcon_dict.keys()
+                keys.sort()
+		for k in keys:
+			if fcon_dict[k]:
 				if is_mls_enabled:
-					print "%-50s %-18s %s:%s:%s:%s " % (fcon[0], fcon[1], fcon[2], fcon[3], fcon[4], translate(fcon[5],False))
+					print "%-50s %-18s %s:%s:%s:%s " % (k[0], k[1], fcon_dict[k][0], fcon_dict[k][1], fcon_dict[k][2], translate(fcon_dict[k][3],False))
 				else:
-					print "%-50s %-18s %s:%s:%s " % (fcon[0], fcon[1], fcon[2], fcon[3],fcon[4])
+					print "%-50s %-18s %s:%s:%s " % (k[0], k[1], fcon_dict[k][0], fcon_dict[k][1],fcon_dict[k][2])
 			else:
-				print "%-50s %-18s <<None>>" % (fcon[0], fcon[1])
+				print "%-50s %-18s <<None>>" % (k[0], k[1])
 				
 class booleanRecords(semanageRecords):
 	def __init__(self, store = ""):
#1 lore raw
Quoted 9 lines · Daniel J Walsh

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Currently semanage is not allowed to change a file context mapping if it matches exactly, this patch allows you to modify the file context. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

Quoted 5 lines

iEYEARECAAYFAkkUVMwACgkQrlYvE4MpobONMgCgi6UbaQXR2yK+tXzh6ouLNtfY PFQAn38zI31rZtdBqKTS34SaEfQ5K4VG
=6jM8
-----END PGP SIGNATURE-----

Merged in to policycoreutils-2.0.58

With one minor change, I removed the list l that was no longer being referenced.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.