Skip to contentSkip to conversation

Patch to fix up sestatus, audit2allow and first version of semanage

PATCH Daniel J Walsh 2 participants 3 messages Nov 29, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Signature · 1 line
-- 
audit2allow/audit2allow +56 -39
diff --exclude-from=exclude -N -u -r nsapolicycoreutils/audit2allow/audit2allow policycoreutils-1.27.29/audit2allow/audit2allow
@@ -24,7 +24,7 @@
 #                                        02111-1307  USA
 #
 #  
-import commands, sys, os, pwd, string, getopt, re
+import commands, sys, os, pwd, string, getopt, re, selinux
 class allow:
 	def __init__(self, source, target, seclass):
 		self.source=source
@@ -81,6 +81,11 @@
 		self.roles=[]
 		self.load(input)
 		
+	def warning(self, error):
+		sys.stderr.write("%s: " % sys.argv[0])
+		sys.stderr.write("%s\n" % error)
+		sys.stderr.flush()
+
 	def load(self, input):
 		avc=[]
 		found=0
@@ -114,43 +119,47 @@
 			if "load_policy" in avc and self.last_reload:
 				self.allowRules={}
 			return
-		for i in range (0, len(avc)):
-			if avc[i]=="{":
-				i=i+1
-				while i<len(avc) and avc[i] != "}":
-					access.append(avc[i])
+		try:
+			for i in range (0, len(avc)):
+				if avc[i]=="{":
 					i=i+1
-				continue
+					while i<len(avc) and avc[i] != "}":
+						access.append(avc[i])
+						i=i+1
+					continue
 			
-			t=avc[i].split('=')
-			if len(t) < 2:
-				continue
-			if t[0]=="scontext":
-				context=t[1].split(":")
-				scon=context[2]
-				srole=context[1]
-				continue
-			if t[0]=="tcontext":
-				context=t[1].split(":")
-				tcon=context[2]
-				trole=context[1]
-				continue
-			if t[0]=="tclass":
-				seclass=t[1]
-				continue
-			if t[0]=="comm":
-				comm=t[1]
-				continue
-			if t[0]=="name":
-				name=t[1]
-				continue
-			if t[0]=="msg":
-				msg=t[1]
-				continue
-
-		if scon=="" or tcon =="" or seclass=="":
+				t=avc[i].split('=')
+				if len(t) < 2:
+					continue
+				if t[0]=="scontext":
+					context=t[1].split(":")
+					scon=context[2]
+					srole=context[1]
+					continue
+				if t[0]=="tcontext":
+					context=t[1].split(":")
+					tcon=context[2]
+					trole=context[1]
+					continue
+				if t[0]=="tclass":
+					seclass=t[1]
+					continue
+				if t[0]=="comm":
+					comm=t[1]
+					continue
+				if t[0]=="name":
+					name=t[1]
+					continue
+				if t[0]=="msg":
+					msg=t[1]
+					continue
+
+			if scon=="" or tcon =="" or seclass=="":
+				return
+		except IndexError, e:
+			self.warning("Bad AVC Line: %s" % avc)
 			return
-
+			
 		self.add_seclass(seclass, access)
 		self.add_type(tcon)
 		self.add_type(scon)
@@ -220,6 +229,12 @@
 
 if __name__ == '__main__':
 
+	def get_mls_flag():
+		if selinux.is_selinux_mls_enabled():
+			return "-M"
+		else:
+			return ""
+
 	def usage():
 		print 'audit2allow [-adhilrv] [-i <inputfile> ] [[-m|-M] <modulename> ] [-o <outputfile>]\n\
 		-a, --all        read input from audit and message log, conflicts with -i\n\
@@ -313,15 +328,17 @@
 		if buildPP:
 			print ("Generating type enforcment file: %s.te" % module)
 		output.write(out.out(requires, module))
+		output.flush()
 		if buildPP:
