Skip to content

Commit

Permalink
Added some more (stubbed-in) server code and functions. Minor doc tweak.
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/mbr/svn/fwknop/trunk@148 510a4753-2344-4c79-9c09-4d669213fbeb
  • Loading branch information
Damien Stuart committed Sep 14, 2009
1 parent 8a06e36 commit 61c243f
Show file tree
Hide file tree
Showing 18 changed files with 908 additions and 137 deletions.
10 changes: 5 additions & 5 deletions Makefile.am
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ if WANT_SERVER
endif endif


SUBDIRS = \ SUBDIRS = \
lib \ lib \
common \ common \
$(CLIENT_DIR) \ $(CLIENT_DIR) \
$(SERVER_DIR) \ $(SERVER_DIR) \
doc doc


EXTRA_DIST = \ EXTRA_DIST = \
perl/legacy \ perl/legacy \
Expand Down
15 changes: 8 additions & 7 deletions client/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,11 @@
bin_PROGRAMS = fwknop bin_PROGRAMS = fwknop


fwknop_SOURCES = fwknop.c fwknop.h config_init.c config_init.h \ fwknop_SOURCES = fwknop.c fwknop.h config_init.c config_init.h \
fwknop_common.h spa_comm.c spa_comm.h utils.c utils.h \ fwknop_common.h spa_comm.c spa_comm.h utils.c utils.h \
http_resolve_host.c getpasswd.c getpasswd.h http_resolve_host.c getpasswd.c getpasswd.h


fwknop_LDADD = $(top_builddir)/lib/libfko.la fwknop_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/common
fwknop_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/common


dist_man_MANS = fwknop.8 fwknop_LDADD = $(top_builddir)/lib/libfko.la

dist_man_MANS = fwknop.8
8 changes: 4 additions & 4 deletions doc/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
CLEANFILES = libfko.info CLEANFILES = libfko.info


info_TEXINFOS = libfko.texi info_TEXINFOS = libfko.texi
libfko_TEXINFOS = gpl-2.0.texi libfko_TEXINFOS = gpl-2.0.texi


EXTRA_DIST = fwknop.man.asciidoc EXTRA_DIST = fwknop.man.asciidoc
6 changes: 3 additions & 3 deletions doc/libfko.texi
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -708,15 +708,15 @@ main(int argc, char **argv)
rc = fko_new(&ctx); rc = fko_new(&ctx);
if(rc != FKO_SUCCESS) if(rc != FKO_SUCCESS)
@{ @{
fprintf(stderr, "Error creating context: %s\n", fko_errstr()); fprintf(stderr, "Error creating context: %s\n", fko_errstr(rc));
exit(1); exit(1);
@} @}
/* Set the SPA message field */ /* Set the SPA message field */
rc = fko_set_spa_message(ctx, "0.0.0.0,tcp/22"); rc = fko_set_spa_message(ctx, "0.0.0.0,tcp/22");
if(rc != FKO_SUCCESS) if(rc != FKO_SUCCESS)
@{ @{
fprintf(stderr, "Set SPA message failed: %s\n", fko_errstr()); fprintf(stderr, "Set SPA message failed: %s\n", fko_errstr(rc));
exit(1); exit(1);
@} @}
Expand All @@ -736,7 +736,7 @@ main(int argc, char **argv)
rc = fko_spa_data_final(ctx); rc = fko_spa_data_final(ctx);
if(rc != FKO_SUCCESS) if(rc != FKO_SUCCESS)
@{ @{
fprintf(stderr, "Error encoding SPA data: %s\n", fko_errstr()); fprintf(stderr, "Error encoding SPA data: %s\n", fko_errstr(rc));
exit(1); exit(1);
@} @}
Expand Down
18 changes: 10 additions & 8 deletions server/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,16 +1,18 @@
sbin_PROGRAMS = fwknopd sbin_PROGRAMS = fwknopd


fwknopd_SOURCES = fwknopd.c fwknopd.h config_init.c config_init.h \ fwknopd_SOURCES = fwknopd.c fwknopd.h config_init.c config_init.h \
fwknopd_common.h utils.c utils.h fwknopd_common.h incoming_spa.c incoming_spa.h \
pcap_capture.c pcap_capture.h process_packet.c \
process_packet.h log_msg.c log_msg.h utils.c utils.h


fwknopd_LDADD = $(top_builddir)/lib/libfko.la fwknopd_LDADD = $(top_builddir)/lib/libfko.la


if HAVE_LIBPCAP if HAVE_LIBPCAP
fwknopd_LDADD += -lpcap fwknopd_LDADD += -lpcap
endif endif


fwknopd_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/common -DSYSCONFDIR=\"$(sysconfdir)\" fwknopd_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/common -DSYSCONFDIR=\"$(sysconfdir)\"


