core: added the security_limit to setParam
- params with a security greater than security_limit can not be modified - special value: security_limit < 0 disable the check (all params can be modified)
This commit is contained in:
parent
5366490603
commit
2bf3694fd0
1 changed files with 56 additions and 37 deletions
|
|
@ -392,12 +392,12 @@ class Params(object):
|
|||
if security_limit < 0:
|
||||
return False
|
||||
if not node.hasAttribute('security'):
|
||||
debug("filtered param: %s (no security set)"
|
||||
% node.getAttribute("name"))
|
||||
#debug("filtered param: %s (no security set)"
|
||||
# % node.getAttribute("name"))
|
||||
return True
|
||||
if int(node.getAttribute('security')) > security_limit:
|
||||
debug("filtered param: %s (security level > %i)"
|
||||
% (node.getAttribute("name"), security_limit))
|
||||
#debug("filtered param: %s (security level > %i)"
|
||||
# % (node.getAttribute("name"), security_limit))
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -545,7 +545,7 @@ class Params(object):
|
|||
categories.append(cat.getAttribute("name"))
|
||||
return categories
|
||||
|
||||
def setParam(self, name, value, category, profile_key='@NONE@'):
|
||||
def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
|
||||
"""Set a parameter, return None if the parameter is not in param xml"""
|
||||
#TODO: use different behaviour depending of the data type (e.g. password encrypted)
|
||||
if profile_key != "@NONE@":
|
||||
|
|
@ -556,9 +556,20 @@ class Params(object):
|
|||
|
||||
node = self.__getParamNode(name, category, '@ALL@')
|
||||
if not node:
|
||||
error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category': category, 'name': name})
|
||||
error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
|
||||
% {'category': category, 'name': name})
|
||||
return
|
||||
|
||||
if security_limit >= 0:
|
||||
abort = True
|
||||
if node[1].hasAttribute("security"):
|
||||
if int(node[1].getAttribute("security")) <= security_limit:
|
||||
abort = False
|
||||
if abort:
|
||||
warning(_("Trying to set parameter '%s' in category '%s' without authorization!!!"
|
||||
% (name, category)))
|
||||
return
|
||||
|
||||
if node[0] == 'general':
|
||||
self.params_gen[(category, name)] = value
|
||||
self.storage.setGenParam(category, name, value)
|
||||
|
|
@ -921,8 +932,8 @@ class Memory(object):
|
|||
def getParamsCategories(self):
|
||||
return self.params.getParamsCategories()
|
||||
|
||||
def setParam(self, name, value, category, profile_key):
|
||||
return self.params.setParam(name, value, category, profile_key)
|
||||
def setParam(self, name, value, category, security_limit, profile_key):
|
||||
return self.params.setParam(name, value, category, security_limit, profile_key)
|
||||
|
||||
def importParams(self, xml):
|
||||
return self.params.importParams(xml)
|
||||
|
|
|
|||
Loading…
Reference in a new issue