diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2011-01-09 23:39:08 +0100 |
|---|---|---|
| committer | David Sommerseth <davids@redhat.com> | 2011-12-19 11:05:38 +0100 |
| commit | 8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927 (patch) | |
| tree | a778cb9ee6f06b41f256a22450af8fd7916a3ed8 /database/sqlite/administration/firewalladmin.c | |
| parent | f0434a3ad51bf1159a78003a020eeb82a26dfc7f (diff) | |
| download | eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.tar.gz eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.tar.xz eurephia-8d2f8d68e6ae9726fdd2d941e55a7377e3cdf927.zip | |
Modified the whole edb-sqlite driver to use a better error handling
This will change the driver to use the new error routines made available
in the SQLite3 framework. Some of the code is also restructured a little
bit to simplify the code with these changes.
The functionality should be the same as for, but better error messages
are now sent back to the caller on the functions supporting XML.
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
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; } |
