add config file

This commit is contained in:
Max Erenberg 2021-09-04 18:11:36 +00:00
parent 40e3c8c536
commit 06d73731d6
7 changed files with 33 additions and 18 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import argparse
from configparser import ConfigParser
from email.utils import parseaddr
import ipaddress
import logging
@ -13,6 +13,7 @@ import Milter
SOCKETPATH = "/run/csc-milter/csc-milter.sock"
CONFIG_PATH = '/etc/csc/csc_milter.ini'
TIMEOUT = 5
MYORIGIN = ''
MYNETWORKS = []
@ -109,7 +110,7 @@ def get_postconf(param):
shell=True, capture_output=True, check=True
)
value = proc.stdout.decode().strip()
logger.debug(f'Retrieved from postconf: {param} = {value}')
logger.debug(f'retrieved from postconf: {param} = {value}')
return value
@ -120,20 +121,15 @@ def main():
check_postfix_user()
parser = argparse.ArgumentParser(description='Custom milter for CSC.')
parser.add_argument('--myorigin', help='domain name for locally-posted mail')
parser.add_argument('--mynetworks', help='space-separated list of trusted subnets')
args = parser.parse_args()
MYORIGIN = get_postconf('myorigin')
if args.myorigin is not None:
MYORIGIN = args.myorigin
else:
MYORIGIN = get_postconf('myorigin')
if args.mynetworks is not None:
networks = args.mynetworks.split()
else:
networks_str = get_postconf('mynetworks').replace(',', ' ')
networks = networks_str.split()
networks_str = get_postconf('mynetworks').replace(',', ' ')
networks = networks_str.split()
if os.path.isfile(CONFIG_PATH):
config = ConfigParser()
config.read_file(open(CONFIG_PATH))
if 'additional_subnets' in config['main']:
networks += config['main']['additional_subnets'].split(',')
MYNETWORKS = [
ipaddress.ip_network(
s.replace('[', '')
@ -142,6 +138,7 @@ def main():
)
for s in networks
]
logger.debug('trusted subnets: %s' % MYNETWORKS)
re_myorigin = MYORIGIN.replace('.', r'\.')
RECEIVED_REGEX = re.compile(rf"\bby ([\w-]+\.)?{re_myorigin}\b")

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
csc-milter (0.2.1-1) buster; urgency=medium
* Add config file.
-- Max Erenberg <merenber@csclub.uwaterloo.ca> Sat, 04 Sep 2021 17:29:00 +0000
csc-milter (0.2.0-1) buster; urgency=medium
* Add check for Received: header.

3
debian/control vendored
View File

@ -2,8 +2,9 @@ Source: csc-milter
Maintainer: Systems Committee <syscom@csclub.uwaterloo.ca>
Section: mail
Priority: optional
Standards-Version: 3.9.2
Standards-Version: 4.3.0
Build-Depends: debhelper (>=9),
debhelper (>= 9.20160709) | dh-systemd,
dh-python,
python3-setuptools,
python3-all

1
debian/csc-milter.install vendored Normal file
View File

@ -0,0 +1 @@
etc/csc/csc_milter.ini

9
debian/rules vendored
View File

@ -1,6 +1,13 @@
#!/usr/bin/make -f
NAME=csc-milter
export PYBUILD_NAME=csc-milter
%:
dh $@ --with python3 --buildsystem=pybuild
dh $@ --with python3,systemd --buildsystem=pybuild
override_dh_systemd_enable:
dh_systemd_enable --no-enable $(NAME).service
override_dh_systemd_start:
dh_systemd_start --no-start $(NAME).service

3
etc/csc/csc_milter.ini Normal file
View File

@ -0,0 +1,3 @@
[main]
# trust all IP addresses in AS12093
additional_subnets = 129.97.0.0/16, 2620:101:f000::/47

View File

@ -16,7 +16,7 @@ class PyTest(TestCommand):
setup(
name='csc-milter',
version='0.2.0',
version='0.2.1',
description='Custom milter for CSC',
long_description=long_description,
long_description_content_type='text/markdown',