Skip to contentSkip to conversation

Further bugfixes

SEMANAGE Ivan Gyurdiev 4 participants 11 messages Jan 20, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

Changelog:

- UI:
- fix Usage() for file contexts, rename some other things
- document -P --proto option
- "Failed to" -> "Could not" for consistency in error messages

- CLEANUP:
- remove statement with no effect in validate_level(), and some
unused variables
- make pychecker happy - don't shadow "dict", "type", and "range"
- rename p variable according to the object - only use p for ports

- IMPROVEMENTS:
- audit rc value for exists funtions, semanage_connect()
- free key and object on add/modify/delete

- BUGFIX:
- fix delete if/else bug I introduced with my last patch

Notes:
- there's more memory management to be added, particularly disconnect() and handle_destroy() need to be called as Joshua noted, list() probably leaks lots of memory
- role modifications still don't clear the previous roles
- -R with multiple roles does not work
- port ranges do not work

policycoreutils/semanage/semanage +5 -4
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/semanage new/policycoreutils/semanage/semanage
@@ -30,10 +30,10 @@ if __name__ == '__main__':
 
 	def usage(message = ""):
 		print '\
-semanage fcontext [-admhfrst] INTERFACE\n\
-semanage interface [-admtr] INTERFACE\n\
+semanage fcontext [-admhfrst] CONTEXT_EXPRESSION\n\
+semanage interface [-admtr] INTERFACE_NAME\n\
 semanage login [-admsr] LOGIN_NAME\n\
-semanage port [-admtpr] PORT | PORTRANGE\n\
+semanage port [-admtpr] PORT | PORT_RANGE\n\
 semanage translation [-adm] LEVEL\n\
 semanage user [-admLRr] SELINUX_USER\n\
 	-a, --add        Add a OBJECT record NAME\n\
@@ -44,6 +44,7 @@ semanage user [-admLRr] SELINUX_USER\n\
 	-L, --level      Default SELinux Level\n\
 	-n, --noheading  Do not print heading when listing OBJECTS\n\
 	-m, --modify     Modify a OBJECT record NAME\n\
+	-P, --proto      Port protocol\n\
 	-r, --range      MLS/MCS Security Range\n\
 	-R, --roles      SELinux Roles (Separate by spaces)\n\
 	-s, --seuser     SELinux user name\n\
@@ -235,7 +236,7 @@ semanage user [-admLRr] SELINUX_USER\n\
 			if object == "port":
 				OBJECT.delete(target, proto)
 
-			if object == "fcontext":
+			elif object == "fcontext":
 				OBJECT.delete(target, ftype)
 
 			else:
policycoreutils/semanage/seobject.py +202 -111

784 lines not on this page · raw message

#1 lore raw
Quoted 1 line

From a patch to the semanage program:

+semanage fcontext [-admhfrst] CONTEXT_EXPRESSION\n\
+semanage interface [-admtr] INTERFACE_NAME\n\
 semanage login [-admsr] LOGIN_NAME\n\
-semanage port [-admtpr] PORT | PORTRANGE\n\
+semanage port [-admtpr] PORT | PORT_RANGE\n\

I think that all of these should be changed similar to my revised man page (which I posted under the subject "semanage patch" on the 14th of Jan).

semanage fcontext -{a|d|m} [-hfrst] CONTEXT_EXPRESSION\n\
semanage interface -{a|d|m} [-tr] INTERFACE_NAME\n\
semanage login -{a|d|m} [-sr] LOGIN_NAME\n\
semanage port -{a|d|m} [-tpr] PORT | PORT_RANGE\n\

The convention is that anything within [] is optional, however it is not optional to have one of 'a', 'd', or 'm', it is required to have exactly one of them.

