Skip to content

Commit edab2de

Browse files
AlexHearnNIamstewart
authored andcommitted
_auditd_config.py: do not check permissions on file that doesn't exist
This change avoids a FileNotFoundError exception when running 'verify' if auditd.conf doesn't exist. The exception causes 'verify' to print a stack trace and return error 1 rather than EX_CHECK_FAILURE. auditd.conf is not on the nilrt base system image; it's created by nilrt-snac. Thus, that exception would always happen when running 'verify' before running 'configure'. Signed-off-by: Alex Hearn <alex.hearn@ni.com>
1 parent 3c0d032 commit edab2de

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

nilrt_snac/_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def _check_group_ownership(path: str, group: str) -> bool:
9-
"Checks if the group ownership of a file or directory matches the specified group."
9+
"Checks if the group ownership of a file or directory matches the specified group."
1010
stat_info = os.stat(path)
1111
gid = stat_info.st_gid
1212
group_info = grp.getgrgid(gid)
@@ -38,4 +38,4 @@ def get_distro():
3838
if line.startswith("ID="):
3939
return line.split("=")[1].strip()
4040
except NameError:
41-
return None
41+
return None

nilrt_snac/_configs/_auditd_config.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,21 @@ def verify(self, args: argparse.Namespace) -> bool:
182182
if not auditd_config_file.exists():
183183
valid = False
184184
logger.error(f"MISSING: {auditd_config_file.path} not found")
185-
elif not is_valid_email(auditd_config_file.get("action_mail_acct")):
186-
valid = False
187-
logger.error("MISSING: expected action_mail_acct value")
188-
189-
# Check group ownership and permissions of auditd.conf
190-
if not _check_group_ownership(self.audit_config_path, "sudo"):
191-
logger.error(f"ERROR: {self.audit_config_path} is not owned by the 'sudo' group.")
192-
valid = False
193-
if not _check_permissions(self.audit_config_path, 0o660):
194-
logger.error(f"ERROR: {self.audit_config_path} does not have 660 permissions.")
195-
valid = False
196-
if not _check_owner(self.audit_config_path, "root"):
197-
logger.error(f"ERROR: {self.audit_config_path} is not owned by 'root'.")
198-
valid = False
185+
else:
186+
if not is_valid_email(auditd_config_file.get("action_mail_acct")):
187+
valid = False
188+
logger.error("MISSING: expected action_mail_acct value")
189+
190+
# Check group ownership and permissions of auditd.conf
191+
if not _check_group_ownership(self.audit_config_path, "sudo"):
192+
logger.error(f"ERROR: {self.audit_config_path} is not owned by the 'sudo' group.")
193+
valid = False
194+
if not _check_permissions(self.audit_config_path, 0o660):
195+
logger.error(f"ERROR: {self.audit_config_path} does not have 660 permissions.")
196+
valid = False
197+
if not _check_owner(self.audit_config_path, "root"):
198+
logger.error(f"ERROR: {self.audit_config_path} is not owned by 'root'.")
199+
valid = False
199200

200201
# Check group ownership and permissions of /var/log
201202
if not _check_group_ownership(self.log_path, "adm"):

0 commit comments

Comments
 (0)