summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-02-10 03:57:34 +0300
committerDevaev Maxim <[email protected]>2019-02-10 03:57:34 +0300
commitd603a216a37703b5ea24ce4644d4d60b5efebcbd (patch)
treecc48dd738e321c9829625aed607c3aead9c4dbf1 /kvmd
parent8550ace4a1478c9f15c28bac450c22efcfab97e4 (diff)
htpasswd: change tmp permissions
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/htpasswd/__init__.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py
index 5ce0454b..b325262a 100644
--- a/kvmd/apps/htpasswd/__init__.py
+++ b/kvmd/apps/htpasswd/__init__.py
@@ -19,11 +19,17 @@ from .. import init
@contextlib.contextmanager
def _get_htpasswd_for_write(config: Section) -> Generator[passlib.apache.HtpasswdFile, None, None]:
path = config.kvmd.auth.htpasswd
- (tmp_fd, tmp_path) = tempfile.mkstemp(prefix=".", dir=os.path.dirname(path))
+ (tmp_fd, tmp_path) = tempfile.mkstemp(
+ prefix=".%s." % (os.path.basename(path)),
+ dir=os.path.dirname(path),
+ )
try:
+ stat = os.stat(path)
try:
with open(path, "rb") as htpasswd_file:
os.write(tmp_fd, htpasswd_file.read())
+ os.fchown(tmp_fd, stat.st_uid, stat.st_gid)
+ os.fchmod(tmp_fd, stat.st_mode)
finally:
os.close(tmp_fd)
htpasswd = passlib.apache.HtpasswdFile(tmp_path)