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(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"
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 "Error parsing IP to int for: %s", ip_str
261 /* Store our mask converted from CIDR to a 32-bit value.
263 new_sle->mask = (0xFFFFFFFF << (32 - mask));
265 /* Store our masked address for comparisons with future incoming
268 new_sle->maddr = ntohl(in.s_addr) & new_sle->mask;
272 /* Expand the access SOURCE string to a list of masks.
275 expand_acc_source(acc_stanza_t *acc)
282 for(ndx = start; *ndx; ndx++)
286 /* Skip over any leading whitespace.
288 while(isspace(*start))
291 strlcpy(buf, start, (ndx-start)+1);
292 add_source_mask(acc, buf);
297 /* Skip over any leading whitespace (once again for the last in the list).
299 while(isspace(*start))
302 strlcpy(buf, start, (ndx-start)+1);
303 add_source_mask(acc, buf);
307 parse_proto_and_port(char *pstr, int *proto, int *port)
312 /* Parse the string into its components.
314 if((ndx = strchr(pstr, '/')) == NULL)
317 "Parse error on access port entry: %s", pstr);
322 strlcpy(proto_str, pstr, (ndx - pstr)+1);
326 if(strcasecmp(proto_str, "tcp") == 0)
328 else if(strcasecmp(proto_str, "udp") == 0)
333 "Invalid protocol in access port entry: %s", pstr);
341 /* Take a proto/port string and convert it to appropriate integer values
342 * for comparisons of incoming SPA requests.
345 add_port_list_ent(acc_port_list_t **plist, char *port_str)
349 acc_port_list_t *last_plist, *new_plist, *tmp_plist;
351 /* Parse the string into its components and continue only if there
352 * are no problems with the incoming string.
354 if(parse_proto_and_port(port_str, &proto_int, &port) != 0)
357 if((new_plist = calloc(1, sizeof(acc_port_list_t))) == NULL)
360 "Fatal memory allocation error adding stanza source_list entry"
365 /* If this is not the first entry, we walk our pointer to the
377 last_plist = tmp_plist;
378 } while((tmp_plist = tmp_plist->next));
380 last_plist->next = new_plist;
383 new_plist->proto = proto_int;
384 new_plist->port = port;
387 /* Add a string list entry to the given acc_string_list.
390 add_string_list_ent(acc_string_list_t **stlist, const char *str_str)
392 acc_string_list_t *last_stlist, *new_stlist, *tmp_stlist;
394 if((new_stlist = calloc(1, sizeof(acc_string_list_t))) == NULL)
397 "Fatal memory allocation error creating string list entry"
402 /* If this is not the first entry, we walk our pointer to the
407 *stlist = new_stlist;
411 tmp_stlist = *stlist;
414 last_stlist = tmp_stlist;
415 } while((tmp_stlist = tmp_stlist->next));
417 last_stlist->next = new_stlist;
420 new_stlist->str = strdup(str_str);
422 if(new_stlist->str == NULL)
425 "Fatal memory allocation error adding string list entry item"
432 /* Expand a proto/port access string to a list of access proto-port struct.
435 expand_acc_port_list(acc_port_list_t **plist, char *plist_str)
442 for(ndx = start; *ndx; ndx++)
446 /* Skip over any leading whitespace.
448 while(isspace(*start))
451 strlcpy(buf, start, (ndx-start)+1);
452 add_port_list_ent(plist, buf);
457 /* Skip over any leading whitespace (once again for the last in the list).
459 while(isspace(*start))
462 strlcpy(buf, start, (ndx-start)+1);
464 add_port_list_ent(plist, buf);
467 /* Expand a comma-separated string into a simple acc_string_list.
470 expand_acc_string_list(acc_string_list_t **stlist, char *stlist_str)
477 for(ndx = start; *ndx; ndx++)
481 /* Skip over any leading whitespace.
483 while(isspace(*start))
486 strlcpy(buf, start, (ndx-start)+1);
487 add_string_list_ent(stlist, buf);
492 /* Skip over any leading whitespace (once again for the last in the list).
494 while(isspace(*start))
497 strlcpy(buf, start, (ndx-start)+1);
499 add_string_list_ent(stlist, buf);
502 /* Free the acc source_list
505 free_acc_source_list(acc_int_list_t *sle)
507 acc_int_list_t *last_sle;
512 sle = last_sle->next;
521 free_acc_port_list(acc_port_list_t *ple)
523 acc_port_list_t *last_ple;
528 ple = last_ple->next;
534 /* Free a string_list
537 free_acc_string_list(acc_string_list_t *stl)
539 acc_string_list_t *last_stl;
544 stl = last_stl->next;
551 /* Free any allocated content of an access stanza.
553 * NOTE: If a new access.conf parameter is created, and it is a string
554 * value, it also needs to be added to the list of items to check
558 free_acc_stanza_data(acc_stanza_t *acc)
561 if(acc->source != NULL)
564 free_acc_source_list(acc->source_list);
567 if(acc->open_ports != NULL)
569 free(acc->open_ports);
570 free_acc_port_list(acc->oport_list);
573 if(acc->restrict_ports != NULL)
575 free(acc->restrict_ports);
576 free_acc_port_list(acc->rport_list);
579 if(acc->force_nat_ip != NULL)
580 free(acc->force_nat_ip);
585 if(acc->cmd_exec_user != NULL)
586 free(acc->cmd_exec_user);
588 if(acc->require_username != NULL)
589 free(acc->require_username);
591 if(acc->gpg_home_dir != NULL)
592 free(acc->gpg_home_dir);
594 if(acc->gpg_decrypt_id != NULL)
595 free(acc->gpg_decrypt_id);
597 if(acc->gpg_decrypt_pw != NULL)
598 free(acc->gpg_decrypt_pw);
600 if(acc->gpg_remote_id != NULL)
602 free(acc->gpg_remote_id);
603 free_acc_string_list(acc->gpg_remote_id_list);
607 /* Expand any access entries that may be multi-value.
610 expand_acc_ent_lists(fko_srv_options_t *opts)
612 acc_stanza_t *acc = opts->acc_stanzas;
614 /* We need to do this for each stanza.
618 /* Expand the source string to 32-bit integer masks foreach entry.
620 expand_acc_source(acc);
622 /* Now expand the open_ports string.
624 if(acc->open_ports != NULL && strlen(acc->open_ports))
625 expand_acc_port_list(&(acc->oport_list), acc->open_ports);
627 if(acc->restrict_ports != NULL && strlen(acc->restrict_ports))
628 expand_acc_port_list(&(acc->rport_list), acc->restrict_ports);
630 /* Expand the GPG_REMOTE_ID string.
632 if(acc->gpg_remote_id != NULL && strlen(acc->gpg_remote_id))
633 expand_acc_string_list(&(acc->gpg_remote_id_list), acc->gpg_remote_id);
640 free_acc_stanzas(fko_srv_options_t *opts)
642 acc_stanza_t *acc, *last_acc;
644 /* Free any resources first (in case of reconfig). Assume non-NULL
645 * entry needs to be freed.
647 acc = opts->acc_stanzas;
652 acc = last_acc->next;
654 free_acc_stanza_data(last_acc);
661 /* Wrapper for free_acc_stanzas(), we may put additional initialization
665 acc_stanza_init(fko_srv_options_t *opts)
667 /* Free any resources first (in case of reconfig). Assume non-NULL
668 * entry needs to be freed.
670 free_acc_stanzas(opts);
675 /* Add a new stanza bay allocating the required memory at the required
676 * location, yada-yada-yada.
679 acc_stanza_add(fko_srv_options_t *opts)
681 acc_stanza_t *acc = opts->acc_stanzas;
682 acc_stanza_t *new_acc = calloc(1, sizeof(acc_stanza_t));
683 acc_stanza_t *last_acc;
688 "Fatal memory allocation error adding access stanza"
690 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
693 /* If this is not the first acc entry, we walk our acc pointer to the
694 * end of the existing list.
698 opts->acc_stanzas = new_acc;
704 } while((acc = acc->next));
706 last_acc->next = new_acc;
712 /* Scan the access options for entries that have not bees set, but need
716 set_acc_defaults(fko_srv_options_t *opts)
718 acc_stanza_t *acc = opts->acc_stanzas;
725 /* set default fw_access_timeout if necessary
727 if(acc->fw_access_timeout < 1)
728 acc->fw_access_timeout = DEF_FW_ACCESS_TIMEOUT;
730 /* set default gpg keyring path if necessary
732 if(acc->gpg_decrypt_pw != NULL)
734 acc->encryption_mode = FKO_ENC_MODE_ASYMMETRIC;
735 if(acc->gpg_home_dir == NULL)
736 add_acc_string(&(acc->gpg_home_dir), opts->config[CONF_GPG_HOME_DIR]);
739 if (acc->encryption_mode == FKO_ENC_MODE_UNKNOWN)
740 acc->encryption_mode = FKO_DEFAULT_ENC_MODE;
746 /* Perform some sanity checks on an acc stanza data.
749 acc_data_is_valid(const acc_stanza_t *acc)
751 if((acc->key == NULL || !strlen(acc->key))
752 && (acc->gpg_decrypt_pw == NULL || !strlen(acc->gpg_decrypt_pw)))
755 "[*] No keys found for access stanza source: '%s'\n", acc->source
763 /* Read and parse the access file, popluating the access data as we go.
766 parse_access_file(fko_srv_options_t *opts)
771 unsigned int num_lines = 0;
773 char access_line_buf[MAX_LINE_LEN] = {0};
774 char var[MAX_LINE_LEN] = {0};
775 char val[MAX_LINE_LEN] = {0};
780 acc_stanza_t *curr_acc = NULL;
782 /* First see if the access file exists. If it doesn't, complain
785 if(stat(opts->config[CONF_ACCESS_FILE], &st) != 0)
787 fprintf(stderr, "[*] Access file: '%s' was not found.\n",
788 opts->config[CONF_ACCESS_FILE]);
790 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
793 if ((file_ptr = fopen(opts->config[CONF_ACCESS_FILE], "r")) == NULL)
795 fprintf(stderr, "[*] Could not open access file: %s\n",
796 opts->config[CONF_ACCESS_FILE]);
799 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
802 /* Initialize the access list.
804 acc_stanza_init(opts);
806 /* Now walk through access file pulling the access entries into the
809 while ((fgets(access_line_buf, MAX_LINE_LEN, file_ptr)) != NULL)
812 access_line_buf[MAX_LINE_LEN-1] = '\0';
814 /* Get past comments and empty lines (note: we only look at the
817 if(IS_EMPTY_LINE(access_line_buf[0]))
820 if(sscanf(access_line_buf, "%s %[^;\n\r]", var, val) != 2)
823 "*Invalid access file entry in %s at line %i.\n - '%s'",
824 opts->config[CONF_ACCESS_FILE], num_lines, access_line_buf
829 /* Remove any colon that may be on the end of the var
831 if((ndx = strrchr(var, ':')) != NULL)
836 if(opts->verbose > 3)
838 "ACCESS FILE: %s, LINE: %s\tVar: %s, Val: '%s'\n",
839 opts->config[CONF_ACCESS_FILE], access_line_buf, var, val
842 /* Process the entry.
844 * NOTE: If a new access.conf parameter is created. It also needs
845 * to be accounted for in the following if/if else construct.
848 if(CONF_VAR_IS(var, "SOURCE"))
850 /* If this is not the first stanza, sanity check the previous
851 * stanza for the minimum required data.
853 if(curr_acc != NULL) {
854 if(!acc_data_is_valid(curr_acc))
857 "[*] Data error in access file: '%s'\n",
858 opts->config[CONF_ACCESS_FILE]);
859 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
865 curr_acc = acc_stanza_add(opts);
867 add_acc_string(&(curr_acc->source), val);
871 else if (curr_acc == NULL)
873 /* The stanza must start with the "SOURCE" variable
877 else if(CONF_VAR_IS(var, "OPEN_PORTS"))
879 add_acc_string(&(curr_acc->open_ports), val);
881 else if(CONF_VAR_IS(var, "RESTRICT_PORTS"))
883 add_acc_string(&(curr_acc->restrict_ports), val);
885 else if(CONF_VAR_IS(var, "KEY"))
887 if(strcasecmp(val, "__CHANGEME__") == 0)
890 "[*] KEY value is not properly set in stanza source '%s' in access file: '%s'\n",
891 curr_acc->source, opts->config[CONF_ACCESS_FILE]);
892 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
894 add_acc_string(&(curr_acc->key), val);
896 else if(CONF_VAR_IS(var, "FW_ACCESS_TIMEOUT"))
898 add_acc_int(&(curr_acc->fw_access_timeout), val);
900 else if(CONF_VAR_IS(var, "ENCRYPTION_MODE"))
902 if((curr_acc->encryption_mode = enc_mode_strtoint(val)) < 0)
905 "[*] Unrecognized ENCRYPTION_MODE '%s', use {cbc,ecb}\n",
907 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
910 else if(CONF_VAR_IS(var, "ENABLE_CMD_EXEC"))
912 add_acc_bool(&(curr_acc->enable_cmd_exec), val);
914 else if(CONF_VAR_IS(var, "CMD_EXEC_USER"))
916 add_acc_string(&(curr_acc->cmd_exec_user), val);
923 fprintf(stderr, "Unable to determine UID for CMD_EXEC_USER: %s.\n",
924 errno ? strerror(errno) : "Not a user on this system");
925 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
928 curr_acc->cmd_exec_uid = pw->pw_uid;
930 else if(CONF_VAR_IS(var, "REQUIRE_USERNAME"))
932 add_acc_string(&(curr_acc->require_username), val);
934 else if(CONF_VAR_IS(var, "REQUIRE_SOURCE_ADDRESS"))
936 add_acc_bool(&(curr_acc->require_source_address), val);
938 else if(CONF_VAR_IS(var, "REQUIRE_SOURCE")) /* synonym for REQUIRE_SOURCE_ADDRESS */
940 add_acc_bool(&(curr_acc->require_source_address), val);
942 else if(CONF_VAR_IS(var, "GPG_HOME_DIR"))
944 if (is_valid_dir(val))
946 add_acc_string(&(curr_acc->gpg_home_dir), val);
951 "[*] GPG_HOME_DIR directory '%s' stat()/existence problem in stanza source '%s' in access file: '%s'\n",
952 val, curr_acc->source, opts->config[CONF_ACCESS_FILE]);
953 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
956 else if(CONF_VAR_IS(var, "GPG_DECRYPT_ID"))
958 add_acc_string(&(curr_acc->gpg_decrypt_id), val);
960 else if(CONF_VAR_IS(var, "GPG_DECRYPT_PW"))
962 if(strcasecmp(val, "__CHANGEME__") == 0)
965 "[*] GPG_DECRYPT_PW value is not properly set in stanza source '%s' in access file: '%s'\n",
966 curr_acc->source, opts->config[CONF_ACCESS_FILE]);
967 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
969 add_acc_string(&(curr_acc->gpg_decrypt_pw), val);
971 else if(CONF_VAR_IS(var, "GPG_REQUIRE_SIG"))
973 add_acc_bool(&(curr_acc->gpg_require_sig), val);
975 else if(CONF_VAR_IS(var, "GPG_IGNORE_SIG_VERIFY_ERROR"))
977 add_acc_bool(&(curr_acc->gpg_ignore_sig_error), val);
979 else if(CONF_VAR_IS(var, "GPG_REMOTE_ID"))
981 add_acc_string(&(curr_acc->gpg_remote_id), val);
983 else if(CONF_VAR_IS(var, "ACCESS_EXPIRE"))
985 add_acc_expire_time(opts, &(curr_acc->access_expire_time), val);
987 else if(CONF_VAR_IS(var, "ACCESS_EXPIRE_EPOCH"))
989 add_acc_expire_time_epoch(opts, &(curr_acc->access_expire_time), val);
991 else if(CONF_VAR_IS(var, "FORCE_NAT"))
993 #if FIREWALL_IPTABLES
994 if(strncasecmp(opts->config[CONF_ENABLE_IPT_FORWARDING], "Y", 1) !=0 )
997 "[*] FORCE_NAT requires ENABLE_IPT_FORWARDING to be enabled in fwknopd.conf\n");
998 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1000 add_acc_force_nat(opts, curr_acc, val);
1003 "[*] FORCE_NAT not supported.\n");
1004 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1010 "*Ignoring unknown access parameter: '%s' in %s\n",
1011 var, opts->config[CONF_ACCESS_FILE]
1018 /* Basic check to ensure that we got at least one SOURCE stanza with
1019 * a valid KEY defined (valid meaning it has a value that is not
1022 if (got_source == 0)
1025 "[*] Could not find valid SOURCE stanza in access file: '%s'\n",
1026 opts->config[CONF_ACCESS_FILE]);
1027 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1030 /* Sanity check the last stanza
1032 if(!acc_data_is_valid(curr_acc))
1035 "[*] Data error in access file: '%s'\n",
1036 opts->config[CONF_ACCESS_FILE]);
1037 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1040 /* Expand our the expandable fields into their respective data buckets.
1043 expand_acc_ent_lists(opts);
1045 /* Make sure default values are set where needed.
1047 set_acc_defaults(opts);
1053 compare_addr_list(acc_int_list_t *source_list, const uint32_t ip)
1059 if((ip & source_list->mask) == (source_list->maddr & source_list->mask))
1065 source_list = source_list->next;
1071 /* Compare the contents of 2 port lists. Return true on a match.
1072 * Match depends on the match_any flag. if match_any is 1 then any
1073 * entry in the incoming data need only match one item to return true.
1074 * Otherwise all entries in the incoming data must have a corresponding
1075 * match in the access port_list.
1078 compare_port_list(acc_port_list_t *in, acc_port_list_t *ac, const int match_any)
1083 acc_port_list_t *tlist;
1091 if(in->proto == tlist->proto && in->port == tlist->port)
1097 tlist = tlist->next;
1102 return(i_cnt == a_cnt);
1105 /* Take a proto/port string (or mulitple comma-separated strings) and check
1106 * them against the list for the given access stanza.
1108 * Return 1 if we are allowed
1111 acc_check_port_access(acc_stanza_t *acc, char *port_str)
1118 acc_port_list_t *o_pl = acc->oport_list;
1119 acc_port_list_t *r_pl = acc->rport_list;
1121 acc_port_list_t *in_pl = NULL;
1125 /* Create our own internal port_list from the incoming SPA data
1128 for(ndx = start; *ndx; ndx++)
1132 strlcpy(buf, start, (ndx-start)+1);
1133 add_port_list_ent(&in_pl, buf);
1137 strlcpy(buf, start, (ndx-start)+1);
1138 add_port_list_ent(&in_pl, buf);
1143 "Unable to create acc_port_list from incoming data: %s", port_str
1148 /* Start with restricted ports (if any). Any match (even if only one
1149 * entry) means not allowed.
1151 if((acc->rport_list != NULL) && (compare_port_list(in_pl, r_pl, 1)))
1154 goto cleanup_and_bail;
1157 /* For open port list, all must match.
1159 if((acc->oport_list != NULL) && (!compare_port_list(in_pl, o_pl, 0)))
1163 free_acc_port_list(in_pl);
1167 /* Take a GPG ID string and check it against the list of allowed
1170 * Return 1 if we are allowed
1173 acc_check_gpg_remote_id(acc_stanza_t *acc, const char *gpg_id)
1175 acc_string_list_t *ndx;
1177 for(ndx = acc->gpg_remote_id_list; ndx != NULL; ndx=ndx->next)
1178 if(strcasecmp(ndx->str, gpg_id) == 0)
1184 /* Dump the configuration
1187 dump_access_list(const fko_srv_options_t *opts)
1191 acc_stanza_t *acc = opts->acc_stanzas;
1193 fprintf(stdout, "Current fwknopd access settings:\n");
1197 fprintf(stderr, "\n ** No Access Settings Defined **\n\n");
1205 "==============================================================\n"
1207 " RESTRICT_PORTS: %s\n"
1208 " KEY: <see the access.conf file>\n"
1209 " FW_ACCESS_TIMEOUT: %i\n"
1210 " ENABLE_CMD_EXEC: %s\n"
1211 " CMD_EXEC_USER: %s\n"
1212 " REQUIRE_USERNAME: %s\n"
1213 " REQUIRE_SOURCE_ADDRESS: %s\n"
1214 " ACCESS_EXPIRE: %s" /* asctime() adds a newline */
1215 " GPG_HOME_DIR: %s\n"
1216 " GPG_DECRYPT_ID: %s\n"
1217 " GPG_DECRYPT_PW: <see the access.conf file>\n"
1218 " GPG_REQUIRE_SIG: %s\n"
1219 "GPG_IGNORE_SIG_VERIFY_ERROR: %s\n"
1220 " GPG_REMOTE_ID: %s\n",
1223 (acc->open_ports == NULL) ? "<not set>" : acc->open_ports,
1224 (acc->restrict_ports == NULL) ? "<not set>" : acc->restrict_ports,
1225 //(acc->key == NULL) ? "<not set>" : acc->key,
1226 acc->fw_access_timeout,
1227 acc->enable_cmd_exec ? "Yes" : "No",
1228 (acc->cmd_exec_user == NULL) ? "<not set>" : acc->cmd_exec_user,
1229 (acc->require_username == NULL) ? "<not set>" : acc->require_username,
1230 acc->require_source_address ? "Yes" : "No",
1231 (acc->access_expire_time > 0) ? asctime(localtime(&acc->access_expire_time)) : "<not set>\n",
1232 (acc->gpg_home_dir == NULL) ? "<not set>" : acc->gpg_home_dir,
1233 (acc->gpg_decrypt_id == NULL) ? "<not set>" : acc->gpg_decrypt_id,
1234 //(acc->gpg_decrypt_pw == NULL) ? "<not set>" : acc->gpg_decrypt_pw,
1235 acc->gpg_require_sig ? "Yes" : "No",
1236 acc->gpg_ignore_sig_error ? "Yes" : "No",
1237 (acc->gpg_remote_id == NULL) ? "<not set>" : acc->gpg_remote_id
1240 fprintf(stdout, "\n");
1245 fprintf(stdout, "\n");