Those who are still using the Dovecot
's vpopmail
auth driver should consider a migration to another backend, as on January 4, 2021 dovecot-2.3.13
was released and the vpopmail
auth driver removed (more info here).
I'll show below how to support domain aliases with the sql driver both with all domains in the same vpopmail
table and with one table for each domain (--disable-many-domains
). You can find how to setup the driver in this page. A short reference to vpopmail
's vconvert
program is presented toward the bottom of this page, in case one is planning to switch to sql.
If you browse the comments below you'll find some other nice solutions:
- Ali Erturk TURKER maintains a patch to dovecot which restores the old
vpopmail
auth driver to life (dedicated page here) - Tyler Simpkin posted his auth.lua file (enhanced by Rick Richards to work with encrypted passwords)
- Laurent Bercot posted a solution based on passwd-file driver
- Pablo Murillo improved the sql password_query to work with one table for each domain
- erdgeist showed how to convert cdb accounts to postgres
Saving vpopmail
's aliasdomains
to MySQL
As some commentators have pointed out, switching to the dovecot
's sql auth driver can be painful if one has domain aliases. I will show below how to make dovecot
aware of the vpopmail
's aliasdomains
, so that a user who tries to login with a domain alias can pass the authentication.
The idea is to save the pairs alias/domain in a new "aliasdomains" MySQL
table, for example:
MariaDB [vpopmail]> SELECT * FROM aliasdomains; +----------------------+----------------------+ | alias | domain | +----------------------+----------------------+ | alias.net | realdomain.net | +----------------------+----------------------+
...and then modify the dovecot
's sql
query in order to select the user's domain from this table in case the domain is an alias or from the vpopmail
table otherwise.
I patched vpopmail
so that it will transparently do the sql stuff when creating/deleting the alias in the usual way by means of the vaddaliasdomain
/vdeldomain
vpopmail
's programs.
Patching vpopmail
Reconfigure, recompile and reinstall vpopmail
autoreconf -f -i ./configure --other-options-here \ --enable-auth-module=mysql \ --enable-mysql-limits \ --enable-sql-aliasdomains make make install-strip
Be aware that if you already have aliasdomains
and want to switch to the dovecot
's sql driver, you must populate the database adding a record for each aliasdomain
you have.
To do this you can simply delete/create the aliases in the usual way or use the vsavealiasdomains
program. For example, to save all domain aliases to MySQL
just do:
vsavealiasdomains -A
Type
vsavealiasdomains -h
for more options.
Modifing the sql auth
Finally you have to modify the dovecot-sql.conf.ext file as follows. Note the changes in the password_query
.
password_query = \ SELECT \ CONCAT(vpopmail.pw_name, '@', vpopmail.pw_domain) AS user, \ vpopmail.pw_passwd AS password, \ vpopmail.pw_dir AS userdb_home, \ 89 AS userdb_uid, \ 89 AS userdb_gid, \ CONCAT('*:bytes=', REPLACE(SUBSTRING_INDEX(vpopmail.pw_shell, 'S', 1), 'NOQUOTA', '0')) AS userdb_quota_rule \ FROM `vpopmail` \ LEFT JOIN aliasdomains ON aliasdomains.alias='%d' \ LEFT JOIN limits ON limits.domain = '%d' \ WHERE \ vpopmail.pw_name='%n' \ AND \ (vpopmail.pw_domain='%d' OR vpopmail.pw_domain=aliasdomains.domain) \ AND \ ('%a'!='995' OR !(vpopmail.pw_gid & 2)) \ AND \ ('%r'!='<WEBMAIL-IP>' OR !(vpopmail.pw_gid & 4)) \ AND \ ('%r'='<WEBMAIL-IP>' OR '%a'!='993' OR !(vpopmail.pw_gid & 8)) \ AND \ ('%r'!='<WEBMAIL-IP>' OR COALESCE(disable_webmail,0)!=1) \ AND \ ('%r'='<WEBMAIL-IP>' OR COALESCE(disable_imap,0)!=1) # <WEBMAIL-IP> is the IP of your webmail web server. # I'm assuming that the imap connection is only on port 993 and the pop3 connection is on port 995. # Adjust to your needs # # logically this means: # # ************************** USER LIMITS via vpopmail.pw_gid field # SELECT user # WHEN POP is not disabled for that user connecting on port 995 (995 is the pop3s port allowed from remote in my configuration) # AND WHEN webmail access is not disabled for that user when connecting from <WEBMAIL-IP> # AND WHEN IMAP is not disabled for that user connecting on port 993 (993 is the imap port allowed from remote # in my configuration) unless his remote ip the one belonging to the webmail # # ************************* DOMAIN LIMITS via limits table # AND WHEN WEBMAIL access for the domain is not disabled # AND WHEN IMAP access for the domain is not disabled when not connecting from <WEBMAIL-IP>
The user_query
is served with the "prefetch" driver. Look at the dovecot page for all the details about it.
aliasdomains
and mysql-limits
support for "one table per domain" option
The above solution has to be modified when you save your accounts to one table for each domain (--disable-many-domains
). The query turns out to be more advanced and "stored procedures" have to be considered as a valid solution (thanks to Pablo Murillo for sharing his sql example).
I have created a procedure named "dovecot_password_query_disable_many_domains" which does the sql stuff and can be called as follows in your password_query
:
password_query = CALL dovecot_password_query_disable_many_domains('%n','%d','127.0.0.1','%r','%a')
Here is the content of the procedure plus some other sql functions (download):
USE vpopmail; /**************************************************************** Returns the domain table ****************************************************************/ DELIMITER $$ CREATE FUNCTION `get_domain_table`(`d` VARCHAR(100)) RETURNS varchar(100) CHARSET latin1 BEGIN DECLARE domain_table varchar(100); SET domain_table = dot2underscore(get_real_domain(d)); RETURN domain_table; END$$ DELIMITER ; /**************************************************************** Replaces dots and "-" with undescores in domain name ****************************************************************/ DELIMITER $$ CREATE FUNCTION `dot2underscore`(`d` VARCHAR(100)) RETURNS varchar(100) CHARSET latin1 BEGIN RETURN REPLACE(REPLACE(d, ".", "_"), "-", "_"); END$$ DELIMITER ; /******************************************************************* Returns the real domain given an alias domain or the domain name if it's not an alias. *******************************************************************/ DELIMITER $$ CREATE FUNCTION `get_real_domain`(`d` VARCHAR(100)) RETURNS varchar(100) CHARSET latin1 BEGIN DECLARE real_domain varchar(100); IF NOT (SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=dot2underscore(d)) IS NULL THEN SET real_domain = d; ELSEIF NOT (SELECT 1 FROM aliasdomains WHERE alias=d) IS NULL THEN SELECT domain INTO real_domain FROM aliasdomains WHERE alias=d; ELSE SET real_domain = NULL; END IF; RETURN real_domain; END$$ DELIMITER ; /************************************************************************** Stored procedure for password_query in case of "disabled many domains" **************************************************************************/ DELIMITER $$ CREATE PROCEDURE `dovecot_password_query_disable_many_domains`(IN `name` VARCHAR(255), IN `domain` VARCHAR(255), IN `webmail_ip` VARCHAR(255), IN `remote_ip` VARCHAR(255), IN `port` INT) BEGIN DECLARE vpopmail varchar(256); SET vpopmail = get_domain_table(domain); IF (vpopmail) IS NULL THEN SET @SQL = "SELECT NULL"; ELSE SET @SQL = CONCAT("SELECT CONCAT(",vpopmail,".pw_name, '@', '",domain,"') AS user,", vpopmail,".pw_passwd AS password,", vpopmail,".pw_dir AS userdb_home, 89 AS userdb_uid, 89 AS userdb_gid, CONCAT('*:bytes=', REPLACE(SUBSTRING_INDEX(",vpopmail,".pw_shell, 'S', 1), 'NOQUOTA', '0')) AS userdb_quota_rule FROM ",vpopmail," LEFT JOIN limits ON limits.domain='",get_real_domain(domain),"' WHERE ",vpopmail,".pw_name='",name,"' AND ('",port,"'!='995' OR !(",vpopmail,".pw_gid & 2)) AND ('",remote_ip,"'!='",webmail_ip,"' OR !(",vpopmail,".pw_gid & 4)) AND ('",remote_ip,"'='",webmail_ip,"' OR '",port,"'!='993' OR !(",vpopmail,".pw_gid & 8)) AND ('",remote_ip,"'!='",webmail_ip,"' OR COALESCE(disable_webmail,0)!=1) AND ('",remote_ip,"'='",webmail_ip,"' OR COALESCE(disable_imap,0)!=1)"); END IF; PREPARE sql_code FROM @SQL; EXECUTE sql_code; DEALLOCATE PREPARE sql_code; END$$ DELIMITER ;
To install the procedure you have to download and execute the code above as follows:
wget https://notes.sagredo.eu/files/qmail/patches/vpopmail/dovecot-pwd-query_disable-many-domains.txt mysql < dovecot-pwd-query_disable-many-domains.txt -u root -p
The above sql stuff is automatically installed by vpopmail
in the database when you create a new domain having configured the program with --disable-many-domains --sql-aliasdomains --enable-mysql-bin=PATH
. You have to use my vpopmail
patch dated March 9, 2021 or later.
Migrating your accounts to sql format
This solution requires that your accounts are already in sql format. To convert from cdb to sql format use the vpopmail
's vconvert
program:
vconvert: usage The first option sets which format to convert FROM, the second option sets which format to convert TO. -e = etc format -c = cdb format -m = sql format -S = set sqwebmail passwords -v = version -d = debug info
If you want to switch to postgres, take a look to the erdgeist's howto here.
Comments
Why not add the code back in?
WilliamSilverstein February 7, 2022 01:57 CET
Has anyone tried just taking the old vpopmail authorization code from the older version and add it back in to the current?
I have not thought of it until now, but I don't have the time to look into it until next month. I was thinking it would be the obvious path to look at. If it is not, why not?
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera WilliamSilverstein February 7, 2022 07:23 CET
...and patching dovecot again and again and again? I don't think this would be a definitive solution to the problem
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Roberto Puzzanghera February 7, 2023 05:30 CET
Hi Roberto
I have created a patch to add vpopmail authentication to the latest version of dovecot (2.3.20).
It works for me without any problems. I will try to keep the patch up-to-date.
Feel free to share this link in your website.
Regards,
Ali Erturk TURKER
Reply | Permalink
Why not add the code back in?
Bai Borko Ali Erturk TURKER February 8, 2023 08:19 CET
Hi Roberto, Ali,
First i want to say "big thank" for you for your work!
I try to compile dovecot v.2.3.20 with your patch on ubuntu 20.04.5 LTS, but receive the below error.
Please share/explain more details how to use this patch with vpopmail.
Thank you in advance!
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Bai Borko February 8, 2023 13:02 CET
I think it can be cured as Ali certainly knows with an "if vpopmail has been declared" around that part which calls the vpopmail library
Anyway the error should go away if you run autogen
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Bai Borko February 8, 2023 11:38 CET
Hi Bai,
These are the steps I use to build dovecot with vpopmail support. Please try and let us know if it works:
Reply | Permalink
Why not add the code back in?
Bai Borko Ali Erturk TURKER February 8, 2023 12:38 CET
Hi Ali,
Thank you for your quick response!
I try with official source https://dovecot.org/releases/2.3/dovecot-2.3.20.tar.gz but there isn't such file "autogen.sh".
The patching finish without errors/warnings:
I run compilation in your way (without step "sh ./autogen.sh") and receive the same error when run make.
One more thing i don't know how relevant it is bu configure script finish with this warning:
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Bai Borko February 8, 2023 13:03 CET
Hi Bai,
Please download dovecot-core tarball from https://github.com/dovecot/core/tags
I don't know the difference between dovecot and dovecot-core, but the core version
works just fine. Then follow my build procedure and let us know the result.
Regards
Ali Erturk TURKER
Reply | Permalink
Why not add the code back in?
Bai Borko Ali Erturk TURKER February 8, 2023 18:54 CET
Hi Roberto, Ali,
finally i successfully build dovecot with vpopmail support from offigial source in this way:
Thank you very much for support !
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Bai Borko February 9, 2023 01:21 CET
Hi Bai,
I'm glad to hear that the patch builds fine for you. The vpopmail auth patch is pretty straightforward, therefore I don't expect any bugs. But please check the dovecot logs and let us know if you see anything strange.
I will try to keep it up-to-date with future dovecot releases.
Regards
Ali Erturk TURKER
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Ali Erturk TURKER February 9, 2023 07:39 CET
Hi Bai, Roberto,
After another code review, I've found that I missed to correct a section which was ifdef'd,
and never used. So the old patch is perfectly fine. Just to make perfectionist feel comfortable,
I created a revised patch :) The link is here. Feel free to share.
Regards
Ali Erturk TURKER
Reply | Permalink
Why not add the code back in?
Bai Borko Ali Erturk TURKER February 9, 2023 13:04 CET
Hi Ali,
The original source dovecot-2.3.20 + new patch dovecot_2.3.20_vpopmail_auth_rev01.patch is build without any issues.
Thx
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Ali Erturk TURKER February 9, 2023 07:56 CET
Ali, I would like to create a link to your patch and it would be great to have it permanent, i.e. a link which is not changed after any review and not depending on dovecot version. I mean.. it would be great if one can grab the latest version simply following a link to your GitHub project
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Roberto Puzzanghera February 9, 2023 08:21 CET
Hi Robertoi
Please copy the patch to your website. Then I will inform you whenever I update it.
Regards,
Ali Erturk TURKER
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Bai Borko February 8, 2023 12:51 CET
This is because the patch modified the configure.ac You have to run autogen to regenerate the configure script
Reply | Permalink
Why not add the code back in?
Herbert Zaunmair Roberto Puzzanghera February 17, 2023 14:09 CET
Hey guys,
absolute great work here - thanks!
I try to install all the stuff here on Rocky Linux 8 (RedHat more or less) and I don't want to use mysql (running qmail for almost 20 years now) - so I was very happy to find Ali's patch here for the newest dovecot Version. But I have a problem with the patch on my server. The patch applies without any error - but after "autoconf" and "automake" I have the string DOVECOT_WANT_VPOPMAIL in my configure file and this codesnippet is missing:
.....which mistake have I made that it isn't working as intended?
Regards,
Herbert
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Herbert Zaunmair February 17, 2023 14:54 CET
Hi Herbert
I could not understand what has failed for you. Below is the simplest build recipe.
Please do not add or remove any other commands, and follow the exact steps below.
If it builds, you can play with the configure options as you wish.
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Ali Erturk TURKER February 17, 2023 15:00 CET
the autogen.sh script appears only when downloading from github. No file like that if downloading from here https://www.dovecot.org/releases/2.3
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Roberto Puzzanghera February 17, 2023 15:39 CET
Hi Roberto,
I checked myself, and confirm that the dovecot github releases page and the dovecot website provide the same sources
with a minor difference:
When you download from gihub and run autogen.sh script, it becomes the tarball you download from dovecot website,
but with a big bonus: it will configured exactly for your own build environment.
So please download from github, run autogen.sh script yourself, and save your precious time :-)
Ali Erturk TURKER
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Ali Erturk TURKER February 17, 2023 15:42 CET
But I don't need to have autogen :-) as I'm not rebuilding the configure...
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Roberto Puzzanghera February 17, 2023 15:49 CET
Hi Robert
Please check the openzfs build page here:
I have been building ZFS myself with this recipe for ages and did not have a single failure.
If you are building qmail with vpopmail and dovecot (and many others), installing autogen (and friends) should not be a concern.
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Herbert Zaunmair February 17, 2023 14:29 CET
try autoreconf -f -i after patching
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Roberto Puzzanghera February 18, 2023 02:01 CET
Hi Roberto
Today I tested and confirm that your suggestion also works.
I summarized both options here, so you can choose whichever you prefer.
- 1st option (tarball downloaded from dovecot website):
- 2nd option (tarball downloaded from dovecot github repo):
The rest is the same (feel free to add/remove options according to your needs):
Hope this helps.
Reply | Permalink
Why not add the code back in?
Herbert Zaunmair Ali Erturk TURKER February 20, 2023 06:46 CET
Hi Roberto, hi Ali,
thank you so much for clarification - it works like a charm now!
I didn't know that both downloads are different and was wondering why the autogen.sh was missing.
Thanks for your support!
Regards,
Herbert
Reply | Permalink
Why not add the code back in?
Ali Erturk TURKER Herbert Zaunmair February 20, 2023 14:54 CET
Hi Roberto,
if you can provide a link to this post on this page, I believe it will be easier for people to understand and apply the patch.
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Ali Erturk TURKER February 20, 2023 15:07 CET
Sure. I've provided the link here https://notes.sagredo.eu/files/qmail/patches/vpopmail/dovecot_vpopmail-auth/. There is also a link to this thread under your name at the top of this page.
Reply | Permalink
Why not add the code back in?
Roberto Puzzanghera Ali Erturk TURKER February 7, 2023 06:27 CET
Thank you. Very much appreciated. I'll link it here and in the vpopmail page
Reply | Permalink
Lua backend
Tyler Simpkin February 12, 2021 13:28 CET
As of Dovecot 2.3, the lua backend can also be used to emulate something close to the original vpopmail, including default domain,etc. I am new to lua, but this seems to work quite well.
-- auth.lua --
Reply | Permalink
Lua backend
Roberto Puzzanghera Tyler Simpkin February 16, 2021 15:07 CET
This is an improved version of the auth.lua that Tyler sent me today (download)
Reply | Permalink
Lua backend
Rick Richard Roberto Puzzanghera April 27, 2021 18:41 CET
Should note that this lua script only works if you store passwords in plaintext in vpopmail. If using MD5-CRYPT as many of us are then add this function:
and then modify db_lookup to return the crypted password like so:
(password = userparams[2] instead of password = userparams[8])
Reply | Permalink
Lua backend
Florian Rick Richard February 10, 2022 19:18 CET
Thank you, Tyler and Rick - I was finally able to upgrade dovecot without much hassle :)
Just one suggestion:
Add the line
before the end of the function auth_password_verify as follows:
this fixes getting the following error messages in syslog in case of a password failure:
Reply | Permalink
Lua backend
Anonymous Florian March 9, 2022 14:10 CET
In most of the approaches I noticed that work normally done by vpopmail's vuserinfo is duplicated, so I figured that we could just use the tool that was meant to do the lookups for maildir and crypted password.
So here's my shot on a purely lua based lookup into the vpopmail that wraps vuserinfo.
Reply | Permalink
Lua backend
Roberto Puzzanghera Tyler Simpkin February 12, 2021 16:40 CET
Thanks a lot, very much appreciated. I'll check it out
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Pablo Murillo February 9, 2021 16:34 CET
Hi
Now, the dovecot 2.3.13 arrives to FreeBSD ports, and now I found that there is not a patch (or I don't find it) for vpopmail with the option -disable-many-domains
The bigger problem is that domain tables reaplace dots whit underscore
Is there a solution for this or I need to start programming :D ?
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 9, 2021 17:23 CET
I think you meant --enable-many-domains, right? Are you using the sql auth driver? If yes I think it can be sufficient to modify a bit the password_query, in order to look in a different table depending on the user's domain.
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Pablo Murillo Roberto Puzzanghera February 10, 2021 00:27 CET
VpopMail config instruction are confused, but to enable 1 domain per table the config option is -disable-many-domains
The problem is the domain table, is changed to underscore, but I just solve this sending the USER whit the domain with underscore :D
User : xxxx@xxxx_com and I use domain as table name
But after a lot of test I found that only works with PLAIN password, if I use CRAM-MD5 or MD5-CRYPT, I get errors from dovecot
Any idea?
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 10, 2021 20:55 CET
The query works here but the %L{domain_first} had to be embedded into quotes.
Can you clarify how did you pass the domain with the underscore?
btw, modifing the query like this breaks the possibility to authenticate with alias domains. I find that todays Steve's solution in dovecot m/l (using sql view) would do both things.
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 10, 2021 11:02 CET
weird... Let me know if the hint of Aki Tuomi in the dovecot m/l solves.
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Pablo Murillo Roberto Puzzanghera February 10, 2021 16:20 CET
Finally
The hint of Aki Tuomi in the dovecot m/l, don't work, but ... he give me another idea
I set encrypted password on Thunder and RoundCube and set default_pass_scheme to PLAIN on dovecot-sql.conf.ext, and now, is working !
Now I need to change vpopmail, beacuse UID / GID is not saved on domain tables !, more work !
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 10, 2021 17:59 CET
I think adding this to your select will be sufficient
Please post your auth config when finished
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Pablo Murillo Roberto Puzzanghera February 11, 2021 03:36 CET
After a lot of test, I was looking for other thing and I found this :
https://wiki.dovecot.org/AuthDatabase/VPopMail
I can't belive that there was a working example :D
Anyway, I did something different for the way we use vpopmail, and I don't changed vpopmail, I created other table that was updated from the system we use, so the uid was taken from the other table
The BIG difference is the way the user MUST be sent to dovecot
Roundcube must be modified too, in rcube_imap.php on connect fucntion I added:
But I have rouncube modified too, so, I don't know if host has the real host for everybody
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 11, 2021 11:23 CET
what if a user connects with a client dfferent from roundcube? I think that we should consider a solution which doesn't touch the client but only the dovecot query...
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Pablo Murillo Roberto Puzzanghera February 14, 2021 00:20 CET
I find a better solution, made an storage procedure returning the information :
Parameters:
User name
Domanin name
Remote IP
Local IP
The select is the same, I only convert domain to table name (replace "-" and "." to "_")
No need to declare OUT variables
I have a lot of code for our internal system in the procedure, this is why I'm not posting it, but is just a :
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 22, 2021 15:49 CET
Pablo, did you find a way to iterate among users when domains have their own table?
Reply | Permalink
What about using --disable-many-domains on vpopmail configure ?
Roberto Puzzanghera Pablo Murillo February 14, 2021 02:05 CET
Great!
Reply | Permalink
Support for aliasdomains added!
Roberto Puzzanghera January 13, 2021 12:12 CET
Finally I found the time to write a wrapper for vaddaliasdomain and adjust the dovecot's sql query. Please test and let me know.
Have fun!
Reply | Permalink
Support for aliasdomains added!
Roberto Puzzanghera Roberto Puzzanghera January 18, 2021 14:52 CET
Now the script has been replaced by a patch, so that vpopmail will do the new sql stuff transparently!
Reply | Permalink
Convert vpopmail cdb backend to use postgres for dovecot
erdgeist January 9, 2021 15:56 CET
I did a little research and you can easily convert vpopmail cdb backend to an sql one. Since I prefer postgres, this is what is needed. YMMW.
Start by installing postgres and add the table
If you have vpopmail re-compiled with postgres backend, this already should be enough to just create a new domain in there
to create all the needed tables. Now it's time to get all the existing user accounts in there. We run the script (NOTE: For this export to work, vpopmail needs to be installed with cdb as backend, of course.)
That produces an sql script that can be imported to postgres like
Finally, as outlined in https://wiki2.dovecot.org/HowTo/DovecotPostgresql, we need to configure dovecot to use the new sql backend. To use the table format of vpopmail, the sql.conf must like something like this:
The only problem I found is that alias domains don't work anymore for dovecot auth, you always need to auth against the main domain.
Reply | Permalink
Convert vpopmail cdb backend to use postgres for dovecot
Roberto Puzzanghera erdgeist January 9, 2021 16:49 CET
Thank you, appreciated.
Concerning the aliasdomain issue, if one adds a table which links the domain to its aliases, and the sql query is modified in order to check both domain and aliases, the auth would be validated... I hope that someone can find the time to write that sql soon or later...
Reply | Permalink
Convert vpopmail cdb backend to use postgres for dovecot
erdgeist Roberto Puzzanghera January 9, 2021 23:10 CET
Modifying the SQL request is not really hard, the hard part is convincing vpopmail to modify the extra table in the database everytime an aliasdomain is added or existing ones modified.
Currently vpopmail only changes /var/qmail/control/virtualdomains :/
Reply | Permalink
Convert vpopmail cdb backend to use postgres for dovecot
Roberto Puzzanghera erdgeist January 10, 2021 10:48 CET
It will be sufficent to write a vaddaliasdomain's wrapper to add a record on the aliasdomains' table and eventually create that table first. In this case we don't even have to patch vpopmail.
Personally it wouldn't be a simple task to do the auth in one single sql query as it's required...
Reply | Permalink
Convert vpopmail cdb backend to use postgres for dovecot
Roberto Puzzanghera Roberto Puzzanghera January 12, 2021 14:58 CET
Supposing that we have a new table 'aliasdomains' with the couples domain/alias, this is an example of the new queries
It will be a minor task to write up a wrapper of addaliasdomain which populates the 'aliasdomains' table.
Reply | Permalink
The passwd-file driver can replace the vpopmail one
Laurent Bercot January 4, 2021 19:15 CET
Hello,
I use vpopmail and was very, very disappointed by the dovecot team's decision to remove the vpopmail auth driver. The words I have for them would get me banned on the spot from any community.
However, with a bit of doc reading, I was able to migrate to another scheme quite easily, and almost painlessly. The backend you want is the passwd-file one.
- Deactivate the vpopmail backend in your /etc/dovecot/10-auth.conf
- Activate the passwd-file backend in your /etc/dovecot/10-auth.conf. The default extension file is probably named auth-passwdfile.conf.ext
- Edit your auth-passwdfile.conf.ext:
Replace /home/vpopmail/domains with the directory where you actually store your domains. :-)
This assumes you're using the default vpasswd settings, with a CRYPT passwd scheme in the vpasswd file. If you're using something else, you may have a bit more configuration work to do in that auth-passwdfile.conf.ext file.
- And now, the small extra pain: assuming all your vpopmail domains are handled by one vchkpw user, you need to change all the uids and gids in all your vpasswd files to the uid/gid of the vchkpwd user (typically 89:89). By default vpopmail puts 1:0 in the uid:gid fields; this would make dovecot attempt to change to uid 1 in order to read mail belonging to user vchkpwd, and would not work. Changing the uid/gid in the vpasswd files allows dovecot to access all the mail. You don't need to recompile vpasswd to vpasswd.cdb: dovecot will only read the text vpasswd files, never the cdb.
- Bear in mind you need to perform that uid/gid change every time you add/modify a user in a vpasswd file. Every time you run vadduser or equivalent, you need to go behind vadduser to make sure the uid and gid fields are correct, else dovecot won't be able to access mail for the new user. I haven't checked whether vmoduser modifies the uid/gid; if it does, you'll also need to clean up after it every time you invoke it.
- There you go. With a small amount of effort, you can keep using vpopmail together with dovecot, and in particular, you don't need to switch to a SQL backend and pull an unnecessary kitchen sink.
Reply | Permalink
The passwd-file driver can replace the vpopmail one
Roberto Puzzanghera Laurent Bercot January 4, 2021 19:26 CET
Thank's a lot for the contribution, it's very much appreciated. I'll check it out.
Reply | Permalink
The passwd-file driver can replace the vpopmail one
Laurent Bercot Roberto Puzzanghera January 5, 2021 13:44 CET
Note that the steps above worked for me because I only use very simple backends with vpopmail: the text vpasswd file (which is the one passwd-file piggybacks on) and the cdb one (unused by dovecot). If your vpopmail configuration is more complex, and you store vuser data into other databases (via SQL, for instance), then you'll have to perform more steps.
However, the idea should remain the same: look at the auth schemes vpopmail is using, and configure dovecot to use the same ones, but accessing the vpopmail data directly instead of relying on glue code that was implemented in the "vpopmail" auth driver. If you're lucky, there will be an auth driver for dovecot that corresponds to how you're using vpopmail, and you will be able to plug it directly into your vpopmail backends. If you're unlucky, however, you will have to program glue yourself, and use something like dovecot-auth-lua to make dovecot use your own programs that access the vpopmail data.
Reply | Permalink
The passwd-file driver can replace the vpopmail one
Roberto Puzzanghera Laurent Bercot January 5, 2021 13:54 CET
Thank you. I suppose that the passwd-file works well also with valiasdomains...
What about the doveadm iteration feature needed to expunge the mailboxes? Does it work with passwd-file as well?
Personally I'll stick with sql, because I already have a working setup. The problem is for people who have domain aliases which can't be easily transported in the sql database.
Reply | Permalink
The passwd-file driver can replace the vpopmail one
Laurent Bercot Roberto Puzzanghera January 5, 2021 15:14 CET
I don't know about the doveadm expunge feature, but if it's an admin tool it shouldn't need to authenticate like a remote user accessing their mail via IMAP would, so I don't see why it should be impacted by auth backends.
Reply | Permalink
The passwd-file driver can replace the vpopmail one
Roberto Puzzanghera Laurent Bercot January 5, 2021 15:45 CET
It is a feature where dovecot has to iterate among all the accounts in order to purge their Trash and Junk folders. The old vpopmail driver didn't have that feature and this is the reason why I switched to sql.
Reply | Permalink
Using version 2.3.11.3 of dovecot, and vpopmail auth still works !
Pablo Murillo September 28, 2020 18:17 CET
Hi
I'm using version 2.3.11.3 of dovecot and vpopmail auth still working
Reply | Permalink
Dovecot is removing support for vpopmail
Jim April 6, 2020 15:03 CET
Hello again, Roberto. I wanted to share this link with folks to the dovecot mailing list. It appears that the plan is to remove support for vpopmail in an upcoming version of dovecot.
https://dovecot.org/pipermail/dovecot/2020-March/118416.html
The thread is long, and has a many folks complaining about removing features on a point release. My guess is that it will not cause a problem for your suggested mysql install, but it will cause a problem for those who are using vpopmail directly. Your instructions here may need a slight edit about installing without mysql.
Reply | Permalink
Dovecot is removing support for vpopmail
Roberto Puzzanghera Jim April 6, 2020 16:17 CET
I'm also wondering which reasons prevent the migration to the sql driver, apart from the one concerning the alias domains already pointed out by Alexandre below...
Reply | Permalink
Dovecot is removing support for vpopmail
Roberto Puzzanghera Jim April 6, 2020 16:08 CET
Hi Jim,
I'll not fail to post something about the topic if I'll find the time, but I'm confident that some hint may also come from one of you who managed to find a solution with the LUA driver or whatelse. It can be enough to post some raw info about the new configuration, to use as a starting point for me to build the new how to.
Reply | Permalink
without vpopmail driver, what about domain aliases?
Alexandre Fonceca April 1, 2020 19:58 CET
dovecot will ended vpopmail driver! oh no!
and what about domain aliases?
the entries of a domain alias are inside /var/qmail/control and /var/qmail/users and if you only use sql authentication in dovecot, it cannot authenticate any user using the alias domain, only by the main domain
currently, I keep the sql driver first to authenticate users and if it fail, dovecot tries the vpopmail driver, to auth the aliases too.
without the vpopmail driver, how would an email@aliasdomain be authenticated in pop3/imap?!
has anyone thought about it?
Reply | Permalink
without vpopmail driver, what about domain aliases?
Roberto Puzzanghera Alexandre Fonceca April 1, 2020 20:18 CET
Even if not much elegant one work around could be the following:
- build a db_table to save the pairs aliasdomain / realdomain
- save a new record when creating an alias by means of a php script
- modify the sql dovecot/auth accordingly to allow both realdomain and aliasdomain
PS as you may have read, finally the dovecot team announced that they will not break vpopmail until the next major release (2.4)
PS2: sorry, the delay will be just for xz, not vpopmail. Look here
Reply | Permalink
without vpopmail driver, what about domain aliases?
Alexandre Fonceca Roberto Puzzanghera April 1, 2020 20:36 CET
indeed!
I also read about getting around via vchkpw that follows the checkpassword driver pattern, or even using the LUA driver
I will do some tests before dovecot abandon the vpopmail drivers and I will post here if I find a working solution.
Reply | Permalink