PDA

View Full Version : POP3 + MySQL strange problem


hammer
15th July 2006, 10:12
Hi there, i have a problem using pop3 + mysql, everything should run but ... ofcourse this is not the case, even google said that he never saw something like this :)

log file:

Jul 15 11:02:38 opasnivremena pop3d: Connection, ip=[::ffff:84.252.19.48]
Jul 15 11:02:38 opasnivremena pop3d: LOGIN, user=hammer, ip=[::ffff:84.252.19.48]
Jul 15 11:02:38 opasnivremena pop3d: scancur opendir("cur"): Permission denied
Jul 15 11:02:38 opasnivremena authdaemond: received auth request, service=pop3, authtype=login
Jul 15 11:02:38 opasnivremena authdaemond: authmysql: trying this module
Jul 15 11:02:38 opasnivremena authdaemond: SQL query: SELECT email, "", clear, uid, gid, "/home/vmail/", maildir, "", name, "" FROM users WHERE email = "hammer"
Jul 15 11:02:38 opasnivremena authdaemond: authmysql: sysusername=<null>, sysuserid=1200, sysgroupid=1200, homedir=/home/vmail/, address=hammer, fullname=Hristo Mitev, maildir=.maildir/, quota=<null>, options=<null>
Jul 15 11:02:38 opasnivremena authdaemond: authmysql: clearpasswd=blabla, passwd=<null>
Jul 15 11:02:38 opasnivremena authdaemond: Authenticated: sysusername=<null>, sysuserid=1200, sysgroupid=1200, homedir=/home/vmail/, address=hammer, fullname=Hristo Mitev, maildir=.maildir/, quota=<null>, options=<null>
Jul 15 11:02:38 opasnivremena authdaemond: Authenticated: clearpasswd=blabla, passwd=<null>


other than the problem i see (in the bold) i dont see anything else wrong :(


HELP!?!!?!?

here is my main.cf


smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain = $myhostname
smtp_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,
permit_mynetworks,
check_relay_domains

smtp_sasl_password_maps = hash:/etc/postfix/passwd
smtp_sasl_security_options =
mail_spool_directory = /var/spool/mail
home_mailbox = .maildir/
alias_maps = mysql:/etc/postfix/mysql-aliases.cf
relocated_maps = mysql:/etc/postfix/mysql-relocated.cf
local_transport = local
local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname
virtual_transport = virtual
virtual_mailbox_domains =
virtual_minimum_uid = 1000
virtual_gid_maps = static:$vmail-gid
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf
virtual_uid_maps = static:$vmail-uid
virtual_mailbox_base = /



here is my courier mysql config

MYSQL_SERVER localhost
MYSQL_USERNAME mailsql
MYSQL_PASSWORD blabla
MYSQL_DATABASE mailsql
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_USER_TABLE users
#MYSQL_CRYPT_PWFIELD crypt
MYSQL_CLEAR_PWFIELD clear
MYSQL_UID_FIELD uid
MYSQL_GID_FIELD gid
MYSQL_LOGIN_FIELD email
MYSQL_HOME_FIELD "/home/vmail/"
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir


and the daemon rc of the courier

authmodulelist="authmysql"
authmodulelistorig="authuserdb authpwd authshadow authcustom authpipe"
daemons=5
authdaemonvar=/var/lib/courier/authdaemon
DEBUG_LOGIN=2


directory permissions: /home/

drwxr-xr-x 4 vmail users 96 Jul 15 10:21 vmail

directory permissions: /home/vmail/
drwxrwxrwx 5 vmail vmail 120 Jul 15 10:21 .maildir
drwxr-xr-x 3 vmail users 72 Jul 15 10:11 .hammer

directory permissions: /home/vmail/.maildir/
drwx------ 2 vmail users 48 Jul 15 10:21 cur
drwx------ 2 vmail users 48 Jul 15 10:21 new
drwx------ 2 vmail users 48 Jul 15 10:21 tmp



HELP! :)

falko
16th July 2006, 12:43
Is /home/vmail/.maildir/ that user's Maildir? Shouldn't it be in /home/vmail/example.com/user/.maildir/ or something like that?

hammer
16th July 2006, 14:19
i dont think so, i mean the home mail dir is /home/vmail, and the user maildir is .maildir/ so in the end it should say: /home/vmail/.maildir/
Atleast i think so ... can i check somewhere to what dir is the daemon trying to "cd"

falko
17th July 2006, 15:35
i dont think so, i mean the home mail dir is /home/vmail, and the user maildir is .maildir/ so in the end it should say: /home/vmail/.maildir/

But then you can only have one mailbox on your server...
What's in /etc/postfix/mysql-virtual-maps.cf?
Did you have a look at this tutorial? http://www.howtoforge.com/virtual_postfix_mysql_quota_courier

hammer
17th July 2006, 17:18
here is virtual maps:

user = mailsql
password = blabla
dbname = mailsql
table = users
select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')
where_field = email
additional_conditions = and postfix = 'y'
hosts = unix:/tmp/mysql.sock
...

@But then you can only have one mailbox on your server...
No this is just for testing. Later i will change the home dir for each user as needed.


@Did you have a look at this tutorial? http://www.howtoforge.com/virtual_po..._quota_courier

No i have read the gentoo tutorial for my MTA

falko
18th July 2006, 13:02
@Did you have a look at this tutorial? http://www.howtoforge.com/virtual_po..._quota_courier

In this tutorial I use

user = mail_admin
password = mail_admin_password
dbname = mail
table = users
select_field = CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')
where_field = email
hosts = 127.0.0.1

which looks similar to your code, and emails get stored in /home/vmail/user@example.com/..., if I remember correctly...

hammer
18th July 2006, 13:30
Problem Solved ... permissions .. ofcourse! i've changed the uid and gid of the user to match the vmail user/group and everything works now ... BTW is this safe?

And the final problem is the delivery ... smtpd delivers my mail to /home/$user/.maildir/
instead of the /home/vmail/opasnivremena.com/$user/.maildir/

The log file says that it retrieves a valid maildir entry:

Jul 18 15:13:54 opasnivremena postfix/smtpd[20448]: dict_mysql_get_active: found active connection to host unix:/tmp/mysql.sock
Jul 18 15:13:54 opasnivremena postfix/smtpd[20448]: dict_mysql: successful query from host unix:/tmp/mysql.sock
Jul 18 15:13:54 opasnivremena postfix/smtpd[20448]: dict_mysql_lookup: retrieved 1 rows
Jul 18 15:13:54 opasnivremena postfix/smtpd[20448]: maps_find: local_recipient_maps: mysql:/etc/postfix/mysql-virtual-maps.cf(0,100): hammer = /home/vmail/opasnivremena.com/hammer/.maildir/
Jul 18 15:13:54 opasnivremena postfix/smtpd[20448]: mail_addr_find: hammer@opasnivremena.com -> /home/vmail/opasnivremena.com/hammer/.maildir/


But still it delivers the mail to /home/$user/.maildir/

Why is that?

More info:
When i added a virtual mail user test at opasnivremena.com ... everything was fine. I've sended a mail. But when tried to receive mail i got this in the log:

Jul 18 15:27:42 opasnivremena postfix/smtpd[22286]: maps_find: local_recipient_maps: mysql:/etc/postfix/mysql-virtual-maps.cf(0,100): test = /home/vmail/opasnivremena.com/test/.maildir/
Jul 18 15:27:42 opasnivremena postfix/smtpd[22286]: mail_addr_find: test@opasnivremena.com -> /home/vmail/opasnivremena.com/test/.maildir/

Jul 18 15:27:42 opasnivremena postfix/local[22314]: 83FA53720A: to=<test@opasnivremena.com>, relay=local, delay=0, status=bounced
(maildir delivery failed: create /home/test/.maildir/tmp/1153225662.P22314.opasnivremena.com: Permission denied)

why is smtpd so desperade to send my mail to other than the specified by me, folder?

my smtpd config is:

mech_list: PLAIN LOGIN
pwcheck_method: auxprop
auxprop_plugin: sql
log_level: 7

sql_engine: mysql
sql_hostnames: localhost
sql_user: mailsql
sql_passwd: blabla
sql_database: mailsql
sql_verbose: yes
sql_select: select clear from users where email='%u'


Obviously the mysql connection is active and working properly otherwise smtpd wouldnt receive the
Jul 18 15:27:42 opasnivremena postfix/smtpd[22286]: mail_addr_find: test@opasnivremena.com -> /home/vmail/opasnivremena.com/test/.maildir/

the question is why is he igrnoring the maildir i've setted up?!

falko
19th July 2006, 13:19
Hm... You should compare your config files with the ones from the tutorial you followed. Take care about the formatting of the files and also about the permissions described in the tutorial.

hammer
20th July 2006, 19:56
Everything looks fine, i've checked twice :( ... Can you be more specific? From where could this problem be? My guess is my smtpd is messed up ... but i dont know what exactly is messed up .. help again :)

falko
21st July 2006, 13:57
I think the problem might be somewhere in your .cf files or in your database.

hammer
2nd August 2006, 14:00
The darn problem was because i didnt have an virtual_domain_maps assigned ... i've also removed the domain from mydestination so it can be treated as virtual domain. And everything worked out perfectly :)