|
|
|
@ -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() |
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
MYORIGIN = get_postconf('myorigin') |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
|