# courier-imap & mysql - "Input/output error" (not whitespace)

## MidighToker

Trying to set up a mailserver with exim and courier-imap, using a mysql database to store authentication/maildir/other details in.

Exim is set up and working like a charm. It also checks if users exist/routing for users from a mysql database (this works).

I have been trying for about 48 hours to overlay courier-imap over the top of it all, but i keep getting this error when clients connect and try and authenticate:

```
Nov  4 06:45:58 rackmounted authdaemond: stopping authdaemond children

Nov  4 06:45:59 $servername authdaemond: modules="authmysql", daemons=5

Nov  4 06:45:59 $servername authdaemond: Installing libauthmysql

Nov  4 06:45:59 $servername authdaemond: Installation complete: authmysql

Nov  4 06:46:07 $servername imapd: Connection, ip=[$ip]

Nov  4 06:46:07 $servername imapd: LOGIN FAILED, user=$localpart@domain, ip=[$ip]

Nov  4 06:46:07 $servername imapd: authentication error: Input/output error

```

I have already started talking about the errors i'm getting and what things i've tried to resolve it here: https://forums.gentoo.org/viewtopic-t-398373.html when I thought Dr_Stein was having the same problem as myself, but it turns out he was just suffering from whitespace in the authmysqlrc config file.

+ I know my database is working and is accessable using the authentication details I have provided courier-authlib

|

