]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: add a list of bind_conf in struct crtlist
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 25 Mar 2020 14:10:49 +0000 (15:10 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Tue, 31 Mar 2020 10:32:17 +0000 (12:32 +0200)
In order to be able to add new certificate in a crt-list, we need the
list of bind_conf that uses this crt-list so we can create a ckch_inst
for each of them.

include/types/ssl_sock.h
src/ssl_sock.c

index f4cecfb7f65856d908b74777f123f305ab6abf63..add74544d168e5863ade1d5acf9087412944aa23 100644 (file)
@@ -138,8 +138,15 @@ struct ckch_inst {
        struct list by_crtlist_entry; /* chained in crtlist_entry list of inst */
 };
 
+/* list of bind conf used by struct crtlist */
+struct bind_conf_list {
+       struct bind_conf *bind_conf;
+       struct bind_conf_list *next;
+};
+
 /* This structure is basically a crt-list or a directory */
 struct crtlist {
+       struct bind_conf_list *bind_conf; /* list of bind_conf which use this crtlist */
        struct eb_root entries;
        struct list ord_entries; /* list to keep the line order of the crt-list file */
        struct ebmb_node node; /* key is the filename or directory */
index d2e59482b820b064e20ee945bb461a4031767e2a..1207e9c71093250af942bb7de171628b41336c3f 100644 (file)
@@ -4456,6 +4456,7 @@ static int crtlist_load_cert_dir(char *path, struct bind_conf *bind_conf, struct
        }
        memcpy(dir->node.key, path, strlen(path) + 1);
        dir->entries = EB_ROOT_UNIQUE; /* it's a directory, files are unique */
+       dir->bind_conf = NULL;
        LIST_INIT(&dir->ord_entries);
 
        n = scandir(path, &de_list, 0, alphasort);
@@ -4719,6 +4720,7 @@ static int crtlist_parse_file(char *file, struct bind_conf *bind_conf, struct pr
        }
        memcpy(newlist->node.key, file, strlen(file) + 1);
        newlist->entries = EB_ROOT;
+       newlist->bind_conf = NULL;
        LIST_INIT(&newlist->ord_entries);
 
        while (fgets(thisline, sizeof(thisline), f) != NULL) {
@@ -4896,9 +4898,20 @@ int ssl_sock_load_cert_list_file(char *file, int dir, struct bind_conf *bind_con
        struct ebmb_node *eb;
        struct crtlist_entry *entry;
        struct list instances; /* temporary list head */
+       struct bind_conf_list *bind_conf_node = NULL;
        int cfgerr = 0;
 
        LIST_INIT(&instances);
+
+       bind_conf_node = malloc(sizeof(*bind_conf_node));
+       if (!bind_conf_node) {
+               memprintf(err, "%sCan't alloc memory!\n", err && *err ? *err : "");
+               cfgerr |= ERR_FATAL | ERR_ALERT;
+               goto error;
+       }
+       bind_conf_node->next = NULL;
+       bind_conf_node->bind_conf = bind_conf;
+
        /* look for an existing crtlist or create one */
        eb = ebst_lookup(&crtlists_tree, file);
        if (eb) {
@@ -4935,6 +4948,10 @@ int ssl_sock_load_cert_list_file(char *file, int dir, struct bind_conf *bind_con
        /* add the instances to the actual instance list in the crtlist_entry */
        LIST_SPLICE(&entry->ckch_inst, &instances);
 
+       /* add the bind_conf to the list */
+       bind_conf_node->next = crtlist->bind_conf;
+       crtlist->bind_conf = bind_conf_node;
+
        return cfgerr;
 error:
        {
@@ -4952,6 +4969,7 @@ error:
                        LIST_DEL(&inst->by_crtlist_entry);
                        free(inst);
                }
+               free(bind_conf_node);
        }
        return cfgerr;
 }