Mercurial > prosody-modules
comparison mod_auth_external/mod_auth_external.lua @ 846:5ddc43ce8993
mod_auth_external: Work even when the LuaProcessCall library isn't available.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 13 Oct 2012 02:33:06 +0500 |
parents | 960007b0901e |
children | 490cb9161c81 |
comparison
equal
deleted
inserted
replaced
845:1c14edca74a4 | 846:5ddc43ce8993 |
---|---|
10 -- | 10 -- |
11 | 11 |
12 | 12 |
13 local nodeprep = require "util.encodings".stringprep.nodeprep; | 13 local nodeprep = require "util.encodings".stringprep.nodeprep; |
14 --local process = require "process"; | 14 --local process = require "process"; |
15 local lpc = require "lpc"; | 15 local lpc; pcall(function() lpc = require "lpc"; end); |
16 | 16 |
17 local config = require "core.configmanager"; | 17 local config = require "core.configmanager"; |
18 local log = module._log; | 18 local log = module._log; |
19 local host = module.host; | 19 local host = module.host; |
20 local script_type = config.get(host, "core", "external_auth_protocol") or "generic"; | 20 local script_type = config.get(host, "core", "external_auth_protocol") or "generic"; |
24 assert(not host:find(":")); | 24 assert(not host:find(":")); |
25 local usermanager = require "core.usermanager"; | 25 local usermanager = require "core.usermanager"; |
26 local jid_bare = require "util.jid".bare; | 26 local jid_bare = require "util.jid".bare; |
27 local new_sasl = require "util.sasl".new; | 27 local new_sasl = require "util.sasl".new; |
28 | 28 |
29 --local proc; | 29 local function send_query(text) |
30 local pid; | 30 local tmpname = os.tmpname(); |
31 local readfile; | 31 local tmpfile = io.open(tmpname, "wb"); |
32 local writefile; | 32 tmpfile:write(text); |
33 tmpfile:close(); | |
34 local p = io.popen(command.." < "..tmpname, "r"); | |
35 local result; | |
36 if script_type == "ejabberd" then | |
37 result = p:read(4); | |
38 elseif script_type == "generic" then | |
39 result = p:read(); | |
40 end | |
41 os.remove(tmpname); | |
42 p:close(); | |
43 return result; | |
44 end | |
33 | 45 |
34 local function send_query(text) | 46 if lpc then |
35 if pid and lpc.wait(pid,1) ~= nil then | 47 --local proc; |
36 log("debug","error, process died, force reopen"); | 48 local pid; |
37 pid=nil; | 49 local readfile; |
38 end | 50 local writefile; |
39 if not pid then | |
40 log("debug", "Opening process " .. command); | |
41 -- proc = process.popen(command); | |
42 pid, writefile, readfile = lpc.run(command); | |
43 end | |
44 -- if not proc then | |
45 if not pid then | |
46 log("debug", "Process failed to open"); | |
47 return nil; | |
48 end | |
49 -- proc:write(text); | |
50 -- proc:flush(); | |
51 | 51 |
52 writefile:write(text); | 52 function send_query(text) |
53 writefile:flush(); | 53 if pid and lpc.wait(pid,1) ~= nil then |
54 if script_type == "ejabberd" then | 54 log("debug","error, process died, force reopen"); |
55 -- return proc:read(4); -- FIXME do properly | 55 pid=nil; |
56 return readfile:read(4); -- FIXME do properly | 56 end |
57 elseif script_type == "generic" then | 57 if not pid then |
58 -- return proc:read(1); | 58 log("debug", "Opening process " .. command); |
59 return readfile:read(); | 59 -- proc = process.popen(command); |
60 pid, writefile, readfile = lpc.run(command); | |
61 end | |
62 -- if not proc then | |
63 if not pid then | |
64 log("debug", "Process failed to open"); | |
65 return nil; | |
66 end | |
67 -- proc:write(text); | |
68 -- proc:flush(); | |
69 | |
70 writefile:write(text); | |
71 writefile:flush(); | |
72 if script_type == "ejabberd" then | |
73 -- return proc:read(4); -- FIXME do properly | |
74 return readfile:read(4); -- FIXME do properly | |
75 elseif script_type == "generic" then | |
76 -- return proc:read(1); | |
77 return readfile:read(); | |
78 end | |
60 end | 79 end |
61 end | 80 end |
62 | 81 |
63 function do_query(kind, username, password) | 82 function do_query(kind, username, password) |
64 if not username then return nil, "not-acceptable"; end | 83 if not username then return nil, "not-acceptable"; end |