Skip to contentSkip to conversation

semanage patch

PATCH Russell Coker 3 participants 4 messages Apr 14, 2006 – Apr 15, 2006

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

The attached patch against the semanage utility in rawhide allows it to create and modify prefixes.

Also when testing semanage I noticed that it let me remove a SE Linux user when a login still referred to it. After doing so it then wouldn't let me recreate the user (with a confusing error message). But as that bug didn't stop me from doing my work I haven't taken the time to fix it.

As the complexity of the semanage utility continues to increase I think that we need to split it into separate programs selogin, seuser, seport, seinterface, sefcontext, and setranslation. This will make the man page easier to understand and generally increase ease of use. It will also allow shell command-completion to do more of the work for the sysadmin. What do you think?

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
usr/lib/python2.4/site-packages/seobject.py renamed from seobject.py +11 -5
@@ -381,7 +381,7 @@
 	def __init__(self):
 		semanageRecords.__init__(self)
 
-	def add(self, name, roles, selevel, serange):
+	def add(self, name, roles, selevel, serange, prefix):
 		if is_mls_enabled == 1:
 			if serange == "":
 				serange = "s0"
@@ -427,6 +427,9 @@
 				if rc < 0:
 					raise ValueError("Could not set MLS level for %s" % name)
 
+			rc = semanage_user_set_prefix(self.sh, u, prefix)
+			if rc < 0:
+				raise ValueError("Could not add prefix %s for %s" % (r, prefix))
 			(rc,key) = semanage_user_key_extract(self.sh,u)
 			if rc < 0:
 				raise ValueError("Could not extract key for %s" % name)
@@ -451,13 +454,13 @@
 		semanage_user_key_free(k)
 		semanage_user_free(u)
 
-	def modify(self, name, roles = [], selevel = "", serange = ""):
+	def modify(self, name, roles = [], selevel = "", serange = "", prefix = ""):
 		try:
-			if len(roles) == 0  and serange == "" and selevel == "":
+			if prefix == "" and len(roles) == 0  and serange == "" and selevel == "":
 				if is_mls_enabled == 1:
-					raise ValueError("Requires roles, level or range")
+					raise ValueError("Requires prefix, roles, level or range")
 				else:
-					raise ValueError("Requires roles")
+					raise ValueError("Requires prefix or roles")
 
 			(rc,k) = semanage_user_key_create(self.sh, name)
 			if rc < 0:
@@ -478,6 +481,9 @@
 			if selevel != "":
 				semanage_user_set_mlslevel(self.sh, u, untranslate(selevel))
 
+			if prefix != "":
+				semanage_user_set_prefix(self.sh, u, prefix)
+
 			if len(roles) != 0:
 				for r in roles:
 					semanage_user_add_role(self.sh, u, r)
usr/sbin/semanage renamed from semanage +11 -5
@@ -32,7 +32,7 @@
 		print '\
 semanage {login|user|port|interface|fcontext|translation} -l [-n] \n\
 semanage login -{a|d|m} [-sr] login_name\n\
-semanage user -{a|d|m} [-LrR] selinux_name\n\
+semanage user -{a|d|m} [-LrRP] selinux_name\n\
 semanage port -{a|d|m} [-tr] [ -p protocol ] port | port_range\n\
 semanage interface -{a|d|m} [-tr] interface_spec\n\
 semanage fcontext -{a|d|m} [-frst] file_spec\n\
@@ -60,6 +60,7 @@
 		-p (named pipe) \n\n\
 \
 	-p, --proto      Port protocol (tcp or udp)\n\
+	-P, --prefix     Prefix for home directory labeling\n\
 	-L, --level      Default SELinux Level (MLS/MCS Systems only)\n\
 	-R, --roles      SELinux Roles (ex: "sysadm_r staff_r")\n\
 	-T, --trans      SELinux Level Translation (MLS/MCS Systems only)\n\n\
@@ -83,7 +84,7 @@
 		valid_option["login"] = []
 		valid_option["login"] += valid_everyone + [ '-s', '--seuser', '-r', '--range']
 		valid_option["user"] = []
-		valid_option["user"] += valid_everyone + [ '-L', '--level', '-r', '--range', '-R', '--roles' ] 
+		valid_option["user"] += valid_everyone + [ '-L', '--level', '-r', '--range', '-R', '--roles', '-P', '--prefix' ] 
 		valid_option["port"] = []
 		valid_option["port"] += valid_everyone + [ '-t', '--type', '-r', '--range', '-p', '--protocol' ] 
 		valid_option["interface"] = []
@@ -109,6 +110,7 @@
 		setrans = ""
 		roles = ""
 		seuser = ""
+		prefix = ""
 		heading=1
 
 		add = 0
