diff options
-rw-r--r-- | kvmd/apps/htpasswd/__init__.py | 8 |
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) |