conf: port apparmor to new list type

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2021-08-27 14:51:01 +02:00
parent 6446bf47d3
commit 1fb1e6676f
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D
4 changed files with 20 additions and 19 deletions

View File

@ -3378,7 +3378,7 @@ struct lxc_conf *lxc_conf_init(void)
lxc_list_init(&new->groups);
INIT_LIST_HEAD(&new->state_clients);
new->lsm_aa_profile = NULL;
lxc_list_init(&new->lsm_aa_raw);
INIT_LIST_HEAD(&new->lsm_aa_raw);
new->lsm_se_context = NULL;
new->lsm_se_keyring_context = NULL;
new->keyring_disable_session = false;
@ -4716,15 +4716,15 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key)
int lxc_clear_apparmor_raw(struct lxc_conf *c)
{
struct lxc_list *it, *next;
struct string_entry *entry, *nentry;
lxc_list_for_each_safe (it, &c->lsm_aa_raw, next) {
lxc_list_del(it);
free(it->elem);
free(it);
list_for_each_entry_safe(entry, nentry, &c->lsm_aa_raw, head) {
list_del(&entry->head);
free(entry->val);
free(entry);
}
lxc_list_init(&c->lsm_aa_raw);
INIT_LIST_HEAD(&c->lsm_aa_raw);
return 0;
}

View File

@ -424,7 +424,7 @@ struct lxc_conf {
bool lsm_aa_profile_created;
unsigned int lsm_aa_allow_nesting;
unsigned int lsm_aa_allow_incomplete;
struct lxc_list lsm_aa_raw;
struct list_head lsm_aa_raw;
char *lsm_se_context;
char *lsm_se_keyring_context;
bool keyring_disable_session;

View File

@ -1642,21 +1642,22 @@ static int set_config_apparmor_raw(const char *key,
{
#if HAVE_APPARMOR
__do_free char *elem = NULL;
__do_free struct lxc_list *list = NULL;
__do_free struct string_entry *entry = NULL;
if (lxc_config_value_empty(value))
return lxc_clear_apparmor_raw(lxc_conf);
list = lxc_list_new();
if (!list)
entry = zalloc(sizeof(struct string_entry));
if (!entry)
return ret_errno(ENOMEM);
elem = strdup(value);
if (!elem)
return ret_errno(ENOMEM);
list->elem = move_ptr(elem);
lxc_list_add_tail(&lxc_conf->lsm_aa_raw, move_ptr(list));
entry->val = move_ptr(elem);
list_add_tail(&entry->head, &lxc_conf->lsm_aa_raw);
move_ptr(entry);
return 0;
#else
@ -3774,7 +3775,7 @@ static int get_config_apparmor_raw(const char *key, char *retv,
{
#if HAVE_APPARMOR
int len;
struct lxc_list *it;
struct string_entry *entry;
int fulllen = 0;
if (!retv)
@ -3782,8 +3783,8 @@ static int get_config_apparmor_raw(const char *key, char *retv,
else
memset(retv, 0, inlen);
lxc_list_for_each(it, &c->lsm_aa_raw) {
strprint(retv, inlen, "%s\n", (char *)it->elem);
list_for_each_entry(entry, &c->lsm_aa_raw, head) {
strprint(retv, inlen, "%s\n", entry->val);
}
return fulllen;

View File

@ -755,7 +755,7 @@ static char *get_apparmor_profile_content(struct lsm_ops *ops, struct lxc_conf *
{
char *profile, *profile_name_full;
size_t size;
struct lxc_list *it;
struct string_entry *rule;
profile_name_full = apparmor_profile_full(conf->name, lxcpath);
@ -815,8 +815,8 @@ static char *get_apparmor_profile_content(struct lsm_ops *ops, struct lxc_conf *
must_append_sized(&profile, &size, AA_PROFILE_UNPRIVILEGED,
STRARRAYLEN(AA_PROFILE_UNPRIVILEGED));
lxc_list_for_each(it, &conf->lsm_aa_raw) {
const char *line = it->elem;
list_for_each_entry(rule, &conf->lsm_aa_raw, head) {
const char *line = rule->val;
must_append_sized_full(&profile, &size, line, strlen(line), true);
}