Also there should be a line such as the following to indicate the ways in which the "-l" option can be used (it can't be used in conjunction with any other option):
semanage {login|user|port} -l

Do "interface" and "fcontext" support the "-l" option?

I would offer a patch for this, but I think we have enough unmerged patches for the semanage utility floating around at the moment. Once we get the current patches sorted out I'll be happy to write a patch for this.

Finally, when semanage development slows down a bit we will have to put in some decent error checking for command-line parameters. Currently you can pass in parameters that are not used to a command without an error or warning message. For example the following command will work even though -R is not a valid option to the login management interface.

semanage login -a -s user_u -r s0 -R sysadm_r john

Signature · 10 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.
#2 lore raw
Quoted 10 lines

I think that all of these should be changed similar to my revised man page (which I posted under the subject "semanage patch" on the 14th of Jan).

semanage fcontext -{a|d|m} [-hfrst] CONTEXT_EXPRESSION\n\
semanage interface -{a|d|m} [-tr] INTERFACE_NAME\n\
semanage login -{a|d|m} [-sr] LOGIN_NAME\n\
semanage port -{a|d|m} [-tpr] PORT | PORT_RANGE\n\

The convention is that anything within [] is optional, however it is not optional to have one of 'a', 'd', or 'm', it is required to have exactly one of them.

Technically -p is required for ports, since it is part of the port key.
Also, there's required parameters on add that you must enter (but I guess this is better left out of the manpage).

Quoted 5 lines

Also there should be a line such as the following to indicate the ways in which the "-l" option can be used (it can't be used in conjunction with any other option):
semanage {login|user|port} -l

Do "interface" and "fcontext" support the "-l" option?

Sure.. try it..

Quoted 2 lines

I would offer a patch for this, but I think we have enough unmerged patches for the semanage utility floating around at the moment. Once we get the current patches sorted out I'll be happy to write a patch for this.

I think most of them have been merged, but I'm not sure which ones you're referring to.

Quoted 4 lines

Finally, when semanage development slows down a bit we will have to put in some decent error checking for command-line parameters. Currently you can pass in parameters that are not used to a command without an error or warning message. For example the following command will work even though -R is not a valid option to the login management interface.

semanage login -a -s user_u -r s0 -R sysadm_r john

-R doesn't actually work. It can't handle more than one role, and it handles that one role incorrectly. I agree with what you're saying though...

--
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 8 lines · Ivan Gyurdiev
Quoted 8 lines

I think that all of these should be changed similar to my revised man page (which I posted under the subject "semanage patch" on the 14th of Jan).

semanage fcontext -{a|d|m} [-hfrst] CONTEXT_EXPRESSION\n\
semanage interface -{a|d|m} [-tr] INTERFACE_NAME\n\
semanage login -{a|d|m} [-sr] LOGIN_NAME\n\
semanage port -{a|d|m} [-tpr] PORT | PORT_RANGE\n\

I like this format

Quoted 12 lines
Quoted 2 lines

The convention is that anything within [] is optional, however it is not optional to have one of 'a', 'd', or 'm', it is required to have exactly one of them.

Technically -p is required for ports, since it is part of the port key.
Also, there's required parameters on add that you must enter (but I guess this is better left out of the manpage).

Quoted 5 lines

Also there should be a line such as the following to indicate the ways in which the "-l" option can be used (it can't be used in conjunction with any other option):
semanage {login|user|port} -l

Do "interface" and "fcontext" support the "-l" option?

Sure.. try it..

Quoted 2 lines

I would offer a patch for this, but I think we have enough unmerged patches for the semanage utility floating around at the moment. Once we get the current patches sorted out I'll be happy to write a patch for this.

Quoted 9 lines

I think most of them have been merged, but I'm not sure which ones you're referring to.

Quoted 4 lines

Finally, when semanage development slows down a bit we will have to put in some decent error checking for command-line parameters. Currently you can pass in parameters that are not used to a command without an error or warning message. For example the following command will work even though -R is not a valid option to the login management interface.

semanage login -a -s user_u -r s0 -R sysadm_r john

-R doesn't actually work. It can't handle more than one role, and it handles that one role incorrectly.
I agree with what you're saying though...

-R "user_r sysadm_t secadm_r"

works or at least should work.

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

#4 lore raw
Quoted 3 lines

-R "user_r sysadm_t secadm_r"
works or at least should work.

That doesn't match the Usage()... didn't know about it. Also, try this:

[root@cobra ~]# /usr/sbin/semanage user -a -R "secadm_r sysadm_r" Ivan [root@cobra ~]# /usr/sbin/semanage user -m -R "user_r system_r" Ivan [root@cobra ~]# /usr/sbin/semanage user -l

Ivan s0 s0 system_r sysadm_r user_r secadm_r

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

#5 lore raw
In reply to Daniel J Walsh
Quoted 3 lines · Daniel J Walsh

-R "user_r sysadm_t secadm_r"

works or at least should work.

The attached patch does everything my last patch does but also adds support for multiple -R options.

A more sensible (IMHO) and more script-friendly way of doing this is to support -R user_r -R sysadm_r -R secadm_r. Naturally my patch doesn't break the existing functionality, just allows doing it either way.

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
semanage renamed from semanage.orig +109 -8
@@ -30,12 +30,13 @@
 
 	def usage(message = ""):
 		print '\
-semanage fcontext [-admhfrst] INTERFACE\n\
-semanage interface [-admtr] INTERFACE\n\
-semanage login [-admsr] LOGIN_NAME\n\
-semanage port [-admtpr] PORT | PORTRANGE\n\
-semanage translation [-adm] LEVEL\n\
-semanage user [-admLRr] SELINUX_USER\n\
+semanage {login|user|port|interface|fcontext} -l\n\
+semanage login -{a|d|m} [-sr] login_name\n\
+semanage user -{a|d|m} [-LrR] selinux_name\n\
+semanage port -{a|d|m} -p protocol [-t] port_number\n\
+semanage interface -{a|d|m} [-tr] interface_spec\n\
+semanage translation -{a|d|m} [-T] level\n\
+semanage fcontext -{a|d|m} [-frst] file_spec\n\
 	-a, --add        Add a OBJECT record NAME\n\
 	-d, --delete     Delete a OBJECT record NAME\n\
 	-f, --ftype      File Type of OBJECT \n\
@@ -60,6 +61,30 @@
 		sys.stderr.flush()
 		sys.exit(1)
 
+	def unwanted_ftype():
+		if ftype != "":
+			sys.stderr.write("ftype not used\n");
+	def unwanted_selevel():
+		if selevel != "":
+			sys.stderr.write("level not used\n");
+	def unwanted_proto():
+		if proto != "":
+			sys.stderr.write("proto not used\n");
+	def unwanted_roles():
+		if roles != "":
+			sys.stderr.write("role not used\n");
+	def unwanted_serange():
+		if serange != "":
+			sys.stderr.write("range not used\n");
+	def unwanted_seuser():
+		if seuser != "":
+			sys.stderr.write("seuser not used\n");
+	def unwanted_setype():
+		if setype != "":
+			sys.stderr.write("type not used\n");
+	def unwanted_setrans():
+		if setrans != "":
+			sys.stderr.write("trans not used\n");
 	#
 	# 
 	#
@@ -124,7 +149,7 @@
 			if o == "-h" or o == "--help":
 				usage()
 
-			if o == "-n" or o == "--nohead":
+			if o == "-n" or o == "--noheading":
 				heading=0
 
 			if o == "-m"or o == "--modify":
@@ -145,7 +170,7 @@
 				proto = a
 
 			if o == "-R" or o == '--roles':
-				roles = a
+				roles = roles + " " + a
 
 			if o == "-s" or o == "--seuser":
 				seuser = a
@@ -159,25 +184,91 @@
 			if o == "-v" or o == "--verbose":
 				verbose = 1
 
+# Note in this section I intentionally leave the unwanted_*() functions for
+# variabled which are wanted commented out and don't delete those lines.  This
+# will make it easier to modify the code when the list of wanted variables
+# changes.
 		if object == "login":
+			if not delete:
+				unwanted_ftype()
+				unwanted_selevel()
+				unwanted_proto()
+				unwanted_roles()
+#				unwanted_serange()
+#				unwanted_seuser()
+				unwanted_setype()
+				unwanted_setrans()
 			OBJECT = seobject.loginRecords()
 
 		if object == "user":
+			if not delete:
+				unwanted_ftype()
+#				unwanted_selevel()
+				unwanted_proto()
+#				unwanted_roles()
+#				unwanted_serange()
+				unwanted_seuser()
+				unwanted_setype()
+				unwanted_setrans()
 			OBJECT = seobject.seluserRecords()
 
 		if object == "port":
+			if not delete:
+				unwanted_ftype()
+				unwanted_selevel()
+#				unwanted_proto()
+				unwanted_roles()
+				unwanted_serange()
+				unwanted_seuser()
+#				unwanted_setype()
+				unwanted_setrans()
 			OBJECT = seobject.portRecords()
 		
 		if object == "interface":
+			if not delete:
+				unwanted_ftype()
+				unwanted_selevel()
+				unwanted_proto()
+				unwanted_roles()
+#				unwanted_serange()
+				unwanted_seuser()
+#				unwanted_setype()
+				unwanted_setrans()
 			OBJECT = seobject.interfaceRecords()
 		
 		if object == "fcontext":
+			if not delete:
+#				unwanted_ftype()
+				unwanted_selevel()
+				unwanted_proto()
+				unwanted_roles()
+#				unwanted_serange()
+#				unwanted_seuser()
+#				unwanted_setype()
+				unwanted_setrans()
 			OBJECT = seobject.fcontextRecords()
 		
 		if object == "translation":
+			if not delete:
+				unwanted_ftype()
+				unwanted_selevel()
+				unwanted_proto()
+				unwanted_roles()
+				unwanted_serange()
+				unwanted_seuser()
+				unwanted_setype()
+#				unwanted_setrans()
 			OBJECT = seobject.setransRecords()
 		
 		if list:
+			unwanted_ftype()
+			unwanted_selevel()
+			unwanted_proto()
+			unwanted_roles()
+			unwanted_serange()
+			unwanted_seuser()
+			unwanted_setype()
+			unwanted_setrans()
 			OBJECT.list(heading)
 			sys.exit(0);
 			
@@ -232,6 +323,16 @@
 			sys.exit(0);
 
 		if delete:
+			if object != "fcontext":
+				unwanted_ftype()
+			unwanted_selevel()
+			if object == "port":
+				unwanted_proto()
+			unwanted_roles()
+			unwanted_serange()
+			unwanted_seuser()
+			unwanted_setype()
+			unwanted_setrans()
 			if object == "port":
 				OBJECT.delete(target, proto)
 
#6 lore raw
Quoted 11 lines · Russell Coker
Quoted 3 lines · Daniel J Walsh

-R "user_r sysadm_t secadm_r"

works or at least should work.

The attached patch does everything my last patch does but also adds support for multiple -R options.

A more sensible (IMHO) and more script-friendly way of doing this is to support -R user_r -R sysadm_r -R secadm_r. Naturally my patch doesn't break the existing functionality, just allows doing it either way.

Merged along with Ivan's patch. They conflicted on the usage changes, but I went with Russell's version for now, as they synchronized with the man page. Feel free to suggest further modifications (e.g. file_spec isn't very clear, but neither was context_expression).

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.
#7 lore raw
In reply to Ivan Gyurdiev
Quoted 7 lines · Ivan Gyurdiev
Quoted 3 lines

The convention is that anything within [] is optional, however it is not optional to have one of 'a', 'd', or 'm', it is required to have exactly one of them.

Technically -p is required for ports, since it is part of the port key. Also, there's required parameters on add that you must enter (but I guess this is better left out of the manpage).

It's best that nothing is left out of the man page! I've attached a patch for that as well as documenting the -n option.

Quoted 7 lines
Quoted 4 lines

I would offer a patch for this, but I think we have enough unmerged patches for the semanage utility floating around at the moment. Once we get the current patches sorted out I'll be happy to write a patch for this.

I think most of them have been merged, but I'm not sure which ones you're referring to.

I have just realised that they were merged without anyone mentioning it. I've become used to a notification of patches accepted for merging - or more recently notification of my patches being too buggy for merging. :-#

I've attached a patch to semanage to make the usage() function display the same stuff as the man page (a good plan for the future would be to have an automatically generated man page such as used in coreutils).

Also I've made it warn when you set a flag that's not appropriate for the action you are performing. Note that the actual warning messages are extremely terse (I wasn't feeling inspired for creative writing) but the code that calls them is unlikely to need improvement.

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
semanage.8 renamed from semanage.8.orig +5 -2
@@ -3,13 +3,13 @@
 semanage \- SELinux Policy Management tool
 
 .SH "SYNOPSIS"
-.B semanage {login|user|port|interface|fcontext} \-l
+.B semanage {login|user|port|interface|fcontext} \-l [\-n]
 .br
 .B semanage login \-{a|d|m} [\-sr] login_name
 .br
 .B semanage user \-{a|d|m} [\-LrR] selinux_name
 .br
-.B semanage port \-{a|d|m} [\-tp] port_number
+.B semanage port \-{a|d|m} \-p protocol [\-t] port_number
 .br
 .B semanage interface \-{a|d|m} [\-tr] interface_spec
 .br
@@ -45,6 +45,9 @@
 .I                \-l, \-\-list       
 List the OBJECTS
 .TP
+.I                \-n, \-\-noheading       
+Do not print heading when listing OBJECTS
+.TP
 .I                \-L, \-\-level
 Default SELinux Level for SELinux use. (s0)
 .TP
semanage renamed from semanage.orig +108 -7

164 lines not on this page · raw message

#8 lore raw
In reply to Russell Coker
Quoted 9 lines · Russell Coker
Quoted 1 line

From a patch to the semanage program:

policycoreutils/semanage/semanage +3 -1
+semanage fcontext [-admhfrst] CONTEXT_EXPRESSION\n\
+semanage interface [-admtr] INTERFACE_NAME\n\
 semanage login [-admsr] LOGIN_NAME\n\
-semanage port [-admtpr] PORT | PORTRANGE\n\
+semanage port [-admtpr] PORT | PORT_RANGE\n\

I think that all of these should be changed similar to my revised man page (which I posted under the subject "semanage patch" on the 14th of Jan).

IIRC, that was merged as part of a set of diffs from Dan for policycoreutils in 1.29.8 on the 18th of January.

Quoted 3 lines

I would offer a patch for this, but I think we have enough unmerged patches for the semanage utility floating around at the moment. Once we get the current patches sorted out I'll be happy to write a patch for this.

Only ones I have queued are one from Joshua yesterday (libsemanage/semanage - permission check for semanage) and one from Ivan yesterday ([SEMANAGE] Further bugfixes).

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.
#9 lore raw
Quoted 16 lines · Stephen Smalley
Quoted 9 lines · Russell Coker
Quoted 1 line

From a patch to the semanage program:

policycoreutils/semanage/semanage +3 -1
+semanage fcontext [-admhfrst] CONTEXT_EXPRESSION\n\
+semanage interface [-admtr] INTERFACE_NAME\n\
 semanage login [-admsr] LOGIN_NAME\n\
-semanage port [-admtpr] PORT | PORTRANGE\n\
+semanage port [-admtpr] PORT | PORT_RANGE\n\

I think that all of these should be changed similar to my revised man page (which I posted under the subject "semanage patch" on the 14th of Jan).

IIRC, that was merged as part of a set of diffs from Dan for policycoreutils in 1.29.8 on the 18th of January.

Quoted 8 lines
Quoted 2 lines

I would offer a patch for this, but I think we have enough unmerged patches for the semanage utility floating around at the moment. Once we get the current patches sorted out I'll be happy to write a patch for this.

Only ones I have queued are one from Joshua yesterday (libsemanage/semanage - permission check for semanage) and one from Ivan yesterday ([SEMANAGE] Further bugfixes).

I have more, but I will wait til you merge what you have.

Dan

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

#10 lore raw
In reply to Ivan Gyurdiev
Quoted 20 lines · Ivan Gyurdiev

Changelog:

- UI:
- fix Usage() for file contexts, rename some other things
- document -P --proto option
- "Failed to" -> "Could not" for consistency in error messages

- CLEANUP:
- remove statement with no effect in validate_level(), and some
unused variables
- make pychecker happy - don't shadow "dict", "type", and "range"
- rename p variable according to the object - only use p for ports

- IMPROVEMENTS:
- audit rc value for exists funtions, semanage_connect()
- free key and object on add/modify/delete

- BUGFIX:
- fix delete if/else bug I introduced with my last patch

Quoted 7 lines

Notes:
- there's more memory management to be added, particularly disconnect() and handle_destroy() need to be called as Joshua noted, list() probably leaks lots of memory
- role modifications still don't clear the previous roles
- -R with multiple roles does not work
- port ranges do not work

Thanks, merged along with Russell's patch and a separate patch from Fedora Core CVS tree (which didn't touch semanage, just chcat.8 and genhomedircon).

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.