wrappers for writing users and seusers
PATCH 1/1 wrappers for writing users and seusers
This patch adds wrappers necessary to write users and seusers using libsemanage. It also includes the wrappers for ports, but they are commented out since the port functions are not exported via libsemanage.map. Examples of how to write users and seusers (and tests) are in pywrap-test.py as usual. Let me know if there are any problems with this patch.
Joshua
archive/swigify/libsemanage/src/pywrap-test.py renamed from libsemanage/src/pywrap-test.py +82 -3
@@ -7,7 +7,9 @@ usage = "\ Choose one of the following tests:\n\ -m for modules\n\ -u for users\n\n\ +-U for add user (warning this will write!)\n\n\ -s for seusers\n\n\ +-S for add seuser (warning this will write!)\n\n\ Other options:\n\ -h for this help\n\ -v for verbose output\
@@ -25,12 +27,14 @@ class Tests: def __init__(self): self.all = False self.users = False + self.writeuser = False self.seusers = False + self.writeseuser = False self.modules = False self.verbose = False def selected(self): - return (self.all or self.users or self.modules or self.seusers) + return (self.all or self.users or self.modules or self.seusers or self.writeuser or self.writeseuser) def run(self, handle): if (self.users or self.all):
@@ -42,6 +46,12 @@ class Tests: if (self.modules or self.all): self.test_modules(handle) print "" + if (self.writeuser or self.all): + self.test_writeuser(handle) + print "" + if (self.writeseuser or self.all): + self.test_writeseuser(handle) + print "" def test_modules(self,sh): print "Testing modules..."
@@ -100,13 +110,78 @@ class Tests: print " User mls range: ", semanage.semanage_user_get_mlsrange(user) print " User number of roles: ", semanage.semanage_user_get_num_roles(user) print " User default role: ", semanage.semanage_user_get_defrole(user) - + + def test_writeuser(self,sh): + print "Testing user write..." + + (status, user) = semanage.semanage_user_create(sh) + if self.verbose: print "User object created." + + status = semanage.semanage_user_set_name(sh,user, "testPyUser") + if self.verbose: print "User name set: ", semanage.semanage_user_get_name(user) + + status = semanage.semanage_user_add_role(sh, user, "user_r") + if self.verbose: print "User default role: ", semanage.semanage_user_get_defrole(user) + + status = semanage.semanage_user_set_mlsrange(sh, user, "s0") + if self.verbose: print "User mlsrange: ", semanage.semanage_user_get_mlsrange(user) + + status = semanage.semanage_user_set_mlslevel(sh, user, "s0") + if self.verbose: print "User mlslevel: ", semanage.semanage_user_get_mlslevel(user) + + (status,key) = semanage.semanage_user_key_extract(sh,user) + if self.verbose: print "User key extracted : ", key + + print "Starting transaction..." + status = semanage.semanage_begin_transaction(sh) + status = semanage.semanage_user_add_local(sh,key,user) + status = semanage.semanage_commit(sh) + print "Commit status (transaction number): ", status + + print "Removing user..." + status = semanage.semanage_begin_transaction(sh) + status = semanage.semanage_user_del_local(sh, key) + if self.verbose: print "User delete: ", status + status = semanage.semanage_commit(sh) + print "Commit status (transaction number): ", status + + def test_writeseuser(self,sh): + print "Testing seuser write..." + + (status, seuser) = semanage.semanage_seuser_create(sh) + if self.verbose: print "SEUser object created." + + status = semanage.semanage_seuser_set_name(sh,seuser, "testPySEUser") + if self.verbose: print "SEUser name set: ", semanage.semanage_seuser_get_name(seuser) + + status = semanage.semanage_seuser_set_sename(sh, seuser, "root") + if self.verbose: print "SEUser seuser: ", semanage.semanage_seuser_get_sename(seuser) + + status = semanage.semanage_seuser_set_mlsrange(sh, seuser, "s0:c0.c255") + if self.verbose: print "SEUser mlsrange: ", semanage.semanage_seuser_get_mlsrange(seuser) + + (status,key) = semanage.semanage_seuser_key_extract(sh,seuser) + if self.verbose: print "SEUser key extracted : ", key + + print "Starting transaction..." + status = semanage.semanage_begin_transaction(sh) + status = semanage.semanage_seuser_add(sh,key,seuser) + status = semanage.semanage_commit(sh) + print "Commit status (transaction number): ", status + + print "Removing seuser..." + status = semanage.semanage_begin_transaction(sh) + status = semanage.semanage_seuser_del(sh, key) + if self.verbose: print "SEUser delete: ", status + status = semanage.semanage_commit(sh) + print "Commit status (transaction number): ", status + def main(argv=None): if argv is None: argv = sys.argv try: try: - opts, args = getopt.getopt(argv[1:], "hvmusa", ["help", "verbose", "modules", "users", "seusers", "all"]) + opts, args = getopt.getopt(argv[1:], "hvmusUSa", ["help", "verbose", "modules", "users", "seusers", "writeuser", "writeseuser", "all"]) tests = Tests() for o, a in opts: if o == "-v":
@@ -116,8 +191,12 @@ def main(argv=None): tests.all = True if o == "-u": tests.users = True + if o == "-U": + tests.writeuser = True if o == "-s": tests.seusers = True + if o == "-S": + tests.writeseuser = True if o == "-m": tests.modules = True if o == "-h":
archive/swigify/libsemanage/src/semanage.py renamed from libsemanage/src/semanage.py +2 -0
@@ -41,6 +41,8 @@ semanage_user_by_idx = _semanage.semanag semanage_seuser_by_idx = _semanage.semanage_seuser_by_idx +semanage_port_by_idx = _semanage.semanage_port_by_idx + semanage_bool_key_create = _semanage.semanage_bool_key_create semanage_bool_key_extract = _semanage.semanage_bool_key_extract
archive/swigify/libsemanage/src/semanageswig.i renamed from libsemanage/src/semanageswig.i +82 -9
117 lines not on this page · raw message
archive/swigify/libsemanage/src/semanageswig_wrap.c renamed from libsemanage/src/semanageswig_wrap.c +167 -86
520 lines not on this page · raw message
Quoted 8 lines · Joshua Brindle
This patch adds wrappers necessary to write users and seusers using libsemanage. It also includes the wrappers for ports, but they are commented out since the port functions are not exported via libsemanage.map. Examples of how to write users and seusers (and tests) are in
pywrap-test.pyas usual. Let me know if there are any problems with this patch.
Writers should probably be using modify_local, instead of add_local? Actually now's as good a time as any to re-examine whether we want to keep all of those (both internally, and in the interface).
add -> add new object, fail if it exists (should not be used to test existence) set -> modify old object, fail if it does not exist (should not be used to text existence) modify -> add or modify new object, depending on whether it exists
Yes, modify() can be implemented in terms of exists(), add(), and set(), but I don't want to see all of those called outside a transaction with no lock held. Similarly, set() can be implemented in terms of exists() and modify(). add can be implemented in terms of exists() and modify().
The existence test is with respect to local modifications only. The way the objects are eventually loaded into policy is fixed, and right now it's (set) for booleans, and (modify) for everything else. Actually, those are the only ones implemented..
--
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.
Quoted 11 lines · Ivan Gyurdiev
Quoted 8 lines · Joshua Brindle
This patch adds wrappers necessary to write users and seusers using libsemanage. It also includes the wrappers for ports, but they are commented out since the port functions are not exported via libsemanage.map. Examples of how to write users and seusers (and tests) are in
pywrap-test.pyas usual. Let me know if there are any problems with this patch.
Quoted 2 lines
Writers should probably be using
modify_local, instead ofadd_local? Actually now's as good a time as any to re-examine whether we want to keep all of those (both internally, and in the interface).
doesn't matter, either function works, i just used add for the test script, all of the functions are exported however, and Dan can use modify in the semanage tool for convenience if he'd like.
Quoted 5 lines
add -> add new object, fail if it exists (should not be used to test existence) set -> modify old object, fail if it does not exist (should not be used to text existence) modify -> add or modify new object, depending on whether it exists
Yes,
modify()can be implemented in terms ofexists(),add(), andset(), but I don't want to see all of those called outside a transaction with no lock held. Similarly,set()can be implemented in terms ofexists()andmodify(). add can be implemented in terms ofexists()andmodify().
None of this must be done outside a transaction, I did the test that way to hold the lock the shortest amount of time possible but it's certainly possible and appropriate to start a transaction before modifying anything in memory.
Quoted 3 lines
The existence test is with respect to local modifications only. The way the objects are eventually loaded into policy is fixed, and right now it's (set) for booleans, and (modify) for everything else. Actually, those are the only ones implemented..
--
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.
Quoted 6 lines · Joshua Brindle
This patch adds wrappers necessary to write users and seusers using libsemanage. It also includes the wrappers for ports, but they are commented out since the port functions are not exported via libsemanage.map. Examples of how to write users and seusers (and tests) are in
pywrap-test.pyas usual. Let me know if there are any problems with this patch.
Merged as of libsemanage 1.3.57. May conflict with a patch that seems to be in the Fedora CVS.
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.