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:
Daniel Kahn Gillmor
2019-02-21 15:41:35 -05:00
parent ea09bab1a8
commit 9d5316ca0e
3 changed files with 9 additions and 4 deletions
+5 -2
View File
@@ -146,12 +146,15 @@ def write_pid(milterconfig):
return pid
def own_socketfile(milterconfig):
def own_socketfile(milterconfig, sockname=None):
"""If socket is Unix socket, chown to UserID before dropping privileges"""
import os
user, group = user_group(milterconfig.get('UserID'))
offset = None
sockname = milterconfig.get('Socket')
if sockname is None:
sockname = milterconfig.get('Socket')
if sockname is None:
return
if sockname[:1] == '/':
offset = 0
elif sockname[:6] == "local:":