Configuring Courier-auth to use MySQL

Next the configuration of the authentication module, it will be used by everything the mail-server does. SMTP authentication, access to the IMAP mailbox and eventually access to the web based mail program. To enable the authentication module to use the postfix database we created earlier configure it as follows:

Edit the file authmysqlrc in the directory /usr/local/etc/authlib or download it from the bottom of this page. This will configure the database access like where it is, how to connect, which user and password and which tables and fields to use. You see here again that the configuration needs the UID and the GID from the postfix user as we needed for the postfix configuration, again I have taken the value 27.

MYSQL_SERVER            localhost
MYSQL_USERNAME          postfix
MYSQL_PASSWORD          postfix

# if you used the MySQL package from MySQL.com use the
# following settings otherwise check your MySQL installation.
MYSQL_SOCKET            /private/tmp/mysql.sock
MYSQL_PORT              3306

# The name of the MySQL database we will use:
MYSQL_DATABASE          postfix

# the table in the database with the users
MYSQL_USER_TABLE        mailbox

# which field in the table has the password
MYSQL_CRYPT_PWFIELD     password

# the numerical userid of the postfix account
MYSQL_UID_FIELD         '27'

#the numerical groupid of the postfix account
MYSQL_GID_FIELD         '27'

# the username as defined in the table mailbox
MYSQL_LOGIN_FIELD       username

# the location of the mailboxes on the server
# Please change this is you are going to use a different location.
MYSQL_HOME_FIELD        '/usr/local/virtual'

# The user's name (optional)
MYSQL_NAME_FIELD        name

# The location where the user mailbox is defined in the table.
MYSQL_MAILDIR_FIELD     maildir

Next is configuring the authentication module to use the MySQL based authentication module. Edit the file authdaemonrc in the same directory /usr/local/etc/authlib or download the one at the bottom of the page. We only are going to use the MySQL database for authentication so we need to remove the others:

# The authentication modules that are linked into authdaemond.
authmodulelist="authmysql"
# This setting is used by Courier's webadmin module,
# and should be left alone
authmodulelistorig="authuserdb authpam authldap authmysql
        authcustom authpipe"
# The number of daemons running concurrently on the server
daemons=3
# authdaemonvar is here, but is not used directly by authdaemond.
# It's used by various configuration and build scripts.
# So don't touch it !
authdaemonvar=/usr/local/var/spool/authdaemon
# when testing set the level at 2
# when everything runs smoothly set it to 0.
DEBUG_LOGIN=2
# keeping the defaults for the rest for now.
DEFAULTOPTIONS=""
LOGGEROPTS=""

 

Resources:
authmysqlrc, don’t forget to change the user and password.
authdaemonrc

Comments are closed, to find out why read this blogpost for the reason and directions to alternatives.