From 11cedcf3eb610e9e747cd74d7d5de897cff4f02a Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Mon, 4 Jan 2010 04:08:58 +0000 Subject: [PATCH] Added --access-file command line arg to fwknopd so that the path to the access.conf file can be specified from the command line. git-svn-id: file:///home/mbr/svn/fwknop/trunk@187 510a4753-2344-4c79-9c09-4d669213fbeb --- server/access.c | 16 ++++++++-------- server/access.h | 2 +- server/config_init.c | 9 +++++++++ server/config_init.h | 3 ++- server/fwknopd.c | 2 +- server/fwknopd.conf | 2 +- server/fwknopd_common.h | 4 ++-- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/server/access.c b/server/access.c index adaffb69..a37be044 100644 --- a/server/access.c +++ b/server/access.c @@ -488,7 +488,7 @@ set_acc_defaults(fko_srv_options_t *opts) /* Read and parse the access file, popluating the access data as we go. */ void -parse_access_file(fko_srv_options_t *opts, char *access_file) +parse_access_file(fko_srv_options_t *opts) { FILE *file_ptr; int got_source = 0; @@ -507,18 +507,18 @@ parse_access_file(fko_srv_options_t *opts, char *access_file) /* First see if the access file exists. If it doesn't, complain * and go on with program defaults. */ - if(stat(access_file, &st) != 0) + if(stat(opts->config[CONF_ACCESS_FILE], &st) != 0) { fprintf(stderr, "[*] Access file: '%s' was not found.\n", - access_file); + opts->config[CONF_ACCESS_FILE]); exit(EXIT_FAILURE); } - if ((file_ptr = fopen(access_file, "r")) == NULL) + if ((file_ptr = fopen(opts->config[CONF_ACCESS_FILE], "r")) == NULL) { fprintf(stderr, "[*] Could not open access file: %s\n", - access_file); + opts->config[CONF_ACCESS_FILE]); perror(NULL); exit(EXIT_FAILURE); @@ -546,7 +546,7 @@ parse_access_file(fko_srv_options_t *opts, char *access_file) { fprintf(stderr, "*Invalid access file entry in %s at line %i.\n - '%s'", - access_file, num_lines, access_line_buf + opts->config[CONF_ACCESS_FILE], num_lines, access_line_buf ); continue; } @@ -554,7 +554,7 @@ parse_access_file(fko_srv_options_t *opts, char *access_file) /* fprintf(stderr, "ACCESS FILE: %s, LINE: %s\tVar: %s, Val: '%s'\n", - access_file, access_line_buf, var, val + opts->config[CONF_ACCESS_FILE], access_line_buf, var, val ); */ @@ -625,7 +625,7 @@ parse_access_file(fko_srv_options_t *opts, char *access_file) { fprintf(stderr, "*Ignoring unknown access parameter: '%s' in %s\n", - var, access_file + var, opts->config[CONF_ACCESS_FILE] ); } } diff --git a/server/access.h b/server/access.h index d751c399..3f2edd9f 100644 --- a/server/access.h +++ b/server/access.h @@ -31,7 +31,7 @@ /* Function Prototypes */ -void parse_access_file(fko_srv_options_t *opts, char *access_file); +void parse_access_file(fko_srv_options_t *opts); acc_stanza_t* acc_check_source(fko_srv_options_t *opts, uint32_t ip); int acc_check_port_access(acc_stanza_t *acc, char *port_str); void dump_access_list(fko_srv_options_t *opts); diff --git a/server/config_init.c b/server/config_init.c index aed361ac..a5cabb26 100644 --- a/server/config_init.c +++ b/server/config_init.c @@ -223,6 +223,12 @@ validate_options(fko_srv_options_t *opts) if(opts->config[CONF_FWKNOP_CONF_DIR] == NULL) set_config_entry(opts, CONF_FWKNOP_CONF_DIR, DEF_CONF_DIR); + /* If no access.conf path was specified on the command line or set in + * the config file, use the default. + */ + if(opts->config[CONF_ACCESS_FILE] == NULL) + set_config_entry(opts, CONF_ACCESS_FILE, DEF_ACCESS_FILE); + /* If the pid and digest cache files where not set in the config file or * via command-line, then grab the defaults. Start with RUN_DIR as the * files may depend on that. @@ -418,6 +424,9 @@ config_init(fko_srv_options_t *opts, int argc, char **argv) GETOPTS_OPTION_STRING, cmd_opts, &index)) != -1) { switch(cmd_arg) { + case 'a': + set_config_entry(opts, CONF_ACCESS_FILE, optarg); + break; case 'c': /* This was handled earlier */ break; diff --git a/server/config_init.h b/server/config_init.h index 45a02e56..54ead9c5 100644 --- a/server/config_init.h +++ b/server/config_init.h @@ -63,12 +63,13 @@ enum { /* Our getopt_long options string. */ -#define GETOPTS_OPTION_STRING "c:C:Dfhi:KO:RSvV" +#define GETOPTS_OPTION_STRING "a:c:C:Dfhi:KO:RSvV" /* Our program command-line options... */ static struct option cmd_opts[] = { + {"access-file", 1, NULL, 'a'}, {"config-file", 1, NULL, 'c'}, {"packet-limit", 1, NULL, 'C'}, {"dump-config", 0, NULL, 'D'}, diff --git a/server/fwknopd.c b/server/fwknopd.c index 80421891..325a4785 100644 --- a/server/fwknopd.c +++ b/server/fwknopd.c @@ -167,7 +167,7 @@ main(int argc, char **argv) /* Process the access.conf file. */ - parse_access_file(&opts, DEF_ACCESS_FILE); + parse_access_file(&opts); /* If we are a new process (just being started), proceed with normal * startp. Otherwise, we are here as a result of a signal sent to an diff --git a/server/fwknopd.conf b/server/fwknopd.conf index 3bd5a4dd..833d61cf 100644 --- a/server/fwknopd.conf +++ b/server/fwknopd.conf @@ -324,7 +324,7 @@ IPT_EXEC_TRIES 1; # Files # -#ACCESS_CONF $FWKNOP_CONF_DIR/access.conf; +#ACCESS_FILE access.conf; #FWKNOP_PID_FILE $FWKNOP_RUN_DIR/fwknopd.pid; #DIGEST_FILE $FWKNOP_RUN_DIR/digest.cache; #FWKNOP_CMDLINE_FILE $FWKNOP_RUN_DIR/fwknopd.cmd; diff --git a/server/fwknopd_common.h b/server/fwknopd_common.h index 307d23f2..b3a766d9 100644 --- a/server/fwknopd_common.h +++ b/server/fwknopd_common.h @@ -162,7 +162,7 @@ enum { //CONF_FWKNOP_MOD_DIR, CONF_FWKNOP_CONF_DIR, //CONF_FWKNOP_ERR_DIR, - //CONF_ACCESS_CONF, + CONF_ACCESS_FILE, CONF_FWKNOP_PID_FILE, CONF_DIGEST_FILE, //CONF_FWKNOP_CMDLINE_FILE, @@ -247,7 +247,7 @@ static char *config_map[NUMBER_OF_CONFIG_ENTRIES] = { //"FWKNOP_MOD_DIR", "FWKNOP_CONF_DIR", //"FWKNOP_ERR_DIR", - //"ACCESS_CONF", + "ACCESS_FILE", "FWKNOP_PID_FILE", "DIGEST_FILE", //"FWKNOP_CMDLINE_FILE",