Handle defaults for Socket differently
We want to be able to select the default for Socket differently in the future. This change augments the API for dkimpy_milter.util.own_socketfile() by adding an optional sockname argument. This is a backward-compatible change. If we aren't committed to API stability for this function, we could make a more invasive change that would probably be a more reasonable API going forward, but this is probably good enough.
This commit is contained in:
@@ -354,7 +354,9 @@ def main():
|
|||||||
Milter.set_flags(Milter.CHGHDRS + Milter.ADDHDRS)
|
Milter.set_flags(Milter.CHGHDRS + Milter.ADDHDRS)
|
||||||
miltername = 'dkimpy-filter'
|
miltername = 'dkimpy-filter'
|
||||||
socketname = milterconfig.get('Socket')
|
socketname = milterconfig.get('Socket')
|
||||||
own_socketfile(milterconfig)
|
if socketname is None:
|
||||||
|
socketname = 'local:/var/run/dkimpy-milter/dkimpy-milter.sock'
|
||||||
|
own_socketfile(milterconfig, socketname)
|
||||||
drop_privileges(milterconfig)
|
drop_privileges(milterconfig)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
Milter.runmilter(miltername, socketname, 240)
|
Milter.runmilter(miltername, socketname, 240)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ defaultConfigData = {
|
|||||||
'SyslogFacility': 'mail',
|
'SyslogFacility': 'mail',
|
||||||
'UMask': 0o07,
|
'UMask': 0o07,
|
||||||
'Mode': 'sv',
|
'Mode': 'sv',
|
||||||
'Socket': 'local:/var/run/dkimpy-milter/dkimpy-milter.sock',
|
'Socket': None,
|
||||||
'PidFile': '/var/run/dkimpy-milter/dkimpy-milter.pid',
|
'PidFile': '/var/run/dkimpy-milter/dkimpy-milter.pid',
|
||||||
'UserID': 'dkimpy-milter',
|
'UserID': 'dkimpy-milter',
|
||||||
'Canonicalization': 'relaxed/simple',
|
'Canonicalization': 'relaxed/simple',
|
||||||
|
|||||||
@@ -146,12 +146,15 @@ def write_pid(milterconfig):
|
|||||||
return pid
|
return pid
|
||||||
|
|
||||||
|
|
||||||
def own_socketfile(milterconfig):
|
def own_socketfile(milterconfig, sockname=None):
|
||||||
"""If socket is Unix socket, chown to UserID before dropping privileges"""
|
"""If socket is Unix socket, chown to UserID before dropping privileges"""
|
||||||
import os
|
import os
|
||||||
user, group = user_group(milterconfig.get('UserID'))
|
user, group = user_group(milterconfig.get('UserID'))
|
||||||
offset = None
|
offset = None
|
||||||
|
if sockname is None:
|
||||||
sockname = milterconfig.get('Socket')
|
sockname = milterconfig.get('Socket')
|
||||||
|
if sockname is None:
|
||||||
|
return
|
||||||
if sockname[:1] == '/':
|
if sockname[:1] == '/':
|
||||||
offset = 0
|
offset = 0
|
||||||
elif sockname[:6] == "local:":
|
elif sockname[:6] == "local:":
|
||||||
|
|||||||
Reference in New Issue
Block a user