Software /
code /
prosody
Annotate
util/sasl/external.lua @ 11704:0a8671f32424
mod_s2s: Guard against missing 'to' on incoming stream
Given an incoming <stream:stream from="example.com"> this line would
have mistakenly reported the 'from' as the local host. Neither are
technically required and may be missing, especially on connections used
only for Dialback.
Outgoing connections initiated by Prosody always have 'from_host' and
'to_host', so it is safer to check it this way.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 18 Jul 2021 09:08:04 +0200 |
parent | 8555:4f0f5b49bb03 |
child | 12975:d10957394a3c |
rev | line source |
---|---|
5687
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local saslprep = require "util.encodings".stringprep.saslprep; |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
5687
diff
changeset
|
3 local _ENV = nil; |
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
6777
diff
changeset
|
4 -- luacheck: std none |
5687
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local function external(self, message) |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 message = saslprep(message); |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local state |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 self.username, state = self.profile.external(message); |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 if state == false then |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 return "failure", "account-disabled"; |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 elseif state == nil then |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 return "failure", "not-authorized"; |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 elseif state == "expired" then |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 return "false", "credentials-expired"; |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 return "success"; |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
5687
diff
changeset
|
22 local function init(registerMechanism) |
5687
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 registerMechanism("EXTERNAL", {"external"}, external); |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 end |
e879b53e9df8
util.sasl.external: Add SASL EXTERNAL mechanism
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
5687
diff
changeset
|
26 return { |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
5687
diff
changeset
|
27 init = init; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
5687
diff
changeset
|
28 } |