Software /
code /
prosody
Annotate
plugins/mod_auth_anonymous.lua @ 4846:3bc3498df0a0
Merge with Maranda
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 11 May 2012 01:53:32 +0100 |
parent | 4834:878f75ccc4fb |
parent | 4844:3d1ca811eee3 |
child | 4944:72a2eec4204a |
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 -- |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- 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
|
6 -- 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
|
7 -- |
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 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
|
10 local datamanager = require "util.datamanager"; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 function new_default_provider(host) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 local provider = { name = "anonymous" }; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 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
|
16 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
|
17 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 function provider.get_password(username) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 return nil, "Password not available."; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 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
|
22 |
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 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
|
24 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
|
25 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 function provider.user_exists(username) |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 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
|
29 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 function provider.create_user(username, password) |
3191
b6388c4f9250
mod_auth_anonymous: Fixed a syntax error.
Waqas Hussain <waqas20@gmail.com>
parents:
3190
diff
changeset
|
32 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
|
33 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 function provider.get_sasl_handler() |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 local anonymous_authentication_profile = { |
3981
2b0b8fe68df2
util.sasl.*, mod_auth_*, mod_saslauth: Pass SASL handler as first parameter to SASL profile callbacks.
Waqas Hussain <waqas20@gmail.com>
parents:
3425
diff
changeset
|
37 anonymous = function(sasl, username, realm) |
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 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
|
39 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 }; |
4160
f08f649b898b
mod_auth_*: Get rid of undocumented and broken 'sasl_realm' config option.
Waqas Hussain <waqas20@gmail.com>
parents:
3981
diff
changeset
|
41 return new_sasl(module.host, anonymous_authentication_profile); |
3190
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 provider; |
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 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
|
48 if host == module.host then |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 return false; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 return username, host, datastore, data; |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 end |
4821
deec69fc33e5
mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents:
4765
diff
changeset
|
53 |
4834
878f75ccc4fb
mod_s2s, mod_auth_anonymous, hostmanager: Remove disallow_s2s flag, deprecate the config option of the same name (disable mod_s2s instead), and add 'allow_anonymous_s2s' to separately control s2s for anonymous users
Matthew Wild <mwild1@gmail.com>
parents:
4821
diff
changeset
|
54 if not module:get_option_boolean("allow_anonymous_s2s", false) then |
4821
deec69fc33e5
mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents:
4765
diff
changeset
|
55 module:hook("route/remote", function (event) |
deec69fc33e5
mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents:
4765
diff
changeset
|
56 return false; -- Block outgoing s2s from anonymous users |
deec69fc33e5
mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents:
4765
diff
changeset
|
57 end, 300); |
deec69fc33e5
mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents:
4765
diff
changeset
|
58 end |
deec69fc33e5
mod_auth_anonymous: Block s2s when enabled on a host (and disallow_s2s ~= false)
Matthew Wild <mwild1@gmail.com>
parents:
4765
diff
changeset
|
59 |
3190
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 function module.load() |
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 datamanager.remove_callback(dm_callback); |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 end |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 |
c4069680a01c
mod_auth_anonymous: Auth provider with support for SASL ANONYMOUS.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 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
|
68 |