diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-20 00:10:52 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-20 00:10:52 +0100 |
commit | 6c7ebacfe109a1dab260ce1c4b601985616d31ce (patch) | |
tree | 00e6d6ce14e6bf32e59fd23401a3bbc9ff405d8c | |
parent | d565cb958dd431978632ca32030b51b8e3e67e76 (diff) | |
download | eurephia-6c7ebacfe109a1dab260ce1c4b601985616d31ce.tar.gz eurephia-6c7ebacfe109a1dab260ce1c4b601985616d31ce.tar.xz eurephia-6c7ebacfe109a1dab260ce1c4b601985616d31ce.zip |
sqlite3: Added eDBadminAddCertificate(...) function
-rw-r--r-- | database/sqlite/administration.c | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index c384723..33e36fb 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -831,8 +831,57 @@ xmlDoc *eDBadminGetCertificateInfo(eurephiaCTX *ctx, xmlDoc *srchkey) { return NULL; } -int eDBadminAddCertificate(eurephiaCTX *ctx, xmlDoc *crtinf) { - return 0; + +// This functions register a certificate into openvpn_certificates, based on the +// following XML document: +// +// <eurephia format="1"> +// <register_certificate> +// <fieldMapping table="certificates"> +// <depth>{cert.depth}</depth> +// <digest>{SHA1 digest}</digest> +// <common_name>{common_name}</common_name> +// <organisation>{org.}</organisation> +// <email>{email addr}</email> +// </fieldMapping> +// </register_certificate> +// </eurephia> +// +int eDBadminAddCertificate(eurephiaCTX *ctx, xmlDoc *certxml) { + int rc = 0; + xmlNode *crtinf_n = NULL; + eDBfieldMap *crtinf_map = NULL; + dbresult *res = NULL; + + assert( (ctx != NULL) && (certxml != NULL) ); + + crtinf_n = eurephiaXML_getRoot(ctx, certxml, 1, "register_certificate"); + if( crtinf_n == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Could not find a valid XML for registering certificate"); + return 0; + } + + crtinf_n = xmlFindNode(crtinf_n, "fieldMapping"); + if( crtinf_n == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Could not find a valid XML for registering certificate"); + return 0; + } + + crtinf_map = eDBxmlMapping(ctx, tbl_sqlite_certs, NULL, crtinf_n); + assert( crtinf_map != NULL ); + + // Register the certificate + res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_certificates", crtinf_map, NULL); + if( res == NULL ) { + eurephia_log(ctx, LOG_FATAL, 0, "Could not register the certificate"); + rc = 0; + } else { + rc = 1; + } + sqlite_free_results(res); + eDBfreeMapping(crtinf_map); + + return rc; } int eDBadminDeleteCertificate(eurephiaCTX *ctx, const int uid, xmlDoc *crtinf) { |