semanage patch to allow boolean files to be imported.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Added flag to semanage to be able to import and export boolean files into the current system.
Also cleaned up constants to use True/False instead of 1/0 -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iEYEARECAAYFAkhzxbIACgkQrlYvE4MpobNTDACfeq0yKwoeEpqOEEoit4m2g771 IFAAnjZTz0UNNuRA+QfgPtZH9w56C1ta
=nHLb
-----END PGP SIGNATURE-----
semanage/semanage +35 -22
@@ -51,7 +51,7 @@ semanage interface -{a|d|m} [-tr] interface_spec semanage fcontext -{a|d|m} [-frst] file_spec semanage translation -{a|d|m} [-T] level -semanage boolean -{d|m} boolean +semanage boolean -{d|m} [-F] boolean | boolean_file semanage permissive -{d|a} type Primary Options:
@@ -79,6 +79,7 @@ -l (symbolic link) -p (named pipe) + -F, --file Treat target as an input file for command, change multiple settings -p, --proto Port protocol (tcp or udp) -P, --prefix Prefix for home directory labeling -L, --level Default SELinux Level (MLS/MCS Systems only)
@@ -114,7 +115,7 @@ valid_option["translation"] = [] valid_option["translation"] += valid_everyone + [ '-T', '--trans' ] valid_option["boolean"] = [] - valid_option["boolean"] += valid_everyone + [ '--on', "--off", "-1", "-0" ] + valid_option["boolean"] += valid_everyone + [ '--on', "--off", "-1", "-0", "-F", "--file"] valid_option["permissive"] = [] valid_option["permissive"] += [ '-a', '--add', '-d', '--delete', '-l', '--list', '-h', '--help', '-n', '--noheading', '-D', '--deleteall' ] return valid_option
@@ -136,13 +137,14 @@ seuser = "" prefix = "" heading=1 - value=0 - add = 0 - modify = 0 - delete = 0 - deleteall = 0 - list = 0 - locallist = 0 + value = "" + add = False + modify = False + delete = False + deleteall = False + list = False + locallist = False + use_file = False store = "" if len(sys.argv) < 3: usage(_("Requires 2 or more arguments"))
@@ -155,11 +157,12 @@ args = sys.argv[2:] gopts, cmds = getopt.getopt(args, - '01adf:lhmnp:s:CDR:L:r:t:T:P:S:', + '01adf:lhmnp:s:FCDR:L:r:t:T:P:S:', ['add', 'delete', 'deleteall', 'ftype=', + 'file', 'help', 'list', 'modify',
@@ -185,18 +188,22 @@ if o == "-a" or o == "--add": if modify or delete: usage() - add = 1 + add = True if o == "-d" or o == "--delete": if modify or add: usage() - delete = 1 + delete = True if o == "-D" or o == "--deleteall": if modify: usage() - deleteall = 1 + deleteall = True if o == "-f" or o == "--ftype": ftype=a + + if o == "-F" or o == "--file": + use_file = True + if o == "-h" or o == "--help": usage()
@@ -204,12 +211,12 @@ heading=0 if o == "-C" or o == "--locallist": - locallist=1 + locallist = True if o == "-m"or o == "--modify": if delete or add: usage() - modify = 1 + modify = True if o == "-S" or o == '--store': store = a
@@ -220,7 +227,7 @@ serange = a if o == "-l" or o == "--list": - list = 1 + list = True if o == "-L" or o == '--level': if is_mls_enabled == 0:
@@ -246,9 +253,9 @@ setrans = a if o == "--on" or o == "-1": - value = 1 + value = True if o == "-off" or o == "-0": - value = 0 + value = False if object == "login": OBJECT = seobject.loginRecords(store)
@@ -275,7 +282,10 @@ OBJECT = seobject.permissiveRecords(store) if list: - OBJECT.list(heading, locallist) + if object == "boolean": + OBJECT.list(heading, locallist, use_file) + else: + OBJECT.list(heading, locallist) sys.exit(0); if deleteall:
@@ -298,8 +308,6 @@ rlist = roles.split() if len(rlist) == 0: raise ValueError(_("You must specify a role")) - if prefix == "": - raise ValueError(_("You must specify a prefix")) OBJECT.add(target, rlist, selevel, serange, prefix) if object == "port":
@@ -317,7 +325,12 @@ if modify: if object == "boolean": - OBJECT.modify(target, value) + if use_file: + OBJECT.modify(target, use_file = use_file) + else: + if value == "": + raise ValueError(_("boolean requires value")) + OBJECT.modify(target, value) if object == "login": OBJECT.modify(target, seuser, serange)
semanage/semanage.8 +10 -2
@@ -3,9 +3,9 @@ semanage \- SELinux Policy Management tool .SH "SYNOPSIS" -.B semanage {boolean|login|user|port|interface|fcontext|translation} \-{l|lC|D} [\-n] +.B semanage {boolean|login|user|port|interface|fcontext|translation} \-{l|D} [\-n] [\-S store] .br -.B semanage boolean \-{d|m} [\-\-on|\-\-off|\-1|\-0] boolean +.B semanage boolean \-{d|m} [\-\-on|\-\-off|\-1|\-0] -F boolean | boolean_file .br .B semanage login \-{a|d|m} [\-sr] login_name .br
@@ -54,6 +54,11 @@ File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use -d to match only directories or -- to match only regular files. .TP +.I \-F, \-\-file +Set multiple records from the input file. When used with the \-l \-\-list, it will output the current settings to stdout in the proper format. + +Currently booleans only. +.TP .I \-h, \-\-help display this message .TP
@@ -87,6 +92,9 @@ .I \-s, \-\-seuser SELinux user name .TP +.I \-S, \-\-store +Select and alternate SELinux store to manage +.TP .I \-t, \-\-type SELinux Type for the object .TP
semanage/seobject.py +47 -35
108 lines not on this page · raw message
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 4 lines · Karl MacMillan
Quoted 3 lines · Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 9 lines
Quoted 3 lines
Added flag to semanage to be able to import and export boolean files into the current system.
[snip]
Review
Quoted 2 lines
(quoted diff) +2
-0+ def modify(self, name, value=False, use_file=False): +
Fixed
Quoted 27 lines
I think it is more idiomatic to use None instead of False when the argument is a value rather than just a boolean.
Review
Quoted 11 lines
rc =
semanage_begin_transaction(self.sh)
if rc < 0:
raiseValueError(_("Could not start semanage transaction"))(quoted diff) +1
-7- - rc = semanage_bool_set_active(self.sh, k, b) - if rc < 0: - raise ValueError(_("Could not set active value of boolean %s") % name) - rc = semanage_bool_modify_local(self.sh, k, b) - if rc < 0: - raise ValueError(_("Could not modify boolean %s") % name) + if use_file:And then "if
use_fileis not None:" here.Review
Quoted 3 lines
(quoted diff) +3
-0+ fd = open(name) + for b in fd.read().split(): + bool, val = b.split("=")I think you need a little more error checking here. For example, if the
b.split("=")resulted in less than two items the split into the two variables would fail, raising an exception. I think that we would want it to be both more tolerant to malformed files and provide better error reporting to the user.
Quoted 3 lines
With those changes:
Acked-by Karl MacMillan <[email protected]>
Added additional error checking and some better error messages.
Also fixed some indenting problems.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iEYEARECAAYFAkh0tdAACgkQrlYvE4MpobPwngCgwnWEmSAzeCVW7FaD5djbhHg5 tMoAnAuFQMeSnxjZV0lIVUYfpwS33/vK
=d3ho
-----END PGP SIGNATURE-----
semanage/semanage +30 -22
@@ -51,7 +51,7 @@ semanage interface -{a|d|m} [-tr] interface_spec semanage fcontext -{a|d|m} [-frst] file_spec semanage translation -{a|d|m} [-T] level -semanage boolean -{d|m} boolean +semanage boolean -{d|m} [-F] boolean | boolean_file semanage permissive -{d|a} type Primary Options:
@@ -79,6 +79,7 @@ -l (symbolic link) -p (named pipe) + -F, --file Treat target as an input file for command, change multiple settings -p, --proto Port protocol (tcp or udp) -P, --prefix Prefix for home directory labeling -L, --level Default SELinux Level (MLS/MCS Systems only)
@@ -114,7 +115,7 @@ valid_option["translation"] = [] valid_option["translation"] += valid_everyone + [ '-T', '--trans' ] valid_option["boolean"] = [] - valid_option["boolean"] += valid_everyone + [ '--on', "--off", "-1", "-0" ] + valid_option["boolean"] += valid_everyone + [ '--on', "--off", "-1", "-0", "-F", "--file"] valid_option["permissive"] = [] valid_option["permissive"] += [ '-a', '--add', '-d', '--delete', '-l', '--list', '-h', '--help', '-n', '--noheading', '-D', '--deleteall' ] return valid_option
@@ -136,13 +137,14 @@ seuser = "" prefix = "" heading=1 - value=0 - add = 0 - modify = 0 - delete = 0 - deleteall = 0 - list = 0 - locallist = 0 + value = None + add = False + modify = False + delete = False + deleteall = False + list = False + locallist = False + use_file = False store = "" if len(sys.argv) < 3: usage(_("Requires 2 or more arguments"))
@@ -155,11 +157,12 @@ args = sys.argv[2:] gopts, cmds = getopt.getopt(args, - '01adf:lhmnp:s:CDR:L:r:t:T:P:S:', + '01adf:lhmnp:s:FCDR:L:r:t:T:P:S:', ['add', 'delete', 'deleteall', 'ftype=', + 'file', 'help', 'list', 'modify',
@@ -185,18 +188,22 @@ if o == "-a" or o == "--add": if modify or delete: usage() - add = 1 + add = True if o == "-d" or o == "--delete": if modify or add: usage() - delete = 1 + delete = True if o == "-D" or o == "--deleteall": if modify: usage() - deleteall = 1 + deleteall = True if o == "-f" or o == "--ftype": ftype=a + + if o == "-F" or o == "--file": + use_file = True + if o == "-h" or o == "--help": usage()
@@ -204,12 +211,12 @@ heading=0 if o == "-C" or o == "--locallist": - locallist=1 + locallist = True if o == "-m"or o == "--modify": if delete or add: usage() - modify = 1 + modify = True if o == "-S" or o == '--store': store = a
@@ -220,7 +227,7 @@ serange = a if o == "-l" or o == "--list": - list = 1 + list = True if o == "-L" or o == '--level': if is_mls_enabled == 0:
@@ -246,9 +253,9 @@ setrans = a if o == "--on" or o == "-1": - value = 1 + value = True if o == "-off" or o == "-0": - value = 0 + value = False if object == "login": OBJECT = seobject.loginRecords(store)
@@ -275,7 +282,10 @@ OBJECT = seobject.permissiveRecords(store) if list: - OBJECT.list(heading, locallist) + if object == "boolean": + OBJECT.list(heading, locallist, use_file) + else: + OBJECT.list(heading, locallist) sys.exit(0); if deleteall:
@@ -298,8 +308,6 @@ rlist = roles.split() if len(rlist) == 0: raise ValueError(_("You must specify a role")) - if prefix == "": - raise ValueError(_("You must specify a prefix")) OBJECT.add(target, rlist, selevel, serange, prefix) if object == "port":
@@ -317,7 +325,7 @@ if modify: if object == "boolean": - OBJECT.modify(target, value) + OBJECT.modify(target, value, use_file) if object == "login": OBJECT.modify(target, seuser, serange)
semanage/semanage.8 +10 -2
@@ -3,9 +3,9 @@ semanage \- SELinux Policy Management tool .SH "SYNOPSIS" -.B semanage {boolean|login|user|port|interface|fcontext|translation} \-{l|lC|D} [\-n] +.B semanage {boolean|login|user|port|interface|fcontext|translation} \-{l|D} [\-n] [\-S store] .br -.B semanage boolean \-{d|m} [\-\-on|\-\-off|\-1|\-0] boolean +.B semanage boolean \-{d|m} [\-\-on|\-\-off|\-1|\-0] -F boolean | boolean_file .br .B semanage login \-{a|d|m} [\-sr] login_name .br
@@ -54,6 +54,11 @@ File Type. This is used with fcontext. Requires a file type as shown in the mode field by ls, e.g. use -d to match only directories or -- to match only regular files. .TP +.I \-F, \-\-file +Set multiple records from the input file. When used with the \-l \-\-list, it will output the current settings to stdout in the proper format. + +Currently booleans only. +.TP .I \-h, \-\-help display this message .TP
@@ -87,6 +92,9 @@ .I \-s, \-\-seuser SELinux user name .TP +.I \-S, \-\-store +Select and alternate SELinux store to manage +.TP .I \-t, \-\-type SELinux Type for the object .TP
semanage/seobject.py +62 -42
144 lines not on this page · raw message
Karl MacMillan
Acked-byQuoted 6 lines · Daniel J Walsh
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Added flag to semanage to be able to import and export boolean files into the current system.
[snip]
semanage/seobject.py line 1481
Quoted 3 lines
semanage/seobject.py +2
-0+ def modify(self, name, value=False, use_file=False): +
I think it is more idiomatic to use None instead of False when the argument is a value rather than just a boolean.
semanage/seobject.py line 1485
Quoted 11 lines
rc =
semanage_begin_transaction(self.sh)
if rc < 0:
raiseValueError(_("Could not start semanage transaction"))semanage/seobject.py +1
-7- - rc = semanage_bool_set_active(self.sh, k, b) - if rc < 0: - raise ValueError(_("Could not set active value of boolean %s") % name) - rc = semanage_bool_modify_local(self.sh, k, b) - if rc < 0: - raise ValueError(_("Could not modify boolean %s") % name) + if use_file:
And then "if use_file is not None:" here.
semanage/seobject.py line 1488
Quoted 3 lines
semanage/seobject.py +3
-0+ fd = open(name) + for b in fd.read().split(): + bool, val = b.split("=")
I think you need a little more error checking here. For example, if the b.split("=") resulted in less than two items the split into the two variables would fail, raising an exception. I think that we would want it to be both more tolerant to malformed files and provide better error reporting to the user.
With those changes:
--
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.