Software /
code /
prosody
Annotate
plugins/mod_auth_anonymous.lua @ 3320:517ae40a12a2
xmppcomponent_listener: Import jid_split to fix undefined global reference
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 04 Jul 2010 19:15:20 +0100 |
parent | 3292:f2ac2ead80b1 |
child | 3425:26751c628207 |
rev | line source |
---|---|
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- Copyright (C) 2010 Jeff Mitchell |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 -- |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
3270
4710fd513f94
mod_auth_anonymous: Log as "auth_anonymous", not as "usermanager".
Waqas Hussain <waqas20@gmail.com>
parents:
3191
diff
changeset
|
10 local log = require "util.logger".init("auth_anonymous"); |
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local new_sasl = require "util.sasl".new; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local datamanager = require "util.datamanager"; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 function new_default_provider(host) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 local provider = { name = "anonymous" }; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 function provider.test_password(username, password) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 return nil, "Password based auth not supported."; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 function provider.get_password(username) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 return nil, "Password not available."; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 end |
3291
c06b3f7c92b1
mod_auth_anonymous, mod_auth_cyrus: Removed is_admin(), as usermanager already has a default.
Waqas Hussain <waqas20@gmail.com>
parents:
3270
diff
changeset
|
24 |
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 function provider.set_password(username, password) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 return nil, "Password based auth not supported."; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 function provider.user_exists(username) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 return nil, "Only anonymous users are supported."; -- FIXME check if anonymous user is connected? |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 function provider.create_user(username, password) |
3191
b6388c4f9250
mod_auth_anonymous: Fixed a syntax error.
Waqas Hussain <waqas20@gmail.com>
parents:
3190
diff
changeset
|
34 return nil, "Account creation/modification not supported."; |
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 function provider.get_sasl_handler() |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 local realm = module:get_option("sasl_realm") or module.host; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 local anonymous_authentication_profile = { |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 anonymous = function(username, realm) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 return true; -- for normal usage you should always return true here |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 }; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 return new_sasl(realm, anonymous_authentication_profile); |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 return provider; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 local function dm_callback(username, host, datastore, data) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 if host == module.host then |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 return false; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 return username, host, datastore, data; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 local host = hosts[module.host]; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 local _saved_disallow_s2s = host.disallow_s2s; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 function module.load() |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 _saved_disallow_s2s = host.disallow_s2s; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 host.disallow_s2s = module:get_option("disallow_s2s") ~= false; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 datamanager.add_callback(dm_callback); |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 function module.unload() |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 host.disallow_s2s = _saved_disallow_s2s; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 datamanager.remove_callback(dm_callback); |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 module:add_item("auth-provider", new_default_provider(module.host)); |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 |