summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-09-21 19:04:36 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-09-21 19:04:36 +0200
commit8fc41296cd27af9757f571627f7fd16befc9b8aa (patch)
tree9a2d242654c938ae0b0a327d649f7d7e7f875586 /database
parent854f3bb476a3cb7cf370c0f7690d9a376d219609 (diff)
downloadeurephia-8fc41296cd27af9757f571627f7fd16befc9b8aa.tar.gz
eurephia-8fc41296cd27af9757f571627f7fd16befc9b8aa.tar.xz
eurephia-8fc41296cd27af9757f571627f7fd16befc9b8aa.zip
Rewrote eurephiaXML_ResultMsg() to also support adding an xmlNode* with more info
The eurephia result XML document is also changed, and all parsing of the result must be rewritten. To simplify this parsing, a new function is introduced, eurephiaXML_ParseResultMsg().
Diffstat (limited to 'database')
-rw-r--r--database/sqlite/administration/attempts.c14
-rw-r--r--database/sqlite/administration/blacklist.c14
-rw-r--r--database/sqlite/administration/configuration.c12
-rw-r--r--database/sqlite/administration/firewalladmin.c22
-rw-r--r--database/sqlite/administration/useraccount.c8
-rw-r--r--database/sqlite/administration/usercerts.c30
6 files changed, 52 insertions, 48 deletions
diff --git a/database/sqlite/administration/attempts.c b/database/sqlite/administration/attempts.c
index 08c6dc1..e94878a 100644
--- a/database/sqlite/administration/attempts.c
+++ b/database/sqlite/administration/attempts.c
@@ -144,16 +144,16 @@ xmlDoc *attempts_reset(eurephiaCTX *ctx, eDBfieldMap *fmap) {
fields = eDBmappingFieldsPresent(fmap);
if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Missing username, IP address, certificate digest or atpid");
}
res = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_attempts", update_vals, fmap, NULL);
if( res == NULL ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not reset the attempts count");
- ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not reset the attempts count");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not reset the attempts count");
} else {
- ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Attempts count reset");
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Attempts count reset");
sqlite_free_results(res);
}
return ret;
@@ -175,16 +175,16 @@ xmlDoc *attempts_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
fields = eDBmappingFieldsPresent(fmap);
if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Missing username, IP address, certificate digest or atpid");
}
res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_attempts", NULL, fmap, NULL);
if( res == NULL ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not remove attempts record");
- ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not delete the attempts record");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the attempts record");
} else {
- ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Attempts record removed");
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Attempts record removed");
sqlite_free_results(res);
}
return ret;
@@ -234,7 +234,7 @@ xmlDoc *eDBadminAttemptsLog(eurephiaCTX *ctx, xmlDoc *qryxml) {
resxml = attempts_delete(ctx, fmap);
} else {
eurephia_log(ctx, LOG_ERROR, 0, "Attempts - Unknown mode: '%s'", mode);
- resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, "Unknown mode '%s'", mode);
+ resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Unknown mode '%s'", mode);
}
eDBfreeMapping(fmap);
return resxml;
diff --git a/database/sqlite/administration/blacklist.c b/database/sqlite/administration/blacklist.c
index d8824ea..80c4506 100644
--- a/database/sqlite/administration/blacklist.c
+++ b/database/sqlite/administration/blacklist.c
@@ -139,7 +139,7 @@ xmlDoc *blacklist_add(eurephiaCTX *ctx, eDBfieldMap *fmap) {
fields = eDBmappingFieldsPresent(fmap);
if( (fields != FIELD_UNAME) && (fields != FIELD_CERTDIGEST) && (fields != FIELD_REMOTEIP) ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Missing username, IP address or certificate digest, "
"or multiple of these fields were given.");
}
@@ -147,9 +147,9 @@ xmlDoc *blacklist_add(eurephiaCTX *ctx, eDBfieldMap *fmap) {
res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_blacklist", fmap, NULL, NULL);
if( res == NULL ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not blacklist the requested data");
- ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Blacklisting failed");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Blacklisting failed");
} else {
- ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Record registered in the blacklist");
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Record registered in the blacklist");
sqlite_free_results(res);
}
return ret;
@@ -171,16 +171,16 @@ xmlDoc *blacklist_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
fields = eDBmappingFieldsPresent(fmap);
if( (fields & (FIELD_UNAME | FIELD_CERTDIGEST | FIELD_REMOTEIP | FIELD_RECID)) == 0 ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Missing username, IP address, certificate digest or blacklist ID");
}
res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_blacklist", NULL, fmap, NULL);
if( res == NULL ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not remove blacklisting");
- ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Failed to remove the blacklisting");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Failed to remove the blacklisting");
} else {
- ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Blacklisting removed");
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Blacklisting removed");
sqlite_free_results(res);
}
return ret;
@@ -230,7 +230,7 @@ xmlDoc *eDBadminBlacklist(eurephiaCTX *ctx, xmlDoc *qryxml) {
resxml = blacklist_delete(ctx, fmap);
} else {
eurephia_log(ctx, LOG_ERROR, 0, "Blacklist - Unknown mode: '%s'", mode);
- resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, "Unknown mode '%s'", mode);
+ resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Unknown mode '%s'", mode);
}
eDBfreeMapping(fmap);
return resxml;
diff --git a/database/sqlite/administration/configuration.c b/database/sqlite/administration/configuration.c
index e27b257..dbf033e 100644
--- a/database/sqlite/administration/configuration.c
+++ b/database/sqlite/administration/configuration.c
@@ -155,7 +155,7 @@ xmlDoc *validate_key_value(eurephiaCTX *ctx, const char *key, const char *value)
v_null = (value == NULL ? 1 : 0);
if( k_null || v_null ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR, "%s%s%s",
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "%s%s%s",
(k_null ? "The key attribute was not set" : ""),
(k_null && v_null ? " and " : ""),
(v_null ? "The value tag was not set" : "")
@@ -200,11 +200,11 @@ xmlDoc *eDBadminConfiguration(eurephiaCTX *ctx, xmlDoc *cfgxml) {
}
if( config_set(ctx, key, value) ) {
- resxml = eurephiaXML_ResultMsg(ctx, exmlRESULT,
+ resxml = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Configuration key '%s' was set to '%s'",
key, value);
} else {
- resxml = eurephiaXML_ResultMsg(ctx, exmlERROR,
+ resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Failed to set the key '%s' to '%s'",
key, value);
}
@@ -223,15 +223,15 @@ xmlDoc *eDBadminConfiguration(eurephiaCTX *ctx, xmlDoc *cfgxml) {
}
if( config_delete(ctx, key) ) {
- resxml = eurephiaXML_ResultMsg(ctx, exmlRESULT,
+ resxml = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Configuration key '%s' was deleted", key);
} else {
- resxml = eurephiaXML_ResultMsg(ctx, exmlERROR,
+ resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Failed to delete the key '%s'", key);
}
return resxml;
}
// If not, it's an invalid input
- return eurephiaXML_ResultMsg(ctx, exmlERROR, "Unkown XML tag received");
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Unkown XML tag received");
}
diff --git a/database/sqlite/administration/firewalladmin.c b/database/sqlite/administration/firewalladmin.c
index 378f265..6c6b91e 100644
--- a/database/sqlite/administration/firewalladmin.c
+++ b/database/sqlite/administration/firewalladmin.c
@@ -166,16 +166,19 @@ xmlDoc *fwadmin_add(eurephiaCTX *ctx, eDBfieldMap *fmap) {
// Check if we have the needed fields, and only the needed fields
if( eDBmappingFieldsPresent(fmap) != (FIELD_DESCR | FIELD_FWPROFILE) ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR, "Adding firewall profile only accepts "
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
+ "Adding firewall profile only accepts "
"description and firewall profile fields");
}
res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_accesses", fmap, NULL, NULL);
if( res == NULL ) {
eurephia_log(ctx, LOG_FATAL, 0, "Could not register the new firewall profile");
- ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not register the new firewall profile");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
+ "Could not register the new firewall profile");
} else {
- ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Firewall profile registered with id %i",
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
+ "Firewall profile registered with id %i",
res->last_insert_id);
}
sqlite_free_results(res);
@@ -199,7 +202,8 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
// Check if we have the needed fields, and only the needed fields
fields = eDBmappingFieldsPresent(fmap);
if( !(fields & FIELD_FWPROFILE) && !(fields & FIELD_RECID) ) {
- return eurephiaXML_ResultMsg(ctx, exmlERROR, "Deleting firewall profile only accepts "
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
+ "Deleting firewall profile only accepts "
"firewall profile and destination fields");
}
@@ -208,7 +212,7 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
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");
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the firewall profile");
}
// Delete all references to this access profile in openvpn_usercerts
@@ -223,7 +227,7 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
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,
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Could not delete the firewall profile");
sqlite_free_results(res);
return ret;
@@ -236,9 +240,9 @@ xmlDoc *fwadmin_delete(eurephiaCTX *ctx, eDBfieldMap *fmap) {
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");
- ret = eurephiaXML_ResultMsg(ctx, exmlERROR, "Could not delete the firewall profile");
+ ret = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Could not delete the firewall profile");
} else {
- ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, "Firewall profile deleted");
+ ret = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL, "Firewall profile deleted");
}
sqlite_free_results(res);
return ret;
@@ -288,7 +292,7 @@ xmlDoc *eDBadminFirewallProfiles(eurephiaCTX *ctx, xmlDoc *xmlqry) {
resxml = fwadmin_delete(ctx, fmap);
} else {
eurephia_log(ctx, LOG_ERROR, 0, "FirewallProfiles - Unknown mode: '%s'", mode);
- resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, "Unknown mode '%s'", mode);
+ resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Unknown mode '%s'", mode);
}
eDBfreeMapping(fmap);
return resxml;
diff --git a/database/sqlite/administration/useraccount.c b/database/sqlite/administration/useraccount.c
index e7d1da7..4f44789 100644
--- a/database/sqlite/administration/useraccount.c
+++ b/database/sqlite/administration/useraccount.c
@@ -588,7 +588,7 @@ xmlDoc *adminacclvl_Get(eurephiaCTX *ctx, eDBfieldMap *fmap) {
NULL, fmap, "uid, interface, access");
if( res == NULL ) {
eurephia_log(ctx, LOG_ERROR, 0, "Error querying the database for a access levels");
- return eurephiaXML_ResultMsg(ctx, exmlERROR,
+ return eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Error querying the database for a access levels");
}
@@ -656,7 +656,7 @@ xmlDoc *eDBadminAccessLevel(eurephiaCTX *ctx, xmlDoc *qryxml) {
sqlres = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO eurephia_adminaccess",
fmap_m, NULL, NULL);
if( sqlres && (sqlite_get_affected_rows(sqlres) > 0) ) {
- res_d = eurephiaXML_ResultMsg(ctx, exmlRESULT,
+ res_d = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Access level %s (%s) was granted to uid %s",
eDBmappingGetValue(fmap_m, FIELD_ACCESSLVL),
eDBmappingGetValue(fmap_m, FIELD_INTERFACE),
@@ -666,7 +666,7 @@ xmlDoc *eDBadminAccessLevel(eurephiaCTX *ctx, xmlDoc *qryxml) {
sqlres = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM eurephia_adminaccess",
NULL, fmap_m, NULL);
if( sqlres && (sqlite_get_affected_rows(sqlres) > 0) ) {
- res_d = eurephiaXML_ResultMsg(ctx, exmlRESULT,
+ res_d = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Access level %s (%s) was revoked from uid %s",
eDBmappingGetValue(fmap_m, FIELD_ACCESSLVL),
eDBmappingGetValue(fmap_m, FIELD_INTERFACE),
@@ -678,7 +678,7 @@ xmlDoc *eDBadminAccessLevel(eurephiaCTX *ctx, xmlDoc *qryxml) {
if( res_d == NULL ) {
eurephia_log(ctx, LOG_ERROR, 0, "Failed to update admin access");
- res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, "Failed to complete %s operation", mode);
+ res_d = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL, "Failed to complete %s operation", mode);
}
if( sqlres ) {
sqlite_free_results(sqlres);
diff --git a/database/sqlite/administration/usercerts.c b/database/sqlite/administration/usercerts.c
index 408891f..4387dcf 100644
--- a/database/sqlite/administration/usercerts.c
+++ b/database/sqlite/administration/usercerts.c
@@ -165,7 +165,7 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr
dbres = sqlite_query_mapped(ctx, SQL_INSERT,
"INSERT INTO openvpn_usercerts", usrcrt_m, NULL, NULL);
if( dbres ) {
- res = eurephiaXML_ResultMsg(ctx, exmlRESULT,
+ res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Registered new user-cert link with id %i",
dbres->last_insert_id);
}
@@ -173,21 +173,21 @@ xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcr
dbres = sqlite_query_mapped(ctx, SQL_DELETE,
"DELETE FROM openvpn_usercerts", NULL, usrcrt_m, NULL);
if( dbres ) {
- int num_rows = sqlite_get_affected_rows(dbres);
- if( num_rows > 0 ) {
- res = eurephiaXML_ResultMsg(ctx, exmlRESULT,
- "Removed %i user-cert %s successfully",
- num_rows, (num_rows == 1 ? "link" : "links"));
- } else {
- res = eurephiaXML_ResultMsg(ctx, exmlERROR,
- "No user-cert links where removed");
- }
+ int num_rows = sqlite_get_affected_rows(dbres);
+ if( num_rows > 0 ) {
+ res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
+ "Removed %i user-cert %s successfully",
+ num_rows, (num_rows == 1 ? "link" : "links"));
+ } else {
+ res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
+ "No user-cert links where removed");
+ }
}
}
if( dbres == NULL ) {
eurephia_log(ctx, LOG_ERROR, 0, "Failed to %s user-cert link.", mode);
- res = eurephiaXML_ResultMsg(ctx, exmlERROR, "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);
}
@@ -233,17 +233,17 @@ xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *uicid, eDBfieldMap *usrcr
if( dbres ) {
int num_rows = sqlite_get_affected_rows(dbres);
if( num_rows > 0 ) {
- res = eurephiaXML_ResultMsg(ctx, exmlRESULT,
+ res = eurephiaXML_ResultMsg(ctx, exmlRESULT, NULL,
"Updated firewall access profile on %i user-cert %s.",
num_rows, (num_rows == 1 ? "link" : "links"));
} else {
- res = eurephiaXML_ResultMsg(ctx, exmlERROR,
+ res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"No user-cert links where updated");
}
sqlite_free_results(dbres);
} else {
eurephia_log(ctx, LOG_ERROR, 0, "Failed to update user-cert link.(uicid: %s)", uicid);
- res = eurephiaXML_ResultMsg(ctx, exmlERROR,
+ res = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Failed to update user-cert link for uicid %s", uicid);
}
eDBfreeMapping(where_m);
@@ -306,7 +306,7 @@ xmlDoc *eDBadminUserCertsLink(eurephiaCTX *ctx, xmlDoc *usrcrt_xml) {
uicid = xmlGetAttrValue(usrcrt_n->properties, "uicid");
if( uicid == NULL ) {
eurephia_log(ctx, LOG_ERROR, 0, "Missing required attribute, uicid, for updates");
- resxml = eurephiaXML_ResultMsg(ctx, exmlERROR,
+ resxml = eurephiaXML_ResultMsg(ctx, exmlERROR, NULL,
"Can not set firewall access profile without uicid");
goto exit;
}