@@ -126,7 +128,7 @@
 		args = sys.argv[2:]
 
 		gopts, cmds = getopt.getopt(args,
-					    'adf:lhmnp:s:R:L:r:t:T:',
+					    'adf:lhmnp:s:R:L:r:t:T:P:',
 					    ['add',
 					     'delete',
 					     'ftype=',
@@ -140,7 +142,8 @@
 					     'level=',
 					     'roles=',
 					     'type=',
-					     'trans='
+					     'trans=',
+					     'prefix='
 					     ])
 		for o, a in gopts:
 			if o not in option_dict[object]:
@@ -185,6 +188,9 @@
 			if o == "-p" or o == '--proto':
 				proto = a
 
+			if o == "-P" or o == '--prefix':
+				prefix = a
+
 			if o == "-R" or o == '--roles':
 				roles = roles + " " + a
 
@@ -235,7 +241,7 @@
 				rlist = roles.split()
 				if len(rlist) == 0:
 					raise ValueError("You must specify a role")
-				OBJECT.add(target, rlist, selevel, serange)
+				OBJECT.add(target, rlist, selevel, serange, prefix)
 
 			if object == "port":
 				OBJECT.add(target, proto, serange, setype)
#1 lore raw
Quoted 2 lines · Russell Coker

The attached patch against the semanage utility in rawhide allows it to create and modify prefixes.

Thanks, merged as of policycoreutils 1.30.6. Note that adding further examples in the man page to the EXAMPLES section introduced by Thomas Bleher would be helpful.

Quoted 11 lines

Also when testing semanage I noticed that it let me remove a SE Linux user when a login still referred to it. After doing so it then wouldn't let me recreate the user (with a confusing error message). But as that bug didn't stop me from doing my work I haven't taken the time to fix it.

As the complexity of the semanage utility continues to increase I think that we need to split it into separate programs selogin, seuser, seport, seinterface, sefcontext, and setranslation. This will make the man page easier to understand and generally increase ease of use. It will also allow shell command-completion to do more of the work for the sysadmin. What do you think?

Not clear to me whether this will ultimately be helpful to users or more confusing. iptables, auditctl, etc. don't split up the interface like this. More useful to users would likely just be a more extensive description in the man page and more examples there.

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
Quoted 7 lines · Stephen Smalley
Quoted 2 lines · Russell Coker

The attached patch against the semanage utility in rawhide allows it to create and modify prefixes.

Thanks, merged as of policycoreutils 1.30.6. Note that adding further examples in the man page to the EXAMPLES section introduced by Thomas Bleher would be helpful.

Updating the man page is the next stage.

Quoted 12 lines
Quoted 11 lines

Also when testing semanage I noticed that it let me remove a SE Linux user when a login still referred to it. After doing so it then wouldn't let me recreate the user (with a confusing error message). But as that bug didn't stop me from doing my work I haven't taken the time to fix it.

As the complexity of the semanage utility continues to increase I think that we need to split it into separate programs selogin, seuser, seport, seinterface, sefcontext, and setranslation. This will make the man page easier to understand and generally increase ease of use. It will also allow shell command-completion to do more of the work for the sysadmin. What do you think?

Quoted 4 lines

Not clear to me whether this will ultimately be helpful to users or more confusing. iptables, auditctl, etc. don't split up the interface like this. More useful to users would likely just be a more extensive description in the man page and more examples there.

iptables doesn't split the interface because there are two main functions, adding/removing rules from tables and setting table policy for built-in tables. The latter being such a small part of iptables functionality that it doesn't justify a separate program.

It might be worth considering splitting auditctl into two programs, one for adding/removing rules and another for the rest.

There are other examples of the benefits and problems of the two approaches. The best example I can think of is raidtools2 vs mdadm. With raidtools2 there was a separate program for each operation, to add a device to a degraded array it was "raidhotadd /dev/mdX /dev/hdcX", to remove a device from an array that was complete it was "raidsetfaulty /dev/mdX /dev/hdcX ; raidhotremove /dev/mdX /dev/hdcX". The fact that I can still remember all the old raidtools2 commands but can't remember any of the mdadm commands is noteworthy.

But back to semanage, most of the classes of operations have different parameters. The -r option to specify range is the most commonly used parameter (used in all classes of operations apart from translation). The next most common option is -t which is used in 3/6 of the operation classes.

I think that the great divergance of functionality between the different operations that semanage performs is justification for separate programs. The user and login sections could be kept in the same program because they are tightly linked (in fact having a single command that creates both a user and a login at the same time along with an optional Unix account would be beneficial). But the other four are different enough that I think they deserve separate programs.

Signature · 9 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

--
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.
#3 lore raw
Quoted 2 lines · Russell Coker

It might be worth considering splitting auditctl into two programs, one for adding/removing rules and another for the rest.

Auditctl is a focused application that does only one job - configure the kernel side of the audit system. It doesn't do anything else.

-Steve

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