+ I know that courier-imap is using courier-authlib/authdaemond to authenticate (so its not a communication problem between the two (I dont think).

I am completely stumped. Anyone, with any ideas. PLEASE!   :Shocked: 

----------

## MidighToker

i get the same problem if i try and authenticate against courier-pop3d.

[code]Nov  4 07:00:13 $servername pop3d: Connection, ip=[$ip]

Nov  4 07:00:14 $servername pop3d: LOGIN FAILED, user=daniel@fligg.co.uk, ip=[$ip]

Nov  4 07:00:14 $servername pop3d: authentication error: Input/output error[code]

I'm taking this as a good think. I guess it means its all falling over with courier-authlib.

Still no joy tho :S

----------

## MidighToker

have since done:

   + remerged courier-imap & courier-authlib

   |

   + properly gone through etc-update and made sure everything is upto date.

   |

   + deliberatly set the password wrong in authmysqlrc.

  (+ spent 20min on the phone to Bulldog trying to explain that my routing issues are not at the remote end, when a traceroute stops on hop 3)

I have learnt:

   + courier-imap seems to be talking to courier-authlib.

   |

   + courier-authlib is talking and authenticating correctly with mysql.

     \_ If i deliberatly specify a wrong password then i get a message in syslog from authdaemond

---

Thoughts:

Could it be the structure of my database in authmysqlrc?

Could it be a communication problem between courier-imap and my client?

Could it be anything else.

-> Please, I am desperate for some help.

ta.

```

#rackmounted / # grep -v \# /etc/courier/authlib/authmysqlrc

MYSQL_SERVER            localhost

MYSQL_USERNAME          vexim

MYSQL_PASSWORD          $password

MYSQL_SOCKET            /var/run/mysqld/mysqld.sock

MYSQL_OPT               0

MYSQL_DATABASE          vexim

MYSQL_USER_TABLE        users

MYSQL_CRYPT_PWFIELD     crypt

MYSQL_CLEAR_PWFIELD     clear

MYSQL_UID_FIELD         uid

MYSQL_GID_FIELD         gid

MYSQL_LOGIN_FIELD       username

MYSQL_HOME_FIELD        pop

MYSQL_NAME_FIELD        name

MYSQL_MAILDIR_FIELD     imap

MYSQL_QUOTA_FIELD       quota

```

```

mysql> describe users

    -> ;

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

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

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

| user_id         | int(10) unsigned                                            |      | PRI | NULL    | auto_increment |

| domain_id       | mediumint(8) unsigned                                       |      |     | 0       |                |

| localpart       | varchar(192)                                                |      | MUL |         |                |

| username        | varchar(255)                                                |      |     |         |                |

| clear           | varchar(255)                                                | YES  |     | NULL    |                |

| crypt           | varchar(48)                                                 | YES  |     | NULL    |                |

| uid             | smallint(5) unsigned                                        |      |     | 65534   |                |

| gid             | smallint(5) unsigned                                        |      |     | 65534   |                |

| smtp            | varchar(255)                                                | YES  |     | NULL    |                |

| pop             | varchar(255)                                                | YES  |     | NULL    |                |

| type            | enum('local','alias','catch','fail','piped','admin','site') |      |     | local   |                |

| admin           | tinyint(1)                                                  |      |     | 0       |                |

| on_avscan       | tinyint(1)                                                  |      |     | 0       |                |

| on_blocklist    | tinyint(1)                                                  |      |     | 0       |                |

| on_complexpass  | tinyint(1)                                                  |      |     | 0       |                |

| on_forward      | tinyint(1)                                                  |      |     | 0       |                |

| on_piped        | tinyint(1)                                                  |      |     | 0       |                |

| on_spamassassin | tinyint(1)                                                  |      |     | 0       |                |

| on_vacation     | tinyint(1)                                                  |      |     | 0       |                |

| enabled         | tinyint(1)                                                  |      |     | 1       |                |

| flags           | varchar(16)                                                 | YES  |     | NULL    |                |

| forward         | varchar(255)                                                | YES  |     | NULL    |                |

| unseen          | tinyint(1)                                                  | YES  |     | 0       |                |

| maxmsgsize      | mediumint(8) unsigned                                       |      |     | 0       |                |

| quota           | int(10) unsigned                                            |      |     | 0       |                |

| realname        | varchar(255)                                                | YES  |     | NULL    |                |

| sa_tag          | smallint(5) unsigned                                        |      |     | 0       |                |

| sa_refuse       | smallint(5) unsigned                                        |      |     | 0       |                |

| tagline         | varchar(255)                                                | YES  |     | NULL    |                |

| vacation        | varchar(255)                                                | YES  |     | NULL    |                |

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

30 rows in set (0.00 sec)

```

-and an example of contents, just to show you whats in each field:

```

mysql> select * from users where username = "test1@thepopeabused.me.uk";

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

| user_id | domain_id | localpart | username                  | clear  | crypt                              | uid | gid | smtp                                         | pop                                  | type  | admin | on_avscan | on_blocklist | on_complexpass | on_forward | on_piped | on_spamassassin | on_vacation | enabled | flags | forward | unseen | maxmsgsize | quota | realname | sa_tag | sa_refuse | tagline | vacation |

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

|      42 |        12 | test1     | test1@mydomain.me.uk | qwerty | $1$uxwUSFKz$5jXJuKGMu1RXcYo3NpW0f. |  90 |  90 | /var/vmail/mydomain.me.uk/test1/Maildir | /var/vmail/mydomain.me.uk/test1 | local |     0 |         0 |            0 |              0 |          0 |        0 |               0 |           0 |       1 | NULL  | NULL    |      0 |          0 |     0 | test1    |      0 |         0 | NULL    | NULL     |

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

```

ps: sorry for throwing you're browsers h axis off with the long strings.

1 row in set (0.00 sec)

----------

## MidighToker

log story short, alxcm in the chatroom educated me on strace and i managed to find that  had the wrong database fields set in authmysqlrc.

if you're having problems, and none of the other fixes work, then try the following:

```

ps aux | grep auth
```

and write down the pids of your /usr/lib/courier/courier-authlib/authdaemond files (ignore courierlogger).

run the following for each pid you get. (bear in mind, after you first run the command it prints out text, so you have to press enter to clear to a prompt before you can type it in a second time).

```
strace -s 10000 -p $pid &
```

try logging into courier-imap from your mailclient. As well as the logs in syslog, you'll get a full list of what exactly the courier-authlib process is doing -printed to the console, so you can check your mysql connections.

I found it usefull to be logged into mysql at the same time so i could check the mysql queries i was seeing from the strace output.

PS> have a look at the MAILDIR settings in imapd. i found Maildir rather than .maildir very handy  :Very Happy: 

Also: if you have specified a seperate path for the maildir directory as well as the home directory then it seems to use /full-homedirectory-path/full-maildir-path. so if your home directory is "/var/vmail/domain.name/username/" and your maildir is "/var/vmail/domain.name/username/Maildir" then courier-imap uses the path "/var/vmail/domain.name/username/var/vmail/domain.name/username/Maildir" which is a fun one.

Enjoy and i hope some of my wramblings help... someone.

----------

## Dreadfull

checked strace was running

```

root      2909  0.0  0.0   2804   532 pts/1    S    18:11   0:00 strace -s 10000 -p 19695

root     19695  0.0  0.0  30484  1700 ?        S    18:10   0:00 /usr/lib/courier/courier-authlib/authdaemond

root     25973  0.0  0.0   2804   532 pts/1    S    18:11   0:00 strace -s 10000 -p 27153

root     27153  0.0  0.0  30484  1700 ?        S    18:10   0:00 /usr/lib/courier/courier-authlib/authdaemond

root     12671  0.0  0.0   2804   532 pts/1    S    18:11   0:00 strace -s 10000 -p 10960

root     10960  0.0  0.0  30484  1700 ?        S    18:10   0:00 /usr/lib/courier/courier-authlib/authdaemond

root     18879  0.0  0.0   2804   532 pts/1    S    18:11   0:00 strace -s 10000 -p 32528

root     32528  0.0  0.0  30484  1700 ?        S    18:10   0:00 /usr/lib/courier/courier-authlib/authdaemond

root      7611  0.0  0.0   2804   532 pts/1    S    18:11   0:00 strace -s 10000 -p 15660

root     15660  0.0  0.0  30484  1700 ?        S    18:10   0:00 /usr/lib/courier/courier-authlib/authdaemond

root     15528  0.0  0.0   8680   904 pts/1    R+   18:12   0:00 ps aux

```

got this when tryied to login

```

[ 18:12:02 ] root@phantom (/etc/courier-imap)# ) = 1 (in [5], left {208, 401000})

) = 1 (in [5], left {208, 400000})

) = 1 (in [5], left {208, 400000})

) = 1 (in [5], left {208, 400000})

accept(5, accept(5, accept(5, accept(5, 0x7fffffffe550, [16])         = -1 EAGAIN (Resource temporarily unavailable)

0x7fffffffe550, [16])         = -1 EAGAIN (Resource temporarily unavailable)

0x7fffffffe550, [16])         = -1 EAGAIN (Resource temporarily unavailable)

0x7fffffffe550, [16])         = -1 EAGAIN (Resource temporarily unavailable)

select(6, [3 5], NULL, NULL, {300, 0}select(6, [3 5], NULL, NULL, {300, 0}select(6, [3 5], NULL, NULL, {300, 0}select(6, [3 5], NULL, NULL, {300, 0}

```

----------

## MidighToker

I remember getting recorce temp unavailible errors when i was strace-ing my authdaemond but they were red herrings.

what problems are you having?

what have you tried?

----------