-			print ("Compiling policy: checkmodule -M -m -o %s.mod %s.te" % (module, module))
-			rc=commands.getstatusoutput("checkmodule -M -m -o %s.mod %s.te" % (module, module))
+			cmd="checkmodule %s -m -o %s.mod %s.te" % (get_mls_flag(), module, module)
+			print "Compiling policy: %s" % cmd
+			rc=commands.getstatusoutput(cmd)
 			if rc[0]==0:
 				print ("Building package: semodule_package -o %s.pp -m %s.mod" % (module, module))
 				rc=commands.getstatusoutput("semodule_package -o %s.pp -m %s.mod" % (module, module))
 				if rc[0]==0:
-					print ("\n*************** IMPORTANT ***********************\n")
-					print ("In order to load this newly created policy package,\nyou are required to execute \n\n\"semodule -i %s.pp\"\n\nto load the policy\n" % module)
+					print ("\n******************** IMPORTANT ***********************\n")
+					print ("In order to load this newly created policy package into the kernel,\nyou are required to execute \n\nsemodule -i %s.pp\n\n" % module)
 				else:
 					errorExit(rc[1])
 			else:
audit2allow/audit2allow.1 +71 -11

115 lines not on this page · raw message

Makefile +1 -1
diff --exclude-from=exclude -N -u -r nsapolicycoreutils/Makefile policycoreutils-1.27.29/Makefile
@@ -1,4 +1,4 @@
-SUBDIRS=setfiles load_policy newrole run_init restorecon audit2allow audit2why scripts sestatus semodule_package semodule semodule_link semodule_expand setsebool po
+SUBDIRS=setfiles semanage load_policy newrole run_init restorecon audit2allow audit2why scripts sestatus semodule_package semodule semodule_link semodule_expand setsebool po
 
 all install relabel clean: 
 	@for subdir in $(SUBDIRS); do \
semanage/Makefile +19 -0
diff --exclude-from=exclude -N -u -r nsapolicycoreutils/semanage/Makefile policycoreutils-1.27.29/semanage/Makefile
@@ -0,0 +1,19 @@
+# Installation directories.
+PREFIX ?= ${DESTDIR}/usr
+SBINDIR ?= $(PREFIX)/sbin
+MANDIR = $(PREFIX)/share/man
+
+TARGETS=semanage
+
+all: $(TARGETS)
+
+install: all
+	[ -d $(MANDIR)/man8 ] || mkdir -p $(MANDIR)/man8
+	-mkdir -p $(SBINDIR)
+	install -m 755 semanage $(SBINDIR)
+	install -m 644 semanage.8 $(MANDIR)/man8
+
+clean:
+	rm -f semanage
+
+relabel:
semanage/semanage +377 -0

377 lines not on this page · raw message

semanage/semanage.8 +57 -0

57 lines not on this page · raw message

sestatus/sestatus.8 +6 -2
diff --exclude-from=exclude -N -u -r nsapolicycoreutils/sestatus/sestatus.8 policycoreutils-1.27.29/sestatus/sestatus.8
@@ -1,10 +1,10 @@
-.TH "sestatus" "8" "2002031409" "" ""
+.TH "sestatus" "8" "2005111103" "" ""
 .SH "NAME"
 sestatus \- SELinux status tool
 
 .SH "SYNOPSIS"
 .B sestatus
-.I [\-v]  
+.I [\-v] [\-b]  
 .P
 This tool is used to get the status of a system running SELinux.
 
@@ -33,6 +33,10 @@
  Checks the contexts of a files , and a processes listed in the /etc/sestatus.conf file.  It also checks the context of the target, in cases of
 symlinks.
 
+.B \-b
+.P
+Display the current state of booleans.
+
 
 .SH "FILES"
 /etc/sestatus.conf
sestatus/sestatus.c +50 -34

118 lines not on this page · raw message

#1 lore raw

Should getsebool be likewise changed to use on/off rather than active/inactive? I definitely prefer on/off as it is clearer in meaning and you can easily distinguish them (e.g. getsebool -a | grep on). Does this require a change to system-config-securitylevel?

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#2 lore raw
In reply to Daniel J Walsh

Thanks, merged as of policycoreutils 1.27.30.

Signature · 8 lines
Stephen Smalley
National Security Agency


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