Skip to content

Commit

Permalink
Merge pull request #46 from Snawoot/unixmode
Browse files Browse the repository at this point in the history
Unixmode
  • Loading branch information
Snawoot authored Oct 12, 2019
2 parents 4864db7 + d9bd9f1 commit af9a7e2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions config_examples/mta-sts-daemon.yml.sqlite_unixsock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
path: "/var/run/mta-sts.sock"
mode: 0666
shutdown_timeout: 20
cache:
type: sqlite
Expand Down
2 changes: 2 additions & 0 deletions man/mta-sts-daemon.yml.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The file is in YAML syntax with the following elements:

*path*: (_str_) daemon UNIX socket bind address (path). If specified, *host* and *port* are ignored and UNIX socket is bound instead of TCP.

*mode*: (_int_) file mode for daemon UNIX socket. If not specified default filemode is used. This option has effect only when UNIX socket is used. If file mode specified in octal form (most common case), it has to be prepended with leading zero. Example: 0666

*reuse_port*: (_bool_) allow multiple instances to share same port (available on Unix, Windows)

*cache_grace*: (_float_) age of cache entries in seconds which do not require policy refresh and update. Default: 60
Expand Down
3 changes: 3 additions & 0 deletions postfix_mta_sts_resolver/responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, cfg, loop):
if cfg.get('path') is not None:
self._unix = True
self._path = cfg['path']
self._sockmode = cfg.get('mode')
else:
self._unix = False
self._host = cfg['host']
Expand Down Expand Up @@ -63,6 +64,8 @@ def done_cb(task, fut):

if self._unix:
self._server = await asyncio.start_unix_server(_spawn, path=self._path)
if self._sockmode is not None:
os.chmod(self._path, self._sockmode)
else:
if self._reuse_port: # pragma: no cover
if sys.platform in ('win32', 'cygwin'):
Expand Down
1 change: 1 addition & 0 deletions postfix_mta_sts_resolver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def setup_logger(name, verbosity, handler):

def enable_uvloop(): # pragma: no cover
try:
# pylint: disable=import-outside-toplevel
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except ImportError:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import itertools
import socket
import os

import pynetstring
import pytest
Expand All @@ -28,7 +29,7 @@ async def responder(event_loop):
@async_generator
async def unix_responder(event_loop):
import postfix_mta_sts_resolver.utils as utils
cfg = utils.populate_cfg_defaults({'path': '/tmp/mta-sts.sock'})
cfg = utils.populate_cfg_defaults({'path': '/tmp/mta-sts.sock', 'mode': 0o666})
cfg["zones"]["test2"] = cfg["default_zone"]
resp = STSSocketmapResponder(cfg, event_loop)
await resp.start()
Expand Down Expand Up @@ -65,6 +66,7 @@ async def test_responder(responder, params):
async def test_unix_responder(unix_responder, params):
(request, response), bufsize = params
resp, path = unix_responder
assert os.stat(path).st_mode & 0o777 == 0o666
decoder = pynetstring.Decoder()
reader, writer = await asyncio.open_unix_connection(path)
try:
Expand Down

0 comments on commit af9a7e2

Please sign in to comment.