mod_httpserver: Serve index.html if a request is made for a directory and it contains...
[prosody.git] / util / sasl.lua
index 7b7db0247ae50efa6537002a65fb71ed30562a20..c9225f0d776436ab1ad0d44b456318392fc43d71 100644 (file)
@@ -1,5 +1,5 @@
 -- sasl.lua v0.4
--- Copyright (C) 2008-2009 Tobias Markmann
+-- Copyright (C) 2008-2010 Tobias Markmann
 --
 --    All rights reserved.
 --
@@ -41,27 +41,6 @@ Authentication Backend Prototypes:
 state = false : disabled
 state = true : enabled
 state = nil : non-existant
-
-plain:
-       function(username, realm)
-               return password, state;
-       end
-
-plain-test:
-       function(username, realm, password)
-               return true or false, state;
-       end
-
-digest-md5:
-       function(username, domain, realm, encoding) -- domain and realm are usually the same; for some broken
-                                                                                               -- implementations it's not
-               return digesthash, state;
-       end
-
-digest-md5-test:
-       function(username, domain, realm, encoding, digesthash)
-               return true or false, state;
-       end
 ]]
 
 local method = {};
@@ -83,13 +62,19 @@ end
 
 -- create a new SASL object which can be used to authenticate clients
 function new(realm, profile, forbidden)
-       sasl_i = {profile = profile};
+       local sasl_i = {profile = profile};
        sasl_i.realm = realm;
-       s = setmetatable(sasl_i, method);
-       s:forbidden(sasl_i, forbidden)
+       local s = setmetatable(sasl_i, method);
+       if forbidden == nil then forbidden = {} end
+       s:forbidden(forbidden)
        return s;
 end
 
+-- get a fresh clone with the same realm, profiles and forbidden mechanisms
+function method:clean_clone()
+       return new(self.realm, self.profile, self:forbidden())
+end
+
 -- set the forbidden mechanisms
 function method:forbidden( restrict )
        if restrict then
@@ -107,7 +92,7 @@ function method:mechanisms()
        for backend, f in pairs(self.profile) do
                if backend_mechanism[backend] then
                        for _, mechanism in ipairs(backend_mechanism[backend]) do
-                               if not sasl_i.restrict:contains(mechanism) then
+                               if not self.restrict:contains(mechanism) then
                                        mechanisms[mechanism] = true;
                                end
                        end
@@ -123,11 +108,8 @@ function method:select(mechanism)
                return false;
        end
        
-       self.mech_i = mechanisms[mechanism]
-       if self.mech_i == nil then 
-               return false;
-       end
-       return true;
+       self.mech_i = mechanisms[mechanism];
+       return (self.mech_i ~= nil);
 end
 
 -- feed new messages to process into the library
@@ -137,7 +119,7 @@ function method:process(message)
 end
 
 -- load the mechanisms
-load_mechs = {"plain", "digest-md5", "anonymous", "scram"}
+local load_mechs = {"plain", "digest-md5", "anonymous", "scram"}
 for _, mech in ipairs(load_mechs) do
        local name = "util.sasl."..mech;
        local m = require(name);