summaryrefslogtreecommitdiffstats
path: root/database/sqlite/administration/certificates.c
diff options
context:
space:
mode:
Diffstat (limited to 'database/sqlite/administration/certificates.c')
-rw-r--r--database/sqlite/administration/certificates.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/database/sqlite/administration/certificates.c b/database/sqlite/administration/certificates.c
index 78be97e..8db12ff 100644
--- a/database/sqlite/administration/certificates.c
+++ b/database/sqlite/administration/certificates.c
@@ -89,10 +89,13 @@ static xmlDoc *certificate_list(eurephiaCTX *ctx, eDBfieldMap *srch_map, const c
"SELECT depth, lower(digest), common_name, organisation, email, "
" registered, certid"
" FROM openvpn_certificates", NULL, srch_map, sortkeys);
- if( res == NULL ) {
+ if( sqlite_query_status(res) != dbSUCCESS ) {
eurephia_log(ctx, LOG_ERROR, 0, "Could not query the certificate table");
- return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
+ tmp_n = sqlite_log_error_xml(ctx, res);
+ certlist = eurephiaXML_ResultMsg(ctx, exmlERROR, tmp_n,
"Could not query the database for certificate info");
+ xmlFreeNode(tmp_n);
+ goto exit;
}
memset(&tmp, 0, 2050);
@@ -118,8 +121,9 @@ static xmlDoc *certificate_list(eurephiaCTX *ctx, eDBfieldMap *srch_map, const c
sqlite_xml_value(tmp_n, XML_NODE, "email", res, i, 4);
}
- sqlite_free_results(res);
+ exit:
+ sqlite_free_results(res);
return certlist;
}
@@ -159,9 +163,11 @@ static xmlDoc *certificate_add(eurephiaCTX *ctx, eDBfieldMap *crtinf_map) {
// Register the certificate
res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_certificates",
crtinf_map, NULL, NULL);
- if( res == NULL ) {
+ if( sqlite_query_status(res) != dbSUCCESS ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not register the certificate");
- res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not register the certificate");
+ info_n = sqlite_log_error_xml(ctx, res);
+ res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, info_n, "Could not register the certificate");
+ xmlFreeNode(info_n);
} else {
xmlChar *certid = malloc_nullsafe(ctx, 34);
assert( certid != NULL );
@@ -216,9 +222,13 @@ static xmlDoc *certificate_delete(eurephiaCTX *ctx, eDBfieldMap *crtinf_map) {
// Register the certificate
res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_certificates",
NULL, crtinf_map, NULL);
- if( res == NULL ) {
+ if( sqlite_query_status(res) != dbSUCCESS ) {
+ xmlNode *err_n = NULL;
+
eurephia_log(ctx, LOG_FATAL, 0, "Could not complete the delete certificate request");
- res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the certificate(s)");
+ err_n = sqlite_log_error_xml(ctx, res);
+ res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not delete the certificate(s)");
+ xmlFreeNode(err_n);
} else {
res_d = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "%i %s deleted",
sqlite_get_affected_rows(res),