From 42f63b21d79733a2198952245df0673434bd31d2 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 23 May 2010 23:55:01 +0500 Subject: util.datamanager: Return an error string when failing to save. --- util/datamanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index 9d96e5b3..57cd2594 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -145,7 +145,7 @@ function store(username, host, datastore, data) local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+"); if not f then log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); - return; + return nil, "Error saving to storage"; end f:write("return "); append(f, data); -- cgit v1.2.3 From 1ee72fdb1161361d653bead96ea4fb140e9054cc Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 24 May 2010 00:04:22 +0500 Subject: mod_presence: Removed a useless check when handling incoming presence probes and subscriptions. --- plugins/mod_presence.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 535e65d7..255faecc 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -227,10 +227,6 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b stanza.attr.from, stanza.attr.to = from_bare, to_bare; log("debug", "inbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); - if not node then - log("debug", "dropping presence sent to host or invalid address '%s'", tostring(to_bare)); - end - if stanza.attr.type == "probe" then if rostermanager.is_contact_subscribed(node, host, from_bare) then if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then -- cgit v1.2.3 From 054a2d38c1ab12bf6bda2c22b775a91b9fb4dd4a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 24 May 2010 00:29:45 +0500 Subject: rostermanager: Mark rosters which fail to load as broken, and never save them. --- core/rostermanager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/rostermanager.lua b/core/rostermanager.lua index a3315245..285cf4f6 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -96,7 +96,7 @@ function load_roster(username, host) local data, err = datamanager.load(username, host, "roster"); roster = data or {}; if user then user.roster = roster; end - if not roster[false] then roster[false] = { }; end + if not roster[false] then roster[false] = { broken = err or nil }; end if roster[jid] then roster[jid] = nil; log("warn", "roster for "..jid.." has a self-contact"); @@ -125,6 +125,7 @@ function save_roster(username, host, roster) if metadata.version ~= true then metadata.version = (metadata.version or 0) + 1; end + if roster[false].broken then return nil, "Not saving broken roster" end return datamanager.store(username, host, "roster", roster); end log("warn", "save_roster: user had no roster to save"); -- cgit v1.2.3 From e1b4298fde007769a41c0a97fbfcc2f44bb383f9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 24 May 2010 00:35:08 +0500 Subject: rostermanager: Return an error string when subscription test fails due to an error. --- core/rostermanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 285cf4f6..506cf205 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -191,9 +191,9 @@ function process_inbound_unsubscribe(username, host, jid) end function is_contact_subscribed(username, host, jid) - local roster = load_roster(username, host); + local roster, err = load_roster(username, host); local item = roster[jid]; - return item and (item.subscription == "from" or item.subscription == "both"); + return item and (item.subscription == "from" or item.subscription == "both"), err; end function is_contact_pending_in(username, host, jid) -- cgit v1.2.3 From 6523b2bbe5e7ae92e241e10c587acbb61ec8eb77 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 24 May 2010 00:37:15 +0500 Subject: mod_presence: Don't send 'unsubscribed' in response to probes when roster loading fails. --- plugins/mod_presence.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 255faecc..9071ae4c 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -228,11 +228,12 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b log("debug", "inbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); if stanza.attr.type == "probe" then - if rostermanager.is_contact_subscribed(node, host, from_bare) then + local result, err = rostermanager.is_contact_subscribed(node, host, from_bare); + if result then if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end - else + elseif not err then core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); end elseif stanza.attr.type == "subscribe" then -- cgit v1.2.3 From 4353f95a958a306dfb990d84abe7a922ece80126 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 24 May 2010 00:49:12 +0500 Subject: usermanager: Take datamanager errors into account when determining account existance. --- core/usermanager.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/usermanager.lua b/core/usermanager.lua index 42e49d38..698d2f10 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -69,7 +69,8 @@ end function user_exists(username, host) if not(require_provisioning) and is_cyrus(host) then return true; end - return datamanager.load(username, host, "accounts") ~= nil; -- FIXME also check for empty credentials + local account, err = datamanager.load(username, host, "accounts"); + return (account or err) ~= nil; -- FIXME also check for empty credentials end function create_user(username, password, host) -- cgit v1.2.3 From c918263d056fa6c099bbc704d8e0a17b24d546d7 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 24 May 2010 01:00:30 +0500 Subject: mod_private: Detect datamanager read errors, and respond with 'internal-server-error'. --- plugins/mod_private.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mod_private.lua b/plugins/mod_private.lua index 859bf45a..abf1ec03 100644 --- a/plugins/mod_private.lua +++ b/plugins/mod_private.lua @@ -26,7 +26,11 @@ module:add_iq_handler("c2s", "jabber:iq:private", if #query.tags == 1 then local tag = query.tags[1]; local key = tag.name..":"..tag.attr.xmlns; - local data = datamanager.load(node, host, "private"); + local data, err = datamanager.load(node, host, "private"); + if err then + session.send(st.error_reply(stanza, "wait", "internal-server-error")); + return true; + end if stanza.attr.type == "get" then if data and data[key] then session.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key]))); -- cgit v1.2.3