summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-10-04 23:23:07 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-10-04 23:23:07 +0200
commitaf7c53924fffc20b63c7fca26ec8b103d724e58b (patch)
tree95abf7810e6f699ba0c54ceb97c02dc0e828a33a /plugin
parent50f966f34d3ced47b1856719a24a5f5933bd1eb8 (diff)
downloadeurephia-af7c53924fffc20b63c7fca26ec8b103d724e58b.tar.gz
eurephia-af7c53924fffc20b63c7fca26ec8b103d724e58b.tar.xz
eurephia-af7c53924fffc20b63c7fca26ec8b103d724e58b.zip
Moved the get_env() function into its own file
Diffstat (limited to 'plugin')
-rw-r--r--plugin/CMakeLists.txt1
-rw-r--r--plugin/environment.c94
-rw-r--r--plugin/environment.h47
-rw-r--r--plugin/eurephia.c61
4 files changed, 144 insertions, 59 deletions
diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt
index a6ab1ee..17804fe 100644
--- a/plugin/CMakeLists.txt
+++ b/plugin/CMakeLists.txt
@@ -66,6 +66,7 @@ ADD_LIBRARY(eurephia-auth MODULE
eurephia-auth.c
eurephia.c
eurephiadb_session.c
+ environment.c
firewall/eurephiafw.c
firewall/eurephiafw_helpers.c
../common/eurephiadb_session_common.c
diff --git a/plugin/environment.c b/plugin/environment.c
new file mode 100644
index 0000000..7dbeffe
--- /dev/null
+++ b/plugin/environment.c
@@ -0,0 +1,94 @@
+/* environment.c -- Function for extracting data from the OpenVPN environment table
+ *
+ * GPLv2 only - Copyright (C) 2008, 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.
+ *
+ */
+
+/**
+ * @file environment.c
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-08-06
+ *
+ * @brief Function for extracting data from the OpenVPN environment table.
+ *
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include <eurephia_nullsafe.h>
+#include <eurephia_context.h>
+#include <eurephia_log.h>
+
+/**
+ * get_env() retrieve values from the openvpn environment table
+ *
+ * @param ctx eurephiaCTX context
+ * @param logmasking If 1, the value will be masked in the log files (eg. to hide password)
+ * @param len How many bytes to copy out of the environment variable
+ * @param envp the environment table
+ * @param fmt The key to look for (stdarg)
+ *
+ * @return Returns a const char * with the value, or NULL if not found
+ */
+char *get_env(eurephiaCTX *ctx, int logmasking, size_t len,
+ const char *envp[], const char *fmt, ... )
+{
+ if (envp) {
+ va_list ap;
+ char key[384];
+ int keylen = 0;
+ int i;
+
+ // Build up the key we are looking for
+ memset(&key, 0, 384);
+ va_start(ap, fmt);
+ vsnprintf(key, 382, fmt, ap);
+
+ // Find the key
+ keylen = strlen (key);
+ for (i = 0; envp[i]; ++i) {
+ if (!strncmp (envp[i], key, keylen)) {
+ const char *cp = envp[i] + keylen;
+ char *ret = NULL;
+ if (*cp == '=') {
+#ifdef ENABLE_DEBUG
+ int do_mask = 0;
+#ifndef SHOW_SECRETS
+ do_mask = logmasking;
+#endif
+ if( ctx != NULL ) {
+ DEBUG(ctx, 30, "Function call: get_env(envp, '%s') == '%s'",
+ key, (do_mask == 0 ? cp + 1 : "xxxxxxxxxxxxxx"));
+ }
+#endif
+ ret = malloc_nullsafe(ctx, len+2);
+ strncpy(ret, cp+1, len);
+ return ret;
+ }
+ }
+ }
+ if( ctx != NULL ) {
+ DEBUG(ctx, 15, "Function call: get_env(envp, '%s') -- environment variable not found",
+ key);
+ }
+ va_end(ap);
+ }
+ return NULL;
+}
diff --git a/plugin/environment.h b/plugin/environment.h
new file mode 100644
index 0000000..a8355cb
--- /dev/null
+++ b/plugin/environment.h
@@ -0,0 +1,47 @@
+/* environment.h -- Function for extracting data from the OpenVPN environment table
+ *
+ * GPLv2 only - Copyright (C) 2008, 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.
+ *
+ */
+
+/**
+ * @file environment.h
+ * @author David Sommerseth <dazo@users.sourceforge.net>
+ * @date 2008-08-06
+ *
+ * @brief Function for extracting data from the OpenVPN environment table.
+ *
+ */
+
+#ifndef _ENVIRONMENT_H
+#define _ENVIRONMENT_H
+
+/**
+ * get_env() retrieve values from the openvpn environment table
+ *
+ * @param ctx eurephiaCTX context
+ * @param logmasking If 1, the value will be masked in the log files (eg. to hide password)
+ * @param len How many bytes to copy out of the environment variable
+ * @param envp the environment table
+ * @param fmt The key to look for (stdarg)
+ *
+ * @return Returns a const char * with the value, or NULL if not found
+ */
+char *get_env(eurephiaCTX *ctx, int logmasking, size_t len, const char *envp[], const char *fmt, ... );
+
+#endif
diff --git a/plugin/eurephia.c b/plugin/eurephia.c
index f06c684..74b4785 100644
--- a/plugin/eurephia.c
+++ b/plugin/eurephia.c
@@ -49,66 +49,9 @@
#include <certinfo.h>
#include <randstr.h>
#include <passwd.h>
+#include <environment.h>
-#define MAX_ARGUMENTS 64 /**< Maximum arguments we will parse from the openvpn plug-in configuration */
-
-
-/**
- * get_env() retrieve values from the openvpn environment table
- *
- * @param ctx eurephiaCTX context
- * @param logmasking If 1, the value will be masked in the log files (eg. to hide password)
- * @param len How many bytes to copy out of the environment variable
- * @param envp the environment table
- * @param fmt The key to look for (stdarg)
- *
- * @return Returns a const char * with the value, or NULL if not found
- */
-char *get_env(eurephiaCTX *ctx, int logmasking, size_t len,
- const char *envp[], const char *fmt, ... )
-{
- if (envp) {
- va_list ap;
- char key[384];
- int keylen = 0;
- int i;
-
- // Build up the key we are looking for
- memset(&key, 0, 384);
- va_start(ap, fmt);
- vsnprintf(key, 382, fmt, ap);
-
- // Find the key
- keylen = strlen (key);
- for (i = 0; envp[i]; ++i) {
- if (!strncmp (envp[i], key, keylen)) {
- const char *cp = envp[i] + keylen;
- char *ret = NULL;
- if (*cp == '=') {
-#ifdef ENABLE_DEBUG
- int do_mask = 0;
-#ifndef SHOW_SECRETS
- do_mask = logmasking;
-#endif
- if( ctx != NULL ) {
- DEBUG(ctx, 30, "Function call: get_env(envp, '%s') == '%s'",
- key, (do_mask == 0 ? cp + 1 : "xxxxxxxxxxxxxx"));
- }
-#endif
- ret = malloc_nullsafe(ctx, len+2);
- strncpy(ret, cp+1, len);
- return ret;
- }
- }
- }
- if( ctx != NULL ) {
- DEBUG(ctx, 15, "Function call: get_env(envp, '%s') -- environment variable not found",
- key);
- }
- va_end(ap);
- }
- return NULL;
-}
+#define MAX_ARGUMENTS 64 /**< Maximum arguments we will parse from the openvpn plug-in configuration */
/**