]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: crtlist_entry_dup() duplicates a crtlist_entry
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 10 Sep 2020 17:08:49 +0000 (19:08 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 16 Sep 2020 14:28:26 +0000 (16:28 +0200)
Implement crtlist_entry_dup() which allocate and duplicate a
crtlist_entry structure.

src/ssl_crtlist.c

index d70e2ab91d646e7ff72514c9fd4ad718e8e4a329..393f4ea4212ea3c24a9c4fe165e242db7761aa43 100644 (file)
@@ -196,6 +196,45 @@ void crtlist_entry_free(struct crtlist_entry *entry)
        }
        free(entry);
 }
+/*
+ * Duplicate a crt_list entry and its content (ssl_conf, filters/fcount)
+ * Return a pointer to the new entry
+ */
+struct crtlist_entry *crtlist_entry_dup(struct crtlist_entry *src)
+{
+       struct crtlist_entry *entry;
+
+       if (src == NULL)
+               return NULL;
+
+       entry = crtlist_entry_new();
+       if (entry == NULL)
+               return NULL;
+
+       if (src->filters) {
+               entry->filters = crtlist_dup_filters(src->filters, src->fcount);
+               if (!entry->filters)
+                       goto error;
+       }
+       entry->fcount = src->fcount;
+       if (src->ssl_conf) {
+               entry->ssl_conf = crtlist_dup_ssl_conf(src->ssl_conf);
+               if (!entry->ssl_conf)
+                       goto error;
+       }
+       entry->crtlist = src->crtlist;
+
+       return entry;
+
+error:
+
+       crtlist_free_filters(entry->filters);
+       ssl_sock_free_ssl_conf(entry->ssl_conf);
+       free(entry->ssl_conf);
+       free(entry);
+
+       return NULL;
+}
 
 /*
  * Allocate and initialize a crtlist_entry