ia64/xen-unstable

changeset 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 bae52f5cc421
children 797430d25f1b
files tools/python/xen/util/security.py tools/python/xen/xm/addlabel.py tools/python/xen/xm/getlabel.py tools/python/xen/xm/rmlabel.py
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)
     2.1 --- a/tools/python/xen/xm/addlabel.py	Wed Oct 18 17:54:06 2006 +0100
     2.2 +++ b/tools/python/xen/xm/addlabel.py	Wed Oct 18 17:54:58 2006 +0100
     2.3 @@ -72,13 +72,8 @@ def add_resource_label(label, resource, 
     2.4      # sanity check: make sure this label can be instantiated later on
     2.5      ssidref = security.label2ssidref(label, policyref, 'res')
     2.6  
     2.7 -    # sanity check on resource name
     2.8 -    (type, file) = resource.split(":")
     2.9 -    if type == "phy":
    2.10 -        file = "/dev/" + file
    2.11 -    if not os.path.exists(file):
    2.12 -        print "Invalid resource '"+resource+"'"
    2.13 -        return
    2.14 +    #build canonical resource name
    2.15 +    resource = security.unify_resname(resource)
    2.16  
    2.17      # see if this resource is already in the file
    2.18      access_control = {}
     3.1 --- a/tools/python/xen/xm/getlabel.py	Wed Oct 18 17:54:06 2006 +0100
     3.2 +++ b/tools/python/xen/xm/getlabel.py	Wed Oct 18 17:54:58 2006 +0100
     3.3 @@ -33,6 +33,9 @@ def help():
     3.4  def get_resource_label(resource):
     3.5      """Gets the resource label
     3.6      """
     3.7 +    #build canonical resource name
     3.8 +    resource = security.unify_resname(resource)
     3.9 +
    3.10      # read in the resource file
    3.11      file = security.res_label_filename
    3.12      try:
     4.1 --- a/tools/python/xen/xm/rmlabel.py	Wed Oct 18 17:54:06 2006 +0100
     4.2 +++ b/tools/python/xen/xm/rmlabel.py	Wed Oct 18 17:54:58 2006 +0100
     4.3 @@ -37,6 +37,9 @@ def help():
     4.4  def rm_resource_label(resource):
     4.5      """Removes a resource label from the global resource label file.
     4.6      """
     4.7 +    #build canonical resource name
     4.8 +    resource = security.unify_resname(resource)
     4.9 +
    4.10      # read in the resource file
    4.11      file = security.res_label_filename
    4.12      try: