Revert 10534 (xm subcommands for ACM). Doesn't work when ACM disabled.
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 29 Jun 2006 13:38:39 +0000 (14:38 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 29 Jun 2006 13:38:39 +0000 (14:38 +0100)
Signed-off-by: Keir Fraser <keir@xensource.com>
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

index 015de985b106c3ab49a07044b14c4002684267e9..df970f355e27e4c5446194bf29fd3784d7e491de 100644 (file)
@@ -22,10 +22,10 @@ import logging
 import sys, os, string, re
 import traceback
 import shutil
+#from xml.marshal import generic
 from xen.lowlevel import acm
 from xen.xend import sxp
 from xen.xend.XendLogging import log
-from xen.util import dictio
 
 #global directories and tools for security management
 policy_dir_prefix = "/etc/xen/acm-security/policies"
@@ -551,16 +551,20 @@ def get_res_label(resource):
     (label, policy) = default_res_label()
 
     # load the resource label file
-    res_label_cache = {}
-    try:
-        res_label_cache = dictio.dict_read("resources", res_label_filename)
-    except:
+    configfile = res_label_filename
+    if not os.path.isfile(configfile):
         log.info("Resource label file not found.")
         return default_res_label()
+#
+# Commented out pending replacement for xml.marshal.generic
+#
+#     fd = open(configfile, "rb")
+#     res_label_cache = generic.load(fd)
+#     fd.close()
 
-    # find the resource information
-    if res_label_cache.has_key(resource):
-        (policy, label) = res_label_cache[resource]
+    # find the resource information
+    if res_label_cache.has_key(resource):
+        (policy, label) = res_label_cache[resource]
 
     return (label, policy)
 
index 2344bf501f02a55caf93fd3197d086a2a52b9418..e3966c9f59dd6040f1338083e1b7372313118d1d 100644 (file)
@@ -22,7 +22,7 @@
 import sys, os
 import string
 import traceback
-from xen.util import dictio
+#from xml.marshal import generic
 from xen.util import security
 
 def usage():
@@ -79,13 +79,17 @@ def add_resource_label(label, resource, policyref):
             return
 
         # see if this resource is already in the file
-        access_control = {}
         file = security.res_label_filename
-        try:
-            access_control = dictio.dict_read("resources", file)
-        except:
+        if not os.path.isfile(file):
             print "Resource file not found, creating new file at:"
             print "%s" % (file)
+            fd = open(file, "w")
+            fd.close();
+            access_control = {}
+        else:
+            fd = open(file, "rb")
+#            access_control = generic.load(fd)
+            fd.close()
 
         if access_control.has_key(resource):
             security.err("This resource is already labeled.")
@@ -93,7 +97,9 @@ def add_resource_label(label, resource, policyref):
         # write the data to file
         new_entry = { resource : tuple([policyref, label]) }
         access_control.update(new_entry)
-        dictio.dict_write(access_control, "resources", file)
+        fd = open(file, "wb")
+#        generic.dump(access_control, fd)
+        fd.close()
 
     except security.ACMError:
         pass
index c984dec02adf3bc3675d4fc83b6ba009f7472261..e1c62d473aba8e719d26a79620f7f3eed92896fc 100644 (file)
@@ -21,7 +21,7 @@
 import sys, os, re
 import string
 import traceback
-from xen.util import dictio
+#from xml.marshal import generic
 from xen.util import security
 
 def usage():
@@ -33,15 +33,17 @@ def usage():
 def get_resource_label(resource):
     """Gets the resource label
     """
-    # read in the resource file
-    file = security.res_label_filename
     try:
-        access_control = dictio.dict_read("resources", file)
-    except:
-        print "Resource label file not found"
-        return
+        # read in the resource file
+        file = security.res_label_filename
+        if os.path.isfile(file):
+            fd = open(file, "rb")
+#            access_control = generic.load(fd)
+            fd.close()
+        else:
+            print "Resource label file not found"
+            return
 
-    try:
         # get the entry and print label
         if access_control.has_key(resource):
             policy = access_control[resource][0]
@@ -98,6 +100,7 @@ def get_domain_label(configfile):
         data = data.strip()
         data = data.lstrip("[\'")
         data = data.rstrip("\']")
+        (p, l) = data.split(",")
         print data
 
     except security.ACMError:
index a7a93251acd0c6edfb026a67c974a70dfa08426a..0108fed8f9f7b45a868c6713d4ed78abf9cefe63 100644 (file)
@@ -21,7 +21,7 @@
 import sys, os
 import string
 import traceback
-from xen.util import dictio
+#from xml.marshal import generic
 from xen.util import security
 
 def usage():
@@ -40,15 +40,24 @@ def print_resource_data(access_control):
         print "    label:  "+label
 
 
-def main (argv):
-    try:
-        file = security.res_label_filename
-        access_control = dictio.dict_read("resources", file)
-    except:
+def get_resource_data():
+    """Returns the resource dictionary.
+    """
+    file = security.res_label_filename
+    if not os.path.isfile(file):
         security.err("Resource file not found.")
 
+    fd = open(file, "rb")
+#    access_control = generic.load(fd)
+    fd.close()
+    return access_control
+
+
+def main (argv):
     try:
+        access_control = get_resource_data()
         print_resource_data(access_control)
+
     except security.ACMError:
         pass
     except:
index b149ec691bdb52431047435c941b565471837629..c031ab3f87c6305dc0f0c63f42723a13436b7d54 100644 (file)
@@ -21,7 +21,7 @@
 import sys, os, re
 import string
 import traceback
-from xen.util import dictio
+#from xml.marshal import generic
 from xen.util import security
 
 def usage():
@@ -36,18 +36,22 @@ def usage():
 def rm_resource_label(resource):
     """Removes a resource label from the global resource label file.
     """
-    # read in the resource file
-    file = security.res_label_filename
     try:
-        access_control = dictio.dict_read("resources", file)
-    except:
-        security.err("Resource file not found, cannot remove label!")
+        # read in the resource file
+        file = security.res_label_filename
+        if os.path.isfile(file):
+            fd = open(file, "rb")
+#            access_control = generic.load(fd)
+            fd.close()
+        else:
+            security.err("Resource file not found, cannot remove label!")
 
-    try:
         # remove the entry and update file
         if access_control.has_key(resource):
             del access_control[resource]
-            dictio.dict_write(access_control, "resources", file)
+            fd = open(file, "wb")
+#            generic.dump(access_control, fd)
+            fd.close()
         else:
             security.err("Label does not exist in resource label file.")