# #
#############################################################################*/
+#include <errno.h>
#include <sys/stat.h>
-// Enable legacy logging
-#define PAKFIRE_LEGACY_LOGGING
-
+#include <pakfire/ctx.h>
#include <pakfire/fhs.h>
#include <pakfire/file.h>
#include <pakfire/logging.h>
-#include <pakfire/pakfire.h>
#include <pakfire/util.h>
/*
};
static const struct pakfire_fhs_check* pakfire_fhs_find_check(
- struct pakfire* pakfire, struct pakfire_file* file) {
+ struct pakfire_ctx* ctx, struct pakfire_file* file) {
const struct pakfire_fhs_check* check = NULL;
int r;
// Match!
case 1:
- DEBUG(pakfire, "%s matches check '%s'\n", path, check->path);
+ CTX_DEBUG(ctx, "%s matches check '%s'\n", path, check->path);
return check;
}
ERROR:
- ERROR(pakfire, "Could not find FHS entry for %s: %m\n", path);
+ CTX_ERROR(ctx, "Could not find FHS entry for %s: %m\n", path);
return NULL;
}
static int pakfire_fhs_check_world_writable(
- struct pakfire* pakfire, struct pakfire_file* file) {
+ struct pakfire_ctx* ctx, struct pakfire_file* file) {
// Run this check only for regular files
switch (pakfire_file_get_type(file)) {
case S_IFREG:
// Check that none of the executable bits are set
if ((perms & (S_IWUSR|S_IWGRP|S_IWOTH)) == (S_IWUSR|S_IWGRP|S_IWOTH)) {
- DEBUG(pakfire, "%s is world-writable\n", path);
+ CTX_DEBUG(ctx, "%s is world-writable\n", path);
return 1;
}
return 0;
}
-static int pakfire_fhs_check_perms(struct pakfire* pakfire,
+static int pakfire_fhs_check_perms(struct pakfire_ctx* ctx,
const struct pakfire_fhs_check* check, struct pakfire_file* file) {
// No permissions defined. Skipping check...
if (!check->perms)
// Check if they match
if (check->perms != perms) {
- DEBUG(pakfire, "%s: Permissions do not match\n", path);
+ CTX_DEBUG(ctx, "%s: Permissions do not match\n", path);
return 1;
}
return 0;
}
-static int pakfire_fhs_check_ownership(struct pakfire* pakfire,
+static int pakfire_fhs_check_ownership(struct pakfire_ctx* ctx,
const struct pakfire_fhs_check* check, struct pakfire_file* file) {
const char* path = pakfire_file_get_path(file);
return 1;
if (strcmp(check->uname, uname) != 0) {
- DEBUG(pakfire, "%s: uname does not match\n", path);
+ CTX_DEBUG(ctx, "%s: uname does not match\n", path);
return 1;
}
}
return 1;
if (strcmp(check->gname, gname) != 0) {
- DEBUG(pakfire, "%s: gname does not match\n", path);
+ CTX_DEBUG(ctx, "%s: gname does not match\n", path);
return 1;
}
}
return 0;
}
-static int pakfire_fhs_check_noexec(struct pakfire* pakfire,
+static int pakfire_fhs_check_noexec(struct pakfire_ctx* ctx,
const struct pakfire_fhs_check* check, struct pakfire_file* file) {
// Skip this check if PAKFIRE_FHS_NOEXEC is not set
if (!(check->flags & PAKFIRE_FHS_NOEXEC))
// Check that none of the executable bits are set
if (perms & (S_IXUSR|S_IXGRP|S_IXOTH)) {
- DEBUG(pakfire, "%s must not be executable\n", path);
+ CTX_DEBUG(ctx, "%s must not be executable\n", path);
return 1;
}
return 0;
}
-int pakfire_fhs_check_file(struct pakfire* pakfire, struct pakfire_file* file) {
+int pakfire_fhs_check_file(struct pakfire_ctx* ctx, struct pakfire_file* file) {
const struct pakfire_fhs_check* check = NULL;
int r;
// Get the file path
const char* path = pakfire_file_get_path(file);
if (!path)
- return 1;
+ return -errno;
// Check for world-writable permissions
- r = pakfire_fhs_check_world_writable(pakfire, file);
+ r = pakfire_fhs_check_world_writable(ctx, file);
if (r)
return r;
// Find a check
- check = pakfire_fhs_find_check(pakfire, file);
+ check = pakfire_fhs_find_check(ctx, file);
if (!check) {
- ERROR(pakfire, "Could not match file %s: %m\n", path);
- return 1;
+ CTX_ERROR(ctx, "Could not match file %s: %m\n", path);
+ return -errno;
}
// Should this file exist at all?
if (check->flags & PAKFIRE_FHS_MUSTNOTEXIST) {
- DEBUG(pakfire, "%s must not exist here\n", path);
+ CTX_DEBUG(ctx, "%s must not exist here\n", path);
return 1;
}
// Check permissions
- r = pakfire_fhs_check_perms(pakfire, check, file);
+ r = pakfire_fhs_check_perms(ctx, check, file);
if (r)
return r;
// Check ownership
- r = pakfire_fhs_check_ownership(pakfire, check, file);
+ r = pakfire_fhs_check_ownership(ctx, check, file);
if (r)
return r;
// Check for PAKFIRE_FHS_NOEXEC
- r = pakfire_fhs_check_noexec(pakfire, check, file);
- if (r)
+ r = pakfire_fhs_check_noexec(ctx, check, file);
+ if (r < 0)
return r;
// Check passed!