fwknopddir = @sysconfdir@/fwknop fwknopddir = @sysconfdir@/fwknop
dist_fwknopd_DATA = fwknopd.conf


dist_fwknopd_DATA = fwknopd.conf
90 changes: 52 additions & 38 deletions server/config_init.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ config_entry_index(fko_srv_options_t *opts, char *var)
/* Parse the config file... /* Parse the config file...
*/ */
static void static void
parse_config_file(fko_srv_options_t *options, char *config_file) parse_config_file(fko_srv_options_t *opts, char *config_file)
{ {
FILE *cfile_ptr; FILE *cfile_ptr;
unsigned int numLines = 0; unsigned int numLines = 0;
Expand Down Expand Up @@ -166,15 +166,15 @@ parse_config_file(fko_srv_options_t *options, char *config_file)
{ {
if(sscanf((val+1), "%[A-Z_]%s", tmp1, tmp2)) if(sscanf((val+1), "%[A-Z_]%s", tmp1, tmp2))
{ {
if((cndx = config_entry_index(options, tmp1)) >= 0) if((cndx = config_entry_index(opts, tmp1)) >= 0)
{ {
strlcpy(val, options->config[cndx], MAX_LINE_LEN); strlcpy(val, opts->config[cndx], MAX_LINE_LEN);
strlcat(val, tmp2, MAX_LINE_LEN); strlcat(val, tmp2, MAX_LINE_LEN);
} }
} }
} }


set_config_entry(options, i, val); set_config_entry(opts, i, val);
good_ent++; good_ent++;
break; break;
} }
Expand All @@ -195,9 +195,28 @@ parse_config_file(fko_srv_options_t *options, char *config_file)
/* Sanity and bounds checks for the various options. /* Sanity and bounds checks for the various options.
*/ */
static void static void
validate_options(fko_srv_options_t *options) validate_options(fko_srv_options_t *opts)
{ {
/*** TODO: put stuff here ***/ /* Some options just trigger some output of information, or trigger an
* external function, but do not actually start fwknopd. If any of those
* are set, we can return here an skip the validation routines as all
* other options will be ignored anyway.
*
* These are also mutually exclusive (for now).
*/
if((opts->dump_config + opts->kill + opts->restart + opts->status) == 1)
return;

if((opts->dump_config + opts->kill + opts->restart + opts->status) > 1)
{
fprintf(stderr,
"The -D, -K, -R, and -S options are mutually exclusive. Pick only one.\n"
);
exit(EXIT_FAILURE);
}

/* TODO: Add more validation and sanity checks... --DSS */



return; return;
} }
Expand All @@ -206,7 +225,7 @@ validate_options(fko_srv_options_t *options)
* switches. * switches.
*/ */
void void
config_init(fko_srv_options_t *options, int argc, char **argv) config_init(fko_srv_options_t *opts, int argc, char **argv)
{ {
int cmd_arg, index; int cmd_arg, index;
unsigned char got_conf_file = 0, got_override_config = 0; unsigned char got_conf_file = 0, got_override_config = 0;
Expand All @@ -216,7 +235,7 @@ config_init(fko_srv_options_t *options, int argc, char **argv)


/* Zero out options and opts_track. /* Zero out options and opts_track.
*/ */
memset(options, 0x00, sizeof(fko_srv_options_t)); memset(opts, 0x00, sizeof(fko_srv_options_t));


/* First, scan the command-line args for an alternate configuration /* First, scan the command-line args for an alternate configuration
* file. If we find it, use it, otherwise use the default. * file. If we find it, use it, otherwise use the default.
Expand All @@ -229,7 +248,7 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
*/ */
if(cmd_arg == 'c') if(cmd_arg == 'c')
{ {
set_config_entry(options, CONF_CONFIG_FILE, optarg); set_config_entry(opts, CONF_CONFIG_FILE, optarg);
got_conf_file++; got_conf_file++;


/* If we already have the config_override option, we are done. /* If we already have the config_override option, we are done.
Expand All @@ -242,7 +261,7 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
*/ */
if(cmd_arg == 'O') if(cmd_arg == 'O')
{ {
set_config_entry(options, CONF_OVERRIDE_CONFIG, optarg); set_config_entry(opts, CONF_OVERRIDE_CONFIG, optarg);
got_conf_file++; got_conf_file++;


/* If we already have the conf_file option, we are done. /* If we already have the conf_file option, we are done.
Expand All @@ -255,22 +274,22 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
/* If no alternate configuration file was specified, we use the /* If no alternate configuration file was specified, we use the
* default. * default.
*/ */
if(options->config[CONF_CONFIG_FILE] == NULL) if(opts->config[CONF_CONFIG_FILE] == NULL)
set_config_entry(options, CONF_CONFIG_FILE, DEF_CONFIG_FILE); set_config_entry(opts, CONF_CONFIG_FILE, DEF_CONFIG_FILE);


/* Parse configuration file to populate any params not already specified /* Parse configuration file to populate any params not already specified
* via command-line options. * via command-line options.
*/ */
parse_config_file(options, options->config[CONF_CONFIG_FILE]); parse_config_file(opts, opts->config[CONF_CONFIG_FILE]);


/* If there are override configuration entries, process them /* If there are override configuration entries, process them
* here. * here.
*/ */
if(options->config[CONF_OVERRIDE_CONFIG] != NULL) if(opts->config[CONF_OVERRIDE_CONFIG] != NULL)
{ {
/* Make a copy of the overrid_config string so we can munge it. /* Make a copy of the overrid_config string so we can munge it.
*/ */
strlcpy(override_file, options->config[CONF_OVERRIDE_CONFIG], MAX_LINE_LEN); strlcpy(override_file, opts->config[CONF_OVERRIDE_CONFIG], MAX_LINE_LEN);


ndx = override_file; ndx = override_file;
cmrk = strchr(ndx, ','); cmrk = strchr(ndx, ',');
Expand All @@ -279,22 +298,22 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
{ {
/* Only one to process... /* Only one to process...
*/ */
parse_config_file(options, ndx); parse_config_file(opts, ndx);


} else { } else {
/* Walk the string pulling the next config override /* Walk the string pulling the next config override
* at the comma delimiters. * at the comma delimiters.
*/ */
while(cmrk != NULL) { while(cmrk != NULL) {
*cmrk = '\0'; *cmrk = '\0';
parse_config_file(options, ndx); parse_config_file(opts, ndx);
ndx = cmrk + 1; ndx = cmrk + 1;
cmrk = strchr(ndx, ','); cmrk = strchr(ndx, ',');
} }


/* Process the last entry /* Process the last entry
*/ */
parse_config_file(options, ndx); parse_config_file(opts, ndx);
} }
} }


Expand All @@ -313,7 +332,10 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
/* This was handled earlier */ /* This was handled earlier */
break; break;
case 'D': case 'D':
options->dump_config = 1; opts->dump_config = 1;
break;
case 'f':
opts->foreground = 1;
break; break;
case FIREWALL_LIST: case FIREWALL_LIST:
fprintf(stderr, "*NOT IMPLEMENTED YET*\n"); fprintf(stderr, "*NOT IMPLEMENTED YET*\n");
Expand All @@ -328,44 +350,35 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case FIREWALL_LOG: case FIREWALL_LOG:
set_config_entry(options, CONF_FIREWALL_LOG, optarg); set_config_entry(opts, CONF_FIREWALL_LOG, optarg);
break; break;
case GPG_HOME_DIR: case GPG_HOME_DIR:
set_config_entry(options, CONF_GPG_HOME_DIR, optarg); set_config_entry(opts, CONF_GPG_HOME_DIR, optarg);
break; break;
case GPG_KEY: case GPG_KEY:
set_config_entry(options, CONF_GPG_KEY, optarg); set_config_entry(opts, CONF_GPG_KEY, optarg);
break; break;
case 'h': case 'h':
usage(); usage();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'i': case 'i':
set_config_entry(options, CONF_PCAP_INTF, optarg); set_config_entry(opts, CONF_PCAP_INTF, optarg);
break; break;
case 'K': case 'K':
fprintf(stderr, "*NOT IMPLEMENTED YET*\n"); opts->kill = 1;
// TODO: Add this...
//kill_fwknopd();
exit(EXIT_SUCCESS);
break; break;
case 'O': case 'O':
/* This was handled earlier */ /* This was handled earlier */
break; break;
case 'R': case 'R':
fprintf(stderr, "*NOT IMPLEMENTED YET*\n"); opts->restart = 1;
// TODO: Add this...
//restart_fwknopd();
exit(EXIT_SUCCESS);
break; break;
case 'S': case 'S':
fprintf(stderr, "*NOT IMPLEMENTED YET*\n"); opts->status = 1;
// TODO: Add this...
//fwkop_status();
exit(EXIT_SUCCESS);
break; break;
case 'v': case 'v':
options->verbose = 1; opts->verbose = 1;
break; break;
case 'V': case 'V':
fprintf(stdout, "fwknopd server %s\n", MY_VERSION); fprintf(stdout, "fwknopd server %s\n", MY_VERSION);
Expand All @@ -377,9 +390,10 @@ config_init(fko_srv_options_t *options, int argc, char **argv)
} }
} }


/* Now that we have all of our options set, we can validate them. /* Now that we have all of our options set, and we are actually going to
* start fwknopd, we can validate them.
*/ */
validate_options(options); validate_options(opts);


return; return;
} }
Expand Down
Loading

0 comments on commit 61c243f

Please sign in to comment.