diff options
| author | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-01 23:08:03 +0200 |
|---|---|---|
| committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-01 23:08:03 +0200 |
| commit | 44b978bfaca38ebcd47913ac2709ee20baf021c5 (patch) | |
| tree | 54ec097035a40b6d1702397566eb136551fd17c9 /database | |
| parent | 88dcbd1a0b62bde794ab8a56661f2412503574e6 (diff) | |
| download | eurephia-44b978bfaca38ebcd47913ac2709ee20baf021c5.tar.gz eurephia-44b978bfaca38ebcd47913ac2709ee20baf021c5.tar.xz eurephia-44b978bfaca38ebcd47913ac2709ee20baf021c5.zip | |
Added --set-fwprofile mode to the eurephiadm usercerts command
This mode updates the firewall access profile for at user-certs link
Diffstat (limited to 'database')
| -rw-r--r-- | database/sqlite/usercerts.c | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/database/sqlite/usercerts.c b/database/sqlite/usercerts.c index a32932d..ba89f6c 100644 --- a/database/sqlite/usercerts.c +++ b/database/sqlite/usercerts.c @@ -127,11 +127,11 @@ xmlDoc *usercerts_search(eurephiaCTX *ctx, eDBfieldMap *where_m, const char *sor } -xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcrt_m) { +xmlDoc *usercerts_add_del(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcrt_m) { xmlDoc *res = NULL; dbresult *dbres = NULL; - DEBUG(ctx, 21, "Function call: usercerts_update(ctx, xmlDoc)"); + DEBUG(ctx, 21, "Function call: usercerts_add_del(ctx, xmlDoc)"); assert( (ctx != NULL) && (usrcrt_m != NULL) ); if( strcmp(mode, "register") == 0 ) { @@ -169,6 +169,53 @@ xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *mode, eDBfieldMap *usrcrt } +xmlDoc *usercerts_update(eurephiaCTX *ctx, const char *uicid, eDBfieldMap *usrcrt_m) { + xmlNode *where_n = NULL; + eDBfieldMap *where_m = NULL; + dbresult *dbres = NULL; + xmlDoc *where_d = NULL, *res = NULL; + + DEBUG(ctx, 21, "Function call: usercerts_update(ctx, '%s', eDBfieldMap)", uicid); + assert( ctx != NULL && uicid != NULL && usrcrt_m != NULL ); + + // Create a eDBfieldMap which will contain the uicid value + eurephiaXML_CreateDoc(ctx, 1, "usercerts", &where_d, &where_n); + assert( (where_d != NULL) && (where_n != NULL) ); + + where_n = xmlNewChild(where_n, NULL, (xmlChar *) "fieldMapping", NULL); + xmlNewProp(where_n, (xmlChar *) "table", (xmlChar *) "usercerts"); + xmlNewChild(where_n, NULL, (xmlChar *) "uicid", (xmlChar *) uicid); + + // Convert xmlNode with fieldMapping into a eDBfieldMap + where_m = eDBxmlMapping(ctx, tbl_sqlite_usercerts, NULL, where_n); + assert( where_m != NULL ); + + // Send update query to the database + dbres = sqlite_query_mapped(ctx, SQL_UPDATE, "UPDATE openvpn_usercerts", + usrcrt_m, where_m, NULL); + if( dbres ) { + int num_rows = sqlite_get_affected_rows(dbres); + if( num_rows > 0 ) { + res = eurephiaXML_ResultMsg(ctx, exmlRESULT, + "Updated firewall access profile on %i user-cert %s.", + num_rows, (num_rows == 1 ? "link" : "links")); + } else { + res = eurephiaXML_ResultMsg(ctx, exmlERROR, + "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, + "Failed to update user-cert link for uicid %s", uicid); + } + eDBfreeMapping(where_m); + xmlFreeDoc(where_d); + + return res; +} + + // The XML document format: // <eurephia format="1"> // <usercerts mode="{search|register|remove|update}" [uicid="{uicid}"]> @@ -221,17 +268,25 @@ xmlDoc *eDBadminUserCertsLink(eurephiaCTX *ctx, xmlDoc *usrcrt_xml) { usrcrt_m = eDBxmlMapping(ctx, tbl_sqlite_usercerts, NULL, tmp_n); assert(usrcrt_m != NULL); - uicid = xmlGetAttrValue(usrcrt_n->properties, "uicid"); - if( strcmp(mode, "search") == 0 ) { resxml = usercerts_search(ctx, usrcrt_m, sortfields); } else if( strcmp(mode, "register") == 0 ) { - resxml = usercerts_update(ctx, mode, usrcrt_m); + resxml = usercerts_add_del(ctx, mode, usrcrt_m); } else if( strcmp(mode, "remove") == 0 ) { - resxml = usercerts_update(ctx, mode, usrcrt_m); + resxml = usercerts_add_del(ctx, mode, usrcrt_m); + } else if( strcmp(mode, "update") == 0 ) { + 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, + "Can not set firewall access profile without uicid"); + goto exit; + } + resxml = usercerts_update(ctx, uicid, usrcrt_m); } + exit: eDBfreeMapping(usrcrt_m); return resxml; } |
