mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-01 23:05:11 +00:00
libapparmor: refactor init_cache_features() to call cache_check_features()
Signed-off-by: John Johansen <john.johansen@canonical.com> Acked-by: Christian Boltz <apparmor@cboltz.de>
This commit is contained in:
@@ -128,8 +128,9 @@ static char *path_from_fd(int fd)
|
|||||||
static int cache_check_features(int dirfd, const char *cache_name,
|
static int cache_check_features(int dirfd, const char *cache_name,
|
||||||
aa_features *features)
|
aa_features *features)
|
||||||
{
|
{
|
||||||
autofree aa_features *local_features = NULL; /* ingore ref count */
|
aa_features *local_features = NULL;
|
||||||
autofree char *name = NULL;
|
autofree char *name = NULL;
|
||||||
|
bool rc;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = asprintf(&name, "%s/%s", cache_name, CACHE_FEATURES_FILE);
|
len = asprintf(&name, "%s/%s", cache_name, CACHE_FEATURES_FILE);
|
||||||
@@ -144,10 +145,13 @@ static int cache_check_features(int dirfd, const char *cache_name,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!aa_features_is_equal(local_features, features)) {
|
rc = aa_features_is_equal(local_features, features);
|
||||||
|
aa_features_unref(local_features);
|
||||||
|
if (!rc) {
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,30 +172,14 @@ static int create_cache(aa_policy_cache *policy_cache, aa_features *features)
|
|||||||
static int init_cache_features(aa_policy_cache *policy_cache,
|
static int init_cache_features(aa_policy_cache *policy_cache,
|
||||||
aa_features *kernel_features, bool create)
|
aa_features *kernel_features, bool create)
|
||||||
{
|
{
|
||||||
bool call_create_cache = false;
|
if (cache_check_features(policy_cache->dirfd, ".", kernel_features)) {
|
||||||
aa_features *local_features;
|
/* EEXIST must come before ENOENT for short circuit eval */
|
||||||
|
if (!create || errno == EEXIST || errno != ENOENT)
|
||||||
if (aa_features_new(&local_features, policy_cache->dirfd,
|
|
||||||
CACHE_FEATURES_FILE)) {
|
|
||||||
if (!create || errno != ENOENT)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
} else
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* The cache directory needs to be created */
|
return create_cache(policy_cache, kernel_features);
|
||||||
call_create_cache = true;
|
|
||||||
} else if (!aa_features_is_equal(local_features, kernel_features)) {
|
|
||||||
if (!create) {
|
|
||||||
aa_features_unref(local_features);
|
|
||||||
errno = EEXIST;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The cache directory needs to be refreshed */
|
|
||||||
call_create_cache = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
aa_features_unref(local_features);
|
|
||||||
return call_create_cache ?
|
|
||||||
create_cache(policy_cache, kernel_features) : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct miss_cb_data {
|
struct miss_cb_data {
|
||||||
|
Reference in New Issue
Block a user