Changeset

4238:05f991b4a90e

Merge 0.8->trunk
author Matthew Wild <mwild1@gmail.com>
date Tue, 05 Apr 2011 13:26:43 +0100
parents 4226:decfa487e1e8 (current diff) 4237:6b0d7d94eb7f (diff)
children 4243:8973653feb35
files plugins/mod_dialback.lua tools/migration/main.lua
diffstat 11 files changed, 169 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/core/sessionmanager.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/core/sessionmanager.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -108,16 +108,23 @@
 	
 	-- 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);
--- a/core/usermanager.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/core/usermanager.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -96,6 +96,8 @@
 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 "*";
--- a/net/httpserver.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/net/httpserver.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -136,7 +136,6 @@
 			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
--- a/plugins/mod_dialback.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/plugins/mod_dialback.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -12,7 +12,6 @@
 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 @@
 		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
--- a/plugins/mod_privacy.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/plugins/mod_privacy.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -45,28 +45,6 @@
 	end
 end
 
-function sendUnavailable(origin, to, from)
---[[ example unavailable presence stanza
-<presence from="node@host/resource" type="unavailable" to="node@host" >
-	<status>Logged out</status>
-</presence>
-]]--
-	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
@@ -123,7 +101,7 @@
 	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
@@ -323,7 +301,6 @@
 		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
@@ -414,7 +391,6 @@
 		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
--- a/prosody.cfg.lua.dist	Fri Mar 18 10:33:38 2011 +0000
+++ b/prosody.cfg.lua.dist	Tue Apr 05 13:26:43 2011 +0100
@@ -99,6 +99,15 @@
 --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
--- a/tools/migration/Makefile	Fri Mar 18 10:33:38 2011 +0000
+++ b/tools/migration/Makefile	Tue Apr 05 13:26:43 2011 +0100
@@ -14,7 +14,7 @@
 
 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 @@
 	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)';|;" \
--- a/tools/migration/main.lua	Fri Mar 18 10:33:38 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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
-
--- a/tools/migration/migrator/prosody_sql.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/tools/migration/migrator/prosody_sql.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -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 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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/migration/prosody-migrator.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -0,0 +1,124 @@
+#!/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
+
+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");
+	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
+
--- a/util/dependencies.lua	Fri Mar 18 10:33:38 2011 +0000
+++ b/util/dependencies.lua	Tue Apr 05 13:26:43 2011 +0100
@@ -35,6 +35,19 @@
 	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;