diff options
Diffstat (limited to 'database/sqlite/administration/firewalladmin.c')
-rw-r--r-- | database/sqlite/administration/firewalladmin.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/database/sqlite/administration/firewalladmin.c b/database/sqlite/administration/firewalladmin.c index 8ad2717..fd34183 100644 --- a/database/sqlite/administration/firewalladmin.c +++ b/database/sqlite/administration/firewalladmin.c @@ -87,8 +87,10 @@ xmlDoc *fwadmin_search(eurephiaCTX *ctx, eDBfieldMap *fmap) { " LEFT JOIN openvpn_users USING (uid)" " LEFT JOIN openvpn_certificates c ON (uac.certid = c.certid)", NULL, fmap, "accessprofile, uid, c.certid"); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_ERROR, 0, "Error querying the database for firewall profiles"); + sqlite_log_error(ctx, res); + sqlite_free_results(res); return NULL; } @@ -162,10 +164,14 @@ xmlDoc *fwadmin_add(eurephiaCTX *ctx, eDBfieldMap *fmap) { } res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_accesses", fmap, NULL, NULL); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { + xmlNode *err_n = NULL; + eurephia_log(ctx, LOG_FATAL, 0, "Could not register the new firewall profile"); - ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, + err_n = sqlite_log_error_xml(ctx, res); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not register the new firewall profile"); + xmlFreeNode(err_n); } else { ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Firewall profile registered with id %i", @@ -187,6 +193,7 @@ xmlDoc *fwadmin_add(eurephiaCTX *ctx, eDBfieldMap *fmap) { xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { dbresult *res = NULL; xmlDoc *ret = NULL; + xmlNode *err_n = NULL; long int fields; // Check if we have the needed fields, and only the needed fields @@ -200,9 +207,12 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { // Find the accessprofile ID based on the fieldmap res = sqlite_query_mapped(ctx, SQL_SELECT, "SELECT DISTINCT accessprofile FROM openvpn_accesses", NULL, fmap, NULL); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile (1)"); - return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the firewall profile"); + err_n = sqlite_log_error_xml(ctx, res); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not delete the firewall profile"); + xmlFreeNode(err_n); + goto exit; } // Delete all references to this access profile in openvpn_usercerts @@ -215,12 +225,14 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { "DELETE FROM openvpn_usercerts " " WHERE accessprofile = %q", sqlite_get_value(res, i, 0)); - if( dres == NULL ) { + if( sqlite_query_status(dres) != dbSUCCESS ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile (2)"); - ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, + err_n = sqlite_log_error_xml(ctx, res); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not delete the firewall profile"); - sqlite_free_results(res); - return ret; + sqlite_free_results(dres); + xmlFreeNode(err_n); + goto exit; } sqlite_free_results(dres); } @@ -228,12 +240,15 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { // Delete requested access profiles from openvpn_accesses res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_accesses", NULL, fmap, NULL); - if( res == NULL ) { + if( sqlite_query_status(res) != dbSUCCESS ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile"); - ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the firewall profile"); + err_n = sqlite_log_error_xml(ctx, res); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, err_n, "Could not delete the firewall profile"); + xmlFreeNode(err_n); } else { ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Firewall profile deleted"); } + exit: sqlite_free_results(res); return ret; } |