annotate mod_auth_any/mod_auth_any.lua @ 1595:6288591d5edf

mod_storage_gdbm: Prepare for supporting multiple store types
author Kim Alvefur <zash@zash.se>
date Sun, 25 Jan 2015 22:17:20 +0100
parents 7dbde05b48a9
children 75be377b74ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1294
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Prosody IM
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local datamanager = require "util.datamanager";
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local log = require "util.logger".init("auth_any");
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local type = type;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local error = error;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local ipairs = ipairs;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local hashes = require "util.hashes";
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local jid_bare = require "util.jid".bare;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local config = require "core.configmanager";
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local usermanager = require "core.usermanager";
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local new_sasl = require "util.sasl".new;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local nodeprep = require "util.encodings".stringprep.nodeprep;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local hosts = hosts;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local prosody = _G.prosody;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 function new_default_provider(host)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local provider = { name = "any" };
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 log("debug", "initializing default authentication provider for host '%s'", host);
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 function provider.test_password(username, password)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 return true;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 function provider.set_password(username, password)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 local account = datamanager.load(username, host, "accounts");
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 if account then
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 account.password = password;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 return datamanager.store(username, host, "accounts", account);
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 return nil, "Account not available.";
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 function provider.user_exists(username)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 return true;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 function provider.create_user(username, password)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 return datamanager.store(username, host, "accounts", {password = password});
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 1294
diff changeset
48
1294
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 function provider.delete_user(username)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 return datamanager.store(username, host, "accounts", nil);
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 function provider.get_sasl_handler()
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 local getpass_authentication_profile = {
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 plain_test = function(sasl, username, password, realm)
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 return true, true;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 };
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 return new_sasl(module.host, getpass_authentication_profile);
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 1294
diff changeset
61
1294
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 return provider;
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 end
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 module:add_item("auth-provider", new_default_provider(module.host));
bb1fb54360ab mod_auth_any: Allows any username/password to connect
Waqas Hussain <waqas20@gmail.com>, Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66