Comparison

mod_auth_external/mod_auth_external.lua @ 1086:50ee38e95e75

Don't store password in temporary file, pipe instead
author Mikael Nordfeldth <mmn@hethane.se>
date Mon, 24 Jun 2013 14:29:03 +0200
parent 902:490cb9161c81
child 1154:61f95bf51b35
comparison
equal deleted inserted replaced
1085:56fc7a86eb20 1086:50ee38e95e75
2 -- NOTE: currently this uses lpc; when waqas fixes process, it can go back to that 2 -- NOTE: currently this uses lpc; when waqas fixes process, it can go back to that
3 -- 3 --
4 -- Prosody IM 4 -- Prosody IM
5 -- Copyright (C) 2010 Waqas Hussain 5 -- Copyright (C) 2010 Waqas Hussain
6 -- Copyright (C) 2010 Jeff Mitchell 6 -- Copyright (C) 2010 Jeff Mitchell
7 -- Copyright (C) 2013 Mikael Nordfeldth
7 -- 8 --
8 -- This project is MIT/X11 licensed. Please see the 9 -- This project is MIT/X11 licensed. Please see the
9 -- COPYING file in the source package for more information. 10 -- COPYING file in the source package for more information.
10 -- 11 --
11 12
25 local jid_bare = require "util.jid".bare; 26 local jid_bare = require "util.jid".bare;
26 local new_sasl = require "util.sasl".new; 27 local new_sasl = require "util.sasl".new;
27 28
28 local function send_query(text) 29 local function send_query(text)
29 local tmpname = os.tmpname(); 30 local tmpname = os.tmpname();
30 local tmpfile = io.open(tmpname, "wb"); 31 local p = io.popen(command.." > "..tmpname, "w"); -- dump result to file
31 tmpfile:write(text); 32 p:write(text); -- push colon-separated args through pipe to above command
32 tmpfile:close(); 33 p:close();
33 local p = io.popen(command.." < "..tmpname, "r"); 34 local tmpfile = io.open(tmpname, "r"); -- open file to read auth result
34 local result; 35 local result;
35 if script_type == "ejabberd" then 36 if script_type == "ejabberd" then
36 result = p:read(4); 37 result = tmpfile:read(4);
37 elseif script_type == "generic" then 38 elseif script_type == "generic" then
38 result = p:read(); 39 result = tmpfile:read();
39 end 40 end
40 os.remove(tmpname); 41 tmpfile:close();
41 p:close(); 42 os.remove(tmpname); -- clean up after us
42 return result; 43 return result;
43 end 44 end
44 45
45 if lpc then 46 if lpc then
46 --local proc; 47 --local proc;