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)
52 if((*var = strdup(val)) == NULL)
55 "Fatal memory allocation error adding access list entry: %s", var
61 /* Add an access int entry
64 add_acc_int(int *var, const char *val)
66 return(*var = atoi(val));
69 /* Add an access bool entry (unsigned char of 1 or 0)
72 add_acc_bool(unsigned char *var, const char *val)
74 return(*var = (strncasecmp(val, "Y", 1) == 0) ? 1 : 0);
77 /* Add expiration time - convert date to epoch seconds
80 add_acc_expire_time(fko_srv_options_t *opts, time_t *access_expire_time, const char *val)
84 memset(&tm, 0, sizeof(struct tm));
86 if (sscanf(val, "%2d/%2d/%4d", &tm.tm_mon, &tm.tm_mday, &tm.tm_year) != 3)
90 "Fatal: invalid date value '%s' (need MM/DD/YYYY) for access stanza expiration time",
93 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
97 tm.tm_mon -= 1; /* 0-11 */
99 /* number of years since 1900
101 if(tm.tm_year > 1900)
107 *access_expire_time = mktime(&tm);
112 /* Add expiration time via epoch seconds defined in access.conf
115 add_acc_expire_time_epoch(fko_srv_options_t *opts, time_t *access_expire_time, const char *val)
118 unsigned long expire_time = 0;
122 expire_time = (time_t) strtoul(val, &endptr, 10);
124 if (errno == ERANGE || (errno != 0 && expire_time == 0))
127 "Fatal: invalid epoch seconds value '%s' for access stanza expiration time",
130 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
133 *access_expire_time = (time_t) expire_time;
138 #if FIREWALL_IPTABLES
140 add_acc_force_nat(fko_srv_options_t *opts, acc_stanza_t *curr_acc, const char *val)
142 char ip_str[MAX_IPV4_STR_LEN] = {0};
144 if (sscanf(val, "%15s %5u", ip_str, &curr_acc->force_nat_port) != 2)
148 "Fatal: invalid FORCE_NAT arg '%s', need <IP> <PORT>",
151 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
154 if (curr_acc->force_nat_port > MAX_PORT)
157 "Fatal: invalid FORCE_NAT port '%d'", curr_acc->force_nat_port);
158 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
161 curr_acc->force_nat = 1;
162 add_acc_string(&(curr_acc->force_nat_ip), ip_str);
168 /* Take an IP or Subnet/Mask and convert it to mask for later
169 * comparisons of incoming source IPs against this mask.
172 add_source_mask(acc_stanza_t *acc, const char *ip)
175 char ip_str[MAX_IPV4_STR_LEN] = {0};
180 acc_int_list_t *last_sle, *new_sle, *tmp_sle;
182 if((new_sle = calloc(1, sizeof(acc_int_list_t))) == NULL)
185 "Fatal memory allocation error adding stanza source_list entry"
190 /* If this is not the first entry, we walk our pointer to the
193 if(acc->source_list == NULL)
195 acc->source_list = new_sle;
199 tmp_sle = acc->source_list;
203 } while((tmp_sle = tmp_sle->next));
205 last_sle->next = new_sle;
208 /* Convert the IP data into the appropriate mask
210 if(strcasecmp(ip, "ANY") == 0)
212 new_sle->maddr = 0x0;
217 /* See if we have a subnet component. If so pull out the IP and
218 * mask values, then create the final mask value.
220 if((ndx = strchr(ip, '/')) != NULL)
223 strlcpy(ip_str, ip, (ndx-ip)+1);
228 strlcpy(ip_str, ip, strlen(ip)+1);
231 if(inet_aton(ip_str, &in) == 0)
234 "Error parsing IP to int for: %s", ip_str
243 /* Store our mask converted from CIDR to a 32-bit value.
245 new_sle->mask = (0xFFFFFFFF << (32 - mask));
247 /* Store our masked address for comparisons with future incoming
250 new_sle->maddr = ntohl(in.s_addr) & new_sle->mask;
255 /* Expand the access SOURCE string to a list of masks.
258 expand_acc_source(acc_stanza_t *acc)
261 char buf[ACCESS_BUF_LEN];
266 for(ndx = start; *ndx; ndx++)
270 /* Skip over any leading whitespace.
272 while(isspace(*start))
275 if(((ndx-start)+1) >= ACCESS_BUF_LEN)
278 strlcpy(buf, start, (ndx-start)+1);
279 res = add_source_mask(acc, buf);
286 /* Skip over any leading whitespace (once again for the last in the list).
288 while(isspace(*start))
291 if(((ndx-start)+1) >= ACCESS_BUF_LEN)
294 strlcpy(buf, start, (ndx-start)+1);
295 res = add_source_mask(acc, buf);
301 parse_proto_and_port(char *pstr, int *proto, int *port)
304 char proto_str[ACCESS_BUF_LEN];
306 /* Parse the string into its components.
308 if((ndx = strchr(pstr, '/')) == NULL)
311 "Parse error on access port entry: %s", pstr);
316 if(((ndx - pstr)+1) >= ACCESS_BUF_LEN)
319 "Parse error on access port entry: %s", pstr);
323 strlcpy(proto_str, pstr, (ndx - pstr)+1);
327 if((*port < 0) || (*port > MAX_PORT))
330 "Invalid port in access request: %s", pstr);
334 if(strcasecmp(proto_str, "tcp") == 0)
336 else if(strcasecmp(proto_str, "udp") == 0)
341 "Invalid protocol in access port entry: %s", pstr);
348 /* Take a proto/port string and convert it to appropriate integer values
349 * for comparisons of incoming SPA requests.
352 add_port_list_ent(acc_port_list_t **plist, char *port_str)
356 acc_port_list_t *last_plist, *new_plist, *tmp_plist;
358 /* Parse the string into its components and continue only if there
359 * are no problems with the incoming string.
361 if(parse_proto_and_port(port_str, &proto_int, &port) != 0)
364 if((new_plist = calloc(1, sizeof(acc_port_list_t))) == NULL)
367 "Fatal memory allocation error adding stanza source_list entry"
372 /* If this is not the first entry, we walk our pointer to the
384 last_plist = tmp_plist;
385 } while((tmp_plist = tmp_plist->next));
387 last_plist->next = new_plist;
390 new_plist->proto = proto_int;
391 new_plist->port = port;
394 /* Add a string list entry to the given acc_string_list.
397 add_string_list_ent(acc_string_list_t **stlist, const char *str_str)
399 acc_string_list_t *last_stlist, *new_stlist, *tmp_stlist;
401 if((new_stlist = calloc(1, sizeof(acc_string_list_t))) == NULL)
404 "Fatal memory allocation error creating string list entry"
409 /* If this is not the first entry, we walk our pointer to the
414 *stlist = new_stlist;
418 tmp_stlist = *stlist;
421 last_stlist = tmp_stlist;
422 } while((tmp_stlist = tmp_stlist->next));
424 last_stlist->next = new_stlist;
427 if(new_stlist->str != NULL)
428 free(new_stlist->str);
430 new_stlist->str = strdup(str_str);
432 if(new_stlist->str == NULL)
435 "Fatal memory allocation error adding string list entry item"
442 /* Expand a proto/port access string to a list of access proto-port struct.
445 expand_acc_port_list(acc_port_list_t **plist, char *plist_str)
448 char buf[ACCESS_BUF_LEN];
452 for(ndx = start; *ndx != '\0'; ndx++)
456 /* Skip over any leading whitespace.
458 while(isspace(*start))
461 if(((ndx-start)+1) >= ACCESS_BUF_LEN)
464 strlcpy(buf, start, (ndx-start)+1);
465 add_port_list_ent(plist, buf);
470 /* Skip over any leading whitespace (once again for the last in the list).
472 while(isspace(*start))
475 if(((ndx-start)+1) >= ACCESS_BUF_LEN)
478 strlcpy(buf, start, (ndx-start)+1);
480 add_port_list_ent(plist, buf);
485 /* Expand a comma-separated string into a simple acc_string_list.
488 expand_acc_string_list(acc_string_list_t **stlist, char *stlist_str)
495 for(ndx = start; *ndx; ndx++)
499 /* Skip over any leading whitespace.
501 while(isspace(*start))
504 strlcpy(buf, start, (ndx-start)+1);
505 add_string_list_ent(stlist, buf);
510 /* Skip over any leading whitespace (once again for the last in the list).
512 while(isspace(*start))
515 strlcpy(buf, start, (ndx-start)+1);
517 add_string_list_ent(stlist, buf);
520 /* Free the acc source_list
523 free_acc_source_list(acc_int_list_t *sle)
525 acc_int_list_t *last_sle;
530 sle = last_sle->next;
539 free_acc_port_list(acc_port_list_t *ple)
541 acc_port_list_t *last_ple;
546 ple = last_ple->next;
552 /* Free a string_list
555 free_acc_string_list(acc_string_list_t *stl)
557 acc_string_list_t *last_stl;
562 stl = last_stl->next;
569 /* Free any allocated content of an access stanza.
571 * NOTE: If a new access.conf parameter is created, and it is a string
572 * value, it also needs to be added to the list of items to check
576 free_acc_stanza_data(acc_stanza_t *acc)
579 if(acc->source != NULL)
582 free_acc_source_list(acc->source_list);
585 if(acc->open_ports != NULL)
587 free(acc->open_ports);
588 free_acc_port_list(acc->oport_list);
591 if(acc->restrict_ports != NULL)
593 free(acc->restrict_ports);
594 free_acc_port_list(acc->rport_list);
597 if(acc->force_nat_ip != NULL)
598 free(acc->force_nat_ip);
603 if(acc->cmd_exec_user != NULL)
604 free(acc->cmd_exec_user);
606 if(acc->require_username != NULL)
607 free(acc->require_username);
609 if(acc->gpg_home_dir != NULL)
610 free(acc->gpg_home_dir);
612 if(acc->gpg_decrypt_id != NULL)
613 free(acc->gpg_decrypt_id);
615 if(acc->gpg_decrypt_pw != NULL)
616 free(acc->gpg_decrypt_pw);
618 if(acc->gpg_remote_id != NULL)
620 free(acc->gpg_remote_id);
621 free_acc_string_list(acc->gpg_remote_id_list);
625 /* Expand any access entries that may be multi-value.
628 expand_acc_ent_lists(fko_srv_options_t *opts)
630 acc_stanza_t *acc = opts->acc_stanzas;
632 /* We need to do this for each stanza.
636 /* Expand the source string to 32-bit integer masks foreach entry.
638 if(expand_acc_source(acc) == 0)
644 /* Now expand the open_ports string.
646 if(acc->open_ports != NULL && strlen(acc->open_ports))
647 expand_acc_port_list(&(acc->oport_list), acc->open_ports);
649 if(acc->restrict_ports != NULL && strlen(acc->restrict_ports))
650 expand_acc_port_list(&(acc->rport_list), acc->restrict_ports);
652 /* Expand the GPG_REMOTE_ID string.
654 if(acc->gpg_remote_id != NULL && strlen(acc->gpg_remote_id))
655 expand_acc_string_list(&(acc->gpg_remote_id_list), acc->gpg_remote_id);
662 free_acc_stanzas(fko_srv_options_t *opts)
664 acc_stanza_t *acc, *last_acc;
666 /* Free any resources first (in case of reconfig). Assume non-NULL
667 * entry needs to be freed.
669 acc = opts->acc_stanzas;
674 acc = last_acc->next;
676 free_acc_stanza_data(last_acc);
683 /* Wrapper for free_acc_stanzas(), we may put additional initialization
687 acc_stanza_init(fko_srv_options_t *opts)
689 /* Free any resources first (in case of reconfig). Assume non-NULL
690 * entry needs to be freed.
692 free_acc_stanzas(opts);
697 /* Add a new stanza bay allocating the required memory at the required
698 * location, yada-yada-yada.
701 acc_stanza_add(fko_srv_options_t *opts)
703 acc_stanza_t *acc = opts->acc_stanzas;
704 acc_stanza_t *new_acc = calloc(1, sizeof(acc_stanza_t));
705 acc_stanza_t *last_acc;
710 "Fatal memory allocation error adding access stanza"
712 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
715 /* If this is not the first acc entry, we walk our acc pointer to the
716 * end of the existing list.
720 opts->acc_stanzas = new_acc;
726 } while((acc = acc->next));
728 last_acc->next = new_acc;
734 /* Scan the access options for entries that have not bees set, but need
738 set_acc_defaults(fko_srv_options_t *opts)
740 acc_stanza_t *acc = opts->acc_stanzas;
747 /* set default fw_access_timeout if necessary
749 if(acc->fw_access_timeout < 1)
750 acc->fw_access_timeout = DEF_FW_ACCESS_TIMEOUT;
752 /* set default gpg keyring path if necessary
754 if(acc->gpg_decrypt_pw != NULL && acc->gpg_home_dir == NULL)
755 add_acc_string(&(acc->gpg_home_dir), opts->config[CONF_GPG_HOME_DIR]);
761 /* Perform some sanity checks on an acc stanza data.
764 acc_data_is_valid(const acc_stanza_t *acc)
766 if((acc->key == NULL || !strlen(acc->key))
767 && (acc->gpg_decrypt_pw == NULL || !strlen(acc->gpg_decrypt_pw)))
770 "[*] No keys found for access stanza source: '%s'\n", acc->source
778 /* Read and parse the access file, popluating the access data as we go.
781 parse_access_file(fko_srv_options_t *opts)
786 unsigned int num_lines = 0;
788 char access_line_buf[MAX_LINE_LEN] = {0};
789 char var[MAX_LINE_LEN] = {0};
790 char val[MAX_LINE_LEN] = {0};
795 acc_stanza_t *curr_acc = NULL;
797 /* First see if the access file exists. If it doesn't, complain
800 if(stat(opts->config[CONF_ACCESS_FILE], &st) != 0)
802 fprintf(stderr, "[*] Access file: '%s' was not found.\n",
803 opts->config[CONF_ACCESS_FILE]);
805 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
808 if ((file_ptr = fopen(opts->config[CONF_ACCESS_FILE], "r")) == NULL)
810 fprintf(stderr, "[*] Could not open access file: %s\n",
811 opts->config[CONF_ACCESS_FILE]);
814 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
817 /* Initialize the access list.
819 acc_stanza_init(opts);
821 /* Now walk through access file pulling the access entries into the
824 while ((fgets(access_line_buf, MAX_LINE_LEN, file_ptr)) != NULL)
827 access_line_buf[MAX_LINE_LEN-1] = '\0';
829 /* Get past comments and empty lines (note: we only look at the
832 if(IS_EMPTY_LINE(access_line_buf[0]))
835 if(sscanf(access_line_buf, "%s %[^;\n\r]", var, val) != 2)
838 "*Invalid access file entry in %s at line %i.\n - '%s'",
839 opts->config[CONF_ACCESS_FILE], num_lines, access_line_buf
844 /* Remove any colon that may be on the end of the var
846 if((ndx = strrchr(var, ':')) != NULL)
851 if(opts->verbose > 3)
853 "ACCESS FILE: %s, LINE: %s\tVar: %s, Val: '%s'\n",
854 opts->config[CONF_ACCESS_FILE], access_line_buf, var, val
857 /* Process the entry.
859 * NOTE: If a new access.conf parameter is created. It also needs
860 * to be accounted for in the following if/if else construct.
863 if(CONF_VAR_IS(var, "SOURCE"))
865 /* If this is not the first stanza, sanity check the previous
866 * stanza for the minimum required data.
868 if(curr_acc != NULL) {
869 if(!acc_data_is_valid(curr_acc))
872 "[*] Data error in access file: '%s'\n",
873 opts->config[CONF_ACCESS_FILE]);
874 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
880 curr_acc = acc_stanza_add(opts);
882 add_acc_string(&(curr_acc->source), val);
886 else if (curr_acc == NULL)
888 /* The stanza must start with the "SOURCE" variable
892 else if(CONF_VAR_IS(var, "OPEN_PORTS"))
894 add_acc_string(&(curr_acc->open_ports), val);
896 else if(CONF_VAR_IS(var, "RESTRICT_PORTS"))
898 add_acc_string(&(curr_acc->restrict_ports), val);
900 else if(CONF_VAR_IS(var, "KEY"))
902 if(strcasecmp(val, "__CHANGEME__") == 0)
905 "[*] KEY value is not properly set in stanza source '%s' in access file: '%s'\n",
906 curr_acc->source, opts->config[CONF_ACCESS_FILE]);
907 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
909 add_acc_string(&(curr_acc->key), val);
911 else if(CONF_VAR_IS(var, "FW_ACCESS_TIMEOUT"))
913 add_acc_int(&(curr_acc->fw_access_timeout), val);
915 else if(CONF_VAR_IS(var, "ENABLE_CMD_EXEC"))
917 add_acc_bool(&(curr_acc->enable_cmd_exec), val);
919 else if(CONF_VAR_IS(var, "CMD_EXEC_USER"))
921 add_acc_string(&(curr_acc->cmd_exec_user), val);
928 fprintf(stderr, "Unable to determine UID for CMD_EXEC_USER: %s.\n",
929 errno ? strerror(errno) : "Not a user on this system");
930 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
933 curr_acc->cmd_exec_uid = pw->pw_uid;
935 else if(CONF_VAR_IS(var, "REQUIRE_USERNAME"))
937 add_acc_string(&(curr_acc->require_username), val);
939 else if(CONF_VAR_IS(var, "REQUIRE_SOURCE_ADDRESS"))
941 add_acc_bool(&(curr_acc->require_source_address), val);
943 else if(CONF_VAR_IS(var, "REQUIRE_SOURCE")) /* synonym for REQUIRE_SOURCE_ADDRESS */
945 add_acc_bool(&(curr_acc->require_source_address), val);
947 else if(CONF_VAR_IS(var, "GPG_HOME_DIR"))
949 if (is_valid_dir(val))
951 add_acc_string(&(curr_acc->gpg_home_dir), val);
956 "[*] GPG_HOME_DIR directory '%s' stat()/existence problem in stanza source '%s' in access file: '%s'\n",
957 val, curr_acc->source, opts->config[CONF_ACCESS_FILE]);
958 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
961 else if(CONF_VAR_IS(var, "GPG_DECRYPT_ID"))
963 add_acc_string(&(curr_acc->gpg_decrypt_id), val);
965 else if(CONF_VAR_IS(var, "GPG_DECRYPT_PW"))
967 if(strcasecmp(val, "__CHANGEME__") == 0)
970 "[*] GPG_DECRYPT_PW value is not properly set in stanza source '%s' in access file: '%s'\n",
971 curr_acc->source, opts->config[CONF_ACCESS_FILE]);
972 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
974 add_acc_string(&(curr_acc->gpg_decrypt_pw), val);
976 else if(CONF_VAR_IS(var, "GPG_ALLOW_NO_PW"))
978 if(curr_acc->gpg_decrypt_pw != NULL && curr_acc->gpg_decrypt_pw[0] != '\0')
979 free(curr_acc->gpg_decrypt_pw);
981 add_acc_string(&(curr_acc->gpg_decrypt_pw), "");
983 else if(CONF_VAR_IS(var, "GPG_REQUIRE_SIG"))
985 add_acc_bool(&(curr_acc->gpg_require_sig), val);
987 else if(CONF_VAR_IS(var, "GPG_IGNORE_SIG_VERIFY_ERROR"))
989 add_acc_bool(&(curr_acc->gpg_ignore_sig_error), val);
991 else if(CONF_VAR_IS(var, "GPG_REMOTE_ID"))
993 add_acc_string(&(curr_acc->gpg_remote_id), val);
995 else if(CONF_VAR_IS(var, "ACCESS_EXPIRE"))
997 add_acc_expire_time(opts, &(curr_acc->access_expire_time), val);
999 else if(CONF_VAR_IS(var, "ACCESS_EXPIRE_EPOCH"))
1001 add_acc_expire_time_epoch(opts, &(curr_acc->access_expire_time), val);
1003 else if(CONF_VAR_IS(var, "FORCE_NAT"))
1005 #if FIREWALL_IPTABLES
1006 if(strncasecmp(opts->config[CONF_ENABLE_IPT_FORWARDING], "Y", 1) !=0 )
1009 "[*] FORCE_NAT requires ENABLE_IPT_FORWARDING to be enabled in fwknopd.conf\n");
1010 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1012 add_acc_force_nat(opts, curr_acc, val);
1015 "[*] FORCE_NAT not supported.\n");
1016 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1022 "*Ignoring unknown access parameter: '%s' in %s\n",
1023 var, opts->config[CONF_ACCESS_FILE]
1030 /* Basic check to ensure that we got at least one SOURCE stanza with
1031 * a valid KEY defined (valid meaning it has a value that is not
1034 if (got_source == 0)
1037 "[*] Could not find valid SOURCE stanza in access file: '%s'\n",
1038 opts->config[CONF_ACCESS_FILE]);
1039 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1042 /* Sanity check the last stanza
1044 if(!acc_data_is_valid(curr_acc))
1047 "[*] Data error in access file: '%s'\n",
1048 opts->config[CONF_ACCESS_FILE]);
1049 clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
1052 /* Expand our the expandable fields into their respective data buckets.
1055 expand_acc_ent_lists(opts);
1057 /* Make sure default values are set where needed.
1060 set_acc_defaults(opts);
1066 compare_addr_list(acc_int_list_t *source_list, const uint32_t ip)
1072 if((ip & source_list->mask) == (source_list->maddr & source_list->mask))
1078 source_list = source_list->next;
1084 /* Compare the contents of 2 port lists. Return true on a match.
1085 * Match depends on the match_any flag. if match_any is 1 then any
1086 * entry in the incoming data need only match one item to return true.
1087 * Otherwise all entries in the incoming data must have a corresponding
1088 * match in the access port_list.
1091 compare_port_list(acc_port_list_t *in, acc_port_list_t *ac, const int match_any)
1096 acc_port_list_t *tlist;
1104 if(in->proto == tlist->proto && in->port == tlist->port)
1110 tlist = tlist->next;
1115 return(i_cnt == a_cnt);
1118 /* Take a proto/port string (or mulitple comma-separated strings) and check
1119 * them against the list for the given access stanza.
1121 * Return 1 if we are allowed
1124 acc_check_port_access(acc_stanza_t *acc, char *port_str)
1126 int res = 1, ctr = 0;
1128 char buf[ACCESS_BUF_LEN];
1131 acc_port_list_t *o_pl = acc->oport_list;
1132 acc_port_list_t *r_pl = acc->rport_list;
1134 acc_port_list_t *in_pl = NULL;
1138 /* Create our own internal port_list from the incoming SPA data
1141 for(ndx = start; *ndx != '\0'; ndx++)
1145 if((ctr >= ACCESS_BUF_LEN)
1146 || (((ndx-start)+1) >= ACCESS_BUF_LEN))
1149 "Unable to create acc_port_list from incoming data: %s",
1154 strlcpy(buf, start, (ndx-start)+1);
1155 add_port_list_ent(&in_pl, buf);
1161 if((ctr >= ACCESS_BUF_LEN)
1162 || (((ndx-start)+1) >= ACCESS_BUF_LEN))
1165 "Unable to create acc_port_list from incoming data: %s",
1170 strlcpy(buf, start, (ndx-start)+1);
1171 add_port_list_ent(&in_pl, buf);
1176 "Unable to create acc_port_list from incoming data: %s", port_str
1181 /* Start with restricted ports (if any). Any match (even if only one
1182 * entry) means not allowed.
1184 if((acc->rport_list != NULL) && (compare_port_list(in_pl, r_pl, 1)))
1187 goto cleanup_and_bail;
1190 /* For open port list, all must match.
1192 if((acc->oport_list != NULL) && (!compare_port_list(in_pl, o_pl, 0)))
1196 free_acc_port_list(in_pl);
1200 /* Take a GPG ID string and check it against the list of allowed
1203 * Return 1 if we are allowed
1206 acc_check_gpg_remote_id(acc_stanza_t *acc, const char *gpg_id)
1208 acc_string_list_t *ndx;
1210 for(ndx = acc->gpg_remote_id_list; ndx != NULL; ndx=ndx->next)
1211 if(strcasecmp(ndx->str, gpg_id) == 0)
1217 /* Dump the configuration
1220 dump_access_list(const fko_srv_options_t *opts)
1224 acc_stanza_t *acc = opts->acc_stanzas;
1226 fprintf(stdout, "Current fwknopd access settings:\n");
1230 fprintf(stderr, "\n ** No Access Settings Defined **\n\n");
1238 "==============================================================\n"
1240 " RESTRICT_PORTS: %s\n"
1241 " KEY: <see the access.conf file>\n"
1242 " FW_ACCESS_TIMEOUT: %i\n"
1243 " ENABLE_CMD_EXEC: %s\n"
1244 " CMD_EXEC_USER: %s\n"
1245 " REQUIRE_USERNAME: %s\n"
1246 " REQUIRE_SOURCE_ADDRESS: %s\n"
1247 " FORCE_NAT (ip): %s\n"
1248 " FORCE_NAT (proto): %s\n"
1249 " FORCE_NAT (port): %d\n"
1250 " ACCESS_EXPIRE: %s" /* asctime() adds a newline */
1251 " GPG_HOME_DIR: %s\n"
1252 " GPG_DECRYPT_ID: %s\n"
1253 " GPG_DECRYPT_PW: <see the access.conf file>\n"
1254 " GPG_REQUIRE_SIG: %s\n"
1255 "GPG_IGNORE_SIG_VERIFY_ERROR: %s\n"
1256 " GPG_REMOTE_ID: %s\n",
1259 (acc->open_ports == NULL) ? "<not set>" : acc->open_ports,
1260 (acc->restrict_ports == NULL) ? "<not set>" : acc->restrict_ports,
1261 //(acc->key == NULL) ? "<not set>" : acc->key,
1262 acc->fw_access_timeout,
1263 acc->enable_cmd_exec ? "Yes" : "No",
1264 (acc->cmd_exec_user == NULL) ? "<not set>" : acc->cmd_exec_user,
1265 (acc->require_username == NULL) ? "<not set>" : acc->require_username,
1266 acc->require_source_address ? "Yes" : "No",
1267 acc->force_nat ? acc->force_nat_ip : "<not set>",
1268 acc->force_nat && acc->force_nat_proto != NULL ? acc->force_nat_proto : "<not set>",
1269 acc->force_nat ? acc->force_nat_port : 0,
1270 (acc->access_expire_time > 0) ? asctime(localtime(&acc->access_expire_time)) : "<not set>\n",
1271 (acc->gpg_home_dir == NULL) ? "<not set>" : acc->gpg_home_dir,
1272 (acc->gpg_decrypt_id == NULL) ? "<not set>" : acc->gpg_decrypt_id,
1273 //(acc->gpg_decrypt_pw == NULL) ? "<not set>" : acc->gpg_decrypt_pw,
1274 acc->gpg_require_sig ? "Yes" : "No",
1275 acc->gpg_ignore_sig_error ? "Yes" : "No",
1276 (acc->gpg_remote_id == NULL) ? "<not set>" : acc->gpg_remote_id
1279 fprintf(stdout, "\n");
1284 fprintf(stdout, "\n");