[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] Replace changesets 10521, 10526, and 10527 with this new version that does not
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID c77b066f864a4a8f59d70454e08daf4e1b4206c1 # Parent cb9443bfdff811619a94bebb5346ee74e936eee8 Replace changesets 10521, 10526, and 10527 with this new version that does not use xml.marshal. This patch adds new xm subcommands to support working with resource labels. The new subcommands are 'xm resources', 'xm rmlabel', 'xm getlabel' and 'xm dry-run'. In addition, the 'xm addlabel' subcommand now uses an updated syntax to support labeling both domains and resources. See the xm man page for details on each subcommand. Beyond the new subcommands, this patch allows users to immediately see when security checks will fail by pushing some basic security checking into the beginning of 'xm create' and 'xm block-attach'. ACM security attributes for block devices are added to XenStore in order to support the final security enforcement, which will be performed in the kernel and included in a separate patch. Signed-off-by: Bryan D. Payne <bdpayne@xxxxxxxxxx> Signed-off-by: Reiner Sailer <sailer@xxxxxxxxxx> --- tools/python/xen/util/dictio.py | 50 ++++++++++++++++++++++++++++++++++++++ tools/python/xen/util/security.py | 22 ++++++---------- tools/python/xen/xm/addlabel.py | 18 ++++--------- tools/python/xen/xm/getlabel.py | 19 ++++++-------- tools/python/xen/xm/resources.py | 21 ++++----------- tools/python/xen/xm/rmlabel.py | 20 ++++++--------- 6 files changed, 87 insertions(+), 63 deletions(-) diff -r cb9443bfdff8 -r c77b066f864a tools/python/xen/util/security.py --- a/tools/python/xen/util/security.py Thu Jun 29 10:48:07 2006 +0100 +++ b/tools/python/xen/util/security.py Thu Jun 29 11:13:11 2006 +0100 @@ -22,10 +22,10 @@ import sys, os, string, re 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,20 +551,16 @@ def get_res_label(resource): (label, policy) = default_res_label() # load the resource label file - configfile = res_label_filename - if not os.path.isfile(configfile): + res_label_cache = {} + try: + res_label_cache = dictio.dict_read("resources", res_label_filename) + except: 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) diff -r cb9443bfdff8 -r c77b066f864a tools/python/xen/xm/addlabel.py --- a/tools/python/xen/xm/addlabel.py Thu Jun 29 10:48:07 2006 +0100 +++ b/tools/python/xen/xm/addlabel.py Thu Jun 29 11:13:11 2006 +0100 @@ -22,7 +22,7 @@ import sys, os import sys, os import string import traceback -#from xml.marshal import generic +from xen.util import dictio from xen.util import security def usage(): @@ -79,17 +79,13 @@ def add_resource_label(label, resource, return # see if this resource is already in the file + access_control = {} file = security.res_label_filename - if not os.path.isfile(file): + try: + access_control = dictio.dict_read("resources", file) + except: 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.") @@ -97,9 +93,7 @@ def add_resource_label(label, resource, # write the data to file new_entry = { resource : tuple([policyref, label]) } access_control.update(new_entry) - fd = open(file, "wb") -# generic.dump(access_control, fd) - fd.close() + dictio.dict_write(access_control, "resources", file) except security.ACMError: pass diff -r cb9443bfdff8 -r c77b066f864a tools/python/xen/xm/getlabel.py --- a/tools/python/xen/xm/getlabel.py Thu Jun 29 10:48:07 2006 +0100 +++ b/tools/python/xen/xm/getlabel.py Thu Jun 29 11:13:11 2006 +0100 @@ -21,7 +21,7 @@ import sys, os, re import sys, os, re import string import traceback -#from xml.marshal import generic +from xen.util import dictio from xen.util import security def usage(): @@ -33,17 +33,15 @@ def get_resource_label(resource): def get_resource_label(resource): """Gets the resource label """ + # read in the resource file + file = security.res_label_filename try: - # 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 + access_control = dictio.dict_read("resources", file) + except: + 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] @@ -100,7 +98,6 @@ def get_domain_label(configfile): data = data.strip() data = data.lstrip("[\'") data = data.rstrip("\']") - (p, l) = data.split(",") print data except security.ACMError: diff -r cb9443bfdff8 -r c77b066f864a tools/python/xen/xm/resources.py --- a/tools/python/xen/xm/resources.py Thu Jun 29 10:48:07 2006 +0100 +++ b/tools/python/xen/xm/resources.py Thu Jun 29 11:13:11 2006 +0100 @@ -21,7 +21,7 @@ import sys, os import sys, os import string import traceback -#from xml.marshal import generic +from xen.util import dictio from xen.util import security def usage(): @@ -40,24 +40,15 @@ def print_resource_data(access_control): print " label: "+label -def get_resource_data(): - """Returns the resource dictionary. - """ - file = security.res_label_filename - if not os.path.isfile(file): +def main (argv): + try: + file = security.res_label_filename + access_control = dictio.dict_read("resources", file) + except: 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: diff -r cb9443bfdff8 -r c77b066f864a tools/python/xen/xm/rmlabel.py --- a/tools/python/xen/xm/rmlabel.py Thu Jun 29 10:48:07 2006 +0100 +++ b/tools/python/xen/xm/rmlabel.py Thu Jun 29 11:13:11 2006 +0100 @@ -21,7 +21,7 @@ import sys, os, re import sys, os, re import string import traceback -#from xml.marshal import generic +from xen.util import dictio from xen.util import security def usage(): @@ -36,22 +36,18 @@ def rm_resource_label(resource): 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: - # 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!") + access_control = dictio.dict_read("resources", file) + except: + 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] - fd = open(file, "wb") -# generic.dump(access_control, fd) - fd.close() + dictio.dict_write(access_control, "resources", file) else: security.err("Label does not exist in resource label file.") diff -r cb9443bfdff8 -r c77b066f864a tools/python/xen/util/dictio.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/util/dictio.py Thu Jun 29 11:13:11 2006 +0100 @@ -0,0 +1,50 @@ +#=========================================================================== +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +#============================================================================ +# Copyright (C) 2006 International Business Machines Corp. +# Author: Bryan D. Payne <bdpayne@xxxxxxxxxx> +#============================================================================ + + +def dict_read(dictname, filename): + """Loads <filename> and returns the dictionary named <dictname> from + the file. + """ + dict = {} + + # read in the config file + globs = {} + locs = {} + execfile(filename, globs, locs) + + for (k, v) in locs.items(): + if k == dictname: + dict = v + break + + return dict + +def dict_write(dict, dictname, filename): + """Writes <dict> to <filename> using the name <dictname>. If the file + contains any other data, it will be overwritten. + """ + prefix = dictname + " = {\n" + suffix = "}\n" + fd = open(filename, "wb") + fd.write(prefix) + for key in dict: + line = " '" + str(key) + "': " + str(dict[key]) + ",\n" + fd.write(line) + fd.write(suffix) + fd.close() _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |