Repository: modoboa/modoboa

Issue:
error when updating email info
# Impacted versions

* Modoboa: 1.8.2
* installer used: Yes/No Yes
* Webserver: Nginx

# Steps to reproduce
As admin user, edit user.

# Current behavior
When clicking on "update", on the mail tab I see the following error message, "
Failed to retrieve mailbox location (sudo: no tty present and no askpass program specified )"

Other accounts i get the following message, "Email domain does not exist"

And still other accounts -- no issue at all. Seems to work fine.






Discussion:
In another thread, I saw the following "fix" for 1.8.1
https://github.com/modoboa/modoboa/issues/1090

Need to add the following -- 
Also needed to add to /etc/sudoers.d/modoboa:

uwsgi ALL=(vmail) NOPASSWD: /usr/bin/doveadm

I tried that and now I get the following error:

Failed to retrieve mailbox location (doveconf: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:22: 'imaps' protocol is no longer necessary, remove it doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:22: 'pop3s' protocol is no longer necessary, remove it userdb lookup: user joblow@acme.com doesn't exist )
So I think I understand at least part of one of the issues --
When I run userdb lookup from the command line (which I believe is essentially what modoboa is doing) I am able to reproduce the error:
[root@mail sudoers.d]# doveadm user joeblow@acme.com
field   valueuserdb lookup: user joeblow@acme.com doesn't exist

When I run userdb for a domain that doesn't have the error I get:
[root@mail sudoers.d]# doveadm user sarablow@domain1.com
field   value
uid     1002
gid     1002
home    /srv/vmail/domain1.com/sarablow
mail    maildir:~/Maildir
quota_rule      *:bytes=0M

So the issue is that userdb is looking for that directory structure in /srv/vmail that matches the username and domain name.  In the case where I get the error that directory structure does not exist.

So the real issue, in this case, is why does modoboa (or dovecot) care at this point?  I am just configuring accounts and domains -- not ready to receive emails just yet (except in a few cases where I am receiving emails which is why I don't get the error with some of the domains).  I thought the domain structure gets automatically created when postfix/dovecot gets its first email destined for that domain.  Maybe not?  How should this get set?
Looks like an issue with the userdb query... Have you disabled the faulty domain?
I wouldn’t call the domain “faulty” – it is not in use yet.  But, yes, in Modoboa I have the domain checked as disabled.  I tried it both ways – disabled and enabled.  Doesn’t work either way and same error messages.

 

It seems like the query is correct, but modoboa or dovecot seems to be expecting a condition that is not true  -- it seems like Modoboa and/or dovecot should accept configuration changes without requiring that the domain structure exist in the file system.  OR, maybe what should happen is when one creates a domain and/or account in Modoboa that the expected directories get written on update.  How is it supposed to work?

 

From: Antoine Nguyen [mailto:notifications@github.com] 
Sent: Monday, October 09, 2017 3:13 PM
To: modoboa/modoboa <modoboa@noreply.github.com>
Cc: oconshaw <oconshaw@gmail.com>; Author <author@noreply.github.com>
Subject: Re: [modoboa/modoboa] error when updating email info (#1267)

 

Looks like an issue with the userdb query... Have you disabled the faulty domain?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <https://github.com/modoboa/modoboa/issues/1267#issuecomment-335272716> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AYMBgTWtNulFRwTEn42BecQPQ8d3ZkFGks5sqn44gaJpZM4Px5yS> .  <https://github.com/notifications/beacon/AYMBgRDCgL7zqXrCDOsZcfC_-yhHWtNkks5sqn44gaJpZM4Px5yS.gif> 


Modoboa indeed uses doveadm to find mailbox homedir but it should not fail like this. Can you please the userdb query located in /etc/dovecot/dovecot-sql.conf and check the /var/log/mail.log file to see if there is more information?
I see a file in that directory called, “dovecot-sql.conf.ext”, but not “dovecot-sql.conf”.  I don’t see a userdb query per se, but I do see a postgres database query (maybe they are the same thing?) as follows:
#user_query = \

#  SELECT home, uid, gid \

#  FROM users WHERE username = '%n' AND domain = '%d'

user_query = SELECT '/srv/vmail/%d/%n' AS home, 1002 as uid, 1002 as gid, '*:bytes=' || mb.quota || 'M' AS quota_rule FROM admin_mailbox mb INNER JOIN admin_domain dom ON mb.domain_id=dom.id WHERE mb.address='%n' AND dom.name='%d'

 

is this what you are looking for?

 

From: Antoine Nguyen [mailto:notifications@github.com] 
Sent: Tuesday, October 10, 2017 10:30 AM
To: modoboa/modoboa <modoboa@noreply.github.com>
Cc: oconshaw <oconshaw@gmail.com>; Author <author@noreply.github.com>
Subject: Re: [modoboa/modoboa] error when updating email info (#1267)

 

Modoboa indeed uses doveadm to find mailbox homedir but it should not fail like this. Can you please the userdb query located in /etc/dovecot/dovecot-sql.conf and check the /var/log/mail.log file to see if there is more information?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <https://github.com/modoboa/modoboa/issues/1267#issuecomment-335511951> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AYMBgXVwaYcdRC2WI2xMmJJbZfGdWC7Zks5sq418gaJpZM4Px5yS> .  <https://github.com/notifications/beacon/AYMBgUeU2E85bMZGCCoHajFcLY2LSiWkks5sq418gaJpZM4Px5yS.gif> 


Yes it is. The domain/account account state is not checked so it should work... What is the difference between the domain which works and the one which doesn't?
The only difference that I am aware of is the ones that work are actually receiving emails and the ones that don’t work are just setup in Modoboa, but have never received any emails (and don’t have that directory structure present in /srv/vmail).  Why are you building up the path in the query?  It seems like you would be doing this for a reason – to check if it exists.  It doesn’t so modoboa or dovecot returns the error.  No?

 

Also, is this a query that gets sent to postgres?  It seems like in the where clause you are looking for any address that ends with an “n” and any name that ends in a “d”.  There must be some variable substitution going on I don’t understand.

 

user_query = SELECT '/srv/vmail/%d/%n' AS home, 1002 as uid, 1002 as gid, '*:bytes=' || mb.quota || 'M' AS quota_rule FROM admin_mailbox mb INNER JOIN admin_domain dom ON mb.domain_id=dom.id WHERE mb.address='%n' AND dom.name='%d'

 

Thanks for your help with this.

 

From: Antoine Nguyen [mailto:notifications@github.com] 
Sent: Tuesday, October 10, 2017 12:08 PM
To: modoboa/modoboa <modoboa@noreply.github.com>
Cc: oconshaw <oconshaw@gmail.com>; Author <author@noreply.github.com>
Subject: Re: [modoboa/modoboa] error when updating email info (#1267)

 

Yes it is. The domain/account account state is not checked so it should work... What is the difference between the domain which works and the one which doesn't?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <https://github.com/modoboa/modoboa/issues/1267#issuecomment-335542555> , or mute the thread <https://github.com/notifications/unsubscribe-auth/AYMBgRDHQ67liCcEXxkjTwUHQWtR0Ksyks5sq6RlgaJpZM4Px5yS> .  <https://github.com/notifications/beacon/AYMBgaucZTA-bA9ULpHg48E0qvEkZyzAks5sq6RlgaJpZM4Px5yS.gif> 


@oconshaw Sorry for the delay. I still can't reproduce this issue, I thought it was similar to #1190 but it is not.
To answer your questions:
* %d and %n are special dovecot variables replaced by the domain and the local part of the address being checked
* The full path is required to be in the query because a userdb lookup maps username with a path in the filesystem for the delivery

Do you still encounter this issue?

Resolving patch:
diff --git a/modoboa/admin/models/mailbox.py b/modoboa/admin/models/mailbox.py
--- a/modoboa/admin/models/mailbox.py
+++ b/modoboa/admin/models/mailbox.py
@@ -158,11 +158,11 @@ def mail_home(self):
             if curuser != mbowner:
                 options["sudo_user"] = mbowner
             code, output = exec_cmd(
-                "doveadm user %s -f home" % self.full_address, **options
+                "doveadm user -f home %s" % self.full_address, **options
             )
             if code:
                 raise lib_exceptions.InternalError(
-                    _(u"Failed to retrieve mailbox location (%s)") % output)
+                    _("Failed to retrieve mailbox location (%s)") % output)
             self.__mail_home = output.strip()
         return self.__mail_home
 


Test patch: