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); lxc_list_init(&new->groups);
INIT_LIST_HEAD(&new->state_clients); INIT_LIST_HEAD(&new->state_clients);
new->lsm_aa_profile = NULL; 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_context = NULL;
new->lsm_se_keyring_context = NULL; new->lsm_se_keyring_context = NULL;
new->keyring_disable_session = false; 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) 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) { list_for_each_entry_safe(entry, nentry, &c->lsm_aa_raw, head) {
lxc_list_del(it); list_del(&entry->head);
free(it->elem); free(entry->val);
free(it); free(entry);
} }
lxc_list_init(&c->lsm_aa_raw); INIT_LIST_HEAD(&c->lsm_aa_raw);
return 0; return 0;
} }

View File

@ -424,7 +424,7 @@ struct lxc_conf {
bool lsm_aa_profile_created; bool lsm_aa_profile_created;
unsigned int lsm_aa_allow_nesting; unsigned int lsm_aa_allow_nesting;
unsigned int lsm_aa_allow_incomplete; 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_context;
char *lsm_se_keyring_context; char *lsm_se_keyring_context;
bool keyring_disable_session; bool keyring_disable_session;

View File

@ -1642,21 +1642,22 @@ static int set_config_apparmor_raw(const char *key,
{ {
#if HAVE_APPARMOR #if HAVE_APPARMOR
__do_free char *elem = NULL; __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)) if (lxc_config_value_empty(value))
return lxc_clear_apparmor_raw(lxc_conf); return lxc_clear_apparmor_raw(lxc_conf);
list = lxc_list_new(); entry = zalloc(sizeof(struct string_entry));
if (!list) if (!entry)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
elem = strdup(value); elem = strdup(value);
if (!elem) if (!elem)
return ret_errno(ENOMEM); return ret_errno(ENOMEM);
list->elem = move_ptr(elem); entry->val = move_ptr(elem);
lxc_list_add_tail(&lxc_conf->lsm_aa_raw, move_ptr(list)); list_add_tail(&entry->head, &lxc_conf->lsm_aa_raw);
move_ptr(entry);
return 0; return 0;
#else #else
@ -3774,7 +3775,7 @@ static int get_config_apparmor_raw(const char *key, char *retv,
{ {
#if HAVE_APPARMOR #if HAVE_APPARMOR
int len; int len;
struct lxc_list *it; struct string_entry *entry;
int fulllen = 0; int fulllen = 0;
if (!retv) if (!retv)
@ -3782,8 +3783,8 @@ static int get_config_apparmor_raw(const char *key, char *retv,
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
lxc_list_for_each(it, &c->lsm_aa_raw) { list_for_each_entry(entry, &c->lsm_aa_raw, head) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", entry->val);
} }
return fulllen; 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; char *profile, *profile_name_full;
size_t size; size_t size;
struct lxc_list *it; struct string_entry *rule;
profile_name_full = apparmor_profile_full(conf->name, lxcpath); 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, must_append_sized(&profile, &size, AA_PROFILE_UNPRIVILEGED,
STRARRAYLEN(AA_PROFILE_UNPRIVILEGED)); STRARRAYLEN(AA_PROFILE_UNPRIVILEGED));
lxc_list_for_each(it, &conf->lsm_aa_raw) { list_for_each_entry(rule, &conf->lsm_aa_raw, head) {
const char *line = it->elem; const char *line = rule->val;
must_append_sized_full(&profile, &size, line, strlen(line), true); must_append_sized_full(&profile, &size, line, strlen(line), true);
} }