bridge, memory: added the parameter security_limit to asyncGetParamA so it can be used from libervia. refactorization in memory.py are related to that.
This commit is contained in:
parent
010e305d53
commit
6f58566118
4 changed files with 41 additions and 43 deletions
|
|
@ -103,8 +103,8 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
def asyncCreateProfile(self, profile, callback=None, errback=None):
|
||||
return self.db_core_iface.asyncCreateProfile(profile, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
|
||||
|
||||
def asyncGetParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])))
|
||||
def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])))
|
||||
|
||||
def callMenu(self, category, name, menu_type, profile_key):
|
||||
return unicode(self.db_core_iface.callMenu(category, name, menu_type, profile_key))
|
||||
|
|
|
|||
|
|
@ -199,10 +199,10 @@ class DbusObject(dbus.service.Object):
|
|||
return self._callback("asyncCreateProfile", unicode(profile), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssss', out_signature='s',
|
||||
in_signature='sssis', out_signature='s',
|
||||
async_callbacks=('callback', 'errback'))
|
||||
def asyncGetParamA(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("asyncGetParamA", unicode(name), unicode(category), unicode(attribute), unicode(profile_key), callback=callback, errback=errback)
|
||||
def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
|
||||
return self._callback("asyncGetParamA", unicode(name), unicode(category), unicode(attribute), security_limit, unicode(profile_key), callback=callback, errback=errback)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssss', out_signature='s',
|
||||
|
|
|
|||
|
|
@ -426,15 +426,17 @@ doc_param_3=%(doc_profile_key)s
|
|||
async=
|
||||
type=method
|
||||
category=core
|
||||
sig_in=ssss
|
||||
sig_in=sssis
|
||||
sig_out=s
|
||||
param_2_default="value"
|
||||
param_3_default="@DEFAULT@"
|
||||
param_3_default=-1
|
||||
param_4_default="@DEFAULT@"
|
||||
doc=Helper method to get a parameter's attribute
|
||||
doc_param_0=name: as for [setParam]
|
||||
doc_param_1=category: as for [setParam]
|
||||
doc_param_2=attribute: Name of the attribute
|
||||
doc_param_3=%(doc_profile_key)s
|
||||
doc_param_3=security_limit: -1 means no security then the higher the most secure
|
||||
doc_param_4=%(doc_profile_key)s
|
||||
|
||||
[getParamsUI]
|
||||
async=
|
||||
|
|
|
|||
|
|
@ -315,12 +315,12 @@ class Params(object):
|
|||
value = self.__getParam(profile, category, name)
|
||||
return self.__getAttr(node[1], attr, value)
|
||||
|
||||
def asyncGetStringParamA(self, name, category, attr="value", profile_key="@NONE@"):
|
||||
d = self.asyncGetParamA(name, category, attr, profile_key)
|
||||
def asyncGetStringParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key="@NONE@"):
|
||||
d = self.asyncGetParamA(name, category, attr, security_limit, profile_key)
|
||||
d.addCallback(self.__type_to_string)
|
||||
return d
|
||||
|
||||
def asyncGetParamA(self, name, category, attr="value", profile_key="@NONE@"):
|
||||
def asyncGetParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key="@NONE@"):
|
||||
"""Helper method to get a specific attribute
|
||||
@param name: name of the parameter
|
||||
@param category: category of the parameter
|
||||
|
|
@ -331,6 +331,11 @@ class Params(object):
|
|||
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
return None
|
||||
|
||||
if not self.checkSecurityLimit(node[1], security_limit):
|
||||
warning(_("Trying to get parameter '%s' in category '%s' without authorization!!!"
|
||||
% (name, category)))
|
||||
return None
|
||||
|
||||
if node[0] == 'general':
|
||||
value = self.__getParam(None, category, name, 'general')
|
||||
return defer.succeed(self.__getAttr(node[1], attr, value))
|
||||
|
|
@ -386,22 +391,6 @@ class Params(object):
|
|||
"""
|
||||
|
||||
def constructProfile(ignore, profile_cache):
|
||||
|
||||
def filterParam(node):
|
||||
"""Filter with security level.
|
||||
@return: True is this param must be filtered"""
|
||||
if security_limit < 0:
|
||||
return False
|
||||
if not node.hasAttribute('security'):
|
||||
#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))
|
||||
return True
|
||||
return False
|
||||
|
||||
# init the result document
|
||||
prof_xml = minidom.parseString('<params/>')
|
||||
cache = {}
|
||||
|
|
@ -421,7 +410,7 @@ class Params(object):
|
|||
for node in dest_cat.childNodes:
|
||||
if node.nodeName != "param":
|
||||
continue
|
||||
if filterParam(node):
|
||||
if not self.checkSecurityLimit(node, security_limit):
|
||||
dest_cat.removeChild(node)
|
||||
continue
|
||||
dest_params[node.getAttribute('name')] = node
|
||||
|
|
@ -436,7 +425,7 @@ class Params(object):
|
|||
# we have to merge new params (we are parsing individual parameters, we have to add them
|
||||
# to the previously parsed general ones)
|
||||
name = param_node.getAttribute('name')
|
||||
if filterParam(param_node):
|
||||
if not self.checkSecurityLimit(param_node, security_limit):
|
||||
continue
|
||||
if name not in dest_params:
|
||||
# this is reached when a previous category exists
|
||||
|
|
@ -561,15 +550,10 @@ class Params(object):
|
|||
% {'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!!!"
|
||||
if not self.checkSecurityLimit(node[1], security_limit):
|
||||
warning(_("Trying to set parameter '%s' in category '%s' without authorization!!!"
|
||||
% (name, category)))
|
||||
return
|
||||
return
|
||||
|
||||
if node[0] == 'general':
|
||||
self.params_gen[(category, name)] = value
|
||||
|
|
@ -593,6 +577,18 @@ class Params(object):
|
|||
self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
|
||||
self.storage.setIndParam(category, name, value, profile)
|
||||
|
||||
def checkSecurityLimit(self, node, security_limit):
|
||||
"""Check the given node against the given security limit.
|
||||
The value NO_SECURITY_LIMIT (-1) means that everything is allowed.
|
||||
@return: True if this node can be accessed with the given security limit.
|
||||
"""
|
||||
if security_limit < 0:
|
||||
return True
|
||||
if node.hasAttribute("security"):
|
||||
if int(node.getAttribute("security")) <= security_limit:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Memory(object):
|
||||
"""This class manage all persistent informations"""
|
||||
|
|
@ -828,7 +824,7 @@ class Memory(object):
|
|||
"""
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile'))
|
||||
raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile'))
|
||||
if not profile in self.entitiesCache:
|
||||
raise exceptions.ProfileNotInCacheError
|
||||
if entity_jid == "@ALL@":
|
||||
|
|
@ -859,7 +855,7 @@ class Memory(object):
|
|||
"""
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
raise exceptions.UnknownProfileError(_('Trying to get entity data for a non-existant profile'))
|
||||
raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile'))
|
||||
if not profile in self.entitiesCache:
|
||||
raise exceptions.ProfileNotInCacheError
|
||||
if not entity_jid.userhost() in self.entitiesCache[profile]:
|
||||
|
|
@ -915,11 +911,11 @@ class Memory(object):
|
|||
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
return self.params.getParamA(name, category, attr, profile_key)
|
||||
|
||||
def asyncGetParamA(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
return self.params.asyncGetParamA(name, category, attr, profile_key)
|
||||
def asyncGetParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
|
||||
return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key)
|
||||
|
||||
def asyncGetStringParamA(self, name, category, attr="value", profile_key='@NONE@'):
|
||||
return self.params.asyncGetStringParamA(name, category, attr, profile_key)
|
||||
def asyncGetStringParamA(self, name, category, attr="value", security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
|
||||
return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key)
|
||||
|
||||
def getParamsUI(self, security_limit=NO_SECURITY_LIMIT, profile_key='@NONE@'):
|
||||
return self.params.getParamsUI(security_limit, profile_key)
|
||||
|
|
|
|||
Loading…
Reference in a new issue