Skip to contentSkip to conversation

Fix many issues

SEMANAGE(tool) Ivan Gyurdiev 1 participant 4 messages Jan 14, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

Okay, it's my turn to patch semanage (tool).

Changes:

1) Stephen, you changed add -> modify in the places my earlier patch changed them, but Dan had added new records, which were left unchanged. This fixes the rest of them.

2) Fixes use of semanage_seuser_modify_local -> semanage_seuser_modify, the seuser functions don't have _local suffixes.

3) pass ftype to fcontext delete function, as it is part of the key, otherwise variable is undefined

4) fix backwards existence check in selinux user add()

5) fix bug where the same context is passed on interface set_ifcon and set_msgcon - it needs to be cloned, or it will crash - the context passed to those functions is not cloned internally, it is used as the master copy

6) The boolean code incorrectly duplicates fcontext code. I see it's currently disabled, I guess it's work in progress. Fix most of it regardless (but keep it disabled)

7) audit rc values for:
- object set functions that can fail (which is most of them)
- dbase modify, delete, and list calls
- semanage_begin_transaction

8) fix rc handling:
- do not presume to know why commit failed ("is not defined" ->
"Failed to do ...") Commit can fail for many reasons.
- remove rc messages following a get_con() call. It can't fail,
and does not update the rc value

9) restructure code:
- I don't like all those if/else statements that increase the
indentation level - move the failure case first, which is handled via an exception, so no indentation is needed below
- push any code that sets record fields out of the transaction

10) improve error messages:
- fcontext -> "file context for"
- correct SELinux user vs login mapping inconsistencies
- "not defined localy, can not be deleted" -> "defined in policy,
cannot be deleted"
- remove trailing dot to improve consistency
- "Can't" - > "Could not" for consistency
- "Requires," -> "Requires"
- print the object key on failure of modify/delete/add/commit

11) Rename variables:
- status -> rc for consistency

Further notes:
- Multiple roles don't seem to work - I get the usage() printout
- Modifying with -R doesn't work properly - it adds roles on top of the current ones, when it should clear the current role set first - you can use the del_role function, or better, the set_roles function (not sure if it will work, let joshua know if the swig typemaps create problems for that case).
- I would recommend a message be printed out after a delete() that leaves a policy object behind (do exists check again), that says: "Deleted local modifications to <object>, falling back to policy default". This describes what the delete function really does in that case.

policycoreutils/semanage/semanage +6 -0
diff -Naurp --exclude-from excludes old/policycoreutils/semanage/semanage new/policycoreutils/semanage/semanage
@@ -186,6 +186,7 @@ semanage fcontext [-admhfst] INTERFACE\n
 
 			if object == "fcontext":
 				OBJECT.add(target, setype, ftype, serange, seuser)
+
 			sys.exit(0);
 			
 		if modify:
@@ -210,8 +211,13 @@ semanage fcontext [-admhfst] INTERFACE\n
 		if delete:
 			if object == "port":
 				OBJECT.delete(target, proto)
+
+			if object == "fcontext":
+				OBJECT.delete(target, ftype)
+
 			else:
 				OBJECT.delete(target)
+
 			sys.exit(0);
 		usage()
 			
policycoreutils/semanage/seobject.py +414 -262

894 lines not on this page · raw message

#1 lore raw
Quoted 8 lines

Further notes:
- Multiple roles don't seem to work - I get the usage() printout
- Modifying with -R doesn't work properly - it adds roles on top of
the current ones, when it should clear the current role set first - you can use the del_role function, or better, the set_roles function (not sure if it will work, let joshua know if the swig typemaps create problems for that case).
- I would recommend a message be printed out after a delete() that
leaves a policy object behind (do exists check again), that says: "Deleted local modifications to <object>, falling back to policy default". This describes what the delete function really does in that case.

Another thing - I am still not clear on memory management vs python.
I don't see a single thing being freed in the python semanage - is that a problem? Valgrind certainly prints a full 10 screens of errors that complain about uninitialized value and invalid read on PyObject_Free, but I'm not sure I understand what's going on.

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

Further notes:
- Multiple roles don't seem to work - I get the usage() printout
- Modifying with -R doesn't work properly - it adds roles on top of
the current ones, when it should clear the current role set first - you can use the del_role function, or better, the set_roles function (not sure if it will work, let joshua know if the swig typemaps create problems for that case).
- I would recommend a message be printed out after a delete() that
leaves a policy object behind (do exists check again), that says: "Deleted local modifications to <object>, falling back to policy default". This describes what the delete function really does in that case.

Another thing - I am still not clear on memory management vs python.
I don't see a single thing being freed in the python semanage - is that a problem? Valgrind certainly prints a full 10 screens of errors that complain about uninitialized value and invalid read on PyObject_Free, but I'm not sure I understand what's going on.

I doubt that python can manage memory for precompiled code that it calls. I would guess it should be freeing things. Another issue that I hadn't noticed is that the rc value on all exists functions isn't checked anywhere.

--
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
Quoted 8 lines
Quoted 8 lines

Further notes:
- Multiple roles don't seem to work - I get the usage() printout
- Modifying with -R doesn't work properly - it adds roles on top of
the current ones, when it should clear the current role set first - you can use the del_role function, or better, the set_roles function (not sure if it will work, let joshua know if the swig typemaps create problems for that case).
- I would recommend a message be printed out after a delete() that
leaves a policy object behind (do exists check again), that says: "Deleted local modifications to <object>, falling back to policy default". This describes what the delete function really does in that case.

Quoted 4 lines
Quoted 2 lines

Another thing - I am still not clear on memory management vs python.
I don't see a single thing being freed in the python semanage - is that a problem? Valgrind certainly prints a full 10 screens of errors that complain about uninitialized value and invalid read on PyObject_Free, but I'm not sure I understand what's going on.

I doubt that python can manage memory for precompiled code that it calls. I would guess it should be freeing things. Another issue that I hadn't noticed is that the rc value on all exists functions isn't checked anywhere.

... and it should also check if you're root before it tries to do anything else. Right now it fails in a pretty ugly way, when ran as non-root.

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