added plugin load mechanism to pluto and scepclient and improved debug output
This commit is contained in:
+6
-3
@@ -87,10 +87,10 @@ u_int16_t cur_from_port; /* host order */
|
|||||||
static void pluto_dbg(int level, char *fmt, ...)
|
static void pluto_dbg(int level, char *fmt, ...)
|
||||||
{
|
{
|
||||||
int priority = LOG_INFO;
|
int priority = LOG_INFO;
|
||||||
|
int debug_level;
|
||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
char *current = buffer, *next;
|
char *current = buffer, *next;
|
||||||
va_list args;
|
va_list args;
|
||||||
int debug_level;
|
|
||||||
|
|
||||||
if (cur_debugging & DBG_PRIVATE)
|
if (cur_debugging & DBG_PRIVATE)
|
||||||
{
|
{
|
||||||
@@ -115,7 +115,10 @@ static void pluto_dbg(int level, char *fmt, ...)
|
|||||||
|
|
||||||
if (log_to_stderr)
|
if (log_to_stderr)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "| ");
|
if (level > 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "| ");
|
||||||
|
}
|
||||||
vfprintf(stderr, fmt, args);
|
vfprintf(stderr, fmt, args);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
@@ -132,7 +135,7 @@ static void pluto_dbg(int level, char *fmt, ...)
|
|||||||
{
|
{
|
||||||
*(next++) = '\0';
|
*(next++) = '\0';
|
||||||
}
|
}
|
||||||
syslog(priority, "| %s\n", current);
|
syslog(priority, "%s%s\n", (level > 1)? "| ":"", current);
|
||||||
current = next;
|
current = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-2
@@ -40,6 +40,8 @@
|
|||||||
|
|
||||||
#include <freeswan.h>
|
#include <freeswan.h>
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <utils/enumerator.h>
|
||||||
|
|
||||||
#include <pfkeyv2.h>
|
#include <pfkeyv2.h>
|
||||||
#include <pfkey.h>
|
#include <pfkey.h>
|
||||||
@@ -223,6 +225,24 @@ bool pkcs11_proxy = FALSE;
|
|||||||
*/
|
*/
|
||||||
static const char *pkcs11_init_args = NULL;
|
static const char *pkcs11_init_args = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log loaded plugins
|
||||||
|
*/
|
||||||
|
static void print_plugins()
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
len += snprintf(&buf[len], BUF_LEN-len, "%s ", plugin);
|
||||||
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
DBG1("loaded plugins: %s", buf);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
bool fork_desired = TRUE;
|
bool fork_desired = TRUE;
|
||||||
@@ -609,6 +629,11 @@ int main(int argc, char **argv)
|
|||||||
, ipsec_version_code()
|
, ipsec_version_code()
|
||||||
, compile_time_interop_options);
|
, compile_time_interop_options);
|
||||||
|
|
||||||
|
/* load plugins, further infrastructure may need it */
|
||||||
|
lib->plugins->load(lib->plugins, IPSEC_PLUGINDIR,
|
||||||
|
lib->settings->get_str(lib->settings, "pluto.load", ""));
|
||||||
|
print_plugins();
|
||||||
|
|
||||||
init_nat_traversal(nat_traversal, keep_alive, force_keepalive, nat_t_spf);
|
init_nat_traversal(nat_traversal, keep_alive, force_keepalive, nat_t_spf);
|
||||||
init_virtual_ip(virtual_private);
|
init_virtual_ip(virtual_private);
|
||||||
scx_init(pkcs11_module_path, pkcs11_init_args); /* load and initialize PKCS #11 module */
|
scx_init(pkcs11_module_path, pkcs11_init_args); /* load and initialize PKCS #11 module */
|
||||||
@@ -690,8 +715,7 @@ int main(int argc, char **argv)
|
|||||||
* 1 general discomfort
|
* 1 general discomfort
|
||||||
* 10 lock file exists
|
* 10 lock file exists
|
||||||
*/
|
*/
|
||||||
void
|
void exit_pluto(int status)
|
||||||
exit_pluto(int status)
|
|
||||||
{
|
{
|
||||||
reset_globals(); /* needed because we may be called in odd state */
|
reset_globals(); /* needed because we may be called in odd state */
|
||||||
free_preshared_secrets();
|
free_preshared_secrets();
|
||||||
|
|||||||
+88
-32
@@ -29,6 +29,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <freeswan.h>
|
#include <freeswan.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
#include <constants.h>
|
#include <constants.h>
|
||||||
#include <defs.h>
|
#include <defs.h>
|
||||||
@@ -39,24 +40,90 @@ bool
|
|||||||
log_to_stderr = FALSE, /* should log go to stderr? */
|
log_to_stderr = FALSE, /* should log go to stderr? */
|
||||||
log_to_syslog = TRUE; /* should log go to syslog? */
|
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, ...)
|
||||||
{
|
{
|
||||||
if (log_to_stderr)
|
int priority = LOG_INFO;
|
||||||
setbuf(stderr, NULL);
|
int debug_level;
|
||||||
if (log_to_syslog)
|
char buffer[8192];
|
||||||
openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
|
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
|
void init_log(const char *program)
|
||||||
close_log(void)
|
{
|
||||||
|
/* 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)
|
||||||
{
|
{
|
||||||
if (log_to_syslog)
|
if (log_to_syslog)
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void plog(const char *message, ...)
|
||||||
plog(const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
||||||
@@ -71,8 +138,7 @@ plog(const char *message, ...)
|
|||||||
syslog(LOG_WARNING, "%s", m);
|
syslog(LOG_WARNING, "%s", m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void loglog(int mess_no, const char *message, ...)
|
||||||
loglog(int mess_no, const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
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);
|
syslog(LOG_WARNING, "%s", m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void log_errno_routine(int e, const char *message, ...)
|
||||||
log_errno_routine(int e, const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
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));
|
syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void exit_log(const char *message, ...)
|
||||||
exit_log(const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
||||||
@@ -120,8 +184,7 @@ exit_log(const char *message, ...)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void exit_log_errno_routine(int e, const char *message, ...)
|
||||||
exit_log_errno_routine(int e, const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
||||||
@@ -137,8 +200,7 @@ exit_log_errno_routine(int e, const char *message, ...)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void whack_log(int mess_no, const char *message, ...)
|
||||||
whack_log(int mess_no, const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
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)];
|
char diag_space[sizeof(diag_space)];
|
||||||
|
|
||||||
err_t
|
err_t builddiag(const char *fmt, ...)
|
||||||
builddiag(const char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
static char diag_space[LOG_WIDTH]; /* longer messages will be truncated */
|
static char diag_space[LOG_WIDTH]; /* longer messages will be truncated */
|
||||||
char t[sizeof(diag_space)]; /* build result here first */
|
char t[sizeof(diag_space)]; /* build result here first */
|
||||||
@@ -181,8 +242,7 @@ builddiag(const char *fmt, ...)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
void
|
void switch_fail(int n, const char *file_str, unsigned long line_no)
|
||||||
switch_fail(int n, const char *file_str, unsigned long line_no)
|
|
||||||
{
|
{
|
||||||
char buf[30];
|
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);
|
passert_fail(buf, file_str, line_no);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void passert_fail(const char *pred_str, const char *file_str, unsigned long line_no)
|
||||||
passert_fail(const char *pred_str, const char *file_str, unsigned long line_no)
|
|
||||||
{
|
{
|
||||||
/* we will get a possibly unplanned prefix. Hope it works */
|
/* 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);
|
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 */
|
base_debugging = DBG_NONE, /* default to reporting nothing */
|
||||||
cur_debugging = DBG_NONE;
|
cur_debugging = DBG_NONE;
|
||||||
|
|
||||||
void
|
void pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
|
||||||
pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
|
|
||||||
{
|
{
|
||||||
/* we will get a possibly unplanned prefix. Hope it works */
|
/* 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);
|
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 "| ") */
|
/* log a debugging message (prefixed by "| ") */
|
||||||
|
|
||||||
void
|
void DBG_log(const char *message, ...)
|
||||||
DBG_log(const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char m[LOG_WIDTH]; /* longer messages will be truncated */
|
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) */
|
/* dump raw bytes in hex to stderr (for lack of any better destination) */
|
||||||
|
|
||||||
void
|
void DBG_dump(const char *label, const void *p, size_t len)
|
||||||
DBG_dump(const char *label, const void *p, size_t len)
|
|
||||||
{
|
{
|
||||||
# define DUMP_LABEL_WIDTH 20 /* arbitrary modest boundary */
|
# define DUMP_LABEL_WIDTH 20 /* arbitrary modest boundary */
|
||||||
# define DUMP_WIDTH (4 * (1 + 4 * 3) + 1)
|
# define DUMP_WIDTH (4 * (1 + 4 * 3) + 1)
|
||||||
|
|||||||
+20
-40
@@ -27,7 +27,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <syslog.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -41,6 +40,7 @@
|
|||||||
#include <asn1/asn1.h>
|
#include <asn1/asn1.h>
|
||||||
#include <asn1/oid.h>
|
#include <asn1/oid.h>
|
||||||
#include <utils/optionsfrom.h>
|
#include <utils/optionsfrom.h>
|
||||||
|
#include <utils/enumerator.h>
|
||||||
|
|
||||||
#include "../pluto/constants.h"
|
#include "../pluto/constants.h"
|
||||||
#include "../pluto/defs.h"
|
#include "../pluto/defs.h"
|
||||||
@@ -272,47 +272,24 @@ usage(const char *message)
|
|||||||
exit_scepclient(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 buf[BUF_LEN], *plugin;
|
||||||
char buffer[8192];
|
int len = 0;
|
||||||
char *current = buffer, *next;
|
enumerator_t *enumerator;
|
||||||
va_list args;
|
|
||||||
|
enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
|
||||||
if (level <= debug_level)
|
while (len < BUF_LEN && enumerator->enumerate(enumerator, &plugin))
|
||||||
{
|
{
|
||||||
va_start(args, fmt);
|
len += snprintf(&buf[len], BUF_LEN-len, "%s ", plugin);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
enumerator->destroy(enumerator);
|
||||||
|
DBG1(" loaded plugins: %s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief main of scepclient
|
* @brief main of scepclient
|
||||||
*
|
*
|
||||||
@@ -762,12 +739,15 @@ int main(int argc, char **argv)
|
|||||||
/* break from loop */
|
/* break from loop */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
cur_debugging = base_debugging;
|
||||||
/* enable scepclient bugging hook */
|
|
||||||
dbg = scepclient_dbg;
|
|
||||||
|
|
||||||
init_log("scepclient");
|
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_rnd_pool();
|
||||||
init_fetch();
|
init_fetch();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user