summaryrefslogtreecommitdiffstats
path: root/database/sqlite
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2008-12-21 02:08:24 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2008-12-21 02:08:24 +0100
commit33c16185e500e18dbf364dc183a2ce713448931f (patch)
treee65a458004cd20cf27ae0ac3b7f5572041e17db6 /database/sqlite
parent82e9f56cc06ae751a2f34b250d07089b08c147f4 (diff)
downloadeurephia-33c16185e500e18dbf364dc183a2ce713448931f.tar.gz
eurephia-33c16185e500e18dbf364dc183a2ce713448931f.tar.xz
eurephia-33c16185e500e18dbf364dc183a2ce713448931f.zip
Moved all replace_char(...) calls into SQLite3 driver as xmlReplaceChars(...)
Diffstat (limited to 'database/sqlite')
-rw-r--r--database/sqlite/administration.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c
index 4cc0f79..ee4f132 100644
--- a/database/sqlite/administration.c
+++ b/database/sqlite/administration.c
@@ -56,6 +56,22 @@
*
*/
+// local, internal function
+void xmlReplaceChars(xmlChar *str, char s, char r) {
+ if( str != NULL ) {
+ xmlChar *ptr = str;
+
+ while( *ptr != '\0' ) {
+ if( *ptr == s ) {
+ *ptr = r;
+ }
+ ptr++;
+ }
+ }
+}
+
+
+
// Authenticate admin user against user database
int eDBadminAuth(eurephiaCTX *ctx, const char *req_access, const char *uname, const char *pwd) {
dbresult *res = NULL;
@@ -520,6 +536,7 @@ xmlDoc *eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, xmlDoc *srch) {
if( (qres != NULL) && (sqlite_get_numtuples(qres) > 0) ) {
int i;
xmlNode *cert, *acpr;
+ xmlChar *tmp = NULL;
for( i = 0; i < sqlite_get_numtuples(qres); i++ ) {
cert = xmlNewChild(info_n, NULL, (xmlChar *) "certificate", NULL);
@@ -528,8 +545,15 @@ xmlDoc *eDBadminGetUserInfo(eurephiaCTX *ctx, int getInfo, xmlDoc *srch) {
sqlite_xml_value(cert, XML_ATTR, "depth", qres, 0, 0);
sqlite_xml_value(cert, XML_ATTR, "registered", qres, 0, 5);
sqlite_xml_value(cert, XML_NODE, "digest", qres, 0, 1);
- sqlite_xml_value(cert, XML_NODE, "common_name", qres, 0, 2);
- sqlite_xml_value(cert, XML_NODE, "organisation", qres, 0, 3);
+
+ tmp = (xmlChar *)sqlite_get_value(qres, 0, 2);
+ xmlReplaceChars(tmp, '_', ' ');
+ xmlNewChild(cert, NULL, (xmlChar *) "common_name", tmp);
+
+ tmp = (xmlChar *)sqlite_get_value(qres, 0, 3);
+ xmlReplaceChars(tmp, '_', ' ');
+ xmlNewChild(cert, NULL, (xmlChar *) "organisation", tmp);
+
sqlite_xml_value(cert, XML_NODE, "email", qres, 0, 4);
acpr = sqlite_xml_value(cert, XML_NODE, "access_profile", qres, 0, 8);
@@ -908,11 +932,11 @@ xmlDoc *eDBadminGetCertificateInfo(eurephiaCTX *ctx, xmlDoc *srchxml, const char
sqlite_xml_value(tmp_n, XML_NODE, "digest", res, i, 1);
xmlStrPrintf(tmp, 2048, (xmlChar *) "%.2048s", sqlite_get_value(res, i, 2));
- // FIXME: replace_char((char *)&tmp, '_', ' ');
+ xmlReplaceChars(tmp, '_', ' ');
xmlNewChild(tmp_n, NULL, (xmlChar *) "common_name", tmp);
xmlStrPrintf(tmp, 2048, (xmlChar *) "%.2048s", sqlite_get_value(res, i, 3));
- // FIXME: replace_char((char *)&tmp, '_', ' ');
+ xmlReplaceChars(tmp, '_', ' ');
xmlNewChild(tmp_n, NULL, (xmlChar *) "organisation", tmp);
sqlite_xml_value(tmp_n, XML_NODE, "email", res, i, 4);
@@ -942,7 +966,7 @@ xmlDoc *eDBadminGetCertificateInfo(eurephiaCTX *ctx, xmlDoc *srchxml, const char
int eDBadminAddCertificate(eurephiaCTX *ctx, xmlDoc *certxml) {
int rc = 0;
xmlNode *crtinf_n = NULL;
- eDBfieldMap *crtinf_map = NULL;
+ eDBfieldMap *crtinf_map = NULL, *ptr = NULL;
dbresult *res = NULL;
assert( (ctx != NULL) && (certxml != NULL) );
@@ -962,6 +986,14 @@ int eDBadminAddCertificate(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_INSERT, "INSERT INTO openvpn_certificates", crtinf_map, NULL, NULL);
if( res == NULL ) {