Run doveadm command as vmail user.

see #2084
This commit is contained in:
Antoine Nguyen
2021-02-11 17:16:21 +01:00
parent 0cd52d0f04
commit 1827bce52d
5 changed files with 17 additions and 29 deletions
+1 -11
View File
@@ -145,14 +145,6 @@ class AdminParametersForm(param_forms.AdminParametersForm):
)
)
mailboxes_owner = forms.CharField(
label=ugettext_lazy("Mailboxes owner"),
initial="vmail",
help_text=ugettext_lazy(
"The UNIX account who owns mailboxes on the filesystem"
)
)
default_mailbox_quota = forms.IntegerField(
label=ugettext_lazy("Default mailbox quota"),
initial=0,
@@ -198,8 +190,7 @@ class AdminParametersForm(param_forms.AdminParametersForm):
# Visibility rules
visibility_rules = {
"valid_mxs": "enable_mx_checks=True",
"domains_must_have_authorized_mx": "enable_mx_checks=True",
"mailboxes_owner": "handle_mailboxes=True",
"domains_must_have_authorized_mx": "enable_mx_checks=True"
}
def __init__(self, *args, **kwargs):
@@ -234,7 +225,6 @@ class AdminParametersForm(param_forms.AdminParametersForm):
hide_fields = True
if hide_fields:
del self.fields["handle_mailboxes"]
del self.fields["mailboxes_owner"]
def clean_default_domain_quota(self):
"""Ensure quota is a positive integer."""
+1 -11
View File
@@ -1,8 +1,5 @@
"""Models related to mailboxes management."""
import os
import pwd
from reversion import revisions as reversion
from django.contrib.contenttypes.models import ContentType
@@ -153,14 +150,7 @@ class Mailbox(mixins.MessageLimitMixin, AdminObject):
if not admin_params.get("handle_mailboxes"):
return None
if self.__mail_home is None:
curuser = pwd.getpwuid(os.getuid()).pw_name
mbowner = admin_params["mailboxes_owner"]
options = {}
if curuser != mbowner:
options["sudo_user"] = mbowner
code, output = doveadm_cmd(
"user -f home %s" % self.full_address, **options
)
code, output = doveadm_cmd("user -f home %s" % self.full_address)
if code:
raise lib_exceptions.InternalError(
_("Failed to retrieve mailbox location (%s)") % output)
+6 -3
View File
@@ -49,9 +49,7 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
password_scheme = forms.ChoiceField(
label=ugettext_lazy("Default password scheme"),
choices=[(hasher.name, ugettext_lazy(hasher.label))
for hasher in PasswordHasher.get_password_hashers()
if hasher().scheme in get_dovecot_schemes()],
choices=[],
initial="sha512crypt",
help_text=ugettext_lazy("Scheme used to crypt mailbox passwords"),
)
@@ -528,6 +526,11 @@ class GeneralParametersForm(param_forms.AdminParametersForm):
self._add_visibilty_rules(
sms_backends.get_all_backend_visibility_rules()
)
self.fields["password_scheme"].choices = [
(hasher.name, ugettext_lazy(hasher.label))
for hasher in PasswordHasher.get_password_hashers()
if hasher().scheme in get_dovecot_schemes()
]
def _add_dynamic_fields(self):
new_fields = OrderedDict()
@@ -197,6 +197,8 @@ REST_FRAMEWORK = {
# DOVECOT_LOOKUP_PATH = ('/path/to/dovecot', )
# DOVECOT_USER = 'vmail'
MODOBOA_API_URL = 'https://api.modoboa.org/1/'
DISABLE_DASHBOARD_EXTERNAL_QUERIES = False
+7 -4
View File
@@ -5,6 +5,7 @@ This module extra functions/shortcuts to communicate with the system
import inspect
import os
import pwd
import re
import subprocess
@@ -42,8 +43,7 @@ def exec_cmd(cmd, sudo_user=None, pinput=None, capture_output=True, **kwargs):
return process.returncode, output
def doveadm_cmd(params, sudo_user=None, pinput=None,
capture_output=True, **kwargs):
def doveadm_cmd(params, pinput=None, capture_output=True, **kwargs):
"""Execute doveadm command.
Run doveadm command using the current user. Set :keyword:`sudo_user` if
@@ -69,14 +69,17 @@ def doveadm_cmd(params, sudo_user=None, pinput=None,
if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
dpath = fpath
break
dovecot_user = getattr(settings, "DOVECOT_USER", "vmail")
curuser = pwd.getpwuid(os.getuid()).pw_name
sudo_user = dovecot_user if curuser != dovecot_user else None
if dpath:
return exec_cmd("{} {}".format(dpath, params),
sudo_user=sudo_user,
pinput=pinput,
capture_output=capture_output,
**kwargs)
else:
raise OSError("doveadm command not found")
raise OSError("doveadm command not found")
def guess_extension_name():