From 88e67c4360aab6ab79412b79bca7bdf2f8d1264d Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 3 Apr 2009 00:04:30 +0200 Subject: When deleting fwprofiles, delete also records from openvpn_usercerts --- database/sqlite/firewalladmin.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'database/sqlite') diff --git a/database/sqlite/firewalladmin.c b/database/sqlite/firewalladmin.c index 920f1af..4824fdd 100644 --- a/database/sqlite/firewalladmin.c +++ b/database/sqlite/firewalladmin.c @@ -162,6 +162,36 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) { "firewall profile and destination fields"); } + // 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 ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile (1)"); + return eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not delete the firewall profile"); + } + + // Delete all references to this access profile in openvpn_usercerts + if( sqlite_get_numtuples(res) > 0 ) { + dbresult *dres = NULL; + int i = 0; + + for( i = 0; i < sqlite_get_numtuples(res); i++ ) { + dres = sqlite_query(ctx, + "DELETE FROM openvpn_usercerts " + " WHERE accessprofile = %q", + sqlite_get_value(res, i, 0)); + if( dres == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile (2)"); + ret = eurephiaXML_ResultMsg(ctx, exmlERROR, + "Could not delete the firewall profile"); + sqlite_free_results(res); + return ret; + } + sqlite_free_results(dres); + } + } + + // Delete requested access profiles from openvpn_accesses res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_accesses", NULL, fmap, NULL); if( res == NULL ) { eurephia_log(ctx, LOG_FATAL, 0, "Could not delete the firewall profile"); -- cgit