Skip to content

Commit

Permalink
fix: Add delete permission to thesecure_open
Browse files Browse the repository at this point in the history
Signed-off-by: Hongli Chen <honglich@amazon.com>
  • Loading branch information
Honglichenn committed Mar 22, 2024
1 parent 7440c53 commit 9b1ef0f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/openjd/adaptor_runtime/_background/backend_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def run(self) -> None:
os.remove(path)
except FileNotFoundError: # pragma: no cover
pass # File is already cleaned up
except OSError as e: # pragma: no cover
except Exception as e: # pragma: no cover
_logger.warning(f"Failed to delete {path}: {e}")

_logger.info("Background server has been shut down.")
6 changes: 4 additions & 2 deletions src/openjd/adaptor_runtime/_utils/_secure_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
if OSName.is_windows():
import ntsecuritycon as con
import win32security
import win32con

from openjd.adaptor_runtime._osname import OSName

Expand Down Expand Up @@ -88,7 +89,7 @@ def get_file_owner_in_windows(filepath: "StrOrBytesPath") -> str: # pragma: is-

def set_file_permissions_in_windows(filepath: "StrOrBytesPath") -> None: # pragma: is-posix
"""
Sets read and write permissions for the owner of the specified file.
Sets read, write and delete permissions for the owner of the specified file.
Note: This function sets permissions only for the owner of the file and
does not consider existing DACLs.
Expand All @@ -101,9 +102,10 @@ def set_file_permissions_in_windows(filepath: "StrOrBytesPath") -> None: # prag

dacl = win32security.ACL()

# Add read & write permissions
# Add read, write and delete permissions
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_GENERIC_READ, user_sid)
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, con.FILE_GENERIC_WRITE, user_sid)
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, win32con.DELETE, user_sid)

# Apply the DACL to the file
sd = win32security.GetFileSecurity(filepath, win32security.DACL_SECURITY_INFORMATION)
Expand Down

0 comments on commit 9b1ef0f

Please sign in to comment.