From f514cfe6aa8b50c60c61e3f23ec3ac174661fd6b Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 10 Apr 2023 20:33:51 +0300 Subject: audit: report errors as 'e' --- src/app_audit.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/app_audit.c') diff --git a/src/app_audit.c b/src/app_audit.c index 997899b..52dbc73 100644 --- a/src/app_audit.c +++ b/src/app_audit.c @@ -125,15 +125,14 @@ static int audit_file(struct audit_ctx *actx, struct apk_file_info fi; int rv = 0; - if (dbf == NULL) - return 'A'; + if (!dbf) return 'A'; if (apk_fileinfo_get(dirfd, name, APK_FI_NOFOLLOW | APK_FI_XATTR_CSUM(dbf->acl->xattr_csum.type ?: APK_CHECKSUM_DEFAULT) | APK_FI_CSUM(dbf->csum.type), &fi, &db->atoms) != 0) - return -EPERM; + return 'e'; if (dbf->csum.type != APK_CHECKSUM_NONE && apk_checksum_compare(&fi.csum, &dbf->csum) != 0) @@ -221,16 +220,23 @@ static int audit_directory_tree_item(void *ctx, int dirfd, const char *name) struct audit_ctx *actx = atctx->actx; struct apk_database *db = atctx->db; struct apk_db_dir *dir = atctx->dir, *child = NULL; + struct apk_db_file *dbf; struct apk_file_info fi; int reason = 0; if (bdir.len + bent.len + 1 >= sizeof(atctx->path)) return 0; - if (apk_fileinfo_get(dirfd, name, APK_FI_NOFOLLOW, &fi, &db->atoms) < 0) return 0; memcpy(&atctx->path[atctx->pathlen], bent.ptr, bent.len); atctx->pathlen += bent.len; bfull = APK_BLOB_PTR_LEN(atctx->path, atctx->pathlen); + if (apk_fileinfo_get(dirfd, name, APK_FI_NOFOLLOW, &fi, &db->atoms) < 0) { + dbf = apk_db_file_query(db, bdir, bent); + if (dbf) dbf->audited = 1; + report_audit(actx, 'e', bfull, dbf ? dbf->diri->pkg : NULL); + goto done; + } + if (S_ISDIR(fi.mode)) { int recurse = TRUE; @@ -254,8 +260,6 @@ static int audit_directory_tree_item(void *ctx, int dirfd, const char *name) } reason = audit_directory(actx, db, child, &fi); - if (reason < 0) - goto done; recurse_check: atctx->path[atctx->pathlen++] = '/'; @@ -271,7 +275,6 @@ recurse_check: bfull.len--; atctx->pathlen--; } else { - struct apk_db_file *dbf; int protect_mode = determine_file_protect_mode(dir, name); dbf = apk_db_file_query(db, bdir, bent); @@ -324,7 +327,6 @@ recurse_check: goto done; } if (!reason) reason = audit_file(actx, db, dbf, dirfd, name); - if (reason < 0) goto done; report_audit(actx, reason, bfull, dbf ? dbf->diri->pkg : NULL); } -- cgit v1.2.3-60-g2f50