From 67e210a28a89dd605bc50ceaeef37958268f8fed Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 21 Mar 2011 19:32:51 +0000 Subject: mod_dialback: Use session:close() on dialback failure instead of s2smanager.destroy_session() (thanks Zash) --- plugins/mod_dialback.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua index e1fd5a42..8c80dce6 100644 --- a/plugins/mod_dialback.lua +++ b/plugins/mod_dialback.lua @@ -12,7 +12,6 @@ local send_s2s = require "core.s2smanager".send_to_host; local s2s_make_authenticated = require "core.s2smanager".make_authenticated; local s2s_initiate_dialback = require "core.s2smanager".initiate_dialback; local s2s_verify_dialback = require "core.s2smanager".verify_dialback; -local s2s_destroy_session = require "core.s2smanager".destroy_session; local log = module._log; @@ -126,7 +125,7 @@ module:hook("stanza/jabber:server:dialback:result", function(event) if stanza.attr.type == "valid" then s2s_make_authenticated(origin, attr.from); else - s2s_destroy_session(origin) + origin:close("not-authorized", "dialback authentication failed"); end return true; end -- cgit v1.2.3 From b94b9eba5ea54ee73b13c6266f071db9ad685a7d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 21 Mar 2011 19:35:53 +0000 Subject: net.httpserver: Revert commit eccd3c87d717 which has since been fixed in a better way --- net/httpserver.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index e0fd3f86..74f61c56 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -136,7 +136,6 @@ local function request_reader(request, data, startpos) call_callback(request); end local function error_cb(r) - log("error", "Error in HTTP server handler: %s", r or "connection-closed"); call_callback(request, r or "connection-closed"); destroy_request(request); end -- cgit v1.2.3 From 1f049ed80d3a07636a207b859cc236e3d39eb4f1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 21 Mar 2011 19:39:04 +0000 Subject: tools/migration: Rename main.lua -> prosody-migrator.lua and update the Makefile --- tools/migration/Makefile | 6 +- tools/migration/main.lua | 115 ----------------------------------- tools/migration/prosody-migrator.lua | 115 +++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 118 deletions(-) delete mode 100644 tools/migration/main.lua create mode 100644 tools/migration/prosody-migrator.lua diff --git a/tools/migration/Makefile b/tools/migration/Makefile index adceafd4..5998a5f7 100644 --- a/tools/migration/Makefile +++ b/tools/migration/Makefile @@ -14,7 +14,7 @@ INSTALLEDDATA = $(DATADIR) SOURCE_FILES = migrator/*.lua -all: prosody-migrator.install migrator.cfg.lua.install main.lua $(SOURCE_FILES) +all: prosody-migrator.install migrator.cfg.lua.install prosody-migrator.lua $(SOURCE_FILES) install: prosody-migrator.install migrator.cfg.lua.install install -d $(BIN) $(CONFIG) $(SOURCE) $(SOURCE)/migrator @@ -28,10 +28,10 @@ clean: rm -f prosody-migrator.install rm -f migrator.cfg.lua.install -prosody-migrator.install: main.lua +prosody-migrator.install: prosody-migrator.lua sed "s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \ s|^CFG_CONFIGDIR=.*;$$|CFG_CONFIGDIR='$(INSTALLEDCONFIG)';|;" \ - < main.lua > prosody-migrator.install + < prosody-migrator.lua > prosody-migrator.install migrator.cfg.lua.install: migrator.cfg.lua sed "s|^local data_path = .*;$$|local data_path = '$(INSTALLEDDATA)';|;" \ diff --git a/tools/migration/main.lua b/tools/migration/main.lua deleted file mode 100644 index 82eeab9d..00000000 --- a/tools/migration/main.lua +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env lua - -CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); -CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); - -local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua"; - --- Command-line parsing -local options = {}; -local handled_opts = 0; -for i = 1, #arg do - if arg[i]:sub(1,2) == "--" then - local opt, val = arg[i]:match("([%w-]+)=?(.*)"); - if opt then - options[(opt:sub(3):gsub("%-", "_"))] = #val > 0 and val or true; - end - handled_opts = i; - else - break; - end -end -table.remove(arg, handled_opts); - --- Load config file -local function loadfilein(file, env) - if loadin then - return loadin(env, io.open(file):read("*a")); - else - local chunk, err = loadfile(file); - if chunk then - setfenv(chunk, env); - end - return chunk, err; - end -end - -local config_file = options.config or default_config; -local from_store = arg[1] or "input"; -local to_store = arg[2] or "output"; - -config = {}; -local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end }); -local config_chunk, err = loadfilein(config_file, config_env); -if not config_chunk then - print("There was an error loading the config file, check the file exists"); - print("and that the syntax is correct:"); - print("", err); - os.exit(1); -end - -config_chunk(); - -if CFG_SOURCEDIR then - package.path = CFG_SOURCEDIR.."/?.lua;"..package.path; - package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath; -elseif not package.loaded["util.json"] then - package.path = "../../?.lua;"..package.path - package.cpath = "../../?.so;"..package.cpath -end - -local have_err; -if #arg > 0 and #arg ~= 2 then - have_err = true; - print("Error: Incorrect number of parameters supplied."); -end -if not config[from_store] then - have_err = true; - print("Error: Input store '"..from_store.."' not found in the config file."); -end -if not config[to_store] then - have_err = true; - print("Error: Output store '"..to_store.."' not found in the config file."); -end -if not config[from_store].type then - have_err = true; - print("Error: Input store type not specified in the config file"); -elseif not pcall(require, "migrator."..config[from_store].type) then - have_err = true; - print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); -end -if not config[to_store].type then - have_err = true; - print("Error: Output store type not specified in the config file"); -elseif not pcall(require, "migrator."..config[to_store].type) then - have_err = true; - print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); -end - -if have_err then - print(""); - print("Usage: "..arg[0].." FROM_STORE TO_STORE"); - print("If no stores are specified, 'input' and 'output' are used."); - print(""); - print("The available stores in your migrator config are:"); - print(""); - for store in pairs(config) do - print("", store); - end - print(""); - os.exit(1); -end - -local itype = config[from_store].type; -local otype = config[to_store].type; -local reader = require("migrator."..itype).reader(config[from_store]); -local writer = require("migrator."..otype).writer(config[to_store]); - -local json = require "util.json"; - -for x in reader do - --print(json.encode(x)) - writer(x); -end -writer(nil); -- close - diff --git a/tools/migration/prosody-migrator.lua b/tools/migration/prosody-migrator.lua new file mode 100644 index 00000000..82eeab9d --- /dev/null +++ b/tools/migration/prosody-migrator.lua @@ -0,0 +1,115 @@ +#!/usr/bin/env lua + +CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); +CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); + +local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua"; + +-- Command-line parsing +local options = {}; +local handled_opts = 0; +for i = 1, #arg do + if arg[i]:sub(1,2) == "--" then + local opt, val = arg[i]:match("([%w-]+)=?(.*)"); + if opt then + options[(opt:sub(3):gsub("%-", "_"))] = #val > 0 and val or true; + end + handled_opts = i; + else + break; + end +end +table.remove(arg, handled_opts); + +-- Load config file +local function loadfilein(file, env) + if loadin then + return loadin(env, io.open(file):read("*a")); + else + local chunk, err = loadfile(file); + if chunk then + setfenv(chunk, env); + end + return chunk, err; + end +end + +local config_file = options.config or default_config; +local from_store = arg[1] or "input"; +local to_store = arg[2] or "output"; + +config = {}; +local config_env = setmetatable({}, { __index = function(t, k) return function(tbl) config[k] = tbl; end; end }); +local config_chunk, err = loadfilein(config_file, config_env); +if not config_chunk then + print("There was an error loading the config file, check the file exists"); + print("and that the syntax is correct:"); + print("", err); + os.exit(1); +end + +config_chunk(); + +if CFG_SOURCEDIR then + package.path = CFG_SOURCEDIR.."/?.lua;"..package.path; + package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath; +elseif not package.loaded["util.json"] then + package.path = "../../?.lua;"..package.path + package.cpath = "../../?.so;"..package.cpath +end + +local have_err; +if #arg > 0 and #arg ~= 2 then + have_err = true; + print("Error: Incorrect number of parameters supplied."); +end +if not config[from_store] then + have_err = true; + print("Error: Input store '"..from_store.."' not found in the config file."); +end +if not config[to_store] then + have_err = true; + print("Error: Output store '"..to_store.."' not found in the config file."); +end +if not config[from_store].type then + have_err = true; + print("Error: Input store type not specified in the config file"); +elseif not pcall(require, "migrator."..config[from_store].type) then + have_err = true; + print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); +end +if not config[to_store].type then + have_err = true; + print("Error: Output store type not specified in the config file"); +elseif not pcall(require, "migrator."..config[to_store].type) then + have_err = true; + print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); +end + +if have_err then + print(""); + print("Usage: "..arg[0].." FROM_STORE TO_STORE"); + print("If no stores are specified, 'input' and 'output' are used."); + print(""); + print("The available stores in your migrator config are:"); + print(""); + for store in pairs(config) do + print("", store); + end + print(""); + os.exit(1); +end + +local itype = config[from_store].type; +local otype = config[to_store].type; +local reader = require("migrator."..itype).reader(config[from_store]); +local writer = require("migrator."..otype).writer(config[to_store]); + +local json = require "util.json"; + +for x in reader do + --print(json.encode(x)) + writer(x); +end +writer(nil); -- close + -- cgit v1.2.3 From 4e83c7ddd66031d6a67d7c8cfda36f7b514ac1b6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 29 Mar 2011 14:10:00 +0100 Subject: sessionmanager: Fire pre-resource-unbind to allow plugins (such as mod_smacks) to hook and prevent/override session destruction --- core/sessionmanager.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index d36591bf..426763f5 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -108,16 +108,23 @@ function destroy_session(session, err) -- Remove session/resource from user's session list if session.full_jid then - hosts[session.host].sessions[session.username].sessions[session.resource] = nil; + local host_session = hosts[session.host]; + + -- Allow plugins to prevent session destruction + if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then + return; + end + + host_session.sessions[session.username].sessions[session.resource] = nil; full_sessions[session.full_jid] = nil; - if not next(hosts[session.host].sessions[session.username].sessions) then + if not next(host_session.sessions[session.username].sessions) then log("debug", "All resources of %s are now offline", session.username); - hosts[session.host].sessions[session.username] = nil; + host_session.sessions[session.username] = nil; bare_sessions[session.username..'@'..session.host] = nil; end - hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err}); + host_session.events.fire_event("resource-unbind", {session=session, error=err}); end retire_session(session); -- cgit v1.2.3 From 2fb6fd3f3878fa5ff18fe6acdd3ac0a9885ba27f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 29 Mar 2011 14:57:50 +0100 Subject: mod_privacy: Remove unused function, sendUnavailable --- plugins/mod_privacy.lua | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/plugins/mod_privacy.lua b/plugins/mod_privacy.lua index d5842e26..18d7b703 100644 --- a/plugins/mod_privacy.lua +++ b/plugins/mod_privacy.lua @@ -45,28 +45,6 @@ function isAnotherSessionUsingDefaultList(origin) end end -function sendUnavailable(origin, to, from) ---[[ example unavailable presence stanza - - Logged out - -]]-- - local presence = st.presence({from=from, type="unavailable"}); - presence:tag("status"):text("Logged out"); - - local node, host = jid_bare(to); - local bare = node .. "@" .. host; - - local user = bare_sessions[bare]; - if user then - for resource, session in pairs(user.sessions) do - presence.attr.to = session.full_jid; - module:log("debug", "send unavailable to: %s; from: %s", tostring(presence.attr.to), tostring(presence.attr.from)); - origin.send(presence); - end - end -end - function declineList(privacy_lists, origin, stanza, which) if which == "default" then if isAnotherSessionUsingDefaultList(origin) then -- cgit v1.2.3 From 662e978e43b939dd737adff80121c1f482d9eef0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 29 Mar 2011 15:07:14 +0100 Subject: mod_privacy: Remove several unused variable declarations --- plugins/mod_privacy.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/mod_privacy.lua b/plugins/mod_privacy.lua index 18d7b703..2d696154 100644 --- a/plugins/mod_privacy.lua +++ b/plugins/mod_privacy.lua @@ -101,7 +101,7 @@ function deleteList(privacy_lists, origin, stanza, name) return {"modify", "bad-request", "Not existing list specifed to be deleted."}; end -function createOrReplaceList (privacy_lists, origin, stanza, name, entries, roster) +function createOrReplaceList (privacy_lists, origin, stanza, name, entries) local bare_jid = origin.username.."@"..origin.host; if privacy_lists.lists == nil then @@ -301,7 +301,6 @@ function checkIfNeedToBeBlocked(e, session) return; -- from one of a user's resource to another => HANDS OFF! end - local item; local listname = session.activePrivacyList; if listname == nil then listname = privacy_lists.default; -- no active list selected, use default list @@ -392,7 +391,6 @@ function preCheckIncoming(e) end if resource == nil then local prio = 0; - local session_; if bare_sessions[node.."@"..host] ~= nil then for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do if session_.priority ~= nil and session_.priority > prio then -- cgit v1.2.3 From dddc15e0d925ced049794b46f5132ad68e7bf7ae Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 Apr 2011 12:36:56 +0100 Subject: prosody.cfg.lua.dist: Add example of 'authentication' option --- prosody.cfg.lua.dist | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist index d1bd7d67..e513b116 100644 --- a/prosody.cfg.lua.dist +++ b/prosody.cfg.lua.dist @@ -99,6 +99,15 @@ ssl = { --c2s_require_encryption = false --s2s_require_encryption = false +-- Select the authentication backend to use. The 'internal' providers +-- use Prosody's configured data storage to store the authentication data. +-- To allow Prosody to offer secure authentication mechanisms to clients, the +-- default provider stores passwords in plaintext. If you do not trust your +-- server please see http://prosody.im/doc/modules/mod_auth_internal_hashed +-- for information about using the hashed backend. + +authentication = "internal_plain" + -- Select the storage backend to use. By default Prosody uses flat files -- in its configured data directory, but it also supports more backends -- through modules. An "sql" backend is included by default, but requires -- cgit v1.2.3 From cef7f598c03ede6a08a39720c861047d7ebf904d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 Apr 2011 12:58:14 +0100 Subject: tools/migration/migrator/prosody_sql: Throw a friendlier error when LuaDBI is not found --- tools/migration/migrator/prosody_sql.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/migration/migrator/prosody_sql.lua b/tools/migration/migrator/prosody_sql.lua index 3a9172ff..b1f836be 100644 --- a/tools/migration/migrator/prosody_sql.lua +++ b/tools/migration/migrator/prosody_sql.lua @@ -1,6 +1,6 @@ local assert = assert; -local DBI = require "DBI"; +local have_DBI, DBI = pcall(require,"DBI"); local print = print; local type = type; local next = next; @@ -11,6 +11,10 @@ local mtools = require "migrator.mtools"; local tostring = tostring; local tonumber = tonumber; +if not have_DBI then + error("LuaDBI (required for SQL support) was not found, please see http://prosody.im/doc/depends#luadbi", 0); +end + module "prosody_sql" local function create_table(connection, params) -- cgit v1.2.3 From 0e4599d1b5f5adec0105017c7fd0b63d63a132da Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 Apr 2011 12:59:24 +0100 Subject: tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors they throw --- tools/migration/prosody-migrator.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tools/migration/prosody-migrator.lua b/tools/migration/prosody-migrator.lua index 82eeab9d..20631fb1 100644 --- a/tools/migration/prosody-migrator.lua +++ b/tools/migration/prosody-migrator.lua @@ -71,21 +71,30 @@ if not config[to_store] then have_err = true; print("Error: Output store '"..to_store.."' not found in the config file."); end -if not config[from_store].type then - have_err = true; - print("Error: Input store type not specified in the config file"); -elseif not pcall(require, "migrator."..config[from_store].type) then - have_err = true; - print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); -end -if not config[to_store].type then - have_err = true; - print("Error: Output store type not specified in the config file"); -elseif not pcall(require, "migrator."..config[to_store].type) then - have_err = true; - print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); + +function load_store_handler(name) + local store_type = config[name].type; + if not store_type then + print("Error: "..name.." store type not specified in the config file"); + return false; + else + local ok, err = pcall(require, "migrator."..store_type); + if not ok then + if package.loaded["migrator."..store_type] then + print(("Error: Failed to initialize '%s' store:\n\t%s") + :format(name, err)); + else + print(("Error: Unrecognised store type for '%s': %s") + :format(from_store, store_type)); + end + return false; + end + end + return true; end +have_err = have_err or not(load_store_handler(from_store, "input") and load_store_handler(to_store, "output")); + if have_err then print(""); print("Usage: "..arg[0].." FROM_STORE TO_STORE"); -- cgit v1.2.3 From ebb9c9d5859f51592930c012d1da82b1dd294b5c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 Apr 2011 13:20:09 +0100 Subject: util.dependencies: Add a dummy util.ztact loader to log a message for people still using it (e.g. in their Debian-derived config files) --- util/dependencies.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/util/dependencies.lua b/util/dependencies.lua index 9371521c..5baea942 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -35,6 +35,19 @@ function missingdep(name, sources, msg) print(""); end +-- COMPAT w/pre-0.8 Debian: The Debian config file used to use +-- util.ztact, which has been removed from Prosody in 0.8. This +-- is to log an error for people who still use it, so they can +-- update their configs. +package.preload["util.ztact"] = function () + if not package.loaded["core.loggingmanager"] then + error("util.ztact has been removed from Prosody and you need to fix your config " + .."file. More information can be found at http://prosody.im/doc/packagers#ztact", 0); + else + error("module 'util.ztact' has been deprecated in Prosody 0.8."); + end +end; + function check_dependencies() local fatal; -- cgit v1.2.3 From ca74173a8221e9cd93db30c7bb89c8b181f8b60b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 Apr 2011 13:26:19 +0100 Subject: usermanager: Check host exists before trying to look up admins for it --- core/usermanager.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/usermanager.lua b/core/usermanager.lua index 5e2e41fc..0152afd7 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -96,6 +96,8 @@ function get_provider(host) end function is_admin(jid, host) + if host and not hosts[host] then return false; end + local is_admin; jid = jid_bare(jid); host = host or "*"; -- cgit v1.2.3