Skip to content

Commit d2896ea

Browse files
authored
Merge pull request #78 from bawuenet/more_services_next_iteration
Further improvements on extra services configured in master.cf
2 parents 99efe7e + e4b507b commit d2896ea

File tree

3 files changed

+54
-27
lines changed

3 files changed

+54
-27
lines changed

pillar.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ postfix:
77
user: vmail
88
group: vmail
99
flags: DRhu
10-
argv: "/usr/lib/dovecot/deliver -d ${recipient}"
10+
argv: "/usr/lib/dovecot/deliver"
1111

1212
enable_submission: False
1313
# To replace the defaults use this:
@@ -36,6 +36,14 @@ postfix:
3636
chroot: True
3737
uucp:
3838
enable: True
39+
custom-mda:
40+
argv: /usr/local/sbin/mail-handler.py
41+
command: pipe
42+
extras: --rcpt ${recipient}
43+
flags: DRhu
44+
user: mail
45+
# Wrap the output in master.cf at 78 chars for better readability
46+
wrap: True
3947

4048
enable_service: True
4149
reload_service: True

postfix/files/master.cf

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,12 @@ y
111111
{%- endif %}
112112
{%- endfor %}
113113
#
114-
{%- macro extra_service(service_name, wrap=False, force_enable=False) -%}
114+
{%- set handled_extra_services = [] -%}
115+
{%- macro extra_service(service_name, wrap=False) -%}
116+
{%- do handled_extra_services.append(service_name) -%}
115117
{%- set service = salt['pillar.get']('postfix:master_config:services:%s' % (
116118
service_name,),
117119
postfix_master_services_defaults[service_name]) -%}
118-
{%- if force_enable -%}
119-
{%- do service.update({'enable': True}) -%}
120-
{%- endif -%}
121120
{%- if service.get('enable', True) -%}
122121
{%- set comment = '' -%}
123122
{%- else -%}
@@ -149,7 +148,33 @@ y
149148
{%- else %}
150149
{{ parameter_str }}
151150
{%- endif -%}
152-
{%- endmacro %}
151+
{%- endmacro -%}
152+
153+
{#- Handle legacy configuration of services for backwards compatibility
154+
by extending the services dictionary accordingly #}
155+
{%- if salt['pillar.get']('postfix:policyd-spf:enabled', False) %}
156+
{%- do postfix_master_services_defaults.update({'policy-spf': {
157+
'command': 'spawn',
158+
'chroot': False,
159+
'enable': True,
160+
'type': 'unix',
161+
'unpriv': False,
162+
'user': 'nobody',
163+
'argv': '%s/bin/policyd-spf' | format(postfix.xbin_prefix)}}) %}
164+
{%- endif %}
165+
{%- if master_config.get('enable_dovecot', False) -%}
166+
{%- set dovecot = master_config.get('dovecot', {} )%}
167+
{%- do postfix_master_services_defaults.update({'dovecot': {
168+
'command': 'pipe',
169+
'chroot': False,
170+
'enable': True,
171+
'extras': '-d ${recipient}',
172+
'flags': dovecot.get('flags', 'DRhu'),
173+
'type': 'unix',
174+
'unpriv': False,
175+
'user': '%s:%s' | format(dovecot.get('user', 'vmail'), dovecot.get('group', 'vmail')),
176+
'argv': dovecot.get('argv', postfix.dovecot_deliver) }}) %}
177+
{%- endif %}
153178
# ====================================================================
154179
# Interfaces to non-Postfix software. Be sure to examine the manual
155180
# pages of the non-Postfix software to find out what options it wants.
@@ -205,13 +230,17 @@ y
205230
{{ extra_service('scalemail-backend', 79) }}
206231
#
207232
{{ extra_service('mailman', 79) }}
208-
{%- if salt['pillar.get']('postfix:policyd-spf:enabled', False) %}
209-
#
210-
{{ extra_service('policy-spf', False, True) }}
211-
{%- endif %}
212-
{%- if master_config.get('enable_dovecot', False) -%}
213-
{%- set dovecot = master_config.get('dovecot', {} )%}
214-
#
215-
dovecot unix - n n - - pipe
216-
flags={{ dovecot.get('flags', 'DRhu') }} user={{ dovecot.get('user', 'vmail') }}:{{ dovecot.get('group', 'vmail') }} argv={{ dovecot.get('argv', postfix.dovecot_deliver) ~ ' -d ${recipient}' }}
217-
{% endif -%}
233+
{#- Handle custom services configured as pillars by extending the services
234+
dictionary for all defined services that have not been otherwise be
235+
handled yet. -#}
236+
{%- for service in salt['pillar.get']('postfix:master_config:services', []) if not service in handled_extra_services -%}
237+
{%- do postfix_master_services_defaults.update({service: salt['pillar.get']('postfix:master_config:services:%s' % (service,))}) -%}
238+
{%- endfor -%}
239+
{%- for service in postfix_master_services_defaults if not service in handled_extra_services and not service in postfix_master_services_order %}
240+
#
241+
{%- if postfix_master_services_defaults[service].get('wrap', False) %}
242+
{{ extra_service(service, 78) }}
243+
{%- else %}
244+
{{ extra_service(service) }}
245+
{%- endif %}
246+
{%- endfor %}

postfix/services.jinja

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{%- from "postfix/map.jinja" import postfix with context -%}
2-
31
{#-
42
# Default Postfix master processes as defined by postfix
53
#
@@ -312,17 +310,9 @@
312310
'user': 'list',
313311
'argv': '/usr/lib/mailman/bin/postfix-to-mailman.py',
314312
},
315-
'policy-spf': {
316-
'command': 'spawn',
317-
'chroot': False,
318-
'enable': False,
319-
'type': 'unix',
320-
'unpriv': False,
321-
'user': 'nobody',
322-
'argv': '%s/bin/policyd-spf' | format(postfix.xbin_prefix),
323-
},
324313
} %}
325314

315+
326316
{# Service order inside the master.cf file #}
327317
{% set postfix_master_services_order = [
328318
'smtp',

0 commit comments

Comments
 (0)