summaryrefslogtreecommitdiff
path: root/src/medsrv/filter
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2008-07-09 21:02:41 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2008-07-09 21:02:41 +0000
commitdb67c87db3c9089ea8d2e14f617bf3d9e2af261f (patch)
tree665c0caea83d34c11c1517c4c57137bb58cba6fb /src/medsrv/filter
parent1c088a8b6237ec67f63c23f97a0f2dc4e99af869 (diff)
downloadvyos-strongswan-db67c87db3c9089ea8d2e14f617bf3d9e2af261f.tar.gz
vyos-strongswan-db67c87db3c9089ea8d2e14f617bf3d9e2af261f.zip
[svn-upgrade] Integrating new upstream version, strongswan (4.2.4)
Diffstat (limited to 'src/medsrv/filter')
-rwxr-xr-xsrc/medsrv/filter/auth_filter.c100
-rwxr-xr-xsrc/medsrv/filter/auth_filter.h50
2 files changed, 150 insertions, 0 deletions
diff --git a/src/medsrv/filter/auth_filter.c b/src/medsrv/filter/auth_filter.c
new file mode 100755
index 000000000..5036d26f1
--- /dev/null
+++ b/src/medsrv/filter/auth_filter.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Copyright (C) 2008 Philip Boetschi, Adrian Doerig
+ * Hochschule fuer Technik Rapperswil
+ *
+ * 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; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ *
+ * $Id$
+ */
+
+#include "auth_filter.h"
+
+#include <debug.h>
+
+typedef struct private_auth_filter_t private_auth_filter_t;
+
+/**
+ * private data of auth_filter
+ */
+struct private_auth_filter_t {
+ /**
+ * public functions
+ */
+ auth_filter_t public;
+
+ /**
+ * user session
+ */
+ user_t *user;
+
+ /**
+ * database connection
+ */
+ database_t *db;
+};
+
+/**
+ * Implementation of filter_t.run
+ */
+static bool run(private_auth_filter_t *this, request_t *request,
+ char *controller, char *action)
+{
+ if (this->user->get_user(this->user))
+ {
+ enumerator_t *query;
+ char *login;
+
+ query = this->db->query(this->db, "SELECT login FROM user WHERE id = ?",
+ DB_INT, this->user->get_user(this->user),
+ DB_TEXT);
+ if (query && query->enumerate(query, &login))
+ {
+ request->set(request, "login", login);
+ query->destroy(query);
+ return TRUE;
+ }
+ DESTROY_IF(query);
+ this->user->set_user(this->user, 0);
+ }
+ if (controller && streq(controller, "user") && action &&
+ (streq(action, "add") || streq(action, "login") || streq(action, "help")))
+ { /* add/login allowed */
+ return TRUE;
+ }
+ request->redirect(request, "user/login");
+ return FALSE;
+}
+
+/**
+ * Implementation of filter_t.destroy
+ */
+static void destroy(private_auth_filter_t *this)
+{
+ free(this);
+}
+
+/*
+ * see header file
+ */
+filter_t *auth_filter_create(user_t *user, database_t *db)
+{
+ private_auth_filter_t *this= malloc_thing(private_auth_filter_t);
+
+ this->public.filter.destroy = (void(*)(filter_t*))destroy;
+ this->public.filter.run = (bool(*)(filter_t*, request_t*,char*,char*,char*,char*,char*,char*))run;
+
+ this->user = user;
+ this->db = db;
+
+ return &this->public.filter;
+}
+
diff --git a/src/medsrv/filter/auth_filter.h b/src/medsrv/filter/auth_filter.h
new file mode 100755
index 000000000..5ba270e72
--- /dev/null
+++ b/src/medsrv/filter/auth_filter.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2008 Martin Willi
+ * Copyright (C) 2008 Philip Boetschi, Adrian Doerig
+ * Hochschule fuer Technik Rapperswil
+ *
+ * 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; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ *
+ * $Id$
+ */
+
+/**
+ * @defgroup auth_filter_server auth_filter
+ * @{ @ingroup filter_server
+ */
+
+#ifndef AUTH_FILTER_H_
+#define AUTH_FILTER_H_
+
+#include <library.h>
+#include <filter.h>
+
+#include "user.h"
+
+typedef struct auth_filter_t auth_filter_t;
+
+/**
+ * Authentication/Authorization filter.
+ */
+struct auth_filter_t {
+
+ /**
+ * Implements filter_t interface.
+ */
+ filter_t filter;
+};
+
+/**
+ * Create a auth_filter instance.
+ */
+filter_t *auth_filter_create(user_t *user, database_t *db);
+
+#endif /* AUTH_FILTER_H_ @}*/