Help to setup a Unix socket based authentication server for dovecot in Python

Aki Tuomi aki.tuomi at open-xchange.com
Sun Aug 15 18:12:11 EEST 2021


> On 13/08/2021 15:12 Sherin A <sherinmon at gmail.com> wrote:
> 
> 
> Hi,
> I am building a custom server platform in which dovecot is used for imap/pop . But the default authentication mechanism is not suitable for me becuase each domain will have different system users and different location for mail storage . So I need to create a custom authentication mechanism using python . There is an option to use Key-value authentication (dict) database via socket as per 
> 
> https://doc.dovecot.org/configuration_manual/authentication/dict/#complete-example-for-authenticating-via-a-unix-socket
> 
> 
> 
> The above documentation link have a sample perl script too to send authentication to 
> 
> uri = proxy:/var/run/auth_proxy_dovecot/socket:somewhere
> 
> So my question is how the inputs are send to the socket file ? in which format ?
> How the result return ? and in which format ?
> Let us say I can create a python socket program that can listen to /var/run/auth_proxy_dovecot/socket for getting the inputs from dovecot , but what is the format 
> 
> Is it like the following 
> 
> AUTH PLAIN
> USER test at myemail.com
> PASS mypassword
> 
> 
> I looked into the documentation and developer documentation, I am unable to see how dovecot send the data , I can see a sample perl for answering dict lookups. Any one have a python alternative for it. ?
> 
> 
> 
> 
> -- 
> 
> Sherin Abdulkhareem
>  Chairman & Managing Director 

It should work just by reading from socket and writing to the socket. You are sent tab separated lines, which start with L or H followed by first parameter that, as in

Hhandshake-data (you can ignore H)

and actual lookups as

Lnamespace/type/arg

and then you respond with 

O{"json":"blob"}

You could also consider using Lua authentication. See https://doc.dovecot.org/configuration_manual/authentication/lua_based_authentication/ (please note version requirements).

which can be lot easier to do.

Regards,
Aki


More information about the dovecot mailing list