CLEANUP: ssl: make cli_parse_set_cert handle errcode and warnings.
cli_parse_set_cert was re-work to show errors and warnings depending
of ERR_* bitfield value.
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index 10dee6f..458246f 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -9566,7 +9566,7 @@
int i;
int found = 0;
int bundle = -1;
- int ret = 0;
+ int errcode = 0;
if (!*args[3] || !payload)
return cli_err(appctx, "'set ssl cert expects a filename and a certificat as a payload\n");
@@ -9581,7 +9581,7 @@
mem = BIO_new_mem_buf(payload, -1);
if (!mem) {
memprintf(&err, "%sCan't allocate memory\n", err ? err : "");
- ret = 1;
+ errcode |= ERR_ALERT | ERR_FATAL;
goto end;
}
@@ -9595,7 +9595,7 @@
if (bundle < 0 && ckchs->multi) {
memprintf(&err, "%s%s is a multi-cert bundle. Try updating %s.{dsa,rsa,ecdsa}\n",
err ? err : "", args[3], args[3]);
- ret = 1;
+ errcode |= ERR_ALERT | ERR_FATAL;
goto end;
}
@@ -9607,14 +9607,14 @@
if (ckchs->filters) {
memprintf(&err, "%sCertificates used in crt-list with filters are not supported!\n",
err ? err : "");
- ret = 1;
+ errcode |= ERR_ALERT | ERR_FATAL;
goto end;
}
found = 1;
if (ssl_sock_load_crt_file_into_ckch(args[3], mem, ckch, &err) != 0) {
- ret = 1;
+ errcode |= ERR_ALERT | ERR_FATAL;
goto end;
}
@@ -9628,7 +9628,7 @@
new_inst = ckch_inst_new_load_store(args[3], ckchs, ckchi->bind_conf, ckchi->ssl_conf, NULL, 0, &err);
if (!new_inst) {
- ret = 1;
+ errcode |= ERR_ALERT | ERR_FATAL;
goto end;
}
@@ -9685,9 +9685,9 @@
}
if (!found) {
- ret = 1;
memprintf(&err, "%sCan't replace a certificate name which is not referenced by the configuration!\n",
err ? err : "");
+ errcode |= ERR_ALERT | ERR_FATAL;
}
end:
@@ -9696,7 +9696,7 @@
BIO_free(mem);
- if (ret != 0) {
+ if (errcode & ERR_CODE) {
struct ckch_inst *ckchi, *ckchis;
/* if the allocation failed, we need to free everything from the temporary list */
list_for_each_entry_safe(ckchi, ckchis, &tmp_ckchi_list, by_ckchs) {
@@ -9712,7 +9712,11 @@
free(ckchi);
}
return cli_dynerr(appctx, memprintf(&err, "%sCan't update the certificate!\n", err ? err : ""));
- } else {
+ }
+ else if (errcode & ERR_WARN) {
+ return cli_dynmsg(appctx, LOG_WARNING, memprintf(&err, "%sCertificate updated!\n", err ? err : ""));
+ }
+ else {
return cli_dynmsg(appctx, LOG_INFO, memprintf(&err, "Certificate updated!"));
}
}