tools/ Adds getenforce and setenforce functionality to Xen toolchain
PATCH 1/1 tools/ Adds getenforce and setenforce functionality to Xen toolchain
This patch exposes the getenforce and setenforce functionality for the Flask XSM module.
Signed-off-by Machon Gregory <[email protected]>
Signed-off-by George S. Coker, II <[email protected]>
---
tools/flask/Makefile | 2 tools/flask/libflask/flask_op.c | 39 +++++++++ tools/flask/libflask/include/flask.h | 2 tools/flask/loadpolicy/Makefile | 57 ------------- tools/flask/loadpolicy/loadpolicy.c | 129 ------------------------------- tools/flask/utils/Makefile | 54 ++++++++++++ tools/flask/utils/getenforce.c | 66 +++++++++++++++ tools/flask/utils/loadpolicy.c | 129 +++++++++++++++++++++++++++++++ tools/flask/utils/setenforce.c | 73 +++++++++++++++++ tools/python/xen/lowlevel/flask/flask.c | 66 +++++++++++++++ tools/python/xen/util/xsm/flask/flask.py | 11 ++ tools/python/xen/xend/XendXSPolicy.py | 12 ++ tools/python/xen/xm/getenforce.py | 66 +++++++++++++++ tools/python/xen/xm/main.py | 23 ++++- tools/python/xen/xm/setenforce.py | 74 +++++++++++++++++ 15 files changed, 608 insertions(+), 195 deletions(-)
Signature · 2 lines
Machon Gregory National Information Assurance Research Lab (NIARL)
tools/flask/Makefile +1 -1
@@ -3,7 +3,7 @@ SUBDIRS := SUBDIRS += libflask -SUBDIRS += loadpolicy +SUBDIRS += utils .PHONY: all clean install all clean install: %: subdirs-%
tools/flask/libflask/flask_op.c +39 -0
@@ -70,3 +70,42 @@return 0 ; } + +int flask_getenforce (int xc_handle) +{ +int err; +flask_op_t op; +char buf[20 ]; +int size =20 ; +int mode; + + op.cmd =FLASK_GETENFORCE ; + op.buf = buf; + op.size = size; + +if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) +return err; + +sscanf (buf,"%i" , &mode); + +return mode; +} + +int flask_setenforce (int xc_handle,int mode) +{ +int err; +flask_op_t op; +char buf[20 ]; +int size =20 ; + + op.cmd =FLASK_SETENFORCE ; + op.buf = buf; + op.size = size; + +snprintf (buf, size,"%i" , mode); + +if ( (err =xc_flask_op (xc_handle, &op)) !=0 ) +return err; + +return 0 ; +}
tools/flask/libflask/include/flask.h +2 -0
@@ -18,5 +18,7 @@int flask_load (int xc_handle,char *buf,uint32_t size);int flask_context_to_sid (int xc_handle,char *buf,uint32_t size,uint32_t *sid);int flask_sid_to_context (int xc_handle,int sid,char *buf,uint32_t size); +int flask_getenforce (int xc_handle); +int flask_setenforce (int xc_handle,int mode);#endif /* __FLASK_H__ */
tools/flask/loadpolicy/Makefile deleted +0 -57
57 lines not on this page · raw message
tools/flask/loadpolicy/loadpolicy.c deleted +0 -129
129 lines not on this page · raw message
tools/flask/utils/Makefile new file +54 -0
54 lines not on this page · raw message
tools/flask/utils/getenforce.c new file +66 -0
66 lines not on this page · raw message
tools/flask/utils/loadpolicy.c new file +129 -0
129 lines not on this page · raw message
tools/flask/utils/setenforce.c new file +73 -0
73 lines not on this page · raw message
tools/python/xen/lowlevel/flask/flask.c +66 -0
78 lines not on this page · raw message
tools/python/xen/util/xsm/flask/flask.py +9 -2
@@ -7,10 +7,11 @@ #Functions exported through XML-RPC xmlrpc_exports = [ 'on', - 'set_policy' + 'set_policy', + 'getenforce', + 'setenforce' ] - def err(msg): """Raise XSM-Flask exception. """
@@ -56,3 +57,9 @@ def set_policy(xs_type, policy_b64, flags=None, overwrite=None): policy = base64.b64decode(policy_b64); return flask.flask_load(policy), "" + +def getenforce(): + return flask.flask_getenforce() + +def setenforce(mode): + return flask.flask_setenforce(mode)
tools/python/xen/xend/XendXSPolicy.py +11 -1
@@ -49,7 +49,9 @@ 'get_resource_label', 'set_resource_label', 'get_labeled_resources', - 'can_run' ] + 'can_run', + 'getenforce', + 'setenforce'] return XendBase.getFuncs() + funcs getClass = classmethod(getClass)
@@ -205,6 +207,12 @@ raise SecurityError(irc) return security.check_can_run(sec_label) + def getenforce(self): + return security.getenforce() + + def setenforce(self, mode): + return security.setenforce(mode) + get_xstype = classmethod(get_xstype) get_xspolicy = classmethod(get_xspolicy) set_xspolicy = classmethod(set_xspolicy)
@@ -214,6 +222,8 @@ get_resource_label = classmethod(get_resource_label) get_labeled_resources = classmethod(get_labeled_resources) can_run = classmethod(can_run) + getenforce = classmethod(getenforce) + setenforce = classmethod(setenforce) class XendACMPolicy(XendXSPolicy):
tools/python/xen/xm/getenforce.py new file +66 -0
66 lines not on this page · raw message
tools/python/xen/xm/main.py +18 -5
@@ -225,8 +225,7 @@ # security - 'addlabel' : ('<label> {dom <ConfigFile>|res <resource>|mgt <managed domain>}\n' - ' [<policy>]', + 'addlabel' : ('<label> {dom <ConfigFile>|res <resource>|mgt <managed domain>} [<policy>]', 'Add security label to domain.'), 'rmlabel' : ('{dom <ConfigFile>|res <Resource>|mgt<managed domain>}', 'Remove a security label from domain.'),
@@ -244,6 +243,9 @@ 'labels' : ('[policy] [type=dom|res|any]', 'List <type> labels for (active) policy.'), 'serve' : ('', 'Proxy Xend XMLRPC over stdio.'), + 'getenforce' : ('', 'Returns the current enforcing mode for the Flask XSM module (Enforcing,Permissive)'), + 'setenforce' : ('[ (Enforcing|1) | (Permissive|0) ]', + 'Modifies the current enforcing mode for the Flask XSM module'), } SUBCOMMAND_OPTIONS = {
@@ -435,6 +437,10 @@ "vnet-delete", ] +security_commands = [ + "setpolicy", + ] + acm_commands = [ "labels", "addlabel",
@@ -443,11 +449,15 @@ "dry-run", "resources", "dumppolicy", - "setpolicy", "resetpolicy", "getpolicy", ] +flask_commands = [ + "getenforce", + "setenforce", + ] + tmem_commands = [ "tmem-list", "tmem-thaw",
@@ -458,8 +468,9 @@ ] all_commands = (domain_commands + host_commands + scheduler_commands + - device_commands + vnet_commands + acm_commands + - tmem_commands + ['shell', 'event-monitor']) + device_commands + vnet_commands + security_commands + + acm_commands + flask_commands + tmem_commands + + ['shell', 'event-monitor']) ##
@@ -3347,6 +3358,8 @@ 'getpolicy', 'setpolicy', 'resetpolicy', + 'getenforce', + 'setenforce', ] for c in IMPORTED_COMMANDS:
tools/python/xen/xm/setenforce.py new file +74 -0
74 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel