0

System: Debian Jessie

I'm trying to put an environment variable in the sql config like:

password_query = SELECT userid AS user, crypt AS password, maildir as
userdb_home, 500 as userdb_uid, 500 as userdb_gid FROM local_account
WHERE userid = '%u' and mbox_host = '%{env:CLUSTERNAME}' \
    and ( ( imap_aktiv='1' and '%s'='imap' ) or ( pop_aktiv='1' and
'%s'='pop3' ) or ( sieve_aktiv='1' and '%s'='sieve' ) ) \
    and aktiv_abruf='1'

My variable is

%{env:CLUSTERNAME}

CLUSTERNAME is set through /etc/default/dovecot. I tried setting the import_environment config variable to

TZ CLUSTERNAME

but that changed nothing.

When I execute this through a login attempt, I see the following in the tcpflow output:

SELECT userid AS user, crypt AS password, maildir as userdb_home, 508 as
userdb_uid, 503 as userdb_gid FROM local_account WHERE userid = 'te' and
mbox_host = 'env:CLUSTERNAME}' and ( ( imap_aktiv='1' and 'pop3'='imap'
) or ( pop_aktiv='1' and 'pop3'='pop3' ) or ( sieve_aktiv='1' and
'pop3'='sieve' ) ) and aktiv_abruf='1'

So

%{env:CLUSTERNAME}

was parsed to

env:CLUSTERNAME}

which is not what the doc (http://wiki.dovecot.org/Variables) says, and it also seems like the parser somehow sees this as a short variable (removing %+{).

Any hints what might be happening here / how I can make it work?

1 Answer 1

0

For reference:

The problem is twofold:

  1. /etc/default/dovecot is not honored by the systemd unit file

  2. The %{env:VAR} expansion is somewhat flawed: if getenv(VAR) returns NULL dovecot falls back to standard short-variable expansion which tries to expand %{. This fails for ovious reasons.

How to fix:

  1. Add environment option to unit file, ie:

    Environment=CLUSTERNAME=mail.mydomain.com

  2. Allow import of enviroment variable in dovecot.conf:

    import_environment = CLUSTERNAME

  3. Use like

    %{env:CLUSTERNAME}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .