comparison mod_auth_external/mod_auth_external.lua @ 1158:ae1767b54964

mod_auth_external: Fix logging of errors
author Matthew Wild <mwild1@gmail.com>
date Tue, 13 Aug 2013 23:36:40 +0100
parents a7d0d129df6f
children c56a1d449cad
comparison
equal deleted inserted replaced
1157:a7d0d129df6f 1158:ae1767b54964
56 end 56 end
57 if script_type == "generic" then 57 if script_type == "generic" then
58 query = query..'\n'; 58 query = query..'\n';
59 end 59 end
60 60
61 local response = send_query(query); 61 local response, err = send_query(query);
62 if (script_type == "ejabberd" and response == "\0\2\0\0") or 62 if not response then
63 log("warn", "Error while waiting for result from auth process: %s", err or "unknown error");
64 elseif (script_type == "ejabberd" and response == "\0\2\0\0") or
63 (script_type == "generic" and response:gsub("\r?\n$", "") == "0") then 65 (script_type == "generic" and response:gsub("\r?\n$", "") == "0") then
64 return nil, "not-authorized"; 66 return nil, "not-authorized";
65 elseif (script_type == "ejabberd" and response == "\0\2\0\1") or 67 elseif (script_type == "ejabberd" and response == "\0\2\0\1") or
66 (script_type == "generic" and response:gsub("\r?\n$", "") == "1") then 68 (script_type == "generic" and response:gsub("\r?\n$", "") == "1") then
67 return true; 69 return true;
68 else 70 else
69 if response then 71 log("warn", "Unable to interpret data from auth process, %s", (response:match("^error:") and response) or ("["..#response.." bytes]"));
70 log("warn", "Unable to interpret data from auth process, %s", (response:match("^error:") and response) or ("["..#response.." bytes]"));
71 else
72 log("warn", "Error while waiting for result from auth process: %s", response or "unknown error");
73 end
74 return nil, "internal-server-error"; 72 return nil, "internal-server-error";
75 end 73 end
76 end 74 end
77 75
78 local host = module.host; 76 local host = module.host;