From 2bf3694fd0efa855d82d1cd2d642a03c38a36b29 Mon Sep 17 00:00:00 2001 From: souliane Date: Sat, 7 Sep 2013 02:03:17 +0200 Subject: [PATCH] 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) --- frontends/src/bridge/DBus.py | 4 +-- frontends/src/primitivus/primitivus | 3 +-- frontends/src/primitivus/profile_manager.py | 6 ++--- frontends/src/primitivus/xmlui.py | 4 ++- frontends/src/wix/main_window.py | 3 +-- frontends/src/wix/param.py | 4 +-- frontends/src/wix/profile_manager.py | 6 ++--- src/bridge/DBus.py | 6 ++--- .../bridge_constructor/bridge_template.ini | 8 +++--- src/core/sat_main.py | 4 +-- src/memory/memory.py | 27 +++++++++++++------ src/plugins/plugin_misc_account.py | 9 ++++--- src/plugins/plugin_xep_0065.py | 9 ++++--- 13 files changed, 56 insertions(+), 37 deletions(-) diff --git a/frontends/src/bridge/DBus.py b/frontends/src/bridge/DBus.py index 25d018c7..529052d0 100644 --- a/frontends/src/bridge/DBus.py +++ b/frontends/src/bridge/DBus.py @@ -199,8 +199,8 @@ class DBusBridgeFrontend(BridgeFrontend): def sendMessage(self, to_jid, message, subject='', mess_type="auto", options={}, profile_key="@NONE@"): return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, options, profile_key) - def setParam(self, name, value, category, profile_key="@DEFAULT@"): - return self.db_core_iface.setParam(name, value, category, profile_key) + def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"): + return self.db_core_iface.setParam(name, value, category, security_limit, profile_key) def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): return self.db_core_iface.setPresence(to_jid, show, priority, statuses, profile_key) diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index ca2c6343..5a69e438 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -525,8 +525,7 @@ class PrimitivusApp(QuickApp): self.addWindow(XMLUI(self,xml_data=params)) def failure(error): self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters"), ok_cb=self.removePopUp)) - security_limit = -1 - self.bridge.getParamsUI(security_limit, self.profile, callback=success, errback=failure) + self.bridge.getParamsUI(profile_key=self.profile, callback=success, errback=failure) def onExitRequest(self, menu): diff --git a/frontends/src/primitivus/profile_manager.py b/frontends/src/primitivus/profile_manager.py index e777c346..2e8ebee1 100644 --- a/frontends/src/primitivus/profile_manager.py +++ b/frontends/src/primitivus/profile_manager.py @@ -141,10 +141,10 @@ class ProfileManager(urwid.WidgetWrap): new_pass = self.pass_wid.get_edit_text() if old_jid != new_jid: - self.host.bridge.setParam("JabberID", new_jid, "Connection", profile) - self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile) + self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) + self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile) if old_pass != new_pass: - self.host.bridge.setParam("Password", new_pass, "Connection", profile) + self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile) self.host.plug_profile(profile) def getParamError(self, ignore): diff --git a/frontends/src/primitivus/xmlui.py b/frontends/src/primitivus/xmlui.py index 4e8af91c..551143c2 100644 --- a/frontends/src/primitivus/xmlui.py +++ b/frontends/src/primitivus/xmlui.py @@ -34,6 +34,7 @@ def getText(node): data.append(child.wholeText) return u"".join(data) + class Pairs(urwid.WidgetWrap): def __init__(self, weight_0='1', weight_1='1'): @@ -274,5 +275,6 @@ class XMLUI(urwid.WidgetWrap): value = "true" if ctrl.get_state() else "false" else: value = ctrl.get_edit_text() - self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, profile_key = self.host.profile) + self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, + profile_key=self.host.profile) self.host.removeWindow() diff --git a/frontends/src/wix/main_window.py b/frontends/src/wix/main_window.py index a20454ae..d0630261 100644 --- a/frontends/src/wix/main_window.py +++ b/frontends/src/wix/main_window.py @@ -363,8 +363,7 @@ class MainWindow(wx.Frame, QuickApp): def onParam(self, e): debug(_("Param request")) - #security_limit = -1 - #xmlui = self.bridge.getParamsUI(security_limit, profile_key=self.profile) + #xmlui = self.bridge.getParamsUI(profile_key=self.profile) #XMLUI(self, xml_data = xmlui) param=Param(self) diff --git a/frontends/src/wix/param.py b/frontends/src/wix/param.py index 06d0b4c6..263747d5 100644 --- a/frontends/src/wix/param.py +++ b/frontends/src/wix/param.py @@ -103,7 +103,6 @@ class Param(wx.Frame): cat_dom.unlink() self.host.bridge.getParamsForCategory(category, - security_limit=-1, profile_key=self.host.profile, callback=gotParams, errback=errorGettingParams) @@ -137,7 +136,8 @@ class Param(wx.Frame): def __save_parameters(self): for param in self.modified: - self.host.bridge.setParam(param[0], self.modified[param], param[1], profile_key = self.host.profile) + self.host.bridge.setParam(param[0], self.modified[param], param[1], + profile_key=self.host.profile) self.modified.clear() def onClose(self, event): diff --git a/frontends/src/wix/profile_manager.py b/frontends/src/wix/profile_manager.py index 1c0728a0..e2063af2 100644 --- a/frontends/src/wix/profile_manager.py +++ b/frontends/src/wix/profile_manager.py @@ -145,11 +145,11 @@ class ProfileManager(wx.Panel): new_pass = self.login_pass.GetValue() if old_jid != new_jid: debug(_('Saving new JID and server')) - self.host.bridge.setParam("JabberID", new_jid, "Connection", profile) - self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile) + self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) + self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile) if old_pass != new_pass: debug(_('Saving new password')) - self.host.bridge.setParam("Password", new_pass, "Connection", profile) + self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile) self.host.plug_profile(profile) diff --git a/src/bridge/DBus.py b/src/bridge/DBus.py index 04996b3d..715a7895 100755 --- a/src/bridge/DBus.py +++ b/src/bridge/DBus.py @@ -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='', diff --git a/src/bridge/bridge_constructor/bridge_template.ini b/src/bridge/bridge_constructor/bridge_template.ini index 02b62d98..b6066c7f 100644 --- a/src/bridge/bridge_constructor/bridge_template.ini +++ b/src/bridge/bridge_constructor/bridge_template.ini @@ -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 diff --git a/src/core/sat_main.py b/src/core/sat_main.py index bd29ce9e..695af817 100644 --- a/src/core/sat_main.py +++ b/src/core/sat_main.py @@ -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 diff --git a/src/memory/memory.py b/src/memory/memory.py index 37d4c9ff..e2ae59c6 100644 --- a/src/memory/memory.py +++ b/src/memory/memory.py @@ -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) diff --git a/src/plugins/plugin_misc_account.py b/src/plugins/plugin_misc_account.py index eee681a3..bde056f2 100755 --- a/src/plugins/plugin_misc_account.py +++ b/src/plugins/plugin_misc_account.py @@ -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 diff --git a/src/plugins/plugin_xep_0065.py b/src/plugins/plugin_xep_0065.py index d5e9acb6..05a55c95 100755 --- a/src/plugins/plugin_xep_0065.py +++ b/src/plugins/plugin_xep_0065.py @@ -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):