--- xen-unstable.hg/tools/python/xen/util/acmpolicy.py | 81 ++++++------ xen-unstable.hg/tools/python/xen/util/security.py | 69 ---------- xen-unstable.hg/tools/python/xen/xend/XendConfig.py | 2 xen-unstable.hg/tools/python/xen/xm/main.py | 30 +--- xen-unstable.hg/tools/security/policies/security_policy.xsd | 7 - 5 files changed, 57 insertions(+), 132 deletions(-) Index: root/xen-unstable.hg/tools/security/policies/security_policy.xsd =================================================================== --- root.orig/xen-unstable.hg/tools/security/policies/security_policy.xsd +++ root/xen-unstable.hg/tools/security/policies/security_policy.xsd @@ -99,7 +99,7 @@ - + @@ -143,9 +143,4 @@ - - - - - Index: root/xen-unstable.hg/tools/python/xen/util/acmpolicy.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/util/acmpolicy.py +++ root/xen-unstable.hg/tools/python/xen/util/acmpolicy.py @@ -57,12 +57,20 @@ class ACMPolicy(XSPolicy): def __init__(self, name=None, dom=None, ref=None, xml=None): if name: self.name = name - self.dom = minidom.parse(self.path_from_policy_name(name)) + try: + self.dom = minidom.parse(self.path_from_policy_name(name)) + except Exception, e: + raise SecurityError(-xsconstants.XSERR_XML_PROCESSING, + str(e)) elif dom: self.dom = dom self.name = self.get_name() elif xml: - self.dom = minidom.parseString(xml) + try: + self.dom = minidom.parseString(xml) + except Exception, e: + raise SecurityError(-xsconstants.XSERR_XML_PROCESSING, + str(e)) self.name = self.get_name() rc = self.validate() if rc != xsconstants.XSERR_SUCCESS: @@ -481,7 +489,8 @@ class ACMPolicy(XSPolicy): strings = [] i = 0 while i < len(node.childNodes): - if node.childNodes[i].nodeName == "Type": + if node.childNodes[i].nodeName == "Type" and \ + len(node.childNodes[i].childNodes) > 0: strings.append(node.childNodes[i].childNodes[0].nodeValue) i += 1 return strings @@ -564,7 +573,8 @@ class ACMPolicy(XSPolicy): while i < len(node.childNodes): if node.childNodes[i].nodeName == "VirtualMachineLabel": name = self.policy_dom_get(node.childNodes[i], "Name") - strings.append(name.childNodes[0].nodeValue) + if len(name.childNodes) > 0: + strings.append(name.childNodes[0].nodeValue) i += 1 return strings @@ -592,23 +602,24 @@ class ACMPolicy(XSPolicy): i = 0 while i < len(node.childNodes): if node.childNodes[i].nodeName == "VirtualMachineLabel": - _res = {} - _res['type'] = xsconstants.ACM_LABEL_VM name = self.policy_dom_get(node.childNodes[i], "Name") - _res['name'] = name.childNodes[0].nodeValue - stes = self.policy_dom_get(node.childNodes[i], - "SimpleTypeEnforcementTypes") - if stes: - _res['stes'] = self.policy_get_types(stes) - else: - _res['stes'] = [] - chws = self.policy_dom_get(node.childNodes[i], - "ChineseWallTypes") - if chws: - _res['chws'] = self.policy_get_types(chws) - else: - _res['chws'] = [] - res.append(_res) + if len(name.childNodes) > 0: + _res = {} + _res['type'] = xsconstants.ACM_LABEL_VM + _res['name'] = name.childNodes[0].nodeValue + stes = self.policy_dom_get(node.childNodes[i], + "SimpleTypeEnforcementTypes") + if stes: + _res['stes'] = self.policy_get_types(stes) + else: + _res['stes'] = [] + chws = self.policy_dom_get(node.childNodes[i], + "ChineseWallTypes") + if chws: + _res['chws'] = self.policy_get_types(chws) + else: + _res['chws'] = [] + res.append(_res) i += 1 return res @@ -628,7 +639,8 @@ class ACMPolicy(XSPolicy): while i < len(node.childNodes): if node.childNodes[i].nodeName == labeltype: name = self.policy_dom_get(node.childNodes[i], "Name") - if name.childNodes[0].nodeValue == label: + if len(name.childNodes) > 0 and \ + name.childNodes[0].nodeValue == label: stes = self.policy_dom_get(node.childNodes[i], "SimpleTypeEnforcementTypes") if not stes: @@ -662,7 +674,7 @@ class ACMPolicy(XSPolicy): if node.childNodes[i].nodeName == labeltype: name = self.policy_dom_get(node.childNodes[i], "Name") from_name = name.getAttribute("from") - if from_name: + if from_name and len(name.childNodes) > 0: res.update({from_name : name.childNodes[0].nodeValue}) i += 1 return res @@ -700,7 +712,7 @@ class ACMPolicy(XSPolicy): name = self.policy_dom_get(node.childNodes[i], "Name") stes = self.policy_dom_get(node.childNodes[i], "SimpleTypeEnforcementTypes") - if stes: + if stes and len(name.childNodes) > 0: strings.append(name.childNodes[0].nodeValue) i += 1 return strings @@ -715,18 +727,19 @@ class ACMPolicy(XSPolicy): i = 0 while i < len(node.childNodes): if node.childNodes[i].nodeName == "ResourceLabel": - _res = {} - _res['type'] = xsconstants.ACM_LABEL_RES name = self.policy_dom_get(node.childNodes[i], "Name") - _res['name'] = name.childNodes[0].nodeValue - stes = self.policy_dom_get(node.childNodes[i], - "SimpleTypeEnforcementTypes") - if stes: - _res['stes'] = self.policy_get_types(stes) - else: - _res['stes'] = [] - _res['chws'] = [] - res.append(_res) + if len(name.childNodes) > 0: + _res = {} + _res['type'] = xsconstants.ACM_LABEL_RES + _res['name'] = name.childNodes[0].nodeValue + stes = self.policy_dom_get(node.childNodes[i], + "SimpleTypeEnforcementTypes") + if stes: + _res['stes'] = self.policy_get_types(stes) + else: + _res['stes'] = [] + _res['chws'] = [] + res.append(_res) i += 1 return res Index: root/xen-unstable.hg/tools/python/xen/xend/XendConfig.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xend/XendConfig.py +++ root/xen-unstable.hg/tools/python/xen/xend/XendConfig.py @@ -636,6 +636,8 @@ class XendConfig(dict): except ValueError, e: raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e)) + if not 'security' in cfg and sxp.child_value(sxp_cfg, 'security'): + cfg['security'] = sxp.child_value(sxp_cfg, 'security') if 'security' in cfg and not cfg.get('security_label'): secinfo = cfg['security'] if isinstance(secinfo, list): Index: root/xen-unstable.hg/tools/python/xen/xm/main.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/xm/main.py +++ root/xen-unstable.hg/tools/python/xen/xm/main.py @@ -870,17 +870,13 @@ def parse_doms_info(info): 'up_time' : up_time } - if serverType != SERVER_XEN_API: - from xen.util import security - parsed_info['seclabel'] = security.get_security_printlabel(info) - else: - label = get_info('security_label', unicode, '') - tmp = label.split(":") - if len(tmp) != 3: - label = "" - else: - label = tmp[2] - parsed_info['seclabel'] = label + security_label = get_info('security_label', str, '') + tmp = security_label.split(":") + if len(tmp) != 3: + seclabel = "" + else: + seclabel = tmp[2] + parsed_info['seclabel'] = seclabel if serverType == SERVER_XEN_API: parsed_info['mem'] = get_info('memory_actual', int, 0) / 1024 @@ -2051,18 +2047,6 @@ def parse_block_configuration(args): if len(args) == 5: vbd.append(['backend', args[4]]) - if serverType != SERVER_XEN_API: - # verify that policy permits attaching this resource - from xen.util import security - - if security.on(): - dominfo = server.xend.domain(dom) - label = security.get_security_printlabel(dominfo) - else: - label = None - - security.res_security_check(args[1], label) - return (dom, vbd) Index: root/xen-unstable.hg/tools/python/xen/util/security.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/util/security.py +++ root/xen-unstable.hg/tools/python/xen/util/security.py @@ -155,75 +155,6 @@ def calc_dom_ssidref_from_info(info): raise VmError("security.calc_dom_ssidref_from_info: info of type '%s'" "not supported." % type(info)) -# Assumes a 'security' info [security access_control ...] [ssidref ...] -def get_security_info(info, field): - """retrieves security field from self.info['security']) - allowed search fields: ssidref, label, policy - """ - if isinstance(info, dict): - security = info['security'] - elif isinstance(info, list): - security = sxp.child_value(info, 'security') - if not security: - if field == 'ssidref': - #return default ssid - return 0 - else: - err("Security information not found in info struct.") - - if field == 'ssidref': - search = 'ssidref' - elif field in ['policy', 'label']: - search = 'access_control' - else: - err("Illegal field in get_security_info.") - - for idx in range(0, len(security)): - if search != security[idx][0]: - continue - if search == 'ssidref': - return int(security[idx][1]) - else: - for aidx in range(0, len(security[idx])): - if security[idx][aidx][0] == field: - return str(security[idx][aidx][1]) - - if search == 'ssidref': - return 0 - else: - return None - - -def get_security_printlabel(info): - """retrieves printable security label from self.info['security']), - preferably the label name and otherwise (if label is not specified - in config and cannot be found in mapping file) a hex string of the - ssidref or none if both not available - """ - try: - if not on(): - return "INACTIVE" - if active_policy in ["DEFAULT"]: - return "DEFAULT" - - printlabel = get_security_info(info, 'label') - if printlabel: - return printlabel - ssidref = get_security_info(info, 'ssidref') - if not ssidref: - return None - #try to translate ssidref to a label - result = ssidref2label(ssidref) - if not result: - printlabel = "0x%08x" % ssidref - else: - printlabel = result - return printlabel - except ACMError: - #don't throw an exception in xm list - return "ERROR" - - def getmapfile(policyname): """