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
This commit is contained in:
+8
-8
@@ -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]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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'},
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user