<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.mkcs.at/wikien/index.php?action=history&amp;feed=atom&amp;title=Postfix_with_SASL_authentication_against_MySQL</id>
	<title>Postfix with SASL authentication against MySQL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.mkcs.at/wikien/index.php?action=history&amp;feed=atom&amp;title=Postfix_with_SASL_authentication_against_MySQL"/>
	<link rel="alternate" type="text/html" href="https://wiki.mkcs.at/wikien/index.php?title=Postfix_with_SASL_authentication_against_MySQL&amp;action=history"/>
	<updated>2026-05-03T19:34:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.mkcs.at/wikien/index.php?title=Postfix_with_SASL_authentication_against_MySQL&amp;diff=41&amp;oldid=prev</id>
		<title>MkWikiEnSysOp: 3 revisions imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.mkcs.at/wikien/index.php?title=Postfix_with_SASL_authentication_against_MySQL&amp;diff=41&amp;oldid=prev"/>
		<updated>2018-06-28T17:19:35Z</updated>

		<summary type="html">&lt;p&gt;3 revisions imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;General hint:&amp;#039;&amp;#039;&amp;#039; Shells like bash record every command you enter. testsaslauthd requires the password to be supplied via a command line argument which is a severe security issue (see [https://bugzilla.redhat.com/show_bug.cgi?id=469589 Bug 469589 in Red Hat Bugzilla] for example). In bash this can be circumvented by putting a space in front of the command (this prevents bash from saving the command in the history).&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ve setup a mail system (Debian Wheezy, postfix, courier, authentication data stored in a mysql database; postfix should use SASL to authenticate) and my main problem was that SASL didn&amp;#039;t work. After searching around in the WWW, I found there&amp;#039;s a command &amp;quot;testsaslauthd&amp;quot; which can be used to test if SASL works at all (if it doesn&amp;#039;t, Postfix will fail as well). If I issued&lt;br /&gt;
&lt;br /&gt;
 testsaslauthd -u user@domain -p password -f /var/spool/postfix/var/run/saslauthd/mux -s smtp&lt;br /&gt;
&lt;br /&gt;
I just got a&lt;br /&gt;
&lt;br /&gt;
 0: NO &amp;quot;authentication failed&amp;quot;&lt;br /&gt;
&lt;br /&gt;
which wasn&amp;#039;t very helpful. Then I tried if authentication against PAM would work which can be tested by ommiting the &amp;quot;-s&amp;quot; parameter and specifying &amp;quot;-u&amp;quot; accordingly (without the &amp;quot;@domain&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
 testsaslauthd -u user -p password -f /var/spool/postfix/var/run/saslauthd/mux&lt;br /&gt;
&lt;br /&gt;
That worked like a charm and gave me back&lt;br /&gt;
&lt;br /&gt;
 0: OK &amp;quot;Success.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The file &amp;quot;/var/spool/postfix/var/run/saslauthd/mux&amp;quot; is in use by /usr/sbin/saslauthd. Occasionally, &amp;lt;code&amp;gt;service saslauthd restart&amp;lt;/code&amp;gt; (System V) or &amp;lt;code&amp;gt;systemctl restart saslauthd&amp;lt;/code&amp;gt; (SystemD) might help in case of problems.&lt;br /&gt;
&lt;br /&gt;
The log files syslog and mail.log didn&amp;#039;t contain any information what was going wrong. After some hours of searching around I found out that the cause was a very little one. I watched the messages in /var/log/auth.log and found&lt;br /&gt;
&lt;br /&gt;
 Sep 29 19:36:39 v22014092384920520 saslauthd[13364]: PAM unable to dlopen(pam_mysql.so): /lib/security/pam_mysql.so: cannot open shared object file: No such file or directory&lt;br /&gt;
 Sep 29 19:36:39 v22014092384920520 saslauthd[13364]: PAM adding faulty module: pam_mysql.so&lt;br /&gt;
 Sep 29 19:36:39 v22014092384920520 saslauthd[13364]: DEBUG: auth_pam: pam_authenticate failed: Module is unknown&lt;br /&gt;
 Sep 29 19:36:39 v22014092384920520 saslauthd[13364]: do_auth         : auth failure: [user=user@domain] [service=smtp] [realm=] [mech=pam] [reason=PAM auth error]&lt;br /&gt;
&lt;br /&gt;
The module that should be used is specified in /etc/pam.d/smtp. I then connected to a system where all this magic works and issued&lt;br /&gt;
&lt;br /&gt;
 dpkg -S /lib/security/pam_mysql.so&lt;br /&gt;
&lt;br /&gt;
which printed&lt;br /&gt;
&lt;br /&gt;
 libpam-mysql: /lib/security/pam_mysql.so&lt;br /&gt;
&lt;br /&gt;
By simply typing&lt;br /&gt;
&lt;br /&gt;
 apt-get install libpam-mysql&lt;br /&gt;
&lt;br /&gt;
the problem was solved and testsaslauthd returned OK.&lt;br /&gt;
&lt;br /&gt;
The second problem was that postfix denied any attempts to login via SMTP. First it&amp;#039;s interesting how the login works: The username and password are being encoded in BASE64 and transmitted to the server. This encoding can be done using bash:&lt;br /&gt;
&lt;br /&gt;
 echo -ne &amp;#039;\000user@domain\000p@$$w0rd&amp;#039; | openssl base64&lt;br /&gt;
&lt;br /&gt;
which prints a string like &amp;quot;AHVzZXJAZG9tYWluAHBAJCR3MHJk&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The method to check if the server accepts your credentials is by talking SMTP to the server:&lt;br /&gt;
&lt;br /&gt;
 openssl s_client -connect localhost:25 -starttls smtp&lt;br /&gt;
&lt;br /&gt;
First say &amp;quot;helo hostname&amp;quot;, then login with&lt;br /&gt;
&lt;br /&gt;
 auth plain (BASE64 encoding of username/password)&lt;br /&gt;
&lt;br /&gt;
If it says&lt;br /&gt;
&lt;br /&gt;
 235 2.7.0 Authentication successful&lt;br /&gt;
&lt;br /&gt;
you&amp;#039;re lucky and you could try to send mail with&lt;br /&gt;
&lt;br /&gt;
 mail from: &amp;lt;user@domain&amp;gt;&lt;br /&gt;
 rcpt to: &amp;lt;user@domain&amp;gt;&lt;br /&gt;
 data&lt;br /&gt;
 Subject: Some subject&lt;br /&gt;
 (empty line)&lt;br /&gt;
 Some text&lt;br /&gt;
 (empty line)&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
If something goes wrong, postfix replies:&lt;br /&gt;
&lt;br /&gt;
 535 5.7.8 Error: authentication failed: authentication failure&lt;br /&gt;
&lt;br /&gt;
or with some other error like &amp;quot;generic failure&amp;quot; or &amp;quot;no mechanism available&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>MkWikiEnSysOp</name></author>
	</entry>
</feed>