Skip to content

Commit

Permalink
Merge pull request #97 from jschauma/master
Browse files Browse the repository at this point in the history
add command-line options "-g", "-u", "-p"
  • Loading branch information
Snawoot authored Mar 10, 2023
2 parents 03bf1ad + 7f9f791 commit 4fc24ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
11 changes: 10 additions & 1 deletion man/mta-sts-daemon.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ successful authentication of that site when forwarding mail there.
*-v, --verbosity* _VERBOSITY_::
set log verbosity level: _debug_, _info_ (default), _warn_, _error_, or
_fatal_.

*-c, --config* _FILE_::
config file location (default: _/etc/mta-sts-daemon.yml_)

*-g, --group* _GROUP_::
change eGID to this group (default: _none_)

*-l, --logfile* _FILE_::
log file location (default: _none_)

*-p, --pidfile* _PIDFILE_::
name of the file to write the current pid to (default: _none_)

*-u, --user* _USER_::
change eUID to this user (default: _none_)


*--disable-uvloop*::
do not use uvloop even if it is available (default: enabled if available)

Expand Down
27 changes: 26 additions & 1 deletion postfix_mta_sts_resolver/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import os
import argparse
import asyncio
import grp
import logging
import pwd
import signal
import sys
from functools import partial

from .asdnotify import AsyncSystemdNotifier
Expand All @@ -26,12 +29,18 @@ def parse_args():
help="config file location",
metavar="FILE",
default=defaults.CONFIG_LOCATION)
parser.add_argument("-g", "--group",
help="change eGID to this group")
parser.add_argument("-l", "--logfile",
help="log file location",
metavar="FILE")
parser.add_argument("--disable-uvloop",
help="do not use uvloop even if it is available",
action="store_true")
parser.add_argument("-p", "--pidfile",
help="name of the file to write the current pid to")
parser.add_argument("-u", "--user",
help="change eUID to this user")

return parser.parse_args()

Expand Down Expand Up @@ -96,8 +105,24 @@ async def amain(cfg, loop): # pragma: no cover


def main(): # pragma: no cover
# Parse command line arguments and setup basic logging
args = parse_args()
if args.pidfile is not None:
with open(args.pidfile, 'w') as f:
f.write(str(os.getpid()))
if args.group is not None:
try:
g = grp.getgrnam(args.group)
os.setegid(g.gr_gid)
except Exception as e:
print("Unable to change eGID to '{}': {}".format(args.group, e), file=sys.stderr)
return os.EX_OSERR
if args.user is not None:
try:
p = pwd.getpwnam(args.user)
os.seteuid(p.pw_uid)
except Exception as e:
print("Unable to change eUID to '{}': {}".format(args.user, e), file=sys.stderr)
return os.EX_OSERR
with utils.AsyncLoggingHandler(args.logfile) as log_handler:
logger = utils.setup_logger('MAIN', args.verbosity, log_handler)
utils.setup_logger('STS', args.verbosity, log_handler)
Expand Down

0 comments on commit 4fc24ee

Please sign in to comment.