Compare commits
8 Commits
dkg/python3
...
1_0
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eed8995a2 | |||
| a16d887ac6 | |||
| 23d91b2b50 | |||
| 481fbdae29 | |||
| 4b0c39b0c7 | |||
| 7092874729 | |||
| 25fdd3b81c | |||
| 9d5316ca0e |
@@ -1,5 +1,13 @@
|
|||||||
|
1.1.0 UNRELEASED
|
||||||
|
- Port to python3
|
||||||
|
- Add test suite using opendkim miltertest
|
||||||
|
- When Socket is absolute path, do not strip leading /
|
||||||
|
- Handle unix: socket prefix the same as local:
|
||||||
|
- Set up correct AuthservID defaults
|
||||||
|
- config: Reassemble strings sensibly
|
||||||
|
|
||||||
1.0.1 2019-02-11
|
1.0.1 2019-02-11
|
||||||
* Reorder milter start and dropping privileges so permissions on Unix socket
|
- Reorder milter start and dropping privileges so permissions on Unix socket
|
||||||
are correct (LP: 1797720)
|
are correct (LP: 1797720)
|
||||||
- Make domain checks case insensitive for determining if signing should be
|
- Make domain checks case insensitive for determining if signing should be
|
||||||
done (LP: #1815311)
|
done (LP: #1815311)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ to be installed when installing using setup.py, the following incantation is
|
|||||||
required because setuptools developers decided not being able to do this by
|
required because setuptools developers decided not being able to do this by
|
||||||
default is a feature:
|
default is a feature:
|
||||||
|
|
||||||
python setup.py install --single-version-externally-managed --record=/dev/null
|
python3 setup.py install --single-version-externally-managed --record=/dev/null
|
||||||
|
|
||||||
For users of Debian Stable (Debian 9, Codename Squeeze), all dependencies are
|
For users of Debian Stable (Debian 9, Codename Squeeze), all dependencies are
|
||||||
available in either the main or backports repositories:
|
available in either the main or backports repositories:
|
||||||
|
|||||||
@@ -354,7 +354,18 @@ 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:
|
||||||
|
if int(os.environ.get('LISTEN_PID', '0')) == os.getpid():
|
||||||
|
lfds = os.environ.get('LISTEN_FDS')
|
||||||
|
if lfds is not None:
|
||||||
|
if lfds != '1':
|
||||||
|
syslog.syslog('LISTEN_FDS is set to "{0}", but we only know how to deal with "1", ignoring it'.
|
||||||
|
format(lfds))
|
||||||
|
else:
|
||||||
|
socketname = 'fd:3'
|
||||||
|
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,8 +39,8 @@ 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': None,
|
||||||
'UserID': 'dkimpy-milter',
|
'UserID': 'dkimpy-milter',
|
||||||
'Canonicalization': 'relaxed/simple',
|
'Canonicalization': 'relaxed/simple',
|
||||||
'InternalHosts': '127.0.0.1',
|
'InternalHosts': '127.0.0.1',
|
||||||
|
|||||||
+15
-9
@@ -115,43 +115,49 @@ def write_pid(milterconfig):
|
|||||||
"""Write PID in pidfile. Will not overwrite an existing file."""
|
"""Write PID in pidfile. Will not overwrite an existing file."""
|
||||||
import os
|
import os
|
||||||
import syslog
|
import syslog
|
||||||
if not os.path.isfile(milterconfig.get('PidFile')):
|
pidfile = milterconfig.get('PidFile')
|
||||||
|
if pidfile is None:
|
||||||
|
return
|
||||||
|
if not os.path.isfile(pidfile):
|
||||||
pid = str(os.getpid())
|
pid = str(os.getpid())
|
||||||
try:
|
try:
|
||||||
f = open(milterconfig.get('PidFile'), 'w')
|
f = open(pidfile, 'w')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if str(e)[:35] == '[Errno 2] No such file or directory':
|
if str(e)[:35] == '[Errno 2] No such file or directory':
|
||||||
piddir = milterconfig.get('PidFile').rsplit('/', 1)[0]
|
piddir = pidfile.rsplit('/', 1)[0]
|
||||||
os.mkdir(piddir)
|
os.mkdir(piddir)
|
||||||
user, group = user_group(milterconfig.get('UserID'))
|
user, group = user_group(milterconfig.get('UserID'))
|
||||||
os.chown(piddir, user, group)
|
os.chown(piddir, user, group)
|
||||||
f = open(milterconfig.get('PidFile'), 'w')
|
f = open(pidfile, 'w')
|
||||||
if milterconfig.get('Syslog'):
|
if milterconfig.get('Syslog'):
|
||||||
syslog.syslog('PID dir created: {0}'.format(piddir))
|
syslog.syslog('PID dir created: {0}'.format(piddir))
|
||||||
else:
|
else:
|
||||||
if milterconfig.get('Syslog'):
|
if milterconfig.get('Syslog'):
|
||||||
syslog.syslog('Unable to write pidfle {0}. IOError: {1}'
|
syslog.syslog('Unable to write pidfle {0}. IOError: {1}'
|
||||||
.format(milterconfig.get('PidFile'), e))
|
.format(pidfile, e))
|
||||||
raise
|
raise
|
||||||
f.write(pid)
|
f.write(pid)
|
||||||
f.close()
|
f.close()
|
||||||
user, group = user_group(milterconfig.get('UserID'))
|
user, group = user_group(milterconfig.get('UserID'))
|
||||||
os.chown(milterconfig.get('PidFile'), user, group)
|
os.chown(pidfile, user, group)
|
||||||
else:
|
else:
|
||||||
if milterconfig.get('Syslog'):
|
if milterconfig.get('Syslog'):
|
||||||
syslog.syslog('Unable to write pidfle {0}. File exists.'
|
syslog.syslog('Unable to write pidfle {0}. File exists.'
|
||||||
.format(milterconfig.get('PidFile')))
|
.format(pidfile))
|
||||||
raise RuntimeError('Unable to write pidfle {0}. File exists.'
|
raise RuntimeError('Unable to write pidfle {0}. File exists.'
|
||||||
.format(milterconfig.get('PidFile')))
|
.format(pidfile))
|
||||||
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:":
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ will be checked. [PeerList NOT IMPLEMENTED - included for reference only]
|
|||||||
.TP
|
.TP
|
||||||
.I PidFile (string)
|
.I PidFile (string)
|
||||||
Specifies the path to a file that should be created at process start
|
Specifies the path to a file that should be created at process start
|
||||||
containing the process ID.
|
containing the process ID. If not specified, no such file will be created.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.I Selector (string)
|
.I Selector (string)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/python3
|
#! /usr/bin/python3
|
||||||
# dkimpy-milter: A DKIM signing/verification Milter application
|
# dkimpy-milter: A DKIM signing/verification Milter application
|
||||||
# Author: Scott Kitterman <scott@kitterman.com>
|
# Author: Scott Kitterman <scott@kitterman.com>
|
||||||
# Copyright 2018 Scott Kitterman
|
# Copyright 2018,2019 Scott Kitterman
|
||||||
""" This program is free software; you can redistribute it and/or modify
|
""" This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
@@ -30,7 +30,7 @@ except ImportError: # If PyDNS is not installed, prefer dnspython
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='dkimpy-milter',
|
name='dkimpy-milter',
|
||||||
version='1.0.1',
|
version='1.1.0',
|
||||||
author='Scott Kitterman',
|
author='Scott Kitterman',
|
||||||
author_email='scott@kitterman.com',
|
author_email='scott@kitterman.com',
|
||||||
url='https://launchpad.net/dkimpy-milter',
|
url='https://launchpad.net/dkimpy-milter',
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
This directory contains example systemd unit files for running a
|
||||||
|
supervised, socket-activated instance of dkimpy-milter.
|
||||||
|
|
||||||
|
There are several advantages of using socket activation:
|
||||||
|
|
||||||
|
- dkimpy-milter never runs with elevated privileges, they are dropped
|
||||||
|
before any dkimpy-milter code is executed.
|
||||||
|
|
||||||
|
- The socket is opened before dkimpy-milter runs. This means that
|
||||||
|
clients can connect() to the socket immediately. So even if there
|
||||||
|
is a delay in dkimpy-milter startup, or in libmilter itself, the
|
||||||
|
connection will not fail.
|
||||||
|
|
||||||
|
- You can set the privileges of a listening Unix-domain socket by an
|
||||||
|
override of ListenGroup= in dkimpy-milter.socket (see
|
||||||
|
systemd.unit(5) for how to override). This lets you control who has
|
||||||
|
access to the daemon with finer granularity than is available with
|
||||||
|
dkimpy-milter on its own.
|
||||||
|
|
||||||
|
- dkimpy-milter will not consume system resources if it is not used.
|
||||||
|
|
||||||
|
- A fully-supervised dkimpy-milter needs no PIDFile, UMask, UserID, or
|
||||||
|
Socket configuation. This eliminates common race conditions and
|
||||||
|
startup failures, and simplifies the resulting configuration file.
|
||||||
|
|
||||||
|
There is one downside to using socket activation:
|
||||||
|
|
||||||
|
- it will only work on systems where libmilter can support connection
|
||||||
|
strings like "fd:3". This has been supported on Debian and derived
|
||||||
|
systems since sendmail 8.14.4-6 (before Debian Jessie, in early
|
||||||
|
2014), see for example:
|
||||||
|
https://sources.debian.org/src/sendmail/8.15.2-8/debian/patches/socket_activation.patch/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=DKIMpy Milter
|
||||||
|
Documentation=man:dkimpy-milter(8) man:dkimpy-milter.conf(5)
|
||||||
|
Requires=dkimpy-milter.socket
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/dkimpy-milter /etc/dkimpy-milter.conf
|
||||||
|
User=dkimpy-milter
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
Also=dkimpy-milter.socket
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=DKIMpy Milter socket
|
||||||
|
Documentation=man:dkimpy-milter(8) man:dkimpy-milter.conf(5)
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=/run/dkimpy-milter/dkimpy-milter.sock
|
||||||
|
SocketMode=0660
|
||||||
|
# override SocketGroup to grant access to members of another system group:
|
||||||
|
SocketGroup=dkimpy-milter
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=sockets.target
|
||||||
Reference in New Issue
Block a user