diff options
Diffstat (limited to 'database/sqlite/administration/usercerts.c')
-rw-r--r-- | database/sqlite/administration/usercerts.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/database/sqlite/administration/usercerts.c b/database/sqlite/administration/usercerts.c index 8c7e5fd..8e654ab 100644 --- a/database/sqlite/administration/usercerts.c +++ b/database/sqlite/administration/usercerts.c @@ -92,8 +92,10 @@ xmlDoc *usercerts_search(eurephiaCTX *ctx, eDBfieldMap *where_m, const char *sor NULL, // values (not used for SELECT) where_m, // fields and values for the WHERE clause dbsort); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_ERROR, 0, "Could not query the usercerts table"); + sqlite_log_error(ctx, res); + sqlite_free_results(res); return NULL; } @@ -154,7 +156,7 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr if( strcmp(mode, "register") == 0 ) { dbres = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_usercerts", usrcrt_m, NULL, NULL); - if( dbres ) { + if( sqlite_query_status(dbres) == dbSUCCESS ) { res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Registered new user-cert link with id %i", dbres->last_insert_id); @@ -162,7 +164,7 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr } else if( strcmp(mode, "remove") == 0 ) { dbres = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_usercerts", NULL, usrcrt_m, NULL); - if( dbres ) { + if( sqlite_query_status(dbres) == dbSUCCESS ) { int num_rows = sqlite_get_affected_rows(dbres); if( num_rows > 0 ) { res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, @@ -175,12 +177,15 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr } } - if( dbres == NULL ) { + if( sqlite_query_status(dbres) != dbSUCCESS ) { + xmlNode *tmp_n = NULL; + eurephia_log(ctx, LOG_ERROR, 0, "Failed to %s user-cert link.", mode); - res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Failed to %s user-cert link", mode); - } else { - sqlite_free_results(dbres); + tmp_n = sqlite_log_error_xml(ctx, dbres); + res = eurephiaXML_ResultMsg(ctx, exmlERROR, tmp_n, "Failed to %s user-cert link", mode); + xmlFreeNode(tmp_n); } + sqlite_free_results(dbres); return res; } @@ -220,7 +225,7 @@ xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *uicid, eDBfieldMap *usrcr // Send update query to the database dbres = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_usercerts", usrcrt_m, where_m, NULL); - if( dbres ) { + if( sqlite_query_status(dbres) == dbSUCCESS ) { int num_rows = sqlite_get_affected_rows(dbres); if( num_rows > 0 ) { res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, @@ -230,12 +235,16 @@ xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *uicid, eDBfieldMap *usrcr res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "No user-cert links where updated"); } - sqlite_free_results(dbres); } else { + xmlNode *err_n = NULL; + eurephia_log(ctx, LOG_ERROR, 0, "Failed to update user-cert link.(uicid: %s)", uicid); - res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, + err_n = sqlite_log_error_xml(ctx, dbres); + res = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Failed to update user-cert link for uicid %s", uicid); + xmlFreeNode(err_n); } + sqlite_free_results(dbres); eDBfreeMapping(where_m); xmlFreeDoc(where_d); |