# [Courier IMAP] + MySQL authentication not working

## Bart B

Hi all,

I've been working on my Postfix+Courier+MySQL config for a couple of day's, but i still have problems.

Postfix now puts the mail in the right directory, Courier IMAP however is not working :'( . When I connect with it using kmail it give's an error that the login failed.

My relevant config files are:

authmysqlrc.dist

```

MYSQL_SERVER      localhost

MYSQL_USERNAME      postfix

MYSQL_PASSWORD      ***plain password***

MYSQL_SOCKET      /var/mysql/mysql.sock

#MYSQL_PORT      0

MYSQL_OPT      0

MYSQL_DATABASE      SERV_mailconfig

MYSQL_USER_TABLE   users

#MYSQL_CRYPT_PWFIELD   crypt

MYSQL_CLEAR_PWFIELD   password

DEFAULT_DOMAIN      bart-workstation

MYSQL_UID_FIELD      uid

MYSQL_GID_FIELD      gid

MYSQL_LOGIN_FIELD   id

MYSQL_HOME_FIELD   home

MYSQL_NAME_FIELD   realname

MYSQL_MAILDIR_FIELD   maildir

# MYSQL_QUOTA_FIELD   quota

MYSQL_WHERE_CLAUSE   'imapon=1'

```

authdeamonrc

```

authmodulelist="authmysql"

authmodulelistorig="authmysql"

daemons=5

version=""

authdaemonvar=/var/lib/courier-imap/authdaemon

```

the database

```

mysql> USE SERV_mailconfig

Database changed

mysql> show tables;

+---------------------------+

| Tables_in_SERV_mailconfig |

+---------------------------+

| users                     |

+---------------------------+

1 row in set (0.00 sec)

mysql> describe users;

+----------+----------------------+------+-----+---------+----------------+

| Field    | Type                 | Null | Key | Default | Extra          |

+----------+----------------------+------+-----+---------+----------------+

| idnr     | int(11)              |      | MUL | NULL    | auto_increment |

| id       | varchar(128)         |      | PRI |         |                |

| password | varchar(128)         |      |     |         |                |

| realname | varchar(128)         |      |     |         |                |

| uid      | smallint(5) unsigned |      |     | 8       |                |

| gid      | smallint(5) unsigned |      |     | 208     |                |

| home     | varchar(128)         |      |     | /       |                |

| maildir  | varchar(255)         |      |     |         |                |

| imapon   | tinyint(3) unsigned  |      |     | 1       |                |

+----------+----------------------+------+-----+---------+----------------+

9 rows in set (0.00 sec)

```

in my log-files I see the following when I tried to connect:

mail.info

 *Quote:*   

> 
> 
> Jul 11 13:15:45 bart-workstation imapd: Connection, ip=[::ffff:127.0.0.1]
> 
> Jul 11 13:15:50 bart-workstation imapd: LOGIN FAILED, ip=[::ffff:127.0.0.1]
> ...

 

I don't understand why it is going wrong. Can someone help me :'(

----------

## klieber

Can you establish a connection to mysql using courier's credentials?  (to make sure that the password, etc. work?)

--kurt

----------

## Bart B

 *klieber wrote:*   

> Can you establish a connection to mysql using courier's credentials?  (to make sure that the password, etc. work?)
> 
> --kurt

 

I can. It's the same user&pass I use for Postfix

----------

## Nitro

I have this setup on my box at home. Postfix and courier-imap look to mysql for all the info.

Try tail -f /var/log/mysql/<you log>.log.  My inital problems were that it wasn't connecting to MySQL.  I recompiled and it worked fine <shurg>.

I'm in a hurry, (gotta go like -10 mins ago).  I can help you more when I get home like around 12:30 central US time.

----------

## Bart B

It seems mine isn't connecting as well... so... I recompile... something :'(

[edit]

YEE!!! IT's WORKING FINALLY!!!! thanks!

the PID file (or something) was stated incorrect. 

Now I can die peacefully  :Wink: 

----------

## cbrese

I'm having a very simular problem, when I try to login with telnet I just get this

```

1 login jason test

1 NO Login failed.

```

If I tail /var/log/mail/current I get

```

Aug  6 14:52:29 [imapd] Connection, ip=[::ffff:127.0.0.1]

Aug  6 14:52:43 [imapd] LOGIN FAILED, ip=[::ffff:127.0.0.1]

```

I think courier isn't able to talk to mysql, but I don't know why.  I can connect to mysql with the courier user/password and select data.

configs:

```

egrep ^[^#] authmysqlrc

MYSQL_SERVER            localhost

MYSQL_USERNAME          courier

MYSQL_PASSWORD          test

MYSQL_SOCKET            /tmp/mysql.sock

MYSQL_DATABASE          maildb

MYSQL_USER_TABLE        users

MYSQL_CRYPT_PWFIELD     crypt

MYSQL_CLEAR_PWFIELD     clear

MYSQL_UID_FIELD         uid

MYSQL_GID_FIELD         gid

MYSQL_LOGIN_FIELD       id

MYSQL_HOME_FIELD        home

MYSQL_NAME_FIELD        name

MYSQL_MAILDIR_FIELD     maildir

egrep ^[^#] authdaemonrc

authmodulelist="authmysql"

authmodulelistorig="authcustom authcram authuserdb authmysql authpam"

daemons=5

version="authdaemond.mysql"

authdaemonvar=/var/lib/courier-imap/authdaemon

```

this is what I got when I started the services

```

# /etc/init.d/courier-imapd start

 * Starting courier-imapd...                                                                                        [ ok ]

# /etc/init.d/authdaemond start

 * Starting authdaemond.mysql...                                                                                    [ ok ]

```

I had to create /tmp/mysql.sock by doing this:

```

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

```

Was that the correct thing to do?

I'm running out of things to try and I realy want this to work.

----------

## cbrese

I just realized that the link I made to mysql.sock was wrong so I deleted it and did this:

```

ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

```

That didn't fix my problem though.

----------

## cbrese

I have some more information...

I can see that courier is connecting to mysql by looking in /var/log/mysql/mysql.log.  

I'm still not able to connect though, I think the problem may have something to do with how I'm setting the password in mysql.  This is what I did

```

update maildb.users set crypt=PASSWORD('test');

```

Is that the correct way?

If I set crypt to null then courier ends my telnet session.

----------

## cbrese

The password was the problem.  I need to do this:

```

update maildb.users set crypt = encrypt('test');

```

----------

## Beavis

One problem I ran into was having too many spaces in the authmysqlrc file between the variables & settings

e.g.

MYSQL_SERVER    localhost

instead of

MYSQL_SERVER localhost

apparently, you can only have one space/tab between them

----------

## cbrese

I have a few tabs/spaces between my variable names and values and it works fine, but you can't have any trailing spaces/tabs.

----------

