util/selinux: define XATTR_NAME_SELINUX

Define the extended attribute name for SELinux at the module level and
use that in the `getfilecon` function.
This commit is contained in:
Christian Kellner 2022-03-18 14:23:41 +01:00 committed by Achilleas Koutsou
parent e175529f7c
commit e11d86cdf3

View file

@ -5,6 +5,9 @@ import subprocess
from typing import Dict, TextIO
# Extended attribute name for SELinux labels
XATTR_NAME_SELINUX = b"security.selinux"
def parse_config(config_file: TextIO):
"""Parse an SELinux configuration file"""
@ -51,6 +54,6 @@ def setfiles(spec_file: str, root: str, *paths):
def getfilecon(path: str) -> str:
"""Get the security context associated with `path`"""
label = os.getxattr(path, b"security.selinux",
label = os.getxattr(path, XATTR_NAME_SELINUX,
follow_symlinks=False)
return label.decode().strip('\n\0')