Mercurial > prosody-modules
annotate mod_srvinjection/mod_srvinjection.lua @ 1507:6ea13869753f
mod_s2s_auth_dane: Include hostname when logging a failure
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 16 Sep 2014 19:55:54 +0200 |
parents | b21236b6b8d8 |
children | 47fb4f36dacd |
rev | line source |
---|---|
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
662
b3d130e4b3ae
mod_srvinjection: Use module:set_global()
Florian Zeitz <florob@babelmonkeys.de>
parents:
337
diff
changeset
|
2 module:set_global(); |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local adns = require "net.adns"; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 |
1248
69f7840923f5
mod_srvinjection: Make the map a shared table so that other plugins can use/modify it
daurnimator <quae@daurnimator.com>
parents:
662
diff
changeset
|
6 local map_config = module:get_option("srvinjection") or {}; |
69f7840923f5
mod_srvinjection: Make the map a shared table so that other plugins can use/modify it
daurnimator <quae@daurnimator.com>
parents:
662
diff
changeset
|
7 local map = module:shared "s2s_map" |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 |
1248
69f7840923f5
mod_srvinjection: Make the map a shared table so that other plugins can use/modify it
daurnimator <quae@daurnimator.com>
parents:
662
diff
changeset
|
9 for host, mapping in pairs(map_config) do |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 if type(mapping) == "table" and type(mapping[1]) == "string" and (type(mapping[2]) == "number") then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local connecthost, connectport = mapping[1], mapping[2] or 5269; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 map[host] = {{ |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 srv = { |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 target = connecthost.."."; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 port = connectport; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 priority = 1; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 weight = 0; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 }; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 }}; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 else |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 module:log("warn", "Ignoring invalid SRV injection for host '%s'", host); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 map[host] = nil; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 local original_lookup = adns.lookup; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 function adns.lookup(handler, qname, qtype, qclass) |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 if qtype == "SRV" then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 local host = qname:match("^_xmpp%-server%._tcp%.(.*)%.$"); |
337
beb5073b866a
mod_srvinjection: Fix type in variable name.
Waqas Hussain <waqas20@gmail.com>
parents:
336
diff
changeset
|
30 local mapping = map[host] or map["*"]; |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 if mapping then |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 handler(mapping); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 return; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 end |
99
2d03350613c4
mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
Waqas Hussain <waqas20@gmail.com>
parents:
96
diff
changeset
|
35 elseif qtype == "A" and (qname == "localhost." or qname == "127.0.0.1.") then |
2d03350613c4
mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
Waqas Hussain <waqas20@gmail.com>
parents:
96
diff
changeset
|
36 handler({{ a = "127.0.0.1" }}); |
2d03350613c4
mod_srvinjection: Added support for resolving "localhost" and "127.0.0.1".
Waqas Hussain <waqas20@gmail.com>
parents:
96
diff
changeset
|
37 return; |
96
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 return original_lookup(handler, qname, qtype, qclass); |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 end |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 function module.unload() |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 adns.lookup = original_lookup; |
c1f4edf3bea7
mod_srvinjection: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 end |