Skip to content

Commit

Permalink
fix: Remove embedded_files.write_file_for_user Windows exception (#32)
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Luttrell <[email protected]>
  • Loading branch information
roblutt authored Nov 7, 2023
1 parent 5a06c8f commit dc3ffbe
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/openjd/sessions/_embedded_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,19 @@ def write_file_for_user(
with _open_context(filename, flags, mode=mode) as fd:
os.write(fd, data.encode("utf-8"))

if user is not None:
if os.name != "posix":
raise NotImplementedError("Impersonation is not implemented on non-posix systems yet.")
user = cast(PosixSessionUser, user)
# Set the group of the file
chown(filename, group=user.group)
# Update the permissions to include the group after the group is changed
# Note: Only after changing group for security in case the group-ownership
# change fails.
mode |= stat.S_IRGRP | stat.S_IWGRP | (additional_permissions & stat.S_IRWXG)

# The file may have already existed before calling this function (e.g. created by mkstemp)
# so unconditionally set the file permissions to ensure that additional_permissions are set.
os.chmod(filename, mode=mode)
if os.name == "posix":
if user is not None:
user = cast(PosixSessionUser, user)
# Set the group of the file
chown(filename, group=user.group)
# Update the permissions to include the group after the group is changed
# Note: Only after changing group for security in case the group-ownership
# change fails.
mode |= stat.S_IRGRP | stat.S_IWGRP | (additional_permissions & stat.S_IRWXG)

# The file may have already existed before calling this function (e.g. created by mkstemp)
# so unconditionally set the file permissions to ensure that additional_permissions are set.
os.chmod(filename, mode=mode)


class EmbeddedFilesScope(Enum):
Expand Down

0 comments on commit dc3ffbe

Please sign in to comment.