From: Michael Tremer Date: Fri, 27 Jun 2025 14:13:09 +0000 (+0000) Subject: linter file: Create its own type X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7fca241d8583981dfa765f5516c38dd0d00bb287;p=pakfire.git linter file: Create its own type Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/linter-file.c b/src/pakfire/linter-file.c index 26b34eaf..aa921137 100644 --- a/src/pakfire/linter-file.c +++ b/src/pakfire/linter-file.c @@ -69,7 +69,7 @@ struct pakfire_linter_file { /* Maps the file into memory */ -static int pakfire_linter_file_map(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_map(pakfire_linter_file* lfile) { // Store the length lfile->length = lseek(lfile->fd, 0, SEEK_END); if (lfile->length <= 0) @@ -83,7 +83,7 @@ static int pakfire_linter_file_map(struct pakfire_linter_file* lfile) { return 0; } -static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) { +static void pakfire_linter_file_free(pakfire_linter_file* lfile) { int r; if (lfile->elf) @@ -107,9 +107,9 @@ static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) { free(lfile); } -int pakfire_linter_file_create(struct pakfire_linter_file** lfile, +int pakfire_linter_file_create(pakfire_linter_file** lfile, pakfire_ctx* ctx, struct pakfire_linter* linter, pakfire_file* file, int fd) { - struct pakfire_linter_file* l = NULL; + pakfire_linter_file* l = NULL; int r = 0; // Check input @@ -180,13 +180,13 @@ ERROR: } -struct pakfire_linter_file* pakfire_linter_file_ref(struct pakfire_linter_file* lfile) { +pakfire_linter_file* pakfire_linter_file_ref(pakfire_linter_file* lfile) { ++lfile->nrefs; return lfile; } -struct pakfire_linter_file* pakfire_linter_file_unref(struct pakfire_linter_file* lfile) { +pakfire_linter_file* pakfire_linter_file_unref(pakfire_linter_file* lfile) { if (--lfile->nrefs > 0) return lfile; @@ -194,7 +194,7 @@ struct pakfire_linter_file* pakfire_linter_file_unref(struct pakfire_linter_file return NULL; } -static int pakfire_linter_file_check_caps(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_caps(pakfire_linter_file* lfile) { // Files cannot have capabilities but not be executable if (!pakfire_file_is_executable(lfile->file) && pakfire_file_has_caps(lfile->file)) return pakfire_linter_file_error(lfile, "File has capabilities but is not executable"); @@ -205,7 +205,7 @@ static int pakfire_linter_file_check_caps(struct pakfire_linter_file* lfile) { #define pakfire_linter_file_get_script_interpreter(lfile, interpreter) \ __pakfire_linter_file_get_script_interpreter(lfile, interpreter, sizeof(interpreter)) -static int __pakfire_linter_file_get_script_interpreter(struct pakfire_linter_file* lfile, +static int __pakfire_linter_file_get_script_interpreter(pakfire_linter_file* lfile, char* interpreter, size_t length) { char shebang[PATH_MAX]; char* eol = NULL; @@ -273,7 +273,7 @@ static int __pakfire_linter_file_get_script_interpreter(struct pakfire_linter_fi return 0; } -static int pakfire_linter_check_script_interpreter(struct pakfire_linter_file* lfile) { +static int pakfire_linter_check_script_interpreter(pakfire_linter_file* lfile) { char interpreter[PATH_MAX]; int r; @@ -311,14 +311,14 @@ static int pakfire_linter_check_script_interpreter(struct pakfire_linter_file* l return 0; } -static int pakfire_linter_file_check_pie(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_pie(pakfire_linter_file* lfile) { if (!pakfire_elf_is_pie(lfile->elf)) return pakfire_linter_file_error(lfile, "Missing PIE"); return 0; } -static int pakfire_linter_file_check_ssp(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_ssp(pakfire_linter_file* lfile) { // This check will be skipped for these files static const char* whitelist[] = { // Runtime Linker @@ -350,14 +350,14 @@ static int pakfire_linter_file_check_ssp(struct pakfire_linter_file* lfile) { return 0; } -static int pakfire_linter_file_check_execstack(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_execstack(pakfire_linter_file* lfile) { if (pakfire_elf_has_execstack(lfile->elf)) return pakfire_linter_file_error(lfile, "Executable Stack"); return 0; } -static int pakfire_linter_file_check_relro(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_relro(pakfire_linter_file* lfile) { // If the file is fully RELRO, everything is good if (pakfire_elf_is_fully_relro(lfile->elf)) return 0; @@ -370,7 +370,7 @@ static int pakfire_linter_file_check_relro(struct pakfire_linter_file* lfile) { return pakfire_linter_file_error(lfile, "Is not RELRO"); } -static int pakfire_linter_file_check_runpath(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_runpath(pakfire_linter_file* lfile) { char** runpaths = NULL; int r; @@ -406,7 +406,7 @@ ERROR: return r; } -static int pakfire_linter_file_check_cf_protection(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_cf_protection(pakfire_linter_file* lfile) { int r; // Fetch if CF Protection has been enabled @@ -443,7 +443,7 @@ static int pakfire_linter_file_check_cf_protection(struct pakfire_linter_file* l return 0; } -static int pakfire_linter_file_is_stripped(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_is_stripped(pakfire_linter_file* lfile) { switch (pakfire_elf_type(lfile->elf)) { // Do not check Relocatable Objects case ET_REL: @@ -460,7 +460,7 @@ static int pakfire_linter_file_is_stripped(struct pakfire_linter_file* lfile) { return 0; } -static int pakfire_linter_file_has_debuglink(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_has_debuglink(pakfire_linter_file* lfile) { const char* debuglink = NULL; // Fetch the debug link @@ -471,7 +471,7 @@ static int pakfire_linter_file_has_debuglink(struct pakfire_linter_file* lfile) return 0; } -static int pakfire_linter_file_has_build_id(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_has_build_id(pakfire_linter_file* lfile) { const char* build_id = NULL; // Fetch the build ID @@ -483,7 +483,7 @@ static int pakfire_linter_file_has_build_id(struct pakfire_linter_file* lfile) { } // Checks if files in /usr/lib/debug are correct -static int pakfire_linter_file_check_debug(struct pakfire_linter_file* lfile) { +static int pakfire_linter_file_check_debug(pakfire_linter_file* lfile) { // Fail if this file is not an ELF file if (!lfile->elf) return pakfire_linter_file_error(lfile, "File is not in ELF format"); @@ -495,7 +495,7 @@ static int pakfire_linter_file_check_debug(struct pakfire_linter_file* lfile) { return 0; } -int pakfire_linter_file_lint(struct pakfire_linter_file* lfile) { +int pakfire_linter_file_lint(pakfire_linter_file* lfile) { int r = 0; // Check capabilities diff --git a/src/pakfire/linter-file.h b/src/pakfire/linter-file.h index 73a85776..44aab5c9 100644 --- a/src/pakfire/linter-file.h +++ b/src/pakfire/linter-file.h @@ -21,18 +21,18 @@ #ifndef PAKFIRE_LINTER_FILE_H #define PAKFIRE_LINTER_FILE_H -struct pakfire_linter_file; +typedef struct pakfire_linter_file pakfire_linter_file; #include #include #include -int pakfire_linter_file_create(struct pakfire_linter_file** lfile, +int pakfire_linter_file_create(pakfire_linter_file** lfile, pakfire_ctx* ctx, struct pakfire_linter* linter, pakfire_file* file, int fd); -struct pakfire_linter_file* pakfire_linter_file_ref(struct pakfire_linter_file* lfile); -struct pakfire_linter_file* pakfire_linter_file_unref(struct pakfire_linter_file* lfile); +pakfire_linter_file* pakfire_linter_file_ref(pakfire_linter_file* lfile); +pakfire_linter_file* pakfire_linter_file_unref(pakfire_linter_file* lfile); -int pakfire_linter_file_lint(struct pakfire_linter_file* lfile); +int pakfire_linter_file_lint(pakfire_linter_file* lfile); #endif /* PAKFIRE_LINTER_FILE_H */ diff --git a/src/pakfire/linter.c b/src/pakfire/linter.c index 27caad83..1ae7740f 100644 --- a/src/pakfire/linter.c +++ b/src/pakfire/linter.c @@ -348,7 +348,7 @@ ERROR: static int pakfire_linter_payload( struct pakfire_linter* linter, pakfire_file* file, struct archive* a) { - struct pakfire_linter_file* lfile = NULL; + pakfire_linter_file* lfile = NULL; int fd = -EBADF; int r; @@ -478,7 +478,7 @@ static int pakfire_linter_lint_fhs( return 0; } -static int pakfire_linter_file(pakfire_archive* archive, +static int pakfire_linter_lint_file(pakfire_archive* archive, struct archive* a, struct archive_entry* e, void* data) { struct pakfire_linter* linter = data; pakfire_file* file = NULL; @@ -619,7 +619,7 @@ int pakfire_linter_lint(struct pakfire_linter* linter) { return r; // Lint the payload - r = pakfire_archive_walk_payload(linter->archive, pakfire_linter_file, linter); + r = pakfire_archive_walk_payload(linter->archive, pakfire_linter_lint_file, linter); if (r < 0) return r;