ia64/xen-unstable

diff tools/python/xen/util/security.py @ 11887:58144f4b102c

[ACM] Fix the resource representations in the resource_label
file. Without this patch, multiple representations of the same
resource can co-exist in the resource label file and lead to errors
during operation.

Ensures that all resource file names are stored with absolute
path name and are unique. Setting labels of phy-resources, relative
paths will automatically be pre-pended with '/dev/'; labeling
file-resources with relative paths will raise an error.

Signed-off by: Reiner Sailer <sailer@us.ibm.com>
author kfraser@localhost.localdomain
date Wed Oct 18 17:54:58 2006 +0100 (2006-10-18)
parents 8922c1fbe684
children 328606e0705f
line diff
     1.1 --- a/tools/python/xen/util/security.py	Wed Oct 18 17:54:06 2006 +0100
     1.2 +++ b/tools/python/xen/util/security.py	Wed Oct 18 17:54:58 2006 +0100
     1.3 @@ -596,12 +596,34 @@ def get_res_security_details(resource):
     1.4      return (label, ssidref, policy)
     1.5  
     1.6  
     1.7 +def unify_resname(resource):
     1.8 +    """Makes all resource locations absolute. In case of physical
     1.9 +    resources, '/dev/' is added to local file names"""
    1.10 +
    1.11 +    # sanity check on resource name
    1.12 +    (type, resfile) = resource.split(":")
    1.13 +    if type == "phy":
    1.14 +        if not resfile.startswith("/"):
    1.15 +            resfile = "/dev/" + resfile
    1.16 +
    1.17 +    #file: resources must specified with absolute path
    1.18 +    if (not resfile.startswith("/")) or (not os.path.exists(resfile)):
    1.19 +        err("Invalid resource.")
    1.20 +
    1.21 +    # from here on absolute file names with resources
    1.22 +    resource = type + ":" + resfile
    1.23 +    return resource
    1.24 +
    1.25 +
    1.26  def res_security_check(resource, domain_label):
    1.27      """Checks if the given resource can be used by the given domain
    1.28         label.  Returns 1 if the resource can be used, otherwise 0.
    1.29      """
    1.30      rtnval = 1
    1.31  
    1.32 +    #build canonical resource name
    1.33 +    resource = unify_resname(resource)
    1.34 +
    1.35      # if security is on, ask the hypervisor for a decision
    1.36      if on():
    1.37          (label, ssidref, policy) = get_res_security_details(resource)