Skip to content

Commit

Permalink
Add support for LANDLOCK_ACCESS_FS_TRUNCATE in ABI 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward-Knight committed Mar 30, 2024
1 parent da68d40 commit aee2214
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion landlock/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class FSAccess(enum.IntFlag):
"""Open a file with write access."""
READ_FILE = 1 << 2
"""Open a file with read access."""
TRUNCATE = 1 << 14
"""Truncate a file through a variety of means.
Only available if the ABI version >= 3.
"""

# A directory can receive access rights related to files or directories.
# The following access right is applied to the directory itself,
Expand Down Expand Up @@ -79,7 +84,11 @@ def all(cls):

@classmethod
def all_file(cls):
return cls.EXECUTE | cls.WRITE_FILE | cls.READ_FILE
flags = cls.EXECUTE | cls.WRITE_FILE | cls.READ_FILE
# TRUNCATE only available in version 3
if landlock_abi_version() >= 3:
flags |= cls.TRUNCATE
return flags

@classmethod
def all_dir(cls):
Expand Down

0 comments on commit aee2214

Please sign in to comment.