summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-03-28 23:25:51 +0100
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-03-28 23:25:51 +0100
commit5f208d0f6c0281569f14299965beff12807272c6 (patch)
tree8bd4cb21e685ff5535b46f9388a0027f1d462f3d /database
parent44423c753476b5960dd129fc8bdde8778f51ffad (diff)
downloadeurephia-5f208d0f6c0281569f14299965beff12807272c6.tar.gz
eurephia-5f208d0f6c0281569f14299965beff12807272c6.tar.xz
eurephia-5f208d0f6c0281569f14299965beff12807272c6.zip
Added eDBadminGetFirewallProfiles(...) function in DB driver
Diffstat (limited to 'database')
-rw-r--r--database/eurephiadb.c2
-rw-r--r--database/eurephiadb_driver.h2
-rw-r--r--database/sqlite/CMakeLists.txt1
-rw-r--r--database/sqlite/firewalladmin.c136
4 files changed, 141 insertions, 0 deletions
diff --git a/database/eurephiadb.c b/database/eurephiadb.c
index 3b697dc..f90abb2 100644
--- a/database/eurephiadb.c
+++ b/database/eurephiadb.c
@@ -108,6 +108,8 @@ int eDBlink_init(eurephiaCTX *ctx, const char *dbl, const int minver)
eDBadminGetAdminAccess = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetAdminAccess");
eDBadminEditAdminAccess = eGetSym(ctx, ctx->eurephia_driver, "eDBadminEditAdminAccess");
+ eDBadminGetFirewallProfiles = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetFirewallProfiles");
+
eDBadminGetLastlog = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetLastlog");
eDBadminGetAttemptsLog = eGetSym(ctx, ctx->eurephia_driver, "eDBadminGetAttemptsLog");
#endif
diff --git a/database/eurephiadb_driver.h b/database/eurephiadb_driver.h
index 31040d8..5ada459 100644
--- a/database/eurephiadb_driver.h
+++ b/database/eurephiadb_driver.h
@@ -123,6 +123,8 @@ int (*eDBadminUpdateUserCertLink) (eurephiaCTX *ctx, xmlDoc *usrcrt_xml);
xmlDoc *(*eDBadminGetAdminAccess) (eurephiaCTX *ctx, xmlDoc *srch_xml);
int (*eDBadminEditAdminAccess) (eurephiaCTX *ctx, xmlDoc *grant_xml);
+xmlDoc *(*eDBadminGetFirewallProfiles) (eurephiaCTX *ctx, xmlDoc *srch);
+
xmlDoc *(*eDBadminGetLastlog) (eurephiaCTX *ctx, xmlDoc *srch, const char *sortkeys);
xmlDoc *(*eDBadminGetAttemptsLog) (eurephiaCTX *ctx, xmlDoc *usersrch, xmlDoc *certsrch, const char *sortkeys);
#endif /* HAVE_LIBXML2 */
diff --git a/database/sqlite/CMakeLists.txt b/database/sqlite/CMakeLists.txt
index fcd6134..5f1e0f9 100644
--- a/database/sqlite/CMakeLists.txt
+++ b/database/sqlite/CMakeLists.txt
@@ -38,6 +38,7 @@ IF(ADMIN_ENABLED)
../../common/eurephia_xml.c
../eurephiadb_mapping.c
administration.c
+ firewalladmin.c
)
ENDIF(ADMIN_ENABLED)
diff --git a/database/sqlite/firewalladmin.c b/database/sqlite/firewalladmin.c
new file mode 100644
index 0000000..2da930b
--- /dev/null
+++ b/database/sqlite/firewalladmin.c
@@ -0,0 +1,136 @@
+/* firewalladmin.c -- Functions for managing firewall profiles
+ *
+ * GPLv2 only - Copyright (C) 2009
+ * David Sommerseth <dazo@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include <libxml/tree.h>
+
+#ifndef DRIVERAPIVERSION
+# define DRIVERAPIVERSION 2
+#endif
+
+#include <sqlite3.h>
+
+#include <eurephia_nullsafe.h>
+#include <eurephia_context.h>
+#include <eurephia_admin_struct.h>
+#include <eurephia_log.h>
+#include <eurephia_xml.h>
+#include <eurephia_values.h>
+#include <eurephiadb_session_struct.h>
+#include <eurephiadb_mapping.h>
+#include <passwd.h>
+
+#ifndef DRIVER_MODE
+#define DRIVER_MODE
+#endif
+
+#include "sqlite.h"
+#include "fieldmapping.h"
+
+void xmlReplaceChars(xmlChar *str, char s, char r);
+
+
+// The search XML document format is:
+// <eurephia format="1">
+// <firewall_profiles mode="get">
+// <fieldMapping table="fwprofiles">
+// <{search field}>{search value}</{search field}>
+// </fieldMapping>
+// </admin_access>
+// </eurehpia>
+//
+// It can be several search field tags to limit the search even more.
+//
+xmlDoc *eDBadminGetFirewallProfiles(eurephiaCTX *ctx, xmlDoc *srch) {
+ dbresult *res = NULL;
+ eDBfieldMap *fmap = NULL;
+ int last_acp = -1, i = 0;
+
+ xmlDoc *doc = NULL;
+ xmlNode *root_n = NULL, *fieldmap_n = NULL, *rec_n = NULL, *acg_n = NULL, *acc_n = NULL, *tmp_n = NULL;
+
+ DEBUG(ctx, 20, "Function call: eDBadminGetFirewallProfiles(ctx, {xmlDoc})");
+ assert( (ctx != NULL) && (srch != NULL) );
+
+ tmp_n = eurephiaXML_getRoot(ctx, srch, "firewall_profiles", 1);
+ fieldmap_n = xmlFindNode(tmp_n, "fieldMapping");
+ fmap = eDBxmlMapping(ctx, tbl_sqlite_openvpnaccesses, NULL, fieldmap_n);
+
+ // Query the database for accesses
+ res = sqlite_query_mapped(ctx, SQL_SELECT,
+ "SELECT access_descr, fw_profile, accessprofile, "
+ " uid, username, "
+ " uac.certid, common_name, organisation, "
+ " email, digest, c.registered, uicid "
+ " FROM openvpn_accesses"
+ " LEFT JOIN openvpn_usercerts uac USING (accessprofile)"
+ " LEFT JOIN openvpn_users USING (uid)"
+ " LEFT JOIN openvpn_certificates c ON (uac.certid = c.certid)",
+ NULL, fmap, "accessprofile, uid, c.certid");
+ if( res == NULL ) {
+ eurephia_log(ctx, LOG_ERROR, 0, "Error querying the database for firewall profiles");
+ return 0;
+ }
+ eDBfreeMapping(fmap);
+
+ eurephiaXML_CreateDoc(ctx, 1, "firewall_profiles", &doc, &root_n);
+ xmlNewProp(root_n, (xmlChar *) "mode", (xmlChar *) "profiles");
+
+ for( i = 0; i < sqlite_get_numtuples(res); i++ ) {
+ xmlChar *tmp = NULL;
+ if( last_acp != atoi_nullsafe(sqlite_get_value(res, i, 2)) ) {
+ // Create a new block element when we get a new uid
+ rec_n = xmlNewChild(root_n, NULL, (xmlChar *) "profile", NULL);
+ sqlite_xml_value(rec_n, XML_ATTR, "accessprofile", res, i, 2);
+ sqlite_xml_value(rec_n, XML_NODE, "description", res, i, 0);
+ sqlite_xml_value(rec_n, XML_NODE, "firewall_destination", res, i, 1);
+ acg_n = xmlNewChild(rec_n, NULL, (xmlChar *) "granted_accesses", NULL);
+
+ last_acp = atoi_nullsafe(sqlite_get_value(res, i, 2));
+ }
+
+ acc_n = xmlNewChild(acg_n, NULL, (xmlChar *) "access", NULL);
+ sqlite_xml_value(acc_n, XML_ATTR, "uicid", res, i, 11);
+
+ tmp_n = sqlite_xml_value(acc_n, XML_NODE, "username", res, i, 4);
+ sqlite_xml_value(tmp_n, XML_ATTR, "uid", res, i, 3);
+
+ tmp_n = xmlNewChild(acc_n, NULL, (xmlChar *) "certificate", NULL);
+ sqlite_xml_value(tmp_n, XML_ATTR, "certid", res, i, 5);
+ sqlite_xml_value(tmp_n, XML_ATTR, "registered", res, i, 10);
+
+ tmp = (xmlChar *)sqlite_get_value(res, i, 6);
+ xmlReplaceChars(tmp, '_', ' ');
+ xmlNewChild(tmp_n, NULL, (xmlChar *) "common_name", tmp);
+
+ tmp = (xmlChar *)sqlite_get_value(res, i, 7);
+ xmlReplaceChars(tmp, '_', ' ');
+ xmlNewChild(tmp_n, NULL, (xmlChar *) "organisation", tmp);
+ sqlite_xml_value(tmp_n, XML_NODE, "email", res, i, 8);
+ sqlite_xml_value(tmp_n, XML_NODE, "digest", res, i, 9);
+ }
+ sqlite_free_results(res);
+ return doc;
+}
+