summaryrefslogtreecommitdiffstats
path: root/database/sqlite
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-03-27 22:46:01 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-03-27 22:46:01 +0100
commitb1d3a7b2621374d23ef8be5cb79d06fb3a18e3dc (patch)
treed1bb6a5992b43aaede95f6f7861da248bd1c9d5e /database/sqlite
parent4bf03e8daade85c734f202f72b22e855ba05eae0 (diff)
downloadeurephia-b1d3a7b2621374d23ef8be5cb79d06fb3a18e3dc.tar.gz
eurephia-b1d3a7b2621374d23ef8be5cb79d06fb3a18e3dc.tar.xz
eurephia-b1d3a7b2621374d23ef8be5cb79d06fb3a18e3dc.zip
BUGFIX: Fixed missing string replace in certificate functions
When calling eDBadminGetCertificateInfo(...) or eDBadminDeleteCertificate(...) with a search XML document using common_name or organisation and these fields contained spaces, no certificates would be deleted. This is because space is replaced with underscore in the database.
Diffstat (limited to 'database/sqlite')
-rw-r--r--database/sqlite/administration.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c
index ef2e621..0e71e03 100644
--- a/database/sqlite/administration.c
+++ b/database/sqlite/administration.c
@@ -904,7 +904,7 @@ xmlDoc *eDBadminGetCertificateList(eurephiaCTX *ctx, const char *sortkeys) {
xmlDoc *eDBadminGetCertificateInfo(eurephiaCTX *ctx, xmlDoc *srchxml, const char *sortkeys) {
xmlDoc *certlist = NULL;
xmlNode *srch_n = NULL, *cert_n = NULL, *tmp_n = NULL;
- eDBfieldMap *srch_map = NULL;
+ eDBfieldMap *srch_map = NULL, *ptr = NULL;
dbresult *res = NULL;
xmlChar tmp[2050];
char *dbsort = NULL;
@@ -932,6 +932,14 @@ xmlDoc *eDBadminGetCertificateInfo(eurephiaCTX *ctx, xmlDoc *srchxml, const char
srch_map = eDBxmlMapping(ctx, tbl_sqlite_certs, NULL, srch_n);
assert( srch_map != NULL );
+ // Replace spaces with underscore in common name and
+ // in organisation fields, to comply with OpenVPN standards
+ for( ptr = srch_map; ptr != NULL; ptr = ptr->next ) {
+ if( ptr->field_id & (FIELD_CNAME | FIELD_ORG) ) {
+ xmlReplaceChars((xmlChar *) ptr->value, ' ', '_');
+ }
+ }
+
res = sqlite_query_mapped(ctx, SQL_SELECT,
"SELECT depth, digest, common_name, organisation, email, registered, certid"
" FROM openvpn_certificates", NULL, srch_map, dbsort);
@@ -1054,7 +1062,7 @@ int eDBadminAddCertificate(eurephiaCTX *ctx, xmlDoc *certxml) {
int eDBadminDeleteCertificate(eurephiaCTX *ctx, xmlDoc *certxml) {
int rc = 0;
xmlNode *crtinf_n = NULL;
- eDBfieldMap *crtinf_map = NULL;
+ eDBfieldMap *crtinf_map = NULL, *ptr = NULL;
dbresult *res = NULL;
DEBUG(ctx, 20, "Function call: eDBadminDeleteCertificate(ctx, xmlDoc)");
@@ -1075,6 +1083,14 @@ int eDBadminDeleteCertificate(eurephiaCTX *ctx, xmlDoc *certxml) {
crtinf_map = eDBxmlMapping(ctx, tbl_sqlite_certs, NULL, crtinf_n);
assert( crtinf_map != NULL );
+ // Replace spaces with underscore in common name and
+ // in organisation fields, to comply with OpenVPN standards
+ for( ptr = crtinf_map; ptr != NULL; ptr = ptr->next ) {
+ if( ptr->field_id & (FIELD_CNAME | FIELD_ORG) ) {
+ xmlReplaceChars((xmlChar *) ptr->value, ' ', '_');
+ }
+ }
+
// Register the certificate
res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_certificates", NULL, crtinf_map, NULL);
if( res == NULL ) {