aboutsummaryrefslogtreecommitdiffstats
path: root/src/scepclient
diff options
context:
space:
mode:
authorAndreas Steffen <andreas.steffen@strongswan.org>2009-04-21 18:48:58 +0000
committerAndreas Steffen <andreas.steffen@strongswan.org>2009-04-21 18:48:58 +0000
commit6e9fe153fc485c1bf22180fb4189d160c511f2c8 (patch)
tree596dfd04041c1d6119162a43329644d7b2ef6785 /src/scepclient
parentb757ebc2a7829644cf632c67db0e78650ea1dcdd (diff)
downloadstrongswan-6e9fe153fc485c1bf22180fb4189d160c511f2c8.tar.bz2
strongswan-6e9fe153fc485c1bf22180fb4189d160c511f2c8.tar.xz
added plugin load mechanism to pluto and scepclient and improved debug output4.3.0
Diffstat (limited to 'src/scepclient')
-rw-r--r--src/scepclient/loglite.c112
-rw-r--r--src/scepclient/scepclient.c60
2 files changed, 104 insertions, 68 deletions
diff --git a/src/scepclient/loglite.c b/src/scepclient/loglite.c
index 029b6dfcd..78d1c5350 100644
--- a/src/scepclient/loglite.c
+++ b/src/scepclient/loglite.c
@@ -29,6 +29,7 @@
#include <sys/types.h>
#include <freeswan.h>
+#include <debug.h>
#include <constants.h>
#include <defs.h>
@@ -39,24 +40,90 @@ bool
log_to_stderr = FALSE, /* should log go to stderr? */
log_to_syslog = TRUE; /* should log go to syslog? */
-void
-init_log(const char *program)
+/**
+ * @brief scepclient dbg function
+ */
+static void scepclient_dbg(int level, char *fmt, ...)
{
+ int priority = LOG_INFO;
+ int debug_level;
+ char buffer[8192];
+ char *current = buffer, *next;
+ va_list args;
+
+ if (cur_debugging & DBG_PRIVATE)
+ {
+ debug_level = 4;
+ }
+ else if (cur_debugging & DBG_RAW)
+ {
+ debug_level = 3;
+ }
+ else if (cur_debugging & DBG_PARSING)
+ {
+ debug_level = 2;
+ }
+ else
+ {
+ debug_level = 1;
+ }
+
+ if (level <= debug_level)
+ {
+ va_start(args, fmt);
+
+ if (log_to_stderr)
+ {
+ if (level > 1)
+ {
+ fprintf(stderr, "| ");
+ }
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ }
+ if (log_to_syslog)
+ {
+ /* write in memory buffer first */
+ vsnprintf(buffer, sizeof(buffer), fmt, args);
+
+ /* do a syslog with every line */
+ while (current)
+ {
+ next = strchr(current, '\n');
+ if (next)
+ {
+ *(next++) = '\0';
+ }
+ syslog(priority, "%s%s\n", (level > 1)? "| ":"", current);
+ current = next;
+ }
+ }
+ va_end(args);
+ }
+}
+
+void init_log(const char *program)
+{
+ /* enable scepclient bugging hook */
+ dbg = scepclient_dbg;
+
if (log_to_stderr)
+ {
setbuf(stderr, NULL);
+ }
if (log_to_syslog)
+ {
openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
+ }
}
-void
-close_log(void)
+void close_log(void)
{
if (log_to_syslog)
closelog();
}
-void
-plog(const char *message, ...)
+void plog(const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -71,8 +138,7 @@ plog(const char *message, ...)
syslog(LOG_WARNING, "%s", m);
}
-void
-loglog(int mess_no, const char *message, ...)
+void loglog(int mess_no, const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -87,8 +153,7 @@ loglog(int mess_no, const char *message, ...)
syslog(LOG_WARNING, "%s", m);
}
-void
-log_errno_routine(int e, const char *message, ...)
+void log_errno_routine(int e, const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -103,8 +168,7 @@ log_errno_routine(int e, const char *message, ...)
syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e));
}
-void
-exit_log(const char *message, ...)
+void exit_log(const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -120,8 +184,7 @@ exit_log(const char *message, ...)
exit(1);
}
-void
-exit_log_errno_routine(int e, const char *message, ...)
+void exit_log_errno_routine(int e, const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -137,8 +200,7 @@ exit_log_errno_routine(int e, const char *message, ...)
exit(1);
}
-void
-whack_log(int mess_no, const char *message, ...)
+void whack_log(int mess_no, const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -162,8 +224,7 @@ whack_log(int mess_no, const char *message, ...)
*/
char diag_space[sizeof(diag_space)];
-err_t
-builddiag(const char *fmt, ...)
+err_t builddiag(const char *fmt, ...)
{
static char diag_space[LOG_WIDTH]; /* longer messages will be truncated */
char t[sizeof(diag_space)]; /* build result here first */
@@ -181,8 +242,7 @@ builddiag(const char *fmt, ...)
#ifdef DEBUG
-void
-switch_fail(int n, const char *file_str, unsigned long line_no)
+void switch_fail(int n, const char *file_str, unsigned long line_no)
{
char buf[30];
@@ -190,8 +250,7 @@ switch_fail(int n, const char *file_str, unsigned long line_no)
passert_fail(buf, file_str, line_no);
}
-void
-passert_fail(const char *pred_str, const char *file_str, unsigned long line_no)
+void passert_fail(const char *pred_str, const char *file_str, unsigned long line_no)
{
/* we will get a possibly unplanned prefix. Hope it works */
loglog(RC_LOG_SERIOUS, "ASSERTION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
@@ -202,8 +261,7 @@ lset_t
base_debugging = DBG_NONE, /* default to reporting nothing */
cur_debugging = DBG_NONE;
-void
-pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
+void pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
{
/* we will get a possibly unplanned prefix. Hope it works */
loglog(RC_LOG_SERIOUS, "EXPECTATION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
@@ -211,8 +269,7 @@ pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
/* log a debugging message (prefixed by "| ") */
-void
-DBG_log(const char *message, ...)
+void DBG_log(const char *message, ...)
{
va_list args;
char m[LOG_WIDTH]; /* longer messages will be truncated */
@@ -229,8 +286,7 @@ DBG_log(const char *message, ...)
/* dump raw bytes in hex to stderr (for lack of any better destination) */
-void
-DBG_dump(const char *label, const void *p, size_t len)
+void DBG_dump(const char *label, const void *p, size_t len)
{
# define DUMP_LABEL_WIDTH 20 /* arbitrary modest boundary */
# define DUMP_WIDTH (4 * (1 + 4 * 3) + 1)
diff --git a/src/scepclient/scepclient.c b/src/scepclient/scepclient.c
index d8d44fdbc..9c352c2ca 100644
--- a/src/scepclient/scepclient.c
+++ b/src/scepclient/scepclient.c
@@ -27,7 +27,6 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <syslog.h>
#include <string.h>
#include <getopt.h>
#include <ctype.h>
@@ -41,6 +40,7 @@
#include <asn1/asn1.h>
#include <asn1/oid.h>
#include <utils/optionsfrom.h>
+#include <utils/enumerator.h>
#include "../pluto/constants.h"
#include "../pluto/defs.h"
@@ -272,47 +272,24 @@ usage(const char *message)
exit_scepclient(message);
}
-static int debug_level = 1;
-
/**
- * @brief scepclient dbg function
+ * Log loaded plugins
*/
-static void scepclient_dbg(int level, char *fmt, ...)
+static void print_plugins()
{
- int priority = LOG_INFO;
- char buffer[8192];
- char *current = buffer, *next;
- va_list args;
-
- if (level <= debug_level)
+ char buf[BUF_LEN], *plugin;
+ int len = 0;
+ enumerator_t *enumerator;
+
+ enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
+ while (len < BUF_LEN && enumerator->enumerate(enumerator, &plugin))
{
- va_start(args, fmt);
-
- if (log_to_stderr)
- {
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
- }
- if (log_to_syslog)
- {
- /* write in memory buffer first */
- vsnprintf(buffer, sizeof(buffer), fmt, args);
-
- /* do a syslog with every line */
- while (current)
- {
- next = strchr(current, '\n');
- if (next)
- {
- *(next++) = '\0';
- }
- syslog(priority, "%s\n", current);
- current = next;
- }
- }
- va_end(args);
+ len += snprintf(&buf[len], BUF_LEN-len, "%s ", plugin);
}
+ enumerator->destroy(enumerator);
+ DBG1(" loaded plugins: %s", buf);
}
+
/**
* @brief main of scepclient
*
@@ -762,12 +739,15 @@ int main(int argc, char **argv)
/* break from loop */
break;
}
-
- /* enable scepclient bugging hook */
- dbg = scepclient_dbg;
+ cur_debugging = base_debugging;
init_log("scepclient");
- cur_debugging = base_debugging;
+
+ /* load plugins, further infrastructure may need it */
+ lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
+ lib->settings->get_str(lib->settings, "scepclient.load", ""));
+ print_plugins();
+
init_rnd_pool();
init_fetch();