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
6 changed files with 56 additions and 37 deletions
|
|
@ -391,10 +391,10 @@ class DbusObject(dbus.service.Object):
|
|||
return self._callback("sendMessage", unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), options, unicode(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssss', out_signature='',
|
||||
in_signature='sssis', out_signature='',
|
||||
async_callbacks=None)
|
||||
def setParam(self, name, value, category, profile_key="@DEFAULT@"):
|
||||
return self._callback("setParam", unicode(name), unicode(value), unicode(category), unicode(profile_key))
|
||||
def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
|
||||
return self._callback("setParam", unicode(name), unicode(value), unicode(category), security_limit, unicode(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ssia{ss}s', out_signature='',
|
||||
|
|
|
|||
|
|
@ -398,14 +398,16 @@ doc_param_1=name: name of the option
|
|||
[setParam]
|
||||
type=method
|
||||
category=core
|
||||
sig_in=ssss
|
||||
sig_in=sssis
|
||||
sig_out=
|
||||
param_3_default="@DEFAULT@"
|
||||
param_3_default=-1
|
||||
param_4_default="@DEFAULT@"
|
||||
doc=Change a parameter
|
||||
doc_param_0=name: Name of the parameter to change
|
||||
doc_param_1=value: New Value of the parameter
|
||||
doc_param_2=category: Category of the parameter to change
|
||||
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
|
||||
|
||||
[getParamA]
|
||||
type=method
|
||||
|
|
|
|||
|
|
@ -414,10 +414,10 @@ class SAT(service.Service):
|
|||
|
||||
## Client management ##
|
||||
|
||||
def setParam(self, name, value, category, profile_key):
|
||||
def setParam(self, name, value, category, security_limit, profile_key):
|
||||
"""set wanted paramater and notice observers"""
|
||||
info(_("setting param: %(name)s=%(value)s in category %(category)s") % {'name': name, 'value': value, 'category': category})
|
||||
self.memory.setParam(name, value, category, profile_key)
|
||||
self.memory.setParam(name, value, category, security_limit, profile_key)
|
||||
|
||||
def isConnected(self, profile_key):
|
||||
"""Return connection status of profile
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -117,9 +117,12 @@ class MiscAccount(object):
|
|||
def _profileRegistered(self, result, email, password, profile):
|
||||
|
||||
#FIXME: values must be in a config file instead of hardcoded
|
||||
self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile)
|
||||
self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER, "Connection", profile)
|
||||
self.host.memory.setParam("Password", password, "Connection", profile)
|
||||
self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE),
|
||||
"Connection", profile_key=profile)
|
||||
self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER,
|
||||
"Connection", profile_key=profile)
|
||||
self.host.memory.setParam("Password", password,
|
||||
"Connection", profile_key=profile)
|
||||
#and the account
|
||||
|
||||
#XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
|
||||
|
|
|
|||
|
|
@ -798,9 +798,12 @@ class XEP_0065_handler(XMPPHandler):
|
|||
if len(streamhost_elts) != 1:
|
||||
warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one"))
|
||||
streamhost_elt = streamhost_elts[0]
|
||||
proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""), "File Transfer", self.parent.profile)
|
||||
proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""), "File Transfer", self.parent.profile)
|
||||
proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""), "File Transfer", self.parent.profile)
|
||||
proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""),
|
||||
"File Transfer", profile_key=self.parent.profile)
|
||||
proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""),
|
||||
"File Transfer", profile_key=self.parent.profile)
|
||||
proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""),
|
||||
"File Transfer", profile_key=self.parent.profile)
|
||||
|
||||
def connectionInitialized(self):
|
||||
def after_init(ignore):
|
||||
|
|
|
|||
Loading…
Reference in a new issue