diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2007-10-08 19:57:54 +0000 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2007-10-08 19:57:54 +0000 |
commit | 496e76cbdf341dd3c5e6ed8b5bc559327e0fc3c5 (patch) | |
tree | e6133d91d5e91e75ec5bb610789d1027d7840f79 /src/starter | |
parent | 43a87d4211526129e5caf017a847dc97a4ecaec0 (diff) | |
download | strongswan-496e76cbdf341dd3c5e6ed8b5bc559327e0fc3c5.tar.bz2 strongswan-496e76cbdf341dd3c5e6ed8b5bc559327e0fc3c5.tar.xz |
added RCSID
Diffstat (limited to 'src/starter')
30 files changed, 325 insertions, 33 deletions
diff --git a/src/starter/Makefile.am b/src/starter/Makefile.am index 4049d8d11..40725a996 100644 --- a/src/starter/Makefile.am +++ b/src/starter/Makefile.am @@ -3,11 +3,11 @@ starter_SOURCES = y.tab.c netkey.c y.tab.h parser.h args.h netkey.h \ starterwhack.c starterwhack.h starterstroke.c invokepluto.c confread.c \ starterstroke.h interfaces.c invokepluto.h confread.h interfaces.h args.c \ keywords.c files.h keywords.h cmp.c starter.c cmp.h exec.c invokecharon.c \ -exec.h invokecharon.h lex.yy.c +exec.h invokecharon.h lex.yy.c loglite.c INCLUDES = -I$(top_srcdir)/src/libfreeswan -I$(top_srcdir)/src/pluto -I$(top_srcdir)/src/whack -I$(top_srcdir)/src/stroke AM_CFLAGS = -DIPSEC_DIR=\"${ipsecdir}\" -DIPSEC_CONFDIR=\"${confdir}\" -DIPSEC_PIDDIR=\"${piddir}\" -DIPSEC_EAPDIR=\"${eapdir}\" -DDEBUG -starter_LDADD = loglite.o defs.o $(top_srcdir)/src/libfreeswan/libfreeswan.a +starter_LDADD = defs.o $(top_srcdir)/src/libfreeswan/libfreeswan.a EXTRA_DIST = parser.l parser.y keywords.txt ipsec.conf dist_man_MANS = ipsec.conf.5 starter.8 MAINTAINERCLEANFILES = lex.yy.c y.tab.c y.tab.h keywords.c @@ -27,9 +27,6 @@ y.tab.h: parser.l parser.y parser.h keywords.c: keywords.txt keywords.h $(GPERF) -C -G -t < keywords.txt > keywords.c -loglite.o: $(SCEPCLIENTDIR)/loglite.c $(PLUTODIR)/log.h - $(COMPILE) -c -o $@ $< - defs.o: $(PLUTODIR)/defs.c $(PLUTODIR)/defs.h $(COMPILE) -c -o $@ $< diff --git a/src/starter/args.c b/src/starter/args.c index 13c7bb3a7..7b4fcaabb 100644 --- a/src/starter/args.c +++ b/src/starter/args.c @@ -13,7 +13,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: args.c,v 1.9 2006/04/17 10:32:36 as Exp $ + * RCSID $Id$ */ #include <stddef.h> diff --git a/src/starter/args.h b/src/starter/args.h index 302e9bb7b..f6544eae1 100644 --- a/src/starter/args.h +++ b/src/starter/args.h @@ -12,7 +12,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: args.h,v 1.3 2006/01/13 18:02:02 as Exp $ + * RCSID $Id$ */ #ifndef _ARGS_H_ diff --git a/src/starter/cmp.c b/src/starter/cmp.c index ea8e736ce..03d98cbd7 100644 --- a/src/starter/cmp.c +++ b/src/starter/cmp.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: cmp.c,v 1.12 2006/01/13 18:03:25 as Exp $ + * RCSID $Id$ */ #include <string.h> diff --git a/src/starter/cmp.h b/src/starter/cmp.h index ca355e9eb..5a34b9877 100644 --- a/src/starter/cmp.h +++ b/src/starter/cmp.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: cmp.h,v 1.4 2006/01/06 20:24:41 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_CMP_H_ diff --git a/src/starter/confread.c b/src/starter/confread.c index d1abe71a0..cd1859365 100644 --- a/src/starter/confread.c +++ b/src/starter/confread.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: confread.c,v 1.37 2006/04/17 19:35:07 as Exp $ + * RCSID $Id$ */ #include <stddef.h> diff --git a/src/starter/confread.h b/src/starter/confread.h index ec1076e53..11ca29d86 100644 --- a/src/starter/confread.h +++ b/src/starter/confread.h @@ -14,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: confread.h,v 1.23 2006/04/17 10:32:36 as Exp $ + * RCSID $Id$ */ #ifndef _IPSEC_CONFREAD_H_ diff --git a/src/starter/exec.c b/src/starter/exec.c index 98541db75..e506f8448 100644 --- a/src/starter/exec.c +++ b/src/starter/exec.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: exec.c,v 1.4 2006/01/04 23:30:24 as Exp $ + * RCSID $Id$ */ #include <stdlib.h> diff --git a/src/starter/exec.h b/src/starter/exec.h index d4be931dd..3444b7efa 100644 --- a/src/starter/exec.h +++ b/src/starter/exec.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: exec.h,v 1.2 2005/12/28 10:20:32 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_EXEC_H_ diff --git a/src/starter/files.h b/src/starter/files.h index 88b670d94..b2c914514 100644 --- a/src/starter/files.h +++ b/src/starter/files.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: files.h,v 1.5 2006/02/04 18:52:58 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_FILES_H_ diff --git a/src/starter/interfaces.c b/src/starter/interfaces.c index a4baaa83d..9f44cfe89 100644 --- a/src/starter/interfaces.c +++ b/src/starter/interfaces.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: interfaces.c,v 1.15 2006/02/05 10:51:55 as Exp $ + * RCSID $Id$ */ #include <sys/socket.h> diff --git a/src/starter/interfaces.h b/src/starter/interfaces.h index ed6b0ef57..023c80ce9 100644 --- a/src/starter/interfaces.h +++ b/src/starter/interfaces.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: interfaces.h,v 1.6 2006/01/06 20:24:07 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_INTERFACES_H_ diff --git a/src/starter/invokecharon.c b/src/starter/invokecharon.c index 48cb4151b..c07de182e 100644 --- a/src/starter/invokecharon.c +++ b/src/starter/invokecharon.c @@ -14,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: invokecharon.c $ + * RCSID $Id$ */ #include <sys/types.h> diff --git a/src/starter/invokecharon.h b/src/starter/invokecharon.h index b18dba362..f62221da6 100644 --- a/src/starter/invokecharon.h +++ b/src/starter/invokecharon.h @@ -14,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: invokecharon.h $ + * RCSID $Id$ */ #ifndef _STARTER_CHARON_H_ diff --git a/src/starter/invokepluto.c b/src/starter/invokepluto.c index 5ea47f69f..7c995f889 100644 --- a/src/starter/invokepluto.c +++ b/src/starter/invokepluto.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: invokepluto.c,v 1.12 2006/02/17 21:41:50 as Exp $ + * RCSID $Id$ */ #include <sys/types.h> diff --git a/src/starter/invokepluto.h b/src/starter/invokepluto.h index 26858f9b2..6366d1f50 100644 --- a/src/starter/invokepluto.h +++ b/src/starter/invokepluto.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: invokepluto.h,v 1.3 2006/01/04 23:30:24 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_PLUTO_H_ diff --git a/src/starter/ipsec.conf.5 b/src/starter/ipsec.conf.5 index 8e6624f21..4327b5531 100644 --- a/src/starter/ipsec.conf.5 +++ b/src/starter/ipsec.conf.5 @@ -1,5 +1,5 @@ .TH IPSEC.CONF 5 "27 Jun 2007" -.\" RCSID $Id: ipsec.conf.5,v 1.2 2006/01/22 15:33:46 as Exp $ +.\" RCSID $Id$ .SH NAME ipsec.conf \- IPsec configuration and connections .SH DESCRIPTION diff --git a/src/starter/keywords.h b/src/starter/keywords.h index acfc76630..e9fe9ec77 100644 --- a/src/starter/keywords.h +++ b/src/starter/keywords.h @@ -13,7 +13,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: keywords.h,v 1.8 2006/04/17 10:30:27 as Exp $ + * RCSID $Id$ */ #ifndef _KEYWORDS_H_ diff --git a/src/starter/keywords.txt b/src/starter/keywords.txt index 10f7cad1a..1b62937bf 100644 --- a/src/starter/keywords.txt +++ b/src/starter/keywords.txt @@ -14,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: keywords.txt,v 1.6 2006/04/17 10:30:27 as Exp $ + * RCSID $Id$ */ #include <string.h> diff --git a/src/starter/loglite.c b/src/starter/loglite.c new file mode 100644 index 000000000..54b83e382 --- /dev/null +++ b/src/starter/loglite.c @@ -0,0 +1,295 @@ +/* error logging functions + * Copyright (C) 1997 Angelos D. Keromytis. + * Copyright (C) 1998-2001 D. Hugh Redelmeier. + * + * 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. + * + * RCSID $Id$ + */ + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <stdarg.h> +#include <syslog.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> /* used only if MSG_NOSIGNAL not defined */ +#include <libgen.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include <freeswan.h> + +#include <constants.h> +#include <defs.h> +#include <log.h> +#include <whack.h> + +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) +{ + 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) + closelog(); +} + +void +plog(const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + if (log_to_stderr) + fprintf(stderr, "%s\n", m); + if (log_to_syslog) + syslog(LOG_WARNING, "%s", m); +} + +void +loglog(int mess_no, const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + if (log_to_stderr) + fprintf(stderr, "%s\n", m); + if (log_to_syslog) + syslog(LOG_WARNING, "%s", m); +} + +void +log_errno_routine(int e, const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + if (log_to_stderr) + fprintf(stderr, "ERROR: %s. Errno %d: %s\n", m, e, strerror(e)); + if (log_to_syslog) + syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e)); +} + +void +exit_log(const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + if (log_to_stderr) + fprintf(stderr, "FATAL ERROR: %s\n", m); + if (log_to_syslog) + syslog(LOG_ERR, "FATAL ERROR: %s", m); + exit(1); +} + +void +exit_log_errno_routine(int e, const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + if (log_to_stderr) + fprintf(stderr, "FATAL ERROR: %s. Errno %d: %s\n", m, e, strerror(e)); + if (log_to_syslog) + syslog(LOG_ERR, "FATAL ERROR: %s. Errno %d: %s", m, e, strerror(e)); + exit(1); +} + +void +whack_log(int mess_no, const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + fprintf(stderr, "%s\n", m); +} + +/* Build up a diagnostic in a static buffer. + * Although this would be a generally useful function, it is very + * hard to come up with a discipline that prevents different uses + * from interfering. It is intended that by limiting it to building + * diagnostics, we will avoid this problem. + * Juggling is performed to allow an argument to be a previous + * result: the new string may safely depend on the old one. This + * restriction is not checked in any way: violators will produce + * confusing results (without crashing!). + */ +char diag_space[sizeof(diag_space)]; + +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 */ + va_list args; + + va_start(args, fmt); + t[0] = '\0'; /* in case nothing terminates string */ + vsnprintf(t, sizeof(t), fmt, args); + va_end(args); + strcpy(diag_space, t); + return diag_space; +} + +/* Debugging message support */ + +#ifdef DEBUG + +void +switch_fail(int n, const char *file_str, unsigned long line_no) +{ + char buf[30]; + + snprintf(buf, sizeof(buf), "case %d unexpected", n); + passert_fail(buf, file_str, 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); + abort(); /* exiting correctly doesn't always work */ +} + +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) +{ + /* 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); +} + +/* log a debugging message (prefixed by "| ") */ + +void +DBG_log(const char *message, ...) +{ + va_list args; + char m[LOG_WIDTH]; /* longer messages will be truncated */ + + va_start(args, message); + vsnprintf(m, sizeof(m), message, args); + va_end(args); + + if (log_to_stderr) + fprintf(stderr, "| %s\n", m); + if (log_to_syslog) + syslog(LOG_DEBUG, "| %s", m); +} + +/* 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) +{ +# define DUMP_LABEL_WIDTH 20 /* arbitrary modest boundary */ +# define DUMP_WIDTH (4 * (1 + 4 * 3) + 1) + char buf[DUMP_LABEL_WIDTH + DUMP_WIDTH]; + char *bp; + const unsigned char *cp = p; + + bp = buf; + + if (label != NULL && label[0] != '\0') + { + /* Handle the label. Care must be taken to avoid buffer overrun. */ + size_t llen = strlen(label); + + if (llen + 1 > sizeof(buf)) + { + DBG_log("%s", label); + } + else + { + strcpy(buf, label); + if (buf[llen-1] == '\n') + { + buf[llen-1] = '\0'; /* get rid of newline */ + DBG_log("%s", buf); + } + else if (llen < DUMP_LABEL_WIDTH) + { + bp = buf + llen; + } + else + { + DBG_log("%s", buf); + } + } + } + + do { + int i, j; + + for (i = 0; len!=0 && i!=4; i++) + { + *bp++ = ' '; + for (j = 0; len!=0 && j!=4; len--, j++) + { + static const char hexdig[] = "0123456789abcdef"; + + *bp++ = ' '; + *bp++ = hexdig[(*cp >> 4) & 0xF]; + *bp++ = hexdig[*cp & 0xF]; + cp++; + } + } + *bp = '\0'; + DBG_log("%s", buf); + bp = buf; + } while (len != 0); +# undef DUMP_LABEL_WIDTH +# undef DUMP_WIDTH +} + +#endif /* DEBUG */ diff --git a/src/starter/netkey.c b/src/starter/netkey.c index d0b8e0a2c..115403b0d 100644 --- a/src/starter/netkey.c +++ b/src/starter/netkey.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: netkey.c,v 1.4 2006/02/15 18:33:57 as Exp $ + * RCSID $Id$ */ #include <sys/types.h> diff --git a/src/starter/netkey.h b/src/starter/netkey.h index ff8989d34..3666dcfb9 100644 --- a/src/starter/netkey.h +++ b/src/starter/netkey.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: netkey.h,v 1.1 2005/12/30 19:03:15 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_NETKEY_H_ diff --git a/src/starter/parser.h b/src/starter/parser.h index 61bdea974..ac8639cad 100644 --- a/src/starter/parser.h +++ b/src/starter/parser.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: parser.h,v 1.5 2006/01/17 23:43:36 as Exp $ + * RCSID $Id$ */ #ifndef _IPSEC_PARSER_H_ diff --git a/src/starter/parser.l b/src/starter/parser.l index 1469f94bc..33ea5ba60 100644 --- a/src/starter/parser.l +++ b/src/starter/parser.l @@ -12,7 +12,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: parser.l,v 1.5 2006/03/28 22:32:33 as Exp $ + * RCSID $Id$ */ #include <string.h> diff --git a/src/starter/parser.y b/src/starter/parser.y index db984fae3..d61ca0628 100644 --- a/src/starter/parser.y +++ b/src/starter/parser.y @@ -12,7 +12,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: parser.y,v 1.6 2006/01/17 23:43:36 as Exp $ + * RCSID $Id$ */ #include <stdio.h> diff --git a/src/starter/starter.c b/src/starter/starter.c index 3cf7017fd..fe3c2ad59 100644 --- a/src/starter/starter.c +++ b/src/starter/starter.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: starter.c,v 1.23 2006/02/15 18:37:46 as Exp $ + * RCSID $Id$ */ #include <sys/types.h> diff --git a/src/starter/starterstroke.c b/src/starter/starterstroke.c index eeeb2f5b0..c94669115 100644 --- a/src/starter/starterstroke.c +++ b/src/starter/starterstroke.c @@ -13,7 +13,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: starterstroke.c $ + * RCSID $Id$ */ #include <sys/types.h> diff --git a/src/starter/starterstroke.h b/src/starter/starterstroke.h index 95c37094e..38fc18a46 100644 --- a/src/starter/starterstroke.h +++ b/src/starter/starterstroke.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: starterstroke.h $ + * RCSID $Id$ */ #ifndef _STARTER_STROKE_H_ diff --git a/src/starter/starterwhack.c b/src/starter/starterwhack.c index a546304c9..20dda7ca0 100644 --- a/src/starter/starterwhack.c +++ b/src/starter/starterwhack.c @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: starterwhack.c,v 1.17 2006/04/17 10:32:36 as Exp $ + * RCSID $Id$ */ #include <sys/types.h> diff --git a/src/starter/starterwhack.h b/src/starter/starterwhack.h index 2e79c0715..aaae03127 100644 --- a/src/starter/starterwhack.h +++ b/src/starter/starterwhack.h @@ -11,7 +11,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * RCSID $Id: starterwhack.h,v 1.6 2006/01/03 18:37:03 as Exp $ + * RCSID $Id$ */ #ifndef _STARTER_WHACK_H_ |