# [SOLVED]courier-imap & mysql - "Input/output error"

## Dr_Stein

I'm building up a new mail server using Postfix, courier-imap, and a mysql backend.

The *old* (pre 4.x) courier-imap setup is working great on another box and has been for a couple of years now. This is a brand new machine, and even after following the mailserver howto, it's not going so well. 

I keep getting this in my mail.log:

Nov  2 21:42:22 mail imapd: Connection, ip=[192.168.10.10]

Nov  2 21:42:22 mail authdaemond: failed to connect to mysql server (server=127.0.0.1., userid=mailsql.): Access denied for user 'mailsql.'@'localhost' (using password: YES)

Nov  2 21:42:22 mail imapd: LOGIN FAILED, user=jnichols@pbp.net, ip=[192.168.10.10]

Nov  2 21:42:22 mail imapd: authentication error: Input/output error

'mailsql' does have proper permissions to use the db on 127.0.0.1 - I can run mysql command line stuff with no problems. No issues popping up in the mysql logs at all. 

I have compiled courier-authlib and cyrus-sasl with mysql support. I can see that it's loading the libmysql auth module too..

Nov  3 09:14:42 mail authdaemond: stopping authdaemond children

Nov  3 09:14:43 mail authdaemond: modules="authmysql authpam", daemons=5

Nov  3 09:14:43 mail authdaemond: Installing libauthmysql

Nov  3 09:14:43 mail authdaemond: Installation complete: authmysql

Nov  3 09:14:43 mail authdaemond: Installing libauthpam

Nov  3 09:14:43 mail authdaemond: Installation complete: authpam

I have also searched extensively through the forums and found many posts pointing to this, but no solutions (except to remove mysql support, which is not a solution for me) 

Has anyone actually been able to solve this problem?Last edited by Dr_Stein on Fri Nov 04, 2005 5:56 am; edited 1 time in total

----------

## kashani

in your error I see 'mailsql.' and not 'mailsql' Is that just the way it's printed on do you have a typo in a config file?

kashani

----------

## Dr_Stein

# The server name, userid, and password used to log in.

MYSQL_SERVER            127.0.0.1       

MYSQL_USERNAME          mailsql 

MYSQL_PASSWORD         (my password)

That's the way it's printed in the error. I checked for an extra dot, and there isn't one.  :Sad: 

----------

## kashani

Try changing your Mysql server name to localhost instead of 127.0.0.1 in the config. Mysql can be strange about names and DNS when it authenticates.

kashani

----------

## Dr_Stein

I tried that before and got this:

Nov  2 21:41:16 mail authdaemond: failed to connect to mysql server (server=localhost., userid=mailsql.): Unknown MySQL server host 'localhost.' (3)

There was no 'dot' after localhost in my config, either. or after the userid. I have no idea where it's getting these dots from..

----------

## MidighToker

I'm having exactly the same problems as yourself -except i'm using exim.

Check your /etc/courier/authlib/authmysqlrc file. I found that I had whitespace (a space or a tab) after localhost on the MYSQL_SERVER line. 

After i did that, i got as far as i did using 127.0.0.1, which is back to here:

```
Nov  4 00:46:18 $servername d imapd: Connection, ip=[::ffff:$ip]

Nov  4 00:46:19 $servername imapd: LOGIN FAILED, user=daniel@fligg.co.uk, ip=[::ffff:$ip]

Nov  4 00:46:19 $servername imapd: authentication error: Input/output error
```

but atleast its one problem down.

To tick off stages that could be the problem;

+ I know mysql works (with the login details i've provided) as the same database is being accessed by exim.

|

+ I know courier-imap is authenticating against courier-authlib.

  \_ This was a problem i was haivng earlier, and that other people seem to have been having.

Courier-authlib sems to be checking mysql on a port number -exim is using a socket. Will change that next....

----------

## Dr_Stein

Nov  3 22:33:17 mail imapd: Connection, ip=[192.168.10.10]

Nov  3 22:33:17 mail authdaemond: authmysql: mysql_select_db(mailsql.) error: Incorrect database name 'mailsql.'

Nov  3 22:33:17 mail imapd: LOGIN FAILED, user=jnichols@pbp.net, ip=[192.168.10.10]

Nov  3 22:33:17 mail imapd: authentication error: Input/output error

Nov  3 22:36:06 mail authdaemond: stopping authdaemond children

Nov  3 22:36:07 mail authdaemond: modules="authmysql authpam", daemons=5

Nov  3 22:36:07 mail authdaemond: Installing libauthmysql

Nov  3 22:36:07 mail authdaemond: Installation complete: authmysql

Nov  3 22:36:07 mail authdaemond: Installing libauthpam

Nov  3 22:36:07 mail authdaemond: Installation complete: authpam

Nov  3 22:36:13 mail imapd: Connection, ip=[192.168.10.10]

Nov  3 22:36:13 mail imapd: LOGIN FAILED, user=jnichols@pbp.net, ip=[192.168.10.10]

Nov  3 22:36:33 mail imapd: LOGIN, user=jnichols@pbp.net, ip=[192.168.10.10], protocol=IMAP

Nov  3 22:36:52 mail imapd: Connection, ip=[192.168.10.10]

Nov  3 22:36:52 mail imapd: LOGIN, user=jnichols@pbp.net, ip=[192.168.10.10], protocol=IMAP

---------

It was a whitespace! I had just done a find/replace in vi on the default names. The solution? I commented out the original lines and typed in them myself manually and restarted authlib.

And.. voila. It starts to work. What a silly problem, and what's scary is that there are other people asking it and getting hung up on it. This oughta be a sticky.

----------

## MidighToker

If you specify the socket in /etc/courier/authlib/authmysqlrc (my gentoo system seems to have it as /var/run/mysqld/mysqld.sock) and comment out the port number, restart authlib and try again, you still get the same error message.

If i have a look at my exim configuration the socket connection is defined as:

```
localhost::(/var/run/mysqld/mysqld.sock)/$database/$username/$password
```

but then all of these details are defined in the authmysqlrc file, so this is almost certainly nothing and I should stop thinking about it.

If I change the sql authentication details to root and try again, i still get the same errors.

I was wondering if it could be a problem with authlibd not having permissions to contact the socket file, but authdaemon and imapd are both running as root.

It seems some other people are having problems as well. I'm going back to googlewhacking (some advise just not using mysql, but its not that practical) and see if there's anyone who's managed to sort this yet.

----------

## MidighToker

ah, you've got it working.

Mine is still flummuxed (as you can see above).

The only difference i can see between our log files is that my version of courier seems to have ipv6 support, and is also trying to load a couple of more modules: 

```
(Nov  4 05:59:21 $servername authdaemond: modules="authmysql authuserdb authshadow authcustom authpipe", daemons=10
```

I'm going to cut out all the modules except authmysql and pam (tho i'm not quite sure why i need pam if its all for virual users), try it again, and failing that re-compile without ipv6.

Glad you're up and working tho  :Very Happy: 

----------

## MidighToker

well, i've tried it (again) with just mysqlrc as an option (there wasn't pam) so i've gotten rid of ipv6 in my package.use file nd its re-compiling.

my version of sql is out of date;

```
dev-db/mysql

      Latest version available: 4.1.14

      Latest version installed: 4.0.25-r2
```

I'm just wondering if it *needs* to be updated   :Confused: 

If anyone has any suggestions, please please, please -help me.

----------

## MidighToker

As this problem is closed, i have moved my ongoing problems to: https://forums.gentoo.org/viewtopic-p-2851131.html#2851131

any help will be VERY much appriciated   :Very Happy: 

----------

