forked from p34709852/monkey
island: Use `Path().touch()` instead of `os.open()` when securely creating a file on Linux
This commit is contained in:
parent
e01165403a
commit
e90bf52674
|
@ -2,6 +2,7 @@ import logging
|
|||
import os
|
||||
import platform
|
||||
import stat
|
||||
from pathlib import Path
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -64,11 +65,8 @@ def create_secure_file(path: str):
|
|||
|
||||
def _create_secure_file_linux(path: str):
|
||||
try:
|
||||
flags = (
|
||||
os.O_RDWR | os.O_CREAT | os.O_EXCL
|
||||
) # read/write, create new, throw error if file exists
|
||||
mode = stat.S_IRWXU # read/write/execute permissions to owner
|
||||
os.close(os.open(path, flags, mode))
|
||||
Path(path).touch(mode=mode, exist_ok=False)
|
||||
|
||||
except Exception as ex:
|
||||
LOG.error(f'Could not create a file at "{path}": {str(ex)}')
|
||||
|
|
Loading…
Reference in New Issue