whack uses optionsfrom from libstrongswan

This commit is contained in:
Andreas Steffen
2009-05-24 20:59:28 +02:00
parent c0bc85c5b6
commit 4a64f1d3ba
2 changed files with 42 additions and 15 deletions
+3 -1
View File
@@ -7,7 +7,9 @@ INCLUDES = \
-I$(top_srcdir)/src/libfreeswan \ -I$(top_srcdir)/src/libfreeswan \
-I$(top_srcdir)/src/pluto -I$(top_srcdir)/src/pluto
whack_LDADD = $(top_builddir)/src/libfreeswan/libfreeswan.a whack_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libfreeswan/libfreeswan.a
AM_CFLAGS = -DDEBUG AM_CFLAGS = -DDEBUG
+39 -14
View File
@@ -30,6 +30,8 @@
#include <freeswan.h> #include <freeswan.h>
#include <utils/optionsfrom.h>
#include "constants.h" #include "constants.h"
#include "defs.h" #include "defs.h"
#include "whack.h" #include "whack.h"
@@ -236,20 +238,37 @@ static const char *label = NULL; /* --label operand, saved for diagnostic
static const char *name = NULL; /* --name operand, saved for diagnostics */ static const char *name = NULL; /* --name operand, saved for diagnostics */
/* print a string as a diagnostic, then exit whack unhappily */ /* options read by optionsfrom */
options_t *options;
/**
* exit whack after cleaning up
*/
static void whack_exit(int status)
{
options->destroy(options);
exit(status);
}
/**
* print a string as a diagnostic, then exit whack unhappily
*/
static void diag(const char *mess) static void diag(const char *mess)
{ {
if (mess != NULL) if (mess != NULL)
{ {
fprintf(stderr, "whack error: "); fprintf(stderr, "whack error: ");
if (label != NULL) if (label != NULL)
{
fprintf(stderr, "%s ", label); fprintf(stderr, "%s ", label);
}
if (name != NULL) if (name != NULL)
{
fprintf(stderr, "\"%s\" ", name); fprintf(stderr, "\"%s\" ", name);
}
fprintf(stderr, "%s\n", mess); fprintf(stderr, "%s\n", mess);
} }
whack_exit(RC_WHACK_PROBLEM);
exit(RC_WHACK_PROBLEM);
} }
/* conditially calls diag; prints second arg, if non-NULL, as quoted string */ /* conditially calls diag; prints second arg, if non-NULL, as quoted string */
@@ -851,6 +870,8 @@ int main(int argc, char **argv)
msg.crluri2 = NULL; msg.crluri2 = NULL;
msg.ocspuri = NULL; msg.ocspuri = NULL;
options = options_create();
for (;;) for (;;)
{ {
int long_index; int long_index;
@@ -977,7 +998,7 @@ int main(int argc, char **argv)
case 'h' - OPTION_OFFSET: /* --help */ case 'h' - OPTION_OFFSET: /* --help */
help(); help();
return 0; /* GNU coding standards say to stop here */ whack_exit(0); /* GNU coding standards say to stop here */
case 'v' - OPTION_OFFSET: /* --version */ case 'v' - OPTION_OFFSET: /* --version */
{ {
@@ -987,15 +1008,18 @@ int main(int argc, char **argv)
for (; *sp != NULL; sp++) for (; *sp != NULL; sp++)
puts(*sp); puts(*sp);
} }
return 0; /* GNU coding standards say to stop here */ whack_exit(0); /* GNU coding standards say to stop here */
case 'l' - OPTION_OFFSET: /* --label <string> */ case 'l' - OPTION_OFFSET: /* --label <string> */
label = optarg; /* remember for diagnostics */ label = optarg; /* remember for diagnostics */
continue; continue;
case '+' - OPTION_OFFSET: /* --optionsfrom <filename> */ case '+' - OPTION_OFFSET: /* --optionsfrom <filename> */
optionsfrom(optarg, &argc, &argv, optind, stderr); if (!options->from(options, optarg, &argc, &argv, optind))
/* does not return on error */ {
fprintf(stderr, "optionsfrom failed");
whack_exit(RC_WHACK_PROBLEM);
}
continue; continue;
/* the rest of the options combine in complex ways */ /* the rest of the options combine in complex ways */
@@ -1778,7 +1802,7 @@ int main(int argc, char **argv)
, ctl_addr.sun_path, errno, strerror(e)); , ctl_addr.sun_path, errno, strerror(e));
break; break;
} }
exit(RC_WHACK_PROBLEM); whack_exit(RC_WHACK_PROBLEM);
} }
else else
{ {
@@ -1791,7 +1815,7 @@ int main(int argc, char **argv)
int e = errno; int e = errno;
fprintf(stderr, "whack: socket() failed (%d %s)\n", e, strerror(e)); fprintf(stderr, "whack: socket() failed (%d %s)\n", e, strerror(e));
exit(RC_WHACK_PROBLEM); whack_exit(RC_WHACK_PROBLEM);
} }
if (connect(sock, (struct sockaddr *)&ctl_addr if (connect(sock, (struct sockaddr *)&ctl_addr
@@ -1802,7 +1826,7 @@ int main(int argc, char **argv)
fprintf(stderr, "whack:%s connect() for \"%s\" failed (%d %s)\n" fprintf(stderr, "whack:%s connect() for \"%s\" failed (%d %s)\n"
, e == ECONNREFUSED? " is Pluto running? " : "" , e == ECONNREFUSED? " is Pluto running? " : ""
, ctl_addr.sun_path, e, strerror(e)); , ctl_addr.sun_path, e, strerror(e));
exit(RC_WHACK_PROBLEM); whack_exit(RC_WHACK_PROBLEM);
} }
if (write(sock, &msg, len) != len) if (write(sock, &msg, len) != len)
@@ -1810,7 +1834,7 @@ int main(int argc, char **argv)
int e = errno; int e = errno;
fprintf(stderr, "whack: write() failed (%d %s)\n", e, strerror(e)); fprintf(stderr, "whack: write() failed (%d %s)\n", e, strerror(e));
exit(RC_WHACK_PROBLEM); whack_exit(RC_WHACK_PROBLEM);
} }
/* for now, just copy reply back to stdout */ /* for now, just copy reply back to stdout */
@@ -1829,7 +1853,7 @@ int main(int argc, char **argv)
int e = errno; int e = errno;
fprintf(stderr, "whack: read() failed (%d %s)\n", e, strerror(e)); fprintf(stderr, "whack: read() failed (%d %s)\n", e, strerror(e));
exit(RC_WHACK_PROBLEM); whack_exit(RC_WHACK_PROBLEM);
} }
if (rl == 0) if (rl == 0)
{ {
@@ -1886,6 +1910,7 @@ int main(int argc, char **argv)
} }
} }
} }
return exit_status; whack_exit(exit_status);
} }
return -1; /* should never be reached */
} }