comparison mod_auth_dovecot/mod_auth_dovecot.lua @ 431:fb7898826026

mod_auth_dovecot: Added support for TCP sockets, and checks for UNIX socket availability.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 17 Sep 2011 18:19:31 +0500
parents e840b4ce538d
children
comparison
equal deleted inserted replaced
430:f0fafd19fd72 431:fb7898826026
4 -- Copyright (C) 2010-2011 Matthew Wild 4 -- Copyright (C) 2010-2011 Matthew Wild
5 -- Copyright (C) 2010-2011 Waqas Hussain 5 -- Copyright (C) 2010-2011 Waqas Hussain
6 -- Copyright (C) 2011 Kim Alvefur 6 -- Copyright (C) 2011 Kim Alvefur
7 -- 7 --
8 8
9 local socket_unix = require "socket.unix"; 9 pcall(require, "socket.unix");
10 local datamanager = require "util.datamanager"; 10 local datamanager = require "util.datamanager";
11 local usermanager = require "core.usermanager"; 11 local usermanager = require "core.usermanager";
12 local log = require "util.logger".init("auth_dovecot"); 12 local log = require "util.logger".init("auth_dovecot");
13 local new_sasl = require "util.sasl".new; 13 local new_sasl = require "util.sasl".new;
14 local nodeprep = require "util.encodings".stringprep.nodeprep; 14 local nodeprep = require "util.encodings".stringprep.nodeprep;
15 local base64 = require "util.encodings".base64; 15 local base64 = require "util.encodings".base64;
16 local sha1 = require "util.hashes".sha1; 16 local sha1 = require "util.hashes".sha1;
17 17
18 local prosody = prosody; 18 local prosody = prosody;
19 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login"); 19 local socket_path = module:get_option_string("dovecot_auth_socket", "/var/run/dovecot/auth-login");
20 local socket_host = module:get_option_string("dovecot_auth_host", "127.0.0.1");
21 local socket_port = module:get_option_string("dovecot_auth_port");
20 local append_host = module:get_option_boolean("auth_append_host", false); 22 local append_host = module:get_option_boolean("auth_append_host", false);
23 if not socket_port and not socket.unix then
24 error("LuaSocket was not compiled with UNIX socket support. Try using Dovecot 2.x with inet_listener support, or recompile LuaSocket with UNIX socket support.");
25 end
21 26
22 function new_provider(host) 27 function new_provider(host)
23 local provider = { name = "dovecot", request_id = 0 }; 28 local provider = { name = "dovecot", request_id = 0 };
24 log("debug", "initializing dovecot authentication provider for host '%s'", host); 29 log("debug", "initializing dovecot authentication provider for host '%s'", host);
25 30
38 -- The following connects to a new socket and send the handshake 43 -- The following connects to a new socket and send the handshake
39 function provider.connect(self) 44 function provider.connect(self)
40 -- Destroy old socket 45 -- Destroy old socket
41 provider:close(); 46 provider:close();
42 47
43 conn = socket.unix(); 48 local ok, err;
44 49 if socket_port then
45 -- Create a connection to dovecot socket 50 log("debug", "connecting to dovecot TCP socket at '%s':'%s'", socket_host, socket_port);
46 log("debug", "connecting to dovecot socket at '%s'", socket_path); 51 conn = socket.tcp();
47 local ok, err = conn:connect(socket_path); 52 ok, err = conn:connect(socket_host, socket_port);
53 elseif socket.unix then
54 log("debug", "connecting to dovecot UNIX socket at '%s'", socket_path);
55 conn = socket.unix();
56 ok, err = conn:connect(socket_path);
57 else
58 err = "luasocket was not compiled with UNIX sockets support";
59 end
48 if not ok then 60 if not ok then
49 log("error", "error connecting to dovecot socket at '%s'. error was '%s'. check permissions", socket_path, err); 61 if socket_port then
62 log("error", "error connecting to dovecot TCP socket at '%s':'%s'. error was '%s'. check permissions", socket_host, socket_port, err);
63 else
64 log("error", "error connecting to dovecot UNIX socket at '%s'. error was '%s'. check permissions", socket_path, err);
65 end
50 provider:close(); 66 provider:close();
51 return false; 67 return false;
52 end 68 end
53 69
54 -- Send our handshake 70 -- Send our handshake