annotate mod_auth_external/mod_auth_external.lua @ 816:960007b0901e

mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 13 Sep 2012 00:17:42 +0500
parents 881ec9919144
children 5ddc43ce8993
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
1 --
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
2 -- NOTE: currently this uses lpc; when waqas fixes process, it can go back to that
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
3 --
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
4 -- Prosody IM
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
5 -- Copyright (C) 2010 Waqas Hussain
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
6 -- Copyright (C) 2010 Jeff Mitchell
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
7 --
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
8 -- This project is MIT/X11 licensed. Please see the
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
9 -- COPYING file in the source package for more information.
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
10 --
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local nodeprep = require "util.encodings".stringprep.nodeprep;
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
14 --local process = require "process";
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
15 local lpc = require "lpc";
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
17 local config = require "core.configmanager";
168
cd8492748985 mod_auth_external: Renamed from mod_extauth. Update logging and options (external_auth_protocol, external_auth_command)
Matthew Wild <mwild1@gmail.com>
parents: 166
diff changeset
18 local log = module._log;
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
19 local host = module.host;
168
cd8492748985 mod_auth_external: Renamed from mod_extauth. Update logging and options (external_auth_protocol, external_auth_command)
Matthew Wild <mwild1@gmail.com>
parents: 166
diff changeset
20 local script_type = config.get(host, "core", "external_auth_protocol") or "generic";
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
21 assert(script_type == "ejabberd" or script_type == "generic");
168
cd8492748985 mod_auth_external: Renamed from mod_extauth. Update logging and options (external_auth_protocol, external_auth_command)
Matthew Wild <mwild1@gmail.com>
parents: 166
diff changeset
22 local command = config.get(host, "core", "external_auth_command") or "";
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 assert(type(command) == "string");
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 assert(not host:find(":"));
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
25 local usermanager = require "core.usermanager";
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
26 local jid_bare = require "util.jid".bare;
166
75a85eac3c27 mod_extauth: Updated to provide a SASL handler.
Waqas Hussain <waqas20@gmail.com>
parents: 158
diff changeset
27 local new_sasl = require "util.sasl".new;
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
29 --local proc;
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
30 local pid;
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
31 local readfile;
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
32 local writefile;
197
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
33
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 local function send_query(text)
197
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
35 if pid and lpc.wait(pid,1) ~= nil then
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
36 log("debug","error, process died, force reopen");
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
37 pid=nil;
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
38 end
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
39 if not pid then
197
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
40 log("debug", "Opening process " .. command);
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
41 -- proc = process.popen(command);
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
42 pid, writefile, readfile = lpc.run(command);
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
43 end
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
44 -- if not proc then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
45 if not pid then
168
cd8492748985 mod_auth_external: Renamed from mod_extauth. Update logging and options (external_auth_protocol, external_auth_command)
Matthew Wild <mwild1@gmail.com>
parents: 166
diff changeset
46 log("debug", "Process failed to open");
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
47 return nil;
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 end
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
49 -- proc:write(text);
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
50 -- proc:flush();
197
2686221255cf restart authorize command if crashed or ended; added example shell script
Bjoern Kalkbrenner <terminar@cyberphoria.org>
parents: 168
diff changeset
51
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
52 writefile:write(text);
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
53 writefile:flush();
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
54 if script_type == "ejabberd" then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
55 -- return proc:read(4); -- FIXME do properly
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
56 return readfile:read(4); -- FIXME do properly
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
57 elseif script_type == "generic" then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
58 -- return proc:read(1);
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
59 return readfile:read();
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
60 end
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 function do_query(kind, username, password)
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 if not username then return nil, "not-acceptable"; end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 username = nodeprep(username);
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 if not username then return nil, "jid-malformed"; end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 local query = (password and "%s:%s:%s:%s" or "%s:%s:%s"):format(kind, username, host, password);
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 local len = #query
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 if len > 1000 then return nil, "policy-violation"; end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
72 if script_type == "ejabberd" then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
73 local lo = len % 256;
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
74 local hi = (len - lo) / 256;
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
75 query = string.char(hi, lo)..query;
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
76 end
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
77 if script_type == "generic" then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
78 query = query..'\n';
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
79 end
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 local response = send_query(query);
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
82 if (script_type == "ejabberd" and response == "\0\2\0\0") or
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
83 (script_type == "generic" and response == "0") then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
84 return nil, "not-authorized";
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
85 elseif (script_type == "ejabberd" and response == "\0\2\0\1") or
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
86 (script_type == "generic" and response == "1") then
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
87 return true;
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 else
168
cd8492748985 mod_auth_external: Renamed from mod_extauth. Update logging and options (external_auth_protocol, external_auth_command)
Matthew Wild <mwild1@gmail.com>
parents: 166
diff changeset
89 log("debug", "Nonsense back");
158
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
90 --proc:close();
1a5d5d4f08fe Add "generic" script support to mod_extauth, as well as lpc support until waqas fixes process
Jeff Mitchell <jeff@jefferai.org>
parents: 152
diff changeset
91 --proc = nil;
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 return nil, "internal-server-error";
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95
816
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
96 local host = module.host;
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
97 local provider = {};
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98
816
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
99 function provider.test_password(username, password)
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
100 return do_query("auth", username, password);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
101 end
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102
816
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
103 function provider.set_password(username, password)
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
104 return do_query("setpass", username, password);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
105 end
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106
816
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
107 function provider.user_exists(username)
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
108 return do_query("isuser", username);
152
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 end
4ca382e8a4c5 mod_extauth: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110
816
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
111 function provider.create_user(username, password) return nil, "Account creation/modification not available."; end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
112
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
113 function provider.get_sasl_handler()
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
114 local testpass_authentication_profile = {
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
115 plain_test = function(sasl, username, password, realm)
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
116 local prepped_username = nodeprep(username);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
117 if not prepped_username then
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
118 log("debug", "NODEprep failed on username: %s", username);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
119 return "", nil;
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
120 end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
121 return usermanager.test_password(prepped_username, realm, password), true;
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
122 end,
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
123 };
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
124 return new_sasl(host, testpass_authentication_profile);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
125 end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
126
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
127 function provider.is_admin(jid)
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
128 local admins = config.get(host, "core", "admins");
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
129 if admins ~= config.get("*", "core", "admins") then
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
130 if type(admins) == "table" then
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
131 jid = jid_bare(jid);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
132 for _,admin in ipairs(admins) do
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
133 if admin == jid then return true; end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
134 end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
135 elseif admins then
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
136 log("error", "Option 'admins' for host '%s' is not a table", host);
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
137 end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
138 end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
139 return usermanager.is_admin(jid); -- Test whether it's a global admin instead
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
140 end
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
141
960007b0901e mod_auth_external, mod_auth_internal_yubikey: Get rid of useless wrapper function around the auth provider.
Waqas Hussain <waqas20@gmail.com>
parents: 814
diff changeset
142 module:provides("auth", provider);