ia64/xen-unstable

changeset 10598:266573a53949

Revert 10534 (xm subcommands for ACM). Doesn't work when ACM disabled.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Jun 29 14:38:39 2006 +0100 (2006-06-29)
parents a0a93337f9ab
children c157418212d8
files tools/python/xen/util/security.py tools/python/xen/xm/addlabel.py tools/python/xen/xm/getlabel.py tools/python/xen/xm/resources.py tools/python/xen/xm/rmlabel.py
line diff
     1.1 --- a/tools/python/xen/util/security.py	Thu Jun 29 14:37:32 2006 +0100
     1.2 +++ b/tools/python/xen/util/security.py	Thu Jun 29 14:38:39 2006 +0100
     1.3 @@ -22,10 +22,10 @@ import logging
     1.4  import sys, os, string, re
     1.5  import traceback
     1.6  import shutil
     1.7 +#from xml.marshal import generic
     1.8  from xen.lowlevel import acm
     1.9  from xen.xend import sxp
    1.10  from xen.xend.XendLogging import log
    1.11 -from xen.util import dictio
    1.12  
    1.13  #global directories and tools for security management
    1.14  policy_dir_prefix = "/etc/xen/acm-security/policies"
    1.15 @@ -551,16 +551,20 @@ def get_res_label(resource):
    1.16      (label, policy) = default_res_label()
    1.17  
    1.18      # load the resource label file
    1.19 -    res_label_cache = {}
    1.20 -    try:
    1.21 -        res_label_cache = dictio.dict_read("resources", res_label_filename)
    1.22 -    except:
    1.23 +    configfile = res_label_filename
    1.24 +    if not os.path.isfile(configfile):
    1.25          log.info("Resource label file not found.")
    1.26          return default_res_label()
    1.27 +#
    1.28 +# Commented out pending replacement for xml.marshal.generic
    1.29 +#
    1.30 +#     fd = open(configfile, "rb")
    1.31 +#     res_label_cache = generic.load(fd)
    1.32 +#     fd.close()
    1.33  
    1.34 -    # find the resource information
    1.35 -    if res_label_cache.has_key(resource):
    1.36 -        (policy, label) = res_label_cache[resource]
    1.37 +#     # find the resource information
    1.38 +#     if res_label_cache.has_key(resource):
    1.39 +#         (policy, label) = res_label_cache[resource]
    1.40  
    1.41      return (label, policy)
    1.42  
     2.1 --- a/tools/python/xen/xm/addlabel.py	Thu Jun 29 14:37:32 2006 +0100
     2.2 +++ b/tools/python/xen/xm/addlabel.py	Thu Jun 29 14:38:39 2006 +0100
     2.3 @@ -22,7 +22,7 @@
     2.4  import sys, os
     2.5  import string
     2.6  import traceback
     2.7 -from xen.util import dictio
     2.8 +#from xml.marshal import generic
     2.9  from xen.util import security
    2.10  
    2.11  def usage():
    2.12 @@ -79,13 +79,17 @@ def add_resource_label(label, resource, 
    2.13              return
    2.14  
    2.15          # see if this resource is already in the file
    2.16 -        access_control = {}
    2.17          file = security.res_label_filename
    2.18 -        try:
    2.19 -            access_control = dictio.dict_read("resources", file)
    2.20 -        except:
    2.21 +        if not os.path.isfile(file):
    2.22              print "Resource file not found, creating new file at:"
    2.23              print "%s" % (file)
    2.24 +            fd = open(file, "w")
    2.25 +            fd.close();
    2.26 +            access_control = {}
    2.27 +        else:
    2.28 +            fd = open(file, "rb")
    2.29 +#            access_control = generic.load(fd)
    2.30 +            fd.close()
    2.31  
    2.32          if access_control.has_key(resource):
    2.33              security.err("This resource is already labeled.")
    2.34 @@ -93,7 +97,9 @@ def add_resource_label(label, resource, 
    2.35          # write the data to file
    2.36          new_entry = { resource : tuple([policyref, label]) }
    2.37          access_control.update(new_entry)
    2.38 -        dictio.dict_write(access_control, "resources", file)
    2.39 +        fd = open(file, "wb")
    2.40 +#        generic.dump(access_control, fd)
    2.41 +        fd.close()
    2.42  
    2.43      except security.ACMError:
    2.44          pass
     3.1 --- a/tools/python/xen/xm/getlabel.py	Thu Jun 29 14:37:32 2006 +0100
     3.2 +++ b/tools/python/xen/xm/getlabel.py	Thu Jun 29 14:38:39 2006 +0100
     3.3 @@ -21,7 +21,7 @@
     3.4  import sys, os, re
     3.5  import string
     3.6  import traceback
     3.7 -from xen.util import dictio
     3.8 +#from xml.marshal import generic
     3.9  from xen.util import security
    3.10  
    3.11  def usage():
    3.12 @@ -33,15 +33,17 @@ def usage():
    3.13  def get_resource_label(resource):
    3.14      """Gets the resource label
    3.15      """
    3.16 -    # read in the resource file
    3.17 -    file = security.res_label_filename
    3.18      try:
    3.19 -        access_control = dictio.dict_read("resources", file)
    3.20 -    except:
    3.21 -        print "Resource label file not found"
    3.22 -        return
    3.23 +        # read in the resource file
    3.24 +        file = security.res_label_filename
    3.25 +        if os.path.isfile(file):
    3.26 +            fd = open(file, "rb")
    3.27 +#            access_control = generic.load(fd)
    3.28 +            fd.close()
    3.29 +        else:
    3.30 +            print "Resource label file not found"
    3.31 +            return
    3.32  
    3.33 -    try:
    3.34          # get the entry and print label
    3.35          if access_control.has_key(resource):
    3.36              policy = access_control[resource][0]
    3.37 @@ -98,6 +100,7 @@ def get_domain_label(configfile):
    3.38          data = data.strip()
    3.39          data = data.lstrip("[\'")
    3.40          data = data.rstrip("\']")
    3.41 +        (p, l) = data.split(",")
    3.42          print data
    3.43  
    3.44      except security.ACMError:
     4.1 --- a/tools/python/xen/xm/resources.py	Thu Jun 29 14:37:32 2006 +0100
     4.2 +++ b/tools/python/xen/xm/resources.py	Thu Jun 29 14:38:39 2006 +0100
     4.3 @@ -21,7 +21,7 @@
     4.4  import sys, os
     4.5  import string
     4.6  import traceback
     4.7 -from xen.util import dictio
     4.8 +#from xml.marshal import generic
     4.9  from xen.util import security
    4.10  
    4.11  def usage():
    4.12 @@ -40,15 +40,24 @@ def print_resource_data(access_control):
    4.13          print "    label:  "+label
    4.14  
    4.15  
    4.16 +def get_resource_data():
    4.17 +    """Returns the resource dictionary.
    4.18 +    """
    4.19 +    file = security.res_label_filename
    4.20 +    if not os.path.isfile(file):
    4.21 +        security.err("Resource file not found.")
    4.22 +
    4.23 +    fd = open(file, "rb")
    4.24 +#    access_control = generic.load(fd)
    4.25 +    fd.close()
    4.26 +    return access_control
    4.27 +
    4.28 +
    4.29  def main (argv):
    4.30      try:
    4.31 -        file = security.res_label_filename
    4.32 -        access_control = dictio.dict_read("resources", file)
    4.33 -    except:
    4.34 -        security.err("Resource file not found.")
    4.35 +        access_control = get_resource_data()
    4.36 +        print_resource_data(access_control)
    4.37  
    4.38 -    try:
    4.39 -        print_resource_data(access_control)
    4.40      except security.ACMError:
    4.41          pass
    4.42      except:
     5.1 --- a/tools/python/xen/xm/rmlabel.py	Thu Jun 29 14:37:32 2006 +0100
     5.2 +++ b/tools/python/xen/xm/rmlabel.py	Thu Jun 29 14:38:39 2006 +0100
     5.3 @@ -21,7 +21,7 @@
     5.4  import sys, os, re
     5.5  import string
     5.6  import traceback
     5.7 -from xen.util import dictio
     5.8 +#from xml.marshal import generic
     5.9  from xen.util import security
    5.10  
    5.11  def usage():
    5.12 @@ -36,18 +36,22 @@ def usage():
    5.13  def rm_resource_label(resource):
    5.14      """Removes a resource label from the global resource label file.
    5.15      """
    5.16 -    # read in the resource file
    5.17 -    file = security.res_label_filename
    5.18      try:
    5.19 -        access_control = dictio.dict_read("resources", file)
    5.20 -    except:
    5.21 -        security.err("Resource file not found, cannot remove label!")
    5.22 +        # read in the resource file
    5.23 +        file = security.res_label_filename
    5.24 +        if os.path.isfile(file):
    5.25 +            fd = open(file, "rb")
    5.26 +#            access_control = generic.load(fd)
    5.27 +            fd.close()
    5.28 +        else:
    5.29 +            security.err("Resource file not found, cannot remove label!")
    5.30  
    5.31 -    try:
    5.32          # remove the entry and update file
    5.33          if access_control.has_key(resource):
    5.34              del access_control[resource]
    5.35 -            dictio.dict_write(access_control, "resources", file)
    5.36 +            fd = open(file, "wb")
    5.37 +#            generic.dump(access_control, fd)
    5.38 +            fd.close()
    5.39          else:
    5.40              security.err("Label does not exist in resource label file.")
    5.41