archive_entry_set_mode(file->entry, pakfire_file_get_type(file) | perms);
}
-static int pakfire_file_is_executable(struct pakfire_file* file) {
+int pakfire_file_is_executable(struct pakfire_file* file) {
return pakfire_file_get_mode(file) & (S_IXUSR|S_IXGRP|S_IXOTH);
}
return r;
}
-static int pakfire_file_check_capabilities(struct pakfire_file* file) {
- // Files cannot have capabilities but not be executable
- if (!pakfire_file_is_executable(file) && pakfire_file_has_caps(file))
- file->issues |= PAKFIRE_FILE_INVALID_CAPS;
-
- return 0;
-}
-
int pakfire_file_check(struct pakfire_file* file, int* issues) {
int r;
if (r)
return r;
- // Perform capability check
- r = pakfire_file_check_capabilities(file);
- if (r)
- return r;
-
// Run these checks only for ELF files
if (pakfire_file_matches_class(file, PAKFIRE_FILE_ELF)) {
switch (pakfire_file_get_elf_type(file)) {
PAKFIRE_FILE_RUNTIME_LINKER = (1 << 14),
};
+int pakfire_file_is_executable(struct pakfire_file* file);
+
int pakfire_file_has_payload(struct pakfire_file* file);
int pakfire_file_write_fcaps(struct pakfire_file* file, struct vfs_cap_data* cap_data);
return NULL;
}
+static int pakfire_linter_file_check_caps(struct 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");
+
+ return 0;
+}
+
static int pakfire_linter_file_init_libelf(struct pakfire_linter_file* lfile) {
// Initialize libelf
if (elf_version(EV_CURRENT) == EV_NONE) {
return pakfire_linter_file_elf(lfile, __pakfire_linter_file_check_execstack, NULL);
}
-
static int __pakfire_linter_file_has_bind_now(struct pakfire_linter_file* lfile,
Elf* elf, const GElf_Shdr* shdr, const GElf_Dyn* dyn, void* data) {
int* has_bind_now = (int*)data;
int pakfire_linter_file_lint(struct pakfire_linter_file* lfile) {
int r = 0;
+ // Check capabilities
+ r = pakfire_linter_file_check_caps(lfile);
+ if (r < 0)
+ return r;
+
// Skip firmware files
if (pakfire_file_matches(lfile->file, "/usr/lib/firmware/**"))
return 0;