mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
htpasswd: change tmp permissions
This commit is contained in:
@@ -19,11 +19,17 @@ from .. import init
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _get_htpasswd_for_write(config: Section) -> Generator[passlib.apache.HtpasswdFile, None, None]:
|
def _get_htpasswd_for_write(config: Section) -> Generator[passlib.apache.HtpasswdFile, None, None]:
|
||||||
path = config.kvmd.auth.htpasswd
|
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:
|
try:
|
||||||
|
stat = os.stat(path)
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as htpasswd_file:
|
with open(path, "rb") as htpasswd_file:
|
||||||
os.write(tmp_fd, htpasswd_file.read())
|
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:
|
finally:
|
||||||
os.close(tmp_fd)
|
os.close(tmp_fd)
|
||||||
htpasswd = passlib.apache.HtpasswdFile(tmp_path)
|
htpasswd = passlib.apache.HtpasswdFile(tmp_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user