2 ******************************************************************************
6 * Author: Damien Stuart
8 * Purpose: Command-line and config file processing for fwknop server.
10 * Copyright 2010 Damien Stuart (dstuart@dstuart.org)
12 * License (GNU Public License):
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 ******************************************************************************
31 #include "fwknopd_common.h"
32 #include "config_init.h"
38 /* Check to see if an integer variable has a value that is within a
42 range_check(fko_srv_options_t *opts, char *var, char *val, int low, int high)
44 if (low > atoi(val) || high < atoi(val))
46 fprintf(stderr, "[*] var %s value '%s' not in the range %d-%d\n",
48 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
53 /* Take an index and a string value. malloc the space for the value
54 * and assign it to the array at the specified index.
57 set_config_entry(fko_srv_options_t *opts, const int var_ndx, const char *value)
61 /* Sanity check the index value.
63 if(var_ndx < 0 || var_ndx >= NUMBER_OF_CONFIG_ENTRIES)
65 fprintf(stderr, "Index value of %i is not valid\n", var_ndx);
66 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
69 /* If this particular entry was already set (i.e. not NULL), then
70 * assume it needs to be freed first.
72 if(opts->config[var_ndx] != NULL)
73 free(opts->config[var_ndx]);
75 /* If we are setting it to NULL, do it and be done.
79 opts->config[var_ndx] = NULL;
83 /* Otherwise, make the space we need and set it.
85 space_needed = strlen(value) + 1;
87 opts->config[var_ndx] = malloc(space_needed);
89 if(opts->config[var_ndx] == NULL)
91 fprintf(stderr, "*Fatal memory allocation error!\n");
92 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
95 strlcpy(opts->config[var_ndx], value, space_needed);
100 /* Given a config parameter name, return its index or -1 if not found.
103 config_entry_index(const fko_srv_options_t *opts, const char *var)
107 for(i=0; i<NUMBER_OF_CONFIG_ENTRIES; i++)
108 if(opts->config[i] != NULL && CONF_VAR_IS(var, config_map[i]))
114 /* Free the config memory
117 free_configs(fko_srv_options_t *opts)
121 free_acc_stanzas(opts);
123 for(i=0; i<NUMBER_OF_CONFIG_ENTRIES; i++)
124 if(opts->config[i] != NULL)
125 free(opts->config[i]);
129 validate_int_var_ranges(fko_srv_options_t *opts)
131 range_check(opts, "PCAP_LOOP_SLEEP", opts->config[CONF_PCAP_LOOP_SLEEP],
132 1, RCHK_MAX_PCAP_LOOP_SLEEP);
133 range_check(opts, "MAX_SPA_PACKET_AGE", opts->config[CONF_MAX_SPA_PACKET_AGE],
134 1, RCHK_MAX_SPA_PACKET_AGE);
135 range_check(opts, "MAX_SNIFF_BYTES", opts->config[CONF_MAX_SNIFF_BYTES],
136 1, RCHK_MAX_SNIFF_BYTES);
137 range_check(opts, "TCPSERV_PORT", opts->config[CONF_TCPSERV_PORT],
138 1, RCHK_MAX_TCPSERV_PORT);
141 range_check(opts, "IPFW_START_RULE_NUM", opts->config[CONF_IPFW_START_RULE_NUM],
142 0, RCHK_MAX_IPFW_START_RULE_NUM);
143 range_check(opts, "IPFW_MAX_RULES", opts->config[CONF_IPFW_MAX_RULES],
144 1, RCHK_MAX_IPFW_MAX_RULES);
145 range_check(opts, "IPFW_ACTIVE_SET_NUM", opts->config[CONF_IPFW_ACTIVE_SET_NUM],
146 0, RCHK_MAX_IPFW_SET_NUM);
147 range_check(opts, "IPFW_EXPIRE_SET_NUM", opts->config[CONF_IPFW_EXPIRE_SET_NUM],
148 0, RCHK_MAX_IPFW_SET_NUM);
149 range_check(opts, "IPFW_EXPIRE_PURGE_INTERVAL",
150 opts->config[CONF_IPFW_EXPIRE_PURGE_INTERVAL],
151 1, RCHK_MAX_IPFW_PURGE_INTERVAL);
153 /* Make sure the active and expire sets are not identical whenever
156 if((atoi(opts->config[CONF_IPFW_ACTIVE_SET_NUM]) > 0
157 && atoi(opts->config[CONF_IPFW_EXPIRE_SET_NUM]) > 0)
158 && atoi(opts->config[CONF_IPFW_ACTIVE_SET_NUM])
159 == atoi(opts->config[CONF_IPFW_EXPIRE_SET_NUM]))
162 "[*] Cannot set identical ipfw active and expire sets.\n");
163 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
167 range_check(opts, "PF_EXPIRE_INTERVAL", opts->config[CONF_PF_EXPIRE_INTERVAL],
168 1, RCHK_MAX_PF_EXPIRE_INTERVAL);
170 #endif /* FIREWALL type */
175 /* Parse the config file...
178 parse_config_file(fko_srv_options_t *opts, const char *config_file)
181 unsigned int numLines = 0;
182 unsigned int i, good_ent;
185 char conf_line_buf[MAX_LINE_LEN] = {0};
186 char var[MAX_LINE_LEN] = {0};
187 char val[MAX_LINE_LEN] = {0};
188 char tmp1[MAX_LINE_LEN] = {0};
189 char tmp2[MAX_LINE_LEN] = {0};
193 /* First see if the config file exists. If it doesn't, complain
194 * and go on with program defaults.
196 if(stat(config_file, &st) != 0)
198 fprintf(stderr, "[*] Config file: '%s' was not found.\n",
200 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
203 if ((cfile_ptr = fopen(config_file, "r")) == NULL)
205 fprintf(stderr, "[*] Could not open config file: %s\n",
209 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
212 while ((fgets(conf_line_buf, MAX_LINE_LEN, cfile_ptr)) != NULL)
215 conf_line_buf[MAX_LINE_LEN-1] = '\0';
217 /* Get past comments and empty lines (note: we only look at the
220 if(IS_EMPTY_LINE(conf_line_buf[0]))
223 if(sscanf(conf_line_buf, "%s %[^;\n\r]", var, val) != 2)
226 "*Invalid config file entry in %s at line %i.\n - '%s'",
227 config_file, numLines, conf_line_buf
234 "CONF FILE: %s, LINE: %s\tVar: %s, Val: '%s'\n",
235 config_file, conf_line_buf, var, val
240 for(i=0; i<NUMBER_OF_CONFIG_ENTRIES; i++)
242 if(CONF_VAR_IS(config_map[i], var))
244 /* First check to see if we need to do a varable expansion
245 * on this value. Note: this only supports one expansion and
246 * only if the value starts with the variable.
250 if(sscanf((val+1), "%[A-Z_]%s", tmp1, tmp2))
252 if((cndx = config_entry_index(opts, tmp1)) >= 0)
254 strlcpy(val, opts->config[cndx], MAX_LINE_LEN);
255 strlcat(val, tmp2, MAX_LINE_LEN);
260 set_config_entry(opts, i, val);
268 "*Ignoring unknown configuration parameter: '%s' in %s\n",
278 /* Set defaults, and do sanity and bounds checks for the various options.
281 validate_options(fko_srv_options_t *opts)
283 char tmp_path[MAX_PATH_LEN];
285 /* If no conf dir is set in the config file, use the default.
287 if(opts->config[CONF_FWKNOP_CONF_DIR] == NULL)
288 set_config_entry(opts, CONF_FWKNOP_CONF_DIR, DEF_CONF_DIR);
290 /* If no access.conf path was specified on the command line or set in
291 * the config file, use the default.
293 if(opts->config[CONF_ACCESS_FILE] == NULL)
294 set_config_entry(opts, CONF_ACCESS_FILE, DEF_ACCESS_FILE);
296 /* If the pid and digest cache files where not set in the config file or
297 * via command-line, then grab the defaults. Start with RUN_DIR as the
298 * files may depend on that.
300 if(opts->config[CONF_FWKNOP_RUN_DIR] == NULL)
301 set_config_entry(opts, CONF_FWKNOP_RUN_DIR, DEF_RUN_DIR);
303 if(opts->config[CONF_FWKNOP_PID_FILE] == NULL)
305 strlcpy(tmp_path, opts->config[CONF_FWKNOP_RUN_DIR], MAX_PATH_LEN);
307 if(tmp_path[strlen(tmp_path)-1] != '/')
308 strlcat(tmp_path, "/", MAX_PATH_LEN);
310 strlcat(tmp_path, DEF_PID_FILENAME, MAX_PATH_LEN);
312 set_config_entry(opts, CONF_FWKNOP_PID_FILE, tmp_path);
316 if(opts->config[CONF_DIGEST_FILE] == NULL)
318 if(opts->config[CONF_DIGEST_DB_FILE] == NULL)
321 strlcpy(tmp_path, opts->config[CONF_FWKNOP_RUN_DIR], MAX_PATH_LEN);
323 if(tmp_path[strlen(tmp_path)-1] != '/')
324 strlcat(tmp_path, "/", MAX_PATH_LEN);
328 strlcat(tmp_path, DEF_DIGEST_CACHE_FILENAME, MAX_PATH_LEN);
329 set_config_entry(opts, CONF_DIGEST_FILE, tmp_path);
331 strlcat(tmp_path, DEF_DIGEST_CACHE_DB_FILENAME, MAX_PATH_LEN);
332 set_config_entry(opts, CONF_DIGEST_DB_FILE, tmp_path);
336 /* Set remaining require CONF_ vars if they are not already set. */
338 /* PCAP capture interface.
340 if(opts->config[CONF_PCAP_INTF] == NULL)
341 set_config_entry(opts, CONF_PCAP_INTF, DEF_INTERFACE);
343 /* PCAP Promiscuous mode.
345 if(opts->config[CONF_ENABLE_PCAP_PROMISC] == NULL)
346 set_config_entry(opts, CONF_ENABLE_PCAP_PROMISC,
347 DEF_ENABLE_PCAP_PROMISC);
349 /* The packet count argument to pcap_dispatch()
351 if(opts->config[CONF_PCAP_DISPATCH_COUNT] == NULL)
352 set_config_entry(opts, CONF_PCAP_DISPATCH_COUNT,
353 DEF_PCAP_DISPATCH_COUNT);
355 /* Microseconds to sleep between pcap loop iterations
357 if(opts->config[CONF_PCAP_LOOP_SLEEP] == NULL)
358 set_config_entry(opts, CONF_PCAP_LOOP_SLEEP,
359 DEF_PCAP_LOOP_SLEEP);
363 if(opts->config[CONF_PCAP_FILTER] == NULL)
364 set_config_entry(opts, CONF_PCAP_FILTER, DEF_PCAP_FILTER);
366 /* Enable SPA packet aging.
368 if(opts->config[CONF_ENABLE_SPA_PACKET_AGING] == NULL)
369 set_config_entry(opts, CONF_ENABLE_SPA_PACKET_AGING,
370 DEF_ENABLE_SPA_PACKET_AGING);
374 if(opts->config[CONF_MAX_SPA_PACKET_AGE] == NULL)
375 set_config_entry(opts, CONF_MAX_SPA_PACKET_AGE,
376 DEF_MAX_SPA_PACKET_AGE);
379 /* Enable digest persistence.
381 if(opts->config[CONF_ENABLE_DIGEST_PERSISTENCE] == NULL)
382 set_config_entry(opts, CONF_ENABLE_DIGEST_PERSISTENCE,
383 DEF_ENABLE_DIGEST_PERSISTENCE);
387 if(opts->config[CONF_MAX_SNIFF_BYTES] == NULL)
388 set_config_entry(opts, CONF_MAX_SNIFF_BYTES, DEF_MAX_SNIFF_BYTES);
390 #if FIREWALL_IPTABLES
391 /* Enable IPT forwarding.
393 if(opts->config[CONF_ENABLE_IPT_FORWARDING] == NULL)
394 set_config_entry(opts, CONF_ENABLE_IPT_FORWARDING,
395 DEF_ENABLE_IPT_FORWARDING);
397 /* Enable IPT local NAT.
399 if(opts->config[CONF_ENABLE_IPT_LOCAL_NAT] == NULL)
400 set_config_entry(opts, CONF_ENABLE_IPT_LOCAL_NAT,
401 DEF_ENABLE_IPT_LOCAL_NAT);
405 if(opts->config[CONF_ENABLE_IPT_SNAT] == NULL)
406 set_config_entry(opts, CONF_ENABLE_IPT_SNAT,
407 DEF_ENABLE_IPT_SNAT);
409 /* Enable IPT OUTPUT.
411 if(opts->config[CONF_ENABLE_IPT_OUTPUT] == NULL)
412 set_config_entry(opts, CONF_ENABLE_IPT_OUTPUT,
413 DEF_ENABLE_IPT_OUTPUT);
415 /* Flush IPT at init.
417 if(opts->config[CONF_FLUSH_IPT_AT_INIT] == NULL)
418 set_config_entry(opts, CONF_FLUSH_IPT_AT_INIT, DEF_FLUSH_IPT_AT_INIT);
420 /* Flush IPT at exit.
422 if(opts->config[CONF_FLUSH_IPT_AT_EXIT] == NULL)
423 set_config_entry(opts, CONF_FLUSH_IPT_AT_EXIT, DEF_FLUSH_IPT_AT_EXIT);
427 if(opts->config[CONF_IPT_INPUT_ACCESS] == NULL)
428 set_config_entry(opts, CONF_IPT_INPUT_ACCESS,
429 DEF_IPT_INPUT_ACCESS);
431 /* IPT output access.
433 if(opts->config[CONF_IPT_OUTPUT_ACCESS] == NULL)
434 set_config_entry(opts, CONF_IPT_OUTPUT_ACCESS,
435 DEF_IPT_OUTPUT_ACCESS);
437 /* IPT forward access.
439 if(opts->config[CONF_IPT_FORWARD_ACCESS] == NULL)
440 set_config_entry(opts, CONF_IPT_FORWARD_ACCESS,
441 DEF_IPT_FORWARD_ACCESS);
445 if(opts->config[CONF_IPT_DNAT_ACCESS] == NULL)
446 set_config_entry(opts, CONF_IPT_DNAT_ACCESS,
447 DEF_IPT_DNAT_ACCESS);
451 if(opts->config[CONF_IPT_SNAT_ACCESS] == NULL)
452 set_config_entry(opts, CONF_IPT_SNAT_ACCESS,
453 DEF_IPT_SNAT_ACCESS);
455 /* IPT masquerade access.
457 if(opts->config[CONF_IPT_MASQUERADE_ACCESS] == NULL)
458 set_config_entry(opts, CONF_IPT_MASQUERADE_ACCESS,
459 DEF_IPT_MASQUERADE_ACCESS);
461 /* Check for the iptables 'comment' match at init time
463 if(opts->config[CONF_ENABLE_IPT_COMMENT_CHECK] == NULL)
464 set_config_entry(opts, CONF_ENABLE_IPT_COMMENT_CHECK,
465 DEF_ENABLE_IPT_COMMENT_CHECK);
469 /* Flush ipfw rules at init.
471 if(opts->config[CONF_FLUSH_IPFW_AT_INIT] == NULL)
472 set_config_entry(opts, CONF_FLUSH_IPFW_AT_INIT, DEF_FLUSH_IPFW_AT_INIT);
474 /* Flush ipfw rules at exit.
476 if(opts->config[CONF_FLUSH_IPFW_AT_EXIT] == NULL)
477 set_config_entry(opts, CONF_FLUSH_IPFW_AT_EXIT, DEF_FLUSH_IPFW_AT_EXIT);
479 /* Set IPFW start rule number.
481 if(opts->config[CONF_IPFW_START_RULE_NUM] == NULL)
482 set_config_entry(opts, CONF_IPFW_START_RULE_NUM,
483 DEF_IPFW_START_RULE_NUM);
485 /* Set IPFW max rules.
487 if(opts->config[CONF_IPFW_MAX_RULES] == NULL)
488 set_config_entry(opts, CONF_IPFW_MAX_RULES,
491 /* Set IPFW active set number.
493 if(opts->config[CONF_IPFW_ACTIVE_SET_NUM] == NULL)
494 set_config_entry(opts, CONF_IPFW_ACTIVE_SET_NUM,
495 DEF_IPFW_ACTIVE_SET_NUM);
497 /* Set IPFW expire set number.
499 if(opts->config[CONF_IPFW_EXPIRE_SET_NUM] == NULL)
500 set_config_entry(opts, CONF_IPFW_EXPIRE_SET_NUM,
501 DEF_IPFW_EXPIRE_SET_NUM);
503 /* Set IPFW Dynamic rule expiry interval.
505 if(opts->config[CONF_IPFW_EXPIRE_PURGE_INTERVAL] == NULL)
506 set_config_entry(opts, CONF_IPFW_EXPIRE_PURGE_INTERVAL,
507 DEF_IPFW_EXPIRE_PURGE_INTERVAL);
509 /* Set IPFW Dynamic rule expiry interval.
511 if(opts->config[CONF_IPFW_ADD_CHECK_STATE] == NULL)
512 set_config_entry(opts, CONF_IPFW_ADD_CHECK_STATE,
513 DEF_IPFW_ADD_CHECK_STATE);
516 /* Set PF anchor name
518 if(opts->config[CONF_PF_ANCHOR_NAME] == NULL)
519 set_config_entry(opts, CONF_PF_ANCHOR_NAME,
522 /* Set PF rule expiry interval.
524 if(opts->config[CONF_PF_EXPIRE_INTERVAL] == NULL)
525 set_config_entry(opts, CONF_PF_EXPIRE_INTERVAL,
526 DEF_PF_EXPIRE_INTERVAL);
529 /* --DSS Place-holder */
531 #endif /* FIREWALL type */
535 if(opts->config[CONF_GPG_HOME_DIR] == NULL)
536 set_config_entry(opts, CONF_GPG_HOME_DIR, DEF_GPG_HOME_DIR);
538 /* Enable SPA over HTTP.
540 if(opts->config[CONF_ENABLE_SPA_OVER_HTTP] == NULL)
541 set_config_entry(opts, CONF_ENABLE_SPA_OVER_HTTP,
542 DEF_ENABLE_SPA_OVER_HTTP);
544 /* Enable TCP server.
546 if(opts->config[CONF_ENABLE_TCP_SERVER] == NULL)
547 set_config_entry(opts, CONF_ENABLE_TCP_SERVER, DEF_ENABLE_TCP_SERVER);
551 if(opts->config[CONF_TCPSERV_PORT] == NULL)
552 set_config_entry(opts, CONF_TCPSERV_PORT, DEF_TCPSERV_PORT);
556 if(opts->config[CONF_SYSLOG_IDENTITY] == NULL)
557 set_config_entry(opts, CONF_SYSLOG_IDENTITY, DEF_SYSLOG_IDENTITY);
561 if(opts->config[CONF_SYSLOG_FACILITY] == NULL)
562 set_config_entry(opts, CONF_SYSLOG_FACILITY, DEF_SYSLOG_FACILITY);
565 /* Validate integer variable ranges
567 validate_int_var_ranges(opts);
569 /* Some options just trigger some output of information, or trigger an
570 * external function, but do not actually start fwknopd. If any of those
571 * are set, we can return here an skip the validation routines as all
572 * other options will be ignored anyway.
574 * These are also mutually exclusive (for now).
576 if((opts->dump_config + opts->kill + opts->restart + opts->status) == 1)
579 if((opts->dump_config + opts->kill + opts->restart + opts->status) > 1)
582 "The -D, -K, -R, and -S options are mutually exclusive. Pick only one.\n"
584 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
587 if(opts->config[CONF_FIREWALL_EXE] == NULL)
590 "No firewall command executable is set. Please check FIREWALL_EXE in fwknopd.conf.\n"
592 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
599 set_preconfig_entries(fko_srv_options_t *opts)
601 /* First, set any default or otherwise static settings here. Some may
602 * end up being overwritten via config file or command-line.
605 /* Setup the firewall executable based on build-time info.
606 * --DSS Note: We will want to either force external script mode, or
607 * error out if we do not have a firewall executable defined.
610 set_config_entry(opts, CONF_FIREWALL_EXE, FIREWALL_EXE);
615 /* Initialize program configuration via config file and/or command-line
619 config_init(fko_srv_options_t *opts, int argc, char **argv)
622 unsigned char got_conf_file = 0, got_override_config = 0;
624 char override_file[MAX_LINE_LEN];
627 /* Zero out options and opts_track.
629 memset(opts, 0x00, sizeof(fko_srv_options_t));
631 /* Set some preconfiguration options (i.e. build-time defaults)
633 set_preconfig_entries(opts);
635 /* In case this is a re-config.
639 /* First, scan the command-line args for -h/--help or an alternate
640 * configuration file. If we find an alternate config file, use it,
641 * otherwise use the default. We also grab any override config files
644 while ((cmd_arg = getopt_long(argc, argv,
645 GETOPTS_OPTION_STRING, cmd_opts, &index)) != -1) {
647 /* If help is wanted, give it and exit.
652 clean_exit(opts, NO_FW_CLEANUP, EXIT_SUCCESS);
655 /* Look for configuration file arg.
658 set_config_entry(opts, CONF_CONFIG_FILE, optarg);
661 /* If we already have the config_override option, we are done.
663 if(got_override_config > 0)
666 /* Look for override configuration file arg.
669 set_config_entry(opts, CONF_OVERRIDE_CONFIG, optarg);
670 got_override_config++;
672 /* If we already have the conf_file option, we are done.
674 if(got_conf_file > 0)
679 /* If no alternate configuration file was specified, we use the
682 if(opts->config[CONF_CONFIG_FILE] == NULL)
683 set_config_entry(opts, CONF_CONFIG_FILE, DEF_CONFIG_FILE);
685 /* Parse configuration file to populate any params not already specified
686 * via command-line options.
688 parse_config_file(opts, opts->config[CONF_CONFIG_FILE]);
690 /* If there are override configuration entries, process them
693 if(opts->config[CONF_OVERRIDE_CONFIG] != NULL)
695 /* Make a copy of the override_config string so we can munge it.
697 strlcpy(override_file, opts->config[CONF_OVERRIDE_CONFIG], MAX_LINE_LEN);
700 cmrk = strchr(ndx, ',');
704 /* Only one to process...
706 parse_config_file(opts, ndx);
709 /* Walk the string pulling the next config override
710 * at the comma delimiters.
712 while(cmrk != NULL) {
714 parse_config_file(opts, ndx);
716 cmrk = strchr(ndx, ',');
719 /* Process the last entry
721 parse_config_file(opts, ndx);
725 /* Reset the options index so we can run through them again.
729 /* Last, but not least, we process command-line options (some of which
730 * may override configuration file options.
732 while ((cmd_arg = getopt_long(argc, argv,
733 GETOPTS_OPTION_STRING, cmd_opts, &index)) != -1) {
737 set_config_entry(opts, CONF_ACCESS_FILE, optarg);
740 /* This was handled earlier */
743 opts->packet_ctr_limit = atoi(optarg);
747 set_config_entry(opts, CONF_DIGEST_FILE, optarg);
749 set_config_entry(opts, CONF_DIGEST_DB_FILE, optarg);
753 opts->dump_config = 1;
756 opts->foreground = 1;
763 opts->fw_list_all = 1;
769 if (is_valid_dir(optarg))
771 set_config_entry(opts, CONF_GPG_HOME_DIR, optarg);
776 "[*] Directory '%s' could not stat()/does not exist?\n",
778 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
782 set_config_entry(opts, CONF_PCAP_INTF, optarg);
788 set_config_entry(opts, CONF_LOCALE, optarg);
791 /* This was handled earlier */
794 set_config_entry(opts, CONF_FWKNOP_PID_FILE, optarg);
797 set_config_entry(opts, CONF_PCAP_FILTER, optarg);
799 case ROTATE_DIGEST_CACHE:
800 opts->rotate_digest_cache = 1;
812 fprintf(stdout, "fwknopd server %s\n", MY_VERSION);
813 clean_exit(opts, NO_FW_CLEANUP, EXIT_SUCCESS);
817 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
821 /* Now that we have all of our options set, and we are actually going to
822 * start fwknopd, we can validate them.
824 validate_options(opts);
829 /* Dump the configuration
832 dump_config(const fko_srv_options_t *opts)
836 fprintf(stdout, "Current fwknopd config settings:\n");
838 for(i=0; i<NUMBER_OF_CONFIG_ENTRIES; i++)
839 fprintf(stdout, "%3i. %-28s = '%s'\n",
842 (opts->config[i] == NULL) ? "<not set>" : opts->config[i]
845 fprintf(stdout, "\n");
849 /* Print usage message...
854 fprintf(stdout, "\n%s server version %s\n%s\n\n", MY_NAME, MY_VERSION, MY_DESC);
856 "Usage: fwknopd [options]\n\n"
857 " -h, --help - Print this usage message and exit.\n"
858 " -a, --access-file - Specify an alternate access.conf file.\n"
859 " -c, --config-file - Specify an alternate configuration file.\n"
860 " -C, --packet-limit - Limit the number of candidate SPA packets to\n"
861 " process and exit when this limit is reached.\n"
862 " -d, --digest-file - Specify an alternate digest.cache file.\n"
863 " -D, --dump-config - Dump the current fwknop configuration values.\n"
864 " -f, --foreground - Run fwknopd in the foreground (do not become\n"
865 " a background daemon).\n"
866 " -i, --interface - Specify interface to listen for incoming SPA\n"
868 " -K, --kill - Kill the currently running fwknopd.\n"
869 " --gpg-home-dir - Specify the GPG home directory.\n"
870 " -l, --locale - Provide a locale setting other than the system\n"
872 " -O, --override-config - Specify a file with configuration entries that will\n"
873 " overide those in fwknopd.conf\n"
874 " -p, --pid-file - Specify an alternate fwknopd.pid file.\n"
875 " -P, --pcap-filter - Specify a Berkeley packet filter statement to\n"
876 " override the PCAP_FILTER variable in fwknopd.conf.\n"
877 " -R, --restart - Force the currently running fwknopd to restart.\n"
878 " --rotate-digest-cache\n"
879 " - Rotate the digest cache file by renaming it to\n"
880 " '<name>-old', and starting a new one.\n"
881 " -S, --status - Display the status of any running fwknopd process.\n"
882 " -v, --verbose - Set verbose mode.\n"
883 " -V, --version - Print version number.\n"
884 " --fw-list - List all firewall rules that fwknop has created\n"
886 " --fw-list-all - List all firewall rules in the complete policy,\n"
887 " including those that have nothing to do with\n"
889 " --fw-flush - Flush all firewall rules created by fwknop.\n"