2 ******************************************************************************
6 * Author: Damien Stuart
8 * Purpose: Access.conf 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 ******************************************************************************
34 #include <sys/socket.h>
37 #include "fwknopd_common.h"
38 #include <arpa/inet.h>
44 /* Add an access string entry
47 add_acc_string(char **var, const char *val)
49 if((*var = strdup(val)) == NULL)
52 "Fatal memory allocation error adding access list entry: %s", var
58 /* Add an access int entry
61 add_acc_int(int *var, const char *val)
63 return(*var = atoi(val));
66 /* Add an access bool entry (unsigned char of 1 or 0)
69 add_acc_bool(unsigned char *var, const char *val)
71 return(*var = (strncasecmp(val, "Y", 1) == 0) ? 1 : 0);
74 /* Add expiration time - convert date to epoch seconds
77 add_acc_expire_time(fko_srv_options_t *opts, time_t *access_expire_time, const char *val)
81 memset(&tm, 0, sizeof(struct tm));
83 if (sscanf(val, "%2d/%2d/%4d", &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3)
87 "Fatal: invalid date value '%s' (need MM/DD/YYYY) for access stanza expiration time",
90 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
94 tm.tm_mon -= 1; /* 0-11 */
96 /* number of years since 1900
104 *access_expire_time = mktime(&tm);
109 /* Add expiration time via epoch seconds defined in access.conf
112 add_acc_expire_time_epoch(fko_srv_options_t *opts, time_t *access_expire_time, const char *val)
115 unsigned long expire_time = 0;
119 expire_time = (time_t) strtoul(val, &endptr, 10);
121 if (errno == ERANGE || (errno != 0 && expire_time == 0))
124 "Fatal: invalid epoch seconds value '%s' for access stanza expiration time",
127 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
130 *access_expire_time = (time_t) expire_time;
135 /* Convert an encryption_mode string to its integer value.
138 enc_mode_strtoint(const char *enc_mode_str)
140 if(strcasecmp(enc_mode_str, "cbc") == 0)
141 return(FKO_ENC_MODE_CBC);
142 else if(strcasecmp(enc_mode_str, "ecb") == 0)
143 return(FKO_ENC_MODE_ECB);
144 else if(strcasecmp(enc_mode_str, "cfb") == 0)
145 return(FKO_ENC_MODE_CFB);
146 else if(strcasecmp(enc_mode_str, "pcbc") == 0)
147 return(-1); /* not supported yet */
148 else if(strcasecmp(enc_mode_str, "ofb") == 0)
149 return(FKO_ENC_MODE_OFB);
150 else if(strcasecmp(enc_mode_str, "ctr") == 0)
151 return(FKO_ENC_MODE_CTR);
156 #if FIREWALL_IPTABLES
158 add_acc_force_nat(fko_srv_options_t *opts, acc_stanza_t *curr_acc, const char *val)
160 char ip_str[MAX_IPV4_STR_LEN] = {0};
162 if (sscanf(val, "%15s %5u", ip_str, &curr_acc->force_nat_port) != 2)
166 "Fatal: invalid FORCE_NAT arg '%s', need <IP> <PORT>",
169 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
172 if (curr_acc->force_nat_port > MAX_PORT)
175 "Fatal: invalid FORCE_NAT port '%d'", curr_acc->force_nat_port);
176 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
179 curr_acc->force_nat = 1;
180 add_acc_string(&(curr_acc->force_nat_ip), ip_str);
186 /* Take an IP or Subnet/Mask and convert it to mask for later
187 * comparisons of incoming source IPs against this mask.
190 add_source_mask(fko_srv_options_t *opts, acc_stanza_t *acc, const char *ip)
193 char ip_str[MAX_IPV4_STR_LEN] = {0};
198 acc_int_list_t *last_sle, *new_sle, *tmp_sle;
200 if((new_sle = calloc(1, sizeof(acc_int_list_t))) == NULL)
203 "Fatal memory allocation error adding stanza source_list entry"
205 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
208 /* If this is not the first entry, we walk our pointer to the
211 if(acc->source_list == NULL)
213 acc->source_list = new_sle;
217 tmp_sle = acc->source_list;
221 } while((tmp_sle = tmp_sle->next));
223 last_sle->next = new_sle;
226 /* Convert the IP data into the appropriate mask
228 if(strcasecmp(ip, "ANY") == 0)
230 new_sle->maddr = 0x0;
235 /* See if we have a subnet component. If so pull out the IP and
236 * mask values, then create the final mask value.
238 if((ndx = strchr(ip, '/')) != NULL)
241 strlcpy(ip_str, ip, (ndx-ip)+1);
246 strlcpy(ip_str, ip, strlen(ip)+1);
249 if(inet_aton(ip_str, &in) == 0)
252 "Fatal error parsing IP to int for: %s", ip_str
254 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
257 /* Store our mask converted from CIDR to a 32-bit value.
259 new_sle->mask = (0xFFFFFFFF << (32 - mask));
261 /* Store our masked address for comparisons with future incoming
264 new_sle->maddr = ntohl(in.s_addr) & new_sle->mask;
268 /* Expand the access SOURCE string to a list of masks.
271 expand_acc_source(fko_srv_options_t *opts, acc_stanza_t *acc)
278 for(ndx = start; *ndx; ndx++)
282 /* Skip over any leading whitespace.
284 while(isspace(*start))
287 strlcpy(buf, start, (ndx-start)+1);
288 add_source_mask(opts, acc, buf);
293 /* Skip over any leading whitespace (once again for the last in the list).
295 while(isspace(*start))
298 strlcpy(buf, start, (ndx-start)+1);
299 add_source_mask(opts, acc, buf);
303 parse_proto_and_port(char *pstr, int *proto, int *port)
308 /* Parse the string into its components.
310 if((ndx = strchr(pstr, '/')) == NULL)
313 "Parse error on access port entry: %s", pstr);
318 strlcpy(proto_str, pstr, (ndx - pstr)+1);
322 if(strcasecmp(proto_str, "tcp") == 0)
324 else if(strcasecmp(proto_str, "udp") == 0)
329 "Invalid protocol in access port entry: %s", pstr);
337 /* Take a proto/port string and convert it to appropriate integer values
338 * for comparisons of incoming SPA requests.
341 add_port_list_ent(acc_port_list_t **plist, char *port_str)
345 acc_port_list_t *last_plist, *new_plist, *tmp_plist;
347 /* Parse the string into its components and continue only if there
348 * are no problems with the incoming string.
350 if(parse_proto_and_port(port_str, &proto_int, &port) != 0)
353 if((new_plist = calloc(1, sizeof(acc_port_list_t))) == NULL)
356 "Fatal memory allocation error adding stanza source_list entry"
361 /* If this is not the first entry, we walk our pointer to the
373 last_plist = tmp_plist;
374 } while((tmp_plist = tmp_plist->next));
376 last_plist->next = new_plist;
379 new_plist->proto = proto_int;
380 new_plist->port = port;
383 /* Add a string list entry to the given acc_string_list.
386 add_string_list_ent(acc_string_list_t **stlist, const char *str_str)
388 acc_string_list_t *last_stlist, *new_stlist, *tmp_stlist;
390 if((new_stlist = calloc(1, sizeof(acc_string_list_t))) == NULL)
393 "Fatal memory allocation error creating string list entry"
398 /* If this is not the first entry, we walk our pointer to the
403 *stlist = new_stlist;
407 tmp_stlist = *stlist;
410 last_stlist = tmp_stlist;
411 } while((tmp_stlist = tmp_stlist->next));
413 last_stlist->next = new_stlist;
416 new_stlist->str = strdup(str_str);
418 if(new_stlist->str == NULL)
421 "Fatal memory allocation error adding string list entry item"
428 /* Expand a proto/port access string to a list of access proto-port struct.
431 expand_acc_port_list(acc_port_list_t **plist, char *plist_str)
438 for(ndx = start; *ndx; ndx++)
442 /* Skip over any leading whitespace.
444 while(isspace(*start))
447 strlcpy(buf, start, (ndx-start)+1);
448 add_port_list_ent(plist, buf);
453 /* Skip over any leading whitespace (once again for the last in the list).
455 while(isspace(*start))
458 strlcpy(buf, start, (ndx-start)+1);
460 add_port_list_ent(plist, buf);
463 /* Expand a comma-separated string into a simple acc_string_list.
466 expand_acc_string_list(acc_string_list_t **stlist, char *stlist_str)
473 for(ndx = start; *ndx; ndx++)
477 /* Skip over any leading whitespace.
479 while(isspace(*start))
482 strlcpy(buf, start, (ndx-start)+1);
483 add_string_list_ent(stlist, buf);
488 /* Skip over any leading whitespace (once again for the last in the list).
490 while(isspace(*start))
493 strlcpy(buf, start, (ndx-start)+1);
495 add_string_list_ent(stlist, buf);
498 /* Free the acc source_list
501 free_acc_source_list(acc_int_list_t *sle)
503 acc_int_list_t *last_sle;
508 sle = last_sle->next;
517 free_acc_port_list(acc_port_list_t *ple)
519 acc_port_list_t *last_ple;
524 ple = last_ple->next;
530 /* Free a string_list
533 free_acc_string_list(acc_string_list_t *stl)
535 acc_string_list_t *last_stl;
540 stl = last_stl->next;
547 /* Free any allocated content of an access stanza.
549 * NOTE: If a new access.conf parameter is created, and it is a string
550 * value, it also needs to be added to the list of items to check
554 free_acc_stanza_data(acc_stanza_t *acc)
557 if(acc->source != NULL)
560 free_acc_source_list(acc->source_list);
563 if(acc->open_ports != NULL)
565 free(acc->open_ports);
566 free_acc_port_list(acc->oport_list);
569 if(acc->restrict_ports != NULL)
571 free(acc->restrict_ports);
572 free_acc_port_list(acc->rport_list);
575 if(acc->force_nat_ip != NULL)
576 free(acc->force_nat_ip);
581 if(acc->cmd_exec_user != NULL)
582 free(acc->cmd_exec_user);
584 if(acc->require_username != NULL)
585 free(acc->require_username);
587 if(acc->gpg_home_dir != NULL)
588 free(acc->gpg_home_dir);
590 if(acc->gpg_decrypt_id != NULL)
591 free(acc->gpg_decrypt_id);
593 if(acc->gpg_decrypt_pw != NULL)
594 free(acc->gpg_decrypt_pw);
596 if(acc->gpg_remote_id != NULL)
598 free(acc->gpg_remote_id);
599 free_acc_string_list(acc->gpg_remote_id_list);
603 /* Expand any access entries that may be multi-value.
606 expand_acc_ent_lists(fko_srv_options_t *opts)
608 acc_stanza_t *acc = opts->acc_stanzas;
610 /* We need to do this for each stanza.
614 /* Expand the source string to 32-bit integer masks foreach entry.
616 expand_acc_source(opts, acc);
618 /* Now expand the open_ports string.
620 if(acc->open_ports != NULL && strlen(acc->open_ports))
621 expand_acc_port_list(&(acc->oport_list), acc->open_ports);
623 if(acc->restrict_ports != NULL && strlen(acc->restrict_ports))
624 expand_acc_port_list(&(acc->rport_list), acc->restrict_ports);
626 /* Expand the GPG_REMOTE_ID string.
628 if(acc->gpg_remote_id != NULL && strlen(acc->gpg_remote_id))
629 expand_acc_string_list(&(acc->gpg_remote_id_list), acc->gpg_remote_id);
636 free_acc_stanzas(fko_srv_options_t *opts)
638 acc_stanza_t *acc, *last_acc;
640 /* Free any resources first (in case of reconfig). Assume non-NULL
641 * entry needs to be freed.
643 acc = opts->acc_stanzas;
648 acc = last_acc->next;
650 free_acc_stanza_data(last_acc);
657 /* Wrapper for free_acc_stanzas(), we may put additional initialization
661 acc_stanza_init(fko_srv_options_t *opts)
663 /* Free any resources first (in case of reconfig). Assume non-NULL
664 * entry needs to be freed.
666 free_acc_stanzas(opts);
671 /* Add a new stanza bay allocating the required memory at the required
672 * location, yada-yada-yada.
675 acc_stanza_add(fko_srv_options_t *opts)
677 acc_stanza_t *acc = opts->acc_stanzas;
678 acc_stanza_t *new_acc = calloc(1, sizeof(acc_stanza_t));
679 acc_stanza_t *last_acc;
684 "Fatal memory allocation error adding access stanza"
686 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
689 /* If this is not the first acc entry, we walk our acc pointer to the
690 * end of the existing list.
694 opts->acc_stanzas = new_acc;
700 } while((acc = acc->next));
702 last_acc->next = new_acc;
708 /* Scan the access options for entries that have not bees set, but need
712 set_acc_defaults(fko_srv_options_t *opts)
714 acc_stanza_t *acc = opts->acc_stanzas;
721 /* set default fw_access_timeout if necessary
723 if(acc->fw_access_timeout < 1)
724 acc->fw_access_timeout = DEF_FW_ACCESS_TIMEOUT;
726 /* set default gpg keyring path if necessary
728 if(acc->gpg_decrypt_pw != NULL)
730 acc->encryption_mode = FKO_ENC_MODE_ASYMMETRIC;
731 if(acc->gpg_home_dir == NULL)
732 add_acc_string(&(acc->gpg_home_dir), opts->config[CONF_GPG_HOME_DIR]);
735 if (acc->encryption_mode == FKO_ENC_MODE_UNKNOWN)
736 acc->encryption_mode = FKO_DEFAULT_ENC_MODE;
742 /* Perform some sanity checks on an acc stanza data.
745 acc_data_is_valid(const acc_stanza_t *acc)
747 if((acc->key == NULL || !strlen(acc->key))
748 && (acc->gpg_decrypt_pw == NULL || !strlen(acc->gpg_decrypt_pw)))
751 "[*] No keys found for access stanza source: '%s'\n", acc->source
759 /* Read and parse the access file, popluating the access data as we go.
762 parse_access_file(fko_srv_options_t *opts)
767 unsigned int num_lines = 0;
769 char access_line_buf[MAX_LINE_LEN] = {0};
770 char var[MAX_LINE_LEN] = {0};
771 char val[MAX_LINE_LEN] = {0};
776 acc_stanza_t *curr_acc = NULL;
778 /* First see if the access file exists. If it doesn't, complain
781 if(stat(opts->config[CONF_ACCESS_FILE], &st) != 0)
783 fprintf(stderr, "[*] Access file: '%s' was not found.\n",
784 opts->config[CONF_ACCESS_FILE]);
786 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
789 if ((file_ptr = fopen(opts->config[CONF_ACCESS_FILE], "r")) == NULL)
791 fprintf(stderr, "[*] Could not open access file: %s\n",
792 opts->config[CONF_ACCESS_FILE]);
795 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
798 /* Initialize the access list.
800 acc_stanza_init(opts);
802 /* Now walk through access file pulling the access entries into the
805 while ((fgets(access_line_buf, MAX_LINE_LEN, file_ptr)) != NULL)
808 access_line_buf[MAX_LINE_LEN-1] = '\0';
810 /* Get past comments and empty lines (note: we only look at the
813 if(IS_EMPTY_LINE(access_line_buf[0]))
816 if(sscanf(access_line_buf, "%s %[^;\n\r]", var, val) != 2)
819 "*Invalid access file entry in %s at line %i.\n - '%s'",
820 opts->config[CONF_ACCESS_FILE], num_lines, access_line_buf
825 /* Remove any colon that may be on the end of the var
827 if((ndx = strrchr(var, ':')) != NULL)
832 if(opts->verbose > 3)
834 "ACCESS FILE: %s, LINE: %s\tVar: %s, Val: '%s'\n",
835 opts->config[CONF_ACCESS_FILE], access_line_buf, var, val
838 /* Process the entry.
840 * NOTE: If a new access.conf parameter is created. It also needs
841 * to be accounted for in the following if/if else construct.
844 if(CONF_VAR_IS(var, "SOURCE"))
846 /* If this is not the first stanza, sanity check the previous
847 * stanza for the minimum required data.
849 if(curr_acc != NULL) {
850 if(!acc_data_is_valid(curr_acc))
853 "[*] Data error in access file: '%s'\n",
854 opts->config[CONF_ACCESS_FILE]);
855 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
861 curr_acc = acc_stanza_add(opts);
863 add_acc_string(&(curr_acc->source), val);
867 else if (curr_acc == NULL)
869 /* The stanza must start with the "SOURCE" variable
873 else if(CONF_VAR_IS(var, "OPEN_PORTS"))
875 add_acc_string(&(curr_acc->open_ports), val);
877 else if(CONF_VAR_IS(var, "RESTRICT_PORTS"))
879 add_acc_string(&(curr_acc->restrict_ports), val);
881 else if(CONF_VAR_IS(var, "KEY"))
883 if(strcasecmp(val, "__CHANGEME__") == 0)
886 "[*] KEY value is not properly set in stanza source '%s' in access file: '%s'\n",
887 curr_acc->source, opts->config[CONF_ACCESS_FILE]);
888 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
890 add_acc_string(&(curr_acc->key), val);
892 else if(CONF_VAR_IS(var, "FW_ACCESS_TIMEOUT"))
894 add_acc_int(&(curr_acc->fw_access_timeout), val);
896 else if(CONF_VAR_IS(var, "ENCRYPTION_MODE"))
898 if((curr_acc->encryption_mode = enc_mode_strtoint(val)) < 0)
901 "[*] Unrecognized ENCRYPTION_MODE '%s', use {cbc,ecb}\n",
903 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
906 else if(CONF_VAR_IS(var, "ENABLE_CMD_EXEC"))
908 add_acc_bool(&(curr_acc->enable_cmd_exec), val);
910 else if(CONF_VAR_IS(var, "CMD_EXEC_USER"))
912 add_acc_string(&(curr_acc->cmd_exec_user), val);
919 fprintf(stderr, "Unable to determine UID for CMD_EXEC_USER: %s.\n",
920 errno ? strerror(errno) : "Not a user on this system");
921 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
924 curr_acc->cmd_exec_uid = pw->pw_uid;
926 else if(CONF_VAR_IS(var, "REQUIRE_USERNAME"))
928 add_acc_string(&(curr_acc->require_username), val);
930 else if(CONF_VAR_IS(var, "REQUIRE_SOURCE_ADDRESS"))
932 add_acc_bool(&(curr_acc->require_source_address), val);
934 else if(CONF_VAR_IS(var, "REQUIRE_SOURCE")) /* synonym for REQUIRE_SOURCE_ADDRESS */
936 add_acc_bool(&(curr_acc->require_source_address), val);
938 else if(CONF_VAR_IS(var, "GPG_HOME_DIR"))
940 if (is_valid_dir(val))
942 add_acc_string(&(curr_acc->gpg_home_dir), val);
947 "[*] GPG_HOME_DIR directory '%s' stat()/existence problem in stanza source '%s' in access file: '%s'\n",
948 val, curr_acc->source, opts->config[CONF_ACCESS_FILE]);
949 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
952 else if(CONF_VAR_IS(var, "GPG_DECRYPT_ID"))
954 add_acc_string(&(curr_acc->gpg_decrypt_id), val);
956 else if(CONF_VAR_IS(var, "GPG_DECRYPT_PW"))
958 if(strcasecmp(val, "__CHANGEME__") == 0)
961 "[*] GPG_DECRYPT_PW value is not properly set in stanza source '%s' in access file: '%s'\n",
962 curr_acc->source, opts->config[CONF_ACCESS_FILE]);
963 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
965 add_acc_string(&(curr_acc->gpg_decrypt_pw), val);
967 else if(CONF_VAR_IS(var, "GPG_REQUIRE_SIG"))
969 add_acc_bool(&(curr_acc->gpg_require_sig), val);
971 else if(CONF_VAR_IS(var, "GPG_IGNORE_SIG_VERIFY_ERROR"))
973 add_acc_bool(&(curr_acc->gpg_ignore_sig_error), val);
975 else if(CONF_VAR_IS(var, "GPG_REMOTE_ID"))
977 add_acc_string(&(curr_acc->gpg_remote_id), val);
979 else if(CONF_VAR_IS(var, "ACCESS_EXPIRE"))
981 add_acc_expire_time(opts, &(curr_acc->access_expire_time), val);
983 else if(CONF_VAR_IS(var, "ACCESS_EXPIRE_EPOCH"))
985 add_acc_expire_time_epoch(opts, &(curr_acc->access_expire_time), val);
987 else if(CONF_VAR_IS(var, "FORCE_NAT"))
989 #if FIREWALL_IPTABLES
990 if(strncasecmp(opts->config[CONF_ENABLE_IPT_FORWARDING], "Y", 1) !=0 )
993 "[*] FORCE_NAT requires ENABLE_IPT_FORWARDING to be enabled in fwknopd.conf\n");
994 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
996 add_acc_force_nat(opts, curr_acc, val);
999 "[*] FORCE_NAT not supported.\n");
1000 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1006 "*Ignoring unknown access parameter: '%s' in %s\n",
1007 var, opts->config[CONF_ACCESS_FILE]
1014 /* Basic check to ensure that we got at least one SOURCE stanza with
1015 * a valid KEY defined (valid meaning it has a value that is not
1018 if (got_source == 0)
1021 "[*] Could not find valid SOURCE stanza in access file: '%s'\n",
1022 opts->config[CONF_ACCESS_FILE]);
1023 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1026 /* Sanity check the last stanza
1028 if(!acc_data_is_valid(curr_acc))
1031 "[*] Data error in access file: '%s'\n",
1032 opts->config[CONF_ACCESS_FILE]);
1033 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1036 /* Expand our the expandable fields into their respective data buckets.
1039 expand_acc_ent_lists(opts);
1041 /* Make sure default values are set where needed.
1043 set_acc_defaults(opts);
1049 compare_addr_list(acc_int_list_t *source_list, const uint32_t ip)
1055 if((ip & source_list->mask) == (source_list->maddr & source_list->mask))
1061 source_list = source_list->next;
1067 /* Compare the contents of 2 port lists. Return true on a match.
1068 * Match depends on the match_any flag. if match_any is 1 then any
1069 * entry in the incoming data need only match one item to return true.
1070 * Otherwise all entries in the incoming data must have a corresponding
1071 * match in the access port_list.
1074 compare_port_list(acc_port_list_t *in, acc_port_list_t *ac, const int match_any)
1079 acc_port_list_t *tlist;
1087 if(in->proto == tlist->proto && in->port == tlist->port)
1093 tlist = tlist->next;
1098 return(i_cnt == a_cnt);
1101 /* Take a proto/port string (or mulitple comma-separated strings) and check
1102 * them against the list for the given access stanza.
1104 * Return 1 if we are allowed
1107 acc_check_port_access(acc_stanza_t *acc, char *port_str)
1114 acc_port_list_t *o_pl = acc->oport_list;
1115 acc_port_list_t *r_pl = acc->rport_list;
1117 acc_port_list_t *in_pl = NULL;
1121 /* Create our own internal port_list from the incoming SPA data
1124 for(ndx = start; *ndx; ndx++)
1128 strlcpy(buf, start, (ndx-start)+1);
1129 add_port_list_ent(&in_pl, buf);
1133 strlcpy(buf, start, (ndx-start)+1);
1134 add_port_list_ent(&in_pl, buf);
1139 "Unable to create acc_port_list from incoming data: %s", port_str
1144 /* Start with restricted ports (if any). Any match (even if only one
1145 * entry) means not allowed.
1147 if((acc->rport_list != NULL) && (compare_port_list(in_pl, r_pl, 1)))
1150 goto cleanup_and_bail;
1153 /* For open port list, all must match.
1155 if((acc->oport_list != NULL) && (!compare_port_list(in_pl, o_pl, 0)))
1159 free_acc_port_list(in_pl);
1163 /* Take a GPG ID string and check it against the list of allowed
1166 * Return 1 if we are allowed
1169 acc_check_gpg_remote_id(acc_stanza_t *acc, const char *gpg_id)
1171 acc_string_list_t *ndx;
1173 for(ndx = acc->gpg_remote_id_list; ndx != NULL; ndx=ndx->next)
1174 if(strcasecmp(ndx->str, gpg_id) == 0)
1180 /* Dump the configuration
1183 dump_access_list(const fko_srv_options_t *opts)
1187 acc_stanza_t *acc = opts->acc_stanzas;
1189 fprintf(stdout, "Current fwknopd access settings:\n");
1193 fprintf(stderr, "\n ** No Access Settings Defined **\n\n");
1201 "==============================================================\n"
1203 " RESTRICT_PORTS: %s\n"
1204 " KEY: <see the access.conf file>\n"
1205 " FW_ACCESS_TIMEOUT: %i\n"
1206 " ENABLE_CMD_EXEC: %s\n"
1207 " CMD_EXEC_USER: %s\n"
1208 " REQUIRE_USERNAME: %s\n"
1209 " REQUIRE_SOURCE_ADDRESS: %s\n"
1210 " ACCESS_EXPIRE: %s" /* asctime() adds a newline */
1211 " GPG_HOME_DIR: %s\n"
1212 " GPG_DECRYPT_ID: %s\n"
1213 " GPG_DECRYPT_PW: <see the access.conf file>\n"
1214 " GPG_REQUIRE_SIG: %s\n"
1215 "GPG_IGNORE_SIG_VERIFY_ERROR: %s\n"
1216 " GPG_REMOTE_ID: %s\n",
1219 (acc->open_ports == NULL) ? "<not set>" : acc->open_ports,
1220 (acc->restrict_ports == NULL) ? "<not set>" : acc->restrict_ports,
1221 //(acc->key == NULL) ? "<not set>" : acc->key,
1222 acc->fw_access_timeout,
1223 acc->enable_cmd_exec ? "Yes" : "No",
1224 (acc->cmd_exec_user == NULL) ? "<not set>" : acc->cmd_exec_user,
1225 (acc->require_username == NULL) ? "<not set>" : acc->require_username,
1226 acc->require_source_address ? "Yes" : "No",
1227 (acc->access_expire_time > 0) ? asctime(localtime(&acc->access_expire_time)) : "<not set>\n",
1228 (acc->gpg_home_dir == NULL) ? "<not set>" : acc->gpg_home_dir,
1229 (acc->gpg_decrypt_id == NULL) ? "<not set>" : acc->gpg_decrypt_id,
1230 //(acc->gpg_decrypt_pw == NULL) ? "<not set>" : acc->gpg_decrypt_pw,
1231 acc->gpg_require_sig ? "Yes" : "No",
1232 acc->gpg_ignore_sig_error ? "Yes" : "No",
1233 (acc->gpg_remote_id == NULL) ? "<not set>" : acc->gpg_remote_id
1236 fprintf(stdout, "\n");
1241 fprintf(stdout, "\n");