From: Christian Brauner Date: Fri, 27 Aug 2021 12:51:01 +0000 (+0200) Subject: conf: port apparmor to new list type X-Git-Tag: lxc-5.0.0~97^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fb1e6676f58fde5451076f537f7df719250d73a;p=thirdparty%2Flxc.git conf: port apparmor to new list type Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 5937b0c76..dc14708cd 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -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; } diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 53075b3f8..af5de4dc2 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -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; diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 03bdef077..c2f9a0bc2 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -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; diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c index 63d122591..0667526d4 100644 --- a/src/lxc/lsm/apparmor.c +++ b/src/lxc/lsm/apparmor.c @@ -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); }