plugins/mod_saslauth.lua
author Jeff Mitchell <jeff@jefferai.org>
Fri, 28 May 2010 14:47:32 -0400
changeset 3167 546695e80e0a
parent 3164 db9def53fe9c
child 3178 46f5ed897beb
permissions -rw-r--r--
Correct out of order logic in mod_hashpassauth Make saslauth check the existence of the get_password and test_password functions to determine which authentication profile to use.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 1486
diff changeset
     1
-- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2877
diff changeset
     2
-- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2877
diff changeset
     3
-- Copyright (C) 2008-2010 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 449
diff changeset
     4
-- 
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 724
diff changeset
     5
-- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 724
diff changeset
     6
-- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 449
diff changeset
     7
--
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 449
diff changeset
     8
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 449
diff changeset
     9
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
local st = require "util.stanza";
46
d6b3f9dbb624 Resource binding, XMPP sessions (whatever they're for...)
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
    12
local sm_bind_resource = require "core.sessionmanager".bind_resource;
1042
a3d77353c18a mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents: 938
diff changeset
    13
local sm_make_authenticated = require "core.sessionmanager".make_authenticated;
447
c0dae734d3bf Stopped using the lbase64 library
Waqas Hussain <waqas20@gmail.com>
parents: 438
diff changeset
    14
local base64 = require "util.encodings".base64;
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
1721
1dcfb2c64302 Use NODEprep for prepping usernames used during SASL logins.
Tobias Markmann <tm@ayena.de>
parents: 1523
diff changeset
    16
local nodeprep = require "util.encodings".stringprep.nodeprep;
1042
a3d77353c18a mod_*: Fix a load of global accesses
Matthew Wild <mwild1@gmail.com>
parents: 938
diff changeset
    17
local datamanager_load = require "util.datamanager".load;
3167
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
    18
local usermanager_get_provider = require "core.usermanager".get_provider;
1584
ffe8a9296e04 mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
Nick Thomas
parents: 1523
diff changeset
    19
local usermanager_get_supported_methods = require "core.usermanager".get_supported_methods;
1585
edc066730d11 Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents: 1584
diff changeset
    20
local usermanager_user_exists = require "core.usermanager".user_exists;
edc066730d11 Switch to using a more generic credentials_callback/handler for SASL auth.
nick@lupine.me.uk
parents: 1584
diff changeset
    21
local usermanager_get_password = require "core.usermanager".get_password;
3164
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    22
local usermanager_test_password = require "core.usermanager".test_password;
46
d6b3f9dbb624 Resource binding, XMPP sessions (whatever they're for...)
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
    23
local t_concat, t_insert = table.concat, table.insert;
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
local tostring = tostring;
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
    25
local jid_split = require "util.jid".split;
449
c0a4a1e63d70 Completely switched to new hashes library from the old md5 library
Waqas Hussain <waqas20@gmail.com>
parents: 447
diff changeset
    26
local md5 = require "util.hashes".md5;
887
eef21d7bbe04 mod_saslauth: Disable SASL ANONYMOUS unless explicitly enabled with sasl_anonymous = true
Matthew Wild <mwild1@gmail.com>
parents: 799
diff changeset
    27
local config = require "core.configmanager";
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
2415
eb383f58624b mod_saslauth: Use module:get_option()
Paul Aurich <paul@darkrain42.org>
parents: 2414
diff changeset
    29
local secure_auth_only = module:get_option("c2s_require_encryption") or module:get_option("require_encryption");
eb383f58624b mod_saslauth: Use module:get_option()
Paul Aurich <paul@darkrain42.org>
parents: 2414
diff changeset
    30
local sasl_backend = module:get_option("sasl_backend") or "builtin";
3066
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    31
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    32
-- Cyrus config options
3064
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
    33
local require_provisioning = module:get_option("cyrus_require_provisioning") or false;
3066
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    34
local cyrus_service_realm = module:get_option("cyrus_service_realm");
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    35
local cyrus_service_name = module:get_option("cyrus_service_name");
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    36
local cyrus_application_name = module:get_option("cyrus_application_name");
1216
fd8ce71bc72b mod_saslauth, mod_legacyauth: Deny logins to unsecure sessions when require_encryption config option is true
Matthew Wild <mwild1@gmail.com>
parents: 1186
diff changeset
    37
1071
216f9a9001f1 mod_saslauth: Use module logger instead of creating a new one
Matthew Wild <mwild1@gmail.com>
parents: 1042
diff changeset
    38
local log = module._log;
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    39
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    40
local xmlns_sasl ='urn:ietf:params:xml:ns:xmpp-sasl';
46
d6b3f9dbb624 Resource binding, XMPP sessions (whatever they're for...)
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
    41
local xmlns_bind ='urn:ietf:params:xml:ns:xmpp-bind';
d6b3f9dbb624 Resource binding, XMPP sessions (whatever they're for...)
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
    42
local xmlns_stanzas ='urn:ietf:params:xml:ns:xmpp-stanzas';
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    43
2642
333d7e2033b2 mod_saslauth: Warn and fallback gracefully when Cyrus SASL is requested, but missing.
Waqas Hussain <waqas20@gmail.com>
parents: 2634
diff changeset
    44
local new_sasl;
2928
e6380fcaffda mod_saslauth: Tidier code for SASL backend selection.
Waqas Hussain <waqas20@gmail.com>
parents: 2927
diff changeset
    45
if sasl_backend == "builtin" then
e6380fcaffda mod_saslauth: Tidier code for SASL backend selection.
Waqas Hussain <waqas20@gmail.com>
parents: 2927
diff changeset
    46
	new_sasl = require "util.sasl".new;
e6380fcaffda mod_saslauth: Tidier code for SASL backend selection.
Waqas Hussain <waqas20@gmail.com>
parents: 2927
diff changeset
    47
elseif sasl_backend == "cyrus" then
2724
3fcf1048a896 mod_saslauth: Add FIXME to remind myself to fix this as soon as I have time
Matthew Wild <mwild1@gmail.com>
parents: 2721
diff changeset
    48
	prosody.unlock_globals(); --FIXME: Figure out why this is needed and
3fcf1048a896 mod_saslauth: Add FIXME to remind myself to fix this as soon as I have time
Matthew Wild <mwild1@gmail.com>
parents: 2721
diff changeset
    49
	                          -- why cyrussasl isn't caught by the sandbox
2646
064efb684aff mod_saslauth: Correct syntax for gracefully handling a missing cyrussasl library
Matthew Wild <mwild1@gmail.com>
parents: 2642
diff changeset
    50
	local ok, cyrus = pcall(require, "util.sasl_cyrus");
2721
cf97b85c27b5 mod_saslauth: Unlock globals while loading cyrus
Matthew Wild <mwild1@gmail.com>
parents: 2647
diff changeset
    51
	prosody.lock_globals();
2646
064efb684aff mod_saslauth: Correct syntax for gracefully handling a missing cyrussasl library
Matthew Wild <mwild1@gmail.com>
parents: 2642
diff changeset
    52
	if ok then
2642
333d7e2033b2 mod_saslauth: Warn and fallback gracefully when Cyrus SASL is requested, but missing.
Waqas Hussain <waqas20@gmail.com>
parents: 2634
diff changeset
    53
		local cyrus_new = cyrus.new;
333d7e2033b2 mod_saslauth: Warn and fallback gracefully when Cyrus SASL is requested, but missing.
Waqas Hussain <waqas20@gmail.com>
parents: 2634
diff changeset
    54
		new_sasl = function(realm)
3066
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    55
			return cyrus_new(
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    56
				cyrus_service_realm or realm,
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    57
				cyrus_service_name or "xmpp",
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    58
				cyrus_application_name or "prosody"
5e5137057b5f mod_saslauth: Split out cyrus SASL config options into locals, and add support for cyrus_application_name (default: 'prosody')
Matthew Wild <mwild1@gmail.com>
parents: 3064
diff changeset
    59
			);
2642
333d7e2033b2 mod_saslauth: Warn and fallback gracefully when Cyrus SASL is requested, but missing.
Waqas Hussain <waqas20@gmail.com>
parents: 2634
diff changeset
    60
		end
333d7e2033b2 mod_saslauth: Warn and fallback gracefully when Cyrus SASL is requested, but missing.
Waqas Hussain <waqas20@gmail.com>
parents: 2634
diff changeset
    61
	else
2927
c041495f0546 mod_saslauth: Fail with an error when the requested SASL backend cannot be used.
Waqas Hussain <waqas20@gmail.com>
parents: 2925
diff changeset
    62
		module:log("error", "Failed to load Cyrus SASL because: %s", cyrus);
c041495f0546 mod_saslauth: Fail with an error when the requested SASL backend cannot be used.
Waqas Hussain <waqas20@gmail.com>
parents: 2925
diff changeset
    63
		error("Failed to load Cyrus SASL");
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
    64
	end
2928
e6380fcaffda mod_saslauth: Tidier code for SASL backend selection.
Waqas Hussain <waqas20@gmail.com>
parents: 2927
diff changeset
    65
else
e6380fcaffda mod_saslauth: Tidier code for SASL backend selection.
Waqas Hussain <waqas20@gmail.com>
parents: 2927
diff changeset
    66
	module:log("error", "Unknown SASL backend: %s", sasl_backend);
e6380fcaffda mod_saslauth: Tidier code for SASL backend selection.
Waqas Hussain <waqas20@gmail.com>
parents: 2927
diff changeset
    67
	error("Unknown SASL backend");
2390
4f8f9dfa22ac mod_saslauth: Add support for CyrusSASL.
Tobias Markmann <tm@ayena.de>
parents: 2388
diff changeset
    68
end
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    69
3167
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
    70
local getpass_authentication_profile = {
2179
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
    71
	plain = function(username, realm)
2450
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    72
		local prepped_username = nodeprep(username);
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    73
		if not prepped_username then
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    74
			log("debug", "NODEprep failed on username: %s", username);
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    75
			return "", nil;
2179
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
    76
		end
2450
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    77
		local password = usermanager_get_password(prepped_username, realm);
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    78
		if not password then
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    79
			return "", nil;
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    80
		end
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    81
		return password, true;
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    82
	end
2179
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
    83
};
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
    84
3167
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
    85
local testpass_authentication_profile = {
3164
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    86
	plain_test = 	function(username, password, realm)
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    87
			local prepped_username = nodeprep(username);
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    88
			if not prepped_username then
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    89
				log("debug", "NODEprep failed on username: %s", username);
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    90
				return "", nil;
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    91
			end
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    92
			return usermanager_test_password(prepped_username, password, realm), true;
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    93
			end
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    94
};
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
    95
2450
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    96
local anonymous_authentication_profile = {
2193
8fbbdb11a520 Merge with sasl branch.
Tobias Markmann <tm@ayena.de>
parents: 2014 2179
diff changeset
    97
	anonymous = function(username, realm)
2450
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    98
		return true; -- for normal usage you should always return true here
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
    99
	end
03bb0e6d87d5 mod_saslauth: Made some variables local to avoid unnecessary global access.
Waqas Hussain <waqas20@gmail.com>
parents: 2418
diff changeset
   100
};
38
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   101
292
33175ad2f682 Started using realm in password hashing, and added support for error message replies from sasl
Waqas Hussain <waqas20@gmail.com>
parents: 291
diff changeset
   102
local function build_reply(status, ret, err_msg)
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   103
	local reply = st.stanza(status, {xmlns = xmlns_sasl});
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   104
	if status == "challenge" then
2860
ad534f89c758 mod_saslauth: Don't print raw SASL data to avoid logging passwords unnecessarily
Matthew Wild <mwild1@gmail.com>
parents: 2014
diff changeset
   105
		--log("debug", "CHALLENGE: %s", ret or "");
293
b446de4e258e base64 encode the sasl responses
Waqas Hussain <waqas20@gmail.com>
parents: 292
diff changeset
   106
		reply:text(base64.encode(ret or ""));
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   107
	elseif status == "failure" then
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   108
		reply:tag(ret):up();
293
b446de4e258e base64 encode the sasl responses
Waqas Hussain <waqas20@gmail.com>
parents: 292
diff changeset
   109
		if err_msg then reply:tag("text"):text(err_msg); end
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   110
	elseif status == "success" then
2860
ad534f89c758 mod_saslauth: Don't print raw SASL data to avoid logging passwords unnecessarily
Matthew Wild <mwild1@gmail.com>
parents: 2014
diff changeset
   111
		--log("debug", "SUCCESS: %s", ret or "");
293
b446de4e258e base64 encode the sasl responses
Waqas Hussain <waqas20@gmail.com>
parents: 292
diff changeset
   112
		reply:text(base64.encode(ret or ""));
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   113
	else
1073
7c20373d4451 mod_saslauth: Remove 2 instances of raising errors and replacing with more graceful handling
Matthew Wild <mwild1@gmail.com>
parents: 1072
diff changeset
   114
		module:log("error", "Unknown sasl status: %s", status);
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   115
	end
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   116
	return reply;
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   117
end
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   118
3062
892c49869293 mod_saslauth: Add return value and error message to the Cyrus SASL handle_status callback
Matthew Wild <mwild1@gmail.com>
parents: 3061
diff changeset
   119
local function handle_status(session, status, ret, err_msg)
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   120
	if status == "failure" then
2251
18079ede5b62 mod_saslauth: Fix typo in variable name
Matthew Wild <mwild1@gmail.com>
parents: 2242
diff changeset
   121
		session.sasl_handler = session.sasl_handler:clean_clone();
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   122
	elseif status == "success" then
1846
fdb43fc1bafc mod_saslauth: Prep username used for authenticating a session
Matthew Wild <mwild1@gmail.com>
parents: 1721
diff changeset
   123
		local username = nodeprep(session.sasl_handler.username);
fdb43fc1bafc mod_saslauth: Prep username used for authenticating a session
Matthew Wild <mwild1@gmail.com>
parents: 1721
diff changeset
   124
		if not username then -- TODO move this to sessionmanager
1073
7c20373d4451 mod_saslauth: Remove 2 instances of raising errors and replacing with more graceful handling
Matthew Wild <mwild1@gmail.com>
parents: 1072
diff changeset
   125
			module:log("warn", "SASL succeeded but we didn't get a username!");
7c20373d4451 mod_saslauth: Remove 2 instances of raising errors and replacing with more graceful handling
Matthew Wild <mwild1@gmail.com>
parents: 1072
diff changeset
   126
			session.sasl_handler = nil;
7c20373d4451 mod_saslauth: Remove 2 instances of raising errors and replacing with more graceful handling
Matthew Wild <mwild1@gmail.com>
parents: 1072
diff changeset
   127
			session:reset_stream();
3062
892c49869293 mod_saslauth: Add return value and error message to the Cyrus SASL handle_status callback
Matthew Wild <mwild1@gmail.com>
parents: 3061
diff changeset
   128
			return status, ret, err_msg;
1584
ffe8a9296e04 mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
Nick Thomas
parents: 1523
diff changeset
   129
		end
3064
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   130
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   131
		if not(require_provisioning) or usermanager_user_exists(username, session.host) then
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   132
			sm_make_authenticated(session, session.sasl_handler.username);
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   133
			session.sasl_handler = nil;
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   134
			session:reset_stream();
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   135
		else
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   136
			module:log("warn", "SASL succeeded but we don't have an account provisioned for %s", username);
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   137
			session.sasl_handler = session.sasl_handler:clean_clone();
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   138
			return "failure", "not-authorized", "User authenticated successfully, but not provisioned for XMPP";
596303990c7c usermanager, mod_saslauth: Make account provisioning for Cyrus SASL optional (default: not required)
Matthew Wild <mwild1@gmail.com>
parents: 3062
diff changeset
   139
		end
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   140
	end
3062
892c49869293 mod_saslauth: Add return value and error message to the Cyrus SASL handle_status callback
Matthew Wild <mwild1@gmail.com>
parents: 3061
diff changeset
   141
	return status, ret, err_msg;
281
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   142
end
826308c07627 mod_saslauth updated for digest-md5
Waqas Hussain <waqas20@gmail.com>
parents: 120
diff changeset
   143
705
11afa1d88c55 mod_saslauth, mod_tls: minor code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 615
diff changeset
   144
local function sasl_handler(session, stanza)
295
bb078eb1f1de mod_saslauth: Code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 293
diff changeset
   145
	if stanza.name == "auth" then
bb078eb1f1de mod_saslauth: Code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 293
diff changeset
   146
		-- FIXME ignoring duplicates because ejabberd does
1186
078eb3b109e9 mod_saslauth: Fix logic error which prevented SASL ANONYMOUS from working
Matthew Wild <mwild1@gmail.com>
parents: 1073
diff changeset
   147
		if config.get(session.host or "*", "core", "anonymous_login") then
078eb3b109e9 mod_saslauth: Fix logic error which prevented SASL ANONYMOUS from working
Matthew Wild <mwild1@gmail.com>
parents: 1073
diff changeset
   148
			if stanza.attr.mechanism ~= "ANONYMOUS" then
078eb3b109e9 mod_saslauth: Fix logic error which prevented SASL ANONYMOUS from working
Matthew Wild <mwild1@gmail.com>
parents: 1073
diff changeset
   149
				return session.send(build_reply("failure", "invalid-mechanism"));
078eb3b109e9 mod_saslauth: Fix logic error which prevented SASL ANONYMOUS from working
Matthew Wild <mwild1@gmail.com>
parents: 1073
diff changeset
   150
			end
938
663f75dd7b42 Fixed: Some nil access bugs
Waqas Hussain <waqas20@gmail.com>
parents: 935
diff changeset
   151
		elseif stanza.attr.mechanism == "ANONYMOUS" then
935
efe3eaaeff34 Fixed: mod_saslauth: "anonymous_login" currently makes SASL ANONYMOUS an exclusive mechanism. Corrected advertised mechanisms and error replies.
Waqas Hussain <waqas20@gmail.com>
parents: 934
diff changeset
   152
			return session.send(build_reply("failure", "mechanism-too-weak"));
efe3eaaeff34 Fixed: mod_saslauth: "anonymous_login" currently makes SASL ANONYMOUS an exclusive mechanism. Corrected advertised mechanisms and error replies.
Waqas Hussain <waqas20@gmail.com>
parents: 934
diff changeset
   153
		end
2179
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
   154
		local valid_mechanism = session.sasl_handler:select(stanza.attr.mechanism);
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
   155
		if not valid_mechanism then
935
efe3eaaeff34 Fixed: mod_saslauth: "anonymous_login" currently makes SASL ANONYMOUS an exclusive mechanism. Corrected advertised mechanisms and error replies.
Waqas Hussain <waqas20@gmail.com>
parents: 934
diff changeset
   156
			return session.send(build_reply("failure", "invalid-mechanism"));
efe3eaaeff34 Fixed: mod_saslauth: "anonymous_login" currently makes SASL ANONYMOUS an exclusive mechanism. Corrected advertised mechanisms and error replies.
Waqas Hussain <waqas20@gmail.com>
parents: 934
diff changeset
   157
		end
2784
e165414a454c mod_saslauth: Requiring c2s encryption means requiring c2s encryption... thanks Flo
Matthew Wild <mwild1@gmail.com>
parents: 2014
diff changeset
   158
		if secure_auth_only and not session.secure then
e165414a454c mod_saslauth: Requiring c2s encryption means requiring c2s encryption... thanks Flo
Matthew Wild <mwild1@gmail.com>
parents: 2014
diff changeset
   159
			return session.send(build_reply("failure", "encryption-required"));
e165414a454c mod_saslauth: Requiring c2s encryption means requiring c2s encryption... thanks Flo
Matthew Wild <mwild1@gmail.com>
parents: 2014
diff changeset
   160
		end
295
bb078eb1f1de mod_saslauth: Code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 293
diff changeset
   161
	elseif not session.sasl_handler then
bb078eb1f1de mod_saslauth: Code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 293
diff changeset
   162
		return; -- FIXME ignoring out of order stanzas because ejabberd does
bb078eb1f1de mod_saslauth: Code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 293
diff changeset
   163
	end
284
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   164
	local text = stanza[1];
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   165
	if text then
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   166
		text = base64.decode(text);
2860
ad534f89c758 mod_saslauth: Don't print raw SASL data to avoid logging passwords unnecessarily
Matthew Wild <mwild1@gmail.com>
parents: 2014
diff changeset
   167
		--log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " "));
284
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   168
		if not text then
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   169
			session.sasl_handler = nil;
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   170
			session.send(build_reply("failure", "incorrect-encoding"));
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   171
			return;
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   172
		end
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   173
	end
2179
c985536d5452 Making mod_saslauth use the new SASL API.
Tobias Markmann <tm@ayena.de>
parents: 1639
diff changeset
   174
	local status, ret, err_msg = session.sasl_handler:process(text);
3062
892c49869293 mod_saslauth: Add return value and error message to the Cyrus SASL handle_status callback
Matthew Wild <mwild1@gmail.com>
parents: 3061
diff changeset
   175
	status, ret, err_msg = handle_status(session, status, ret, err_msg);
1584
ffe8a9296e04 mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
Nick Thomas
parents: 1523
diff changeset
   176
	local s = build_reply(status, ret, err_msg);
1072
c7967004b5d0 mod_saslauth: Various logging fixes
Matthew Wild <mwild1@gmail.com>
parents: 1071
diff changeset
   177
	log("debug", "sasl reply: %s", tostring(s));
288
dc53343af9ac Set username in a SASL object.
Tobias Markmann <tm@ayena.de>
parents: 286
diff changeset
   178
	session.send(s);
284
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   179
end
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   180
438
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 357
diff changeset
   181
module:add_handler("c2s_unauthed", "auth", xmlns_sasl, sasl_handler);
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 357
diff changeset
   182
module:add_handler("c2s_unauthed", "abort", xmlns_sasl, sasl_handler);
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 357
diff changeset
   183
module:add_handler("c2s_unauthed", "response", xmlns_sasl, sasl_handler);
284
4f540755260c mod_saslauth: Added base64 decoding, encoding check, and cleaned the code up.
Waqas Hussain <waqas20@gmail.com>
parents: 281
diff changeset
   184
357
17bcecb06420 Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
Matthew Wild <mwild1@gmail.com>
parents: 313
diff changeset
   185
local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' };
17bcecb06420 Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
Matthew Wild <mwild1@gmail.com>
parents: 313
diff changeset
   186
local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' };
17bcecb06420 Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
Matthew Wild <mwild1@gmail.com>
parents: 313
diff changeset
   187
local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' };
2612
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   188
module:hook("stream-features", function(event)
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   189
	local origin, features = event.origin, event.features;
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   190
	if not origin.username then
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   191
		if secure_auth_only and not origin.secure then
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   192
			return;
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   193
		end
2894
066c199135d5 mod_saslauth: Add a sasl_realm option
Paul Aurich <paul@darkrain42.org>
parents: 2724
diff changeset
   194
		local realm = module:get_option("sasl_realm") or origin.host;
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   195
		if module:get_option("anonymous_login") then
2894
066c199135d5 mod_saslauth: Add a sasl_realm option
Paul Aurich <paul@darkrain42.org>
parents: 2724
diff changeset
   196
			origin.sasl_handler = new_sasl(realm, anonymous_authentication_profile);
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   197
		else
3167
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
   198
			if usermanager_get_provider(realm).get_password then
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
   199
				origin.sasl_handler = new_sasl(realm, getpass_authentication_profile);
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
   200
			elseif usermanager_get_provider(realm).test_password then
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
   201
				origin.sasl_handler = new_sasl(realm, testpass_authentication_profile);
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
   202
			else
546695e80e0a Correct out of order logic in mod_hashpassauth
Jeff Mitchell <jeff@jefferai.org>
parents: 3164
diff changeset
   203
				log("warning", "AUTH: Could not load an authentication profile for the given provider.");
3164
db9def53fe9c Check in mod_hashpassauth -- works!
Jeff Mitchell <jeff@jefferai.org>
parents: 3066
diff changeset
   204
			end
2612
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   205
			if not (module:get_option("allow_unencrypted_plain_auth")) and not origin.secure then
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   206
				origin.sasl_handler:forbidden({"PLAIN"});
705
11afa1d88c55 mod_saslauth, mod_tls: minor code cleanup
Waqas Hussain <waqas20@gmail.com>
parents: 615
diff changeset
   207
			end
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   208
		end
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   209
		features:tag("mechanisms", mechanisms_attr);
2612
475552b04151 mod_saslauth: Hook stream-features event using new events API.
Waqas Hussain <waqas20@gmail.com>
parents: 2451
diff changeset
   210
		for k, v in pairs(origin.sasl_handler:mechanisms()) do
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   211
			features:tag("mechanism"):text(v):up();
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   212
		end
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   213
		features:up();
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   214
	else
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   215
		features:tag("bind", bind_attr):tag("required"):up():up();
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   216
		features:tag("session", xmpp_session_attr):tag("optional"):up():up();
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   217
	end
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   218
end);
1584
ffe8a9296e04 mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
Nick Thomas
parents: 1523
diff changeset
   219
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   220
module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", function(session, stanza)
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   221
	log("debug", "Client requesting a resource bind");
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   222
	local resource;
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   223
	if stanza.attr.type == "set" then
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   224
		local bind = stanza.tags[1];
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   225
		if bind and bind.attr.xmlns == xmlns_bind then
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   226
			resource = bind:child_with_name("resource");
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   227
			if resource then
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   228
				resource = resource[1];
46
d6b3f9dbb624 Resource binding, XMPP sessions (whatever they're for...)
Matthew Wild <mwild1@gmail.com>
parents: 38
diff changeset
   229
			end
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   230
		end
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   231
	end
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   232
	local success, err_type, err, err_msg = sm_bind_resource(session, resource);
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   233
	if not success then
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   234
		session.send(st.error_reply(stanza, err_type, err, err_msg));
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   235
	else
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   236
		session.send(st.reply(stanza)
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   237
			:tag("bind", { xmlns = xmlns_bind})
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   238
			:tag("jid"):text(session.full_jid));
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   239
	end
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   240
end);
1584
ffe8a9296e04 mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
Nick Thomas
parents: 1523
diff changeset
   241
2451
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   242
module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", function(session, stanza)
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   243
	log("debug", "Client requesting a session");
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   244
	session.send(st.reply(stanza));
d2f747920eaf mod_saslauth: Fixed some indentation and added some semi-colons.
Waqas Hussain <waqas20@gmail.com>
parents: 2450
diff changeset
   245
end);