{"id":297,"date":"2008-09-04T22:21:22","date_gmt":"2008-09-05T02:21:22","guid":{"rendered":"http:\/\/nuxx.net\/blog\/?p=297"},"modified":"2008-09-04T22:47:29","modified_gmt":"2008-09-05T02:47:29","slug":"smtp-auth-for-postfix-via-courier-authlib-authdaemond","status":"publish","type":"post","link":"https:\/\/nuxx.net\/blog\/2008\/09\/04\/smtp-auth-for-postfix-via-courier-authlib-authdaemond\/","title":{"rendered":"SMTP-AUTH for Postfix via courier-authlib (authdaemond)"},"content":{"rendered":"<p>Getting <a href=\"http:\/\/en.wikipedia.org\/wiki\/SMTP-AUTH\">SMTP authentication<\/a> working with Postfix via authdaemond on FreeBSD 7.0 without occasional, useless errors in <tt>\/var\/log\/messages<\/tt> has just caused me an hour of frustration. Therefore, I wish to document what I had to do to make it work right:<\/p>\n<p>First off, <a href=\"http:\/\/www.postfix.org\">Postfix<\/a> (<a href=\"http:\/\/www.freebsd.org\/cgi\/url.cgi?ports\/mail\/postfix\/pkg-descr\">mail\/postfix<\/a>) and <a href=\"http:\/\/www.courier-mta.org\/authlib\/\">courier-authlib<\/a> with MySQL support (<a href=\"http:\/\/www.freebsd.org\/cgi\/url.cgi?ports\/security\/courier-authlib\/pkg-descr\">security\/courier-authlib<\/a> with AUTH_MYSQL set in the config) must be installed. Setting up courier-authlib to talk to a MySQL db is beyond the scope of this document, but it basically involves setting the following lines:<\/p>\n<p><tt>\/usr\/local\/etc\/authlib\/authdaemonrc:<\/tt><\/p>\n<blockquote><p><tt>authmodulelist=\"authmysql\"<\/tt><\/p><\/blockquote>\n<p><tt>\/usr\/local\/etc\/authlib\/authmysqlrc<\/tt>:<\/p>\n<blockquote><p><tt>MYSQL_SERVER localhost<\/tt><br \/>\n<tt>MYSQL_SOCKET \/tmp\/mysql.sock<\/tt><br \/>\n<tt>MYSQL_PORT 0<\/tt><br \/>\n<tt>MYSQL_OPT 0<\/tt><br \/>\n<tt>MYSQL_USERNAME mail<\/tt><br \/>\n<tt>MYSQL_PASSWORD [OBSCURED]<\/tt><br \/>\n<tt>MYSQL_DATABASE mail<\/tt><br \/>\n<tt>MYSQL_USER_TABLE mailbox<\/tt><br \/>\n<tt>MYSQL_CRYPT_PWFIELD password<\/tt><br \/>\n<tt>MYSQL_UID_FIELD uid<\/tt><br \/>\n<tt>MYSQL_GID_FIELD gid<\/tt><br \/>\n<tt>MYSQL_LOGIN_FIELD pobox<\/tt><br \/>\n<tt>MYSQL_HOME_FIELD homedir<\/tt><br \/>\n<tt>MYSQL_MAILDIR_FIELD CONCAT(homedir,'\/',maildir,'\/')<\/tt><br \/>\n<tt>MYSQL_QUOTA_FIELD quota<\/tt><br \/>\n<tt>MYSQL_NAME_FIELD name<\/tt><\/p><\/blockquote>\n<p>After that is set, Postfix&#8217;s <tt>main.cf<\/tt> must have SASL enabled with <tt>smtpd_sasl_auth_enable = yes<\/tt>. Next, the following <tt>smtpd.conf<\/tt> must be placed in <tt>\/usr\/local\/etc\/sasl2<\/tt>:<\/p>\n<p><tt>\/usr\/local\/etc\/sasl2\/smtpd.conf<\/tt><\/p>\n<blockquote><p><tt>pwcheck_method: authdaemond<\/tt><br \/>\n<tt>log_level: 3<\/tt><br \/>\n<tt>mech_list: PLAIN LOGIN<\/tt><br \/>\n<tt>authdaemond_path: \/var\/run\/authdaemond\/socket<\/tt><\/p>\n<p><tt>auxprop_plugin: mysql<\/tt><br \/>\n<tt>sql_select: select password from users where email = '%u@%r'<\/tt><\/p><\/blockquote>\n<p>Now, here&#8217;s the stupid part. See those last two lines, <tt>auxprop_plugin: mysql<\/tt> and <tt>sql_select: select...<\/tt>? They don&#8217;t do anything, and that SELECT statement won&#8217;t even return anything useful on my db. Without them there SMTP AUTH works great. However, if you don&#8217;t have those lines there, Postfix will regularly complain loudly with errors such as these:<\/p>\n<blockquote><p><tt>Sep  4 21:30:02 banstyle postfix\/smtpd[47677]: sql_select option missing<\/tt><br \/>\n<tt>Sep  4 21:30:02 banstyle postfix\/smtpd[47677]: auxpropfunc error no mechanism available<\/tt><\/p><\/blockquote>\n<p>Please note that with authdaemond, CRAM-MD5 and DIGEST-MD5 authentication mechanisms won&#8217;t work. (These would normally be set with <tt>mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5<\/tt>.) If enabled they will appear available but won&#8217;t work.<\/p>\n<p>One final thing&#8230; Want to know how to be sure that the server is notifying clients that it supports authentication? Just simply <a href=\"http:\/\/en.wikipedia.org\/wiki\/Telnet\">telnet<\/a> to port 25 on your mail server and type in <tt>EHLO domain.com<\/tt>. The <tt>AUTH LOGIN PLAIN<\/tt> and <tt>AUTH=LOGIN PLAIN<\/tt> lines show you that plain-text authentication is now available:<\/p>\n<blockquote><p><tt>c0nsumer@banstyle:~&gt; telnet localhost 25<\/tt><br \/>\n<tt>Trying 127.0.0.1...<\/tt><br \/>\n<tt>Connected to localhost.<\/tt><br \/>\n<tt>Escape character is '^]'.<\/tt><br \/>\n<tt>220 banstyle.nuxx.net ESMTP Postfix<\/tt><br \/>\n<tt>EHLO nuxx.net<\/tt><br \/>\n<tt>250-banstyle.nuxx.net<\/tt><br \/>\n<tt>250-PIPELINING<\/tt><br \/>\n<tt>250-SIZE 10240000<\/tt><br \/>\n<tt>250-VRFY<\/tt><br \/>\n<tt>250-ETRN<\/tt><br \/>\n<tt>250-STARTTLS<\/tt><br \/>\n<tt>250-AUTH LOGIN PLAIN<\/tt><br \/>\n<tt>250-AUTH=LOGIN PLAIN<\/tt><br \/>\n<tt>250-ENHANCEDSTATUSCODES<\/tt><br \/>\n<tt>250-8BITMIME<\/tt><br \/>\n<tt>250 DSN<\/tt><br \/>\n<tt>QUIT<\/tt><br \/>\n<tt>221 2.0.0 Bye<\/tt><br \/>\n<tt>Connection closed by foreign host.<\/tt><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Getting SMTP authentication working with Postfix via authdaemond on FreeBSD 7.0 without occasional, useless errors in \/var\/log\/messages has just caused me an hour of frustration.&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/nuxx.net\/blog\/2008\/09\/04\/smtp-auth-for-postfix-via-courier-authlib-authdaemond\/\">Continue reading<span class=\"screen-reader-text\">SMTP-AUTH for Postfix via courier-authlib (authdaemond)<\/span><\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,4],"tags":[],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-computers","category-nuxxnet","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/comments?post=297"}],"version-history":[{"count":12,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/297\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/media?parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/categories?post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/tags?post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}