diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-25 23:13:03 +0100 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-25 23:13:03 +0100 |
| commit | 17ba7983b9decd13931012153af4c193c9437231 (patch) | |
| tree | 41bc74dff90993cc8db9929aadc85edfe79f794d /database/sqlite | |
| parent | 0ec91ae4111fb2d0efdeaa19b2d612b40db39024 (diff) | |
| download | eurephia-17ba7983b9decd13931012153af4c193c9437231.tar.gz eurephia-17ba7983b9decd13931012153af4c193c9437231.tar.xz eurephia-17ba7983b9decd13931012153af4c193c9437231.zip | |
sqlite3 db driver: Added eDBadminUpdateUserCertLink(...) function to add and delete records in openvpn_usercerts
Diffstat (limited to 'database/sqlite')
| -rw-r--r-- | database/sqlite/administration.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/database/sqlite/administration.c b/database/sqlite/administration.c index ccc45b7..9a6bef2 100644 --- a/database/sqlite/administration.c +++ b/database/sqlite/administration.c @@ -1065,6 +1065,54 @@ int eDBadminDeleteCertificate(eurephiaCTX *ctx, xmlDoc *certxml) { return rc; } +int eDBadminUpdateUserCertLink(eurephiaCTX *ctx, xmlDoc *usrcrt_xml) { + dbresult *res = NULL; + xmlNode *usrcrt_n = NULL, *fmap_n = NULL; + eDBfieldMap *usrcrt_m = NULL; + char *mode = NULL; + int rc = 0; + + assert( (ctx != NULL) && (usrcrt_xml != NULL) ); + + usrcrt_n = eurephiaXML_getRoot(ctx, usrcrt_xml, "usercerts_link", 1); + if( usrcrt_n == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Could not find a valid XML for the user-certs link request"); + return 0; + } + mode = xmlGetAttrValue(usrcrt_n->properties, "mode"); + if( mode == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Invalid user-cert link request (1)."); + return 0; + } + + fmap_n = xmlFindNode(usrcrt_n, "fieldMapping"); + if( fmap_n == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Invalid user-cert link request (2)."); + return 0; + } + usrcrt_m = eDBxmlMapping(ctx, tbl_sqlite_usercerts, NULL, fmap_n); + assert(usrcrt_m != NULL); + + if( strcmp(mode, "register") == 0 ) { + res = sqlite_query_mapped(ctx, SQL_INSERT, "INSERT INTO openvpn_usercerts", usrcrt_m, NULL, NULL); + rc = res->last_insert_id; + } else if( strcmp(mode, "remove") == 0 ) { + res = sqlite_query_mapped(ctx, SQL_DELETE, "DELETE FROM openvpn_usercerts", NULL, usrcrt_m, NULL); + rc = 1; + } + + if( res == NULL ) { + eurephia_log(ctx, LOG_ERROR, 0, "Failed to register user account / certificate"); + rc = -1; + } else { + sqlite_free_results(res); + } + + eDBfreeMapping(usrcrt_m); + return rc; +} + + xmlDoc *eDBadminGetLastlog(eurephiaCTX *ctx, xmlDoc *usersrch, xmlDoc *certsrch, const char *sortkeys) { |
