|
|
@@ -46,6 +46,8 @@
|
|
|
|
|
|
#include "../include/acl.h"
|
|
|
|
|
|
+extern int debug;
|
|
|
+
|
|
|
/* This function checks if a char argumnet from valid char range.
|
|
|
* Valid range is: ASCII only, a number or a letter, a space, a dot, a slash, a dash, a comma.
|
|
|
*
|
|
|
@@ -142,18 +144,27 @@ int add_ipv4_to_acl(char *ipv4) {
|
|
|
unsigned long ip, mask;
|
|
|
struct ip_acl *ip_acl_curr;
|
|
|
|
|
|
+ if(debug == TRUE)
|
|
|
+ syslog(LOG_INFO, "add_ipv4_to_acl: checking ip-address >%s<", ipv4);
|
|
|
+
|
|
|
/* Check for min and max IPv4 valid length */
|
|
|
- if (len < 7 || len > 18)
|
|
|
- return 0;
|
|
|
+ if (len < 7 || len > 18) {
|
|
|
+ syslog(LOG_INFO, "add_ipv4_to_acl: Error, ip-address >%s< incorrect length", ipv4);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
/* default mask for ipv4 */
|
|
|
data[4] = 32;
|
|
|
|
|
|
/* Basic IPv4 format check */
|
|
|
for (i = 0; i < len; i++) {
|
|
|
- /* Return 0 on error state */
|
|
|
- if (state == -1)
|
|
|
- return 0;
|
|
|
+ /* Return 0 on error state */
|
|
|
+ if (state == -1) {
|
|
|
+ if(debug == TRUE)
|
|
|
+ syslog(LOG_INFO, "add_ipv4_to_acl: Error, ip-address >%s< incorrect "
|
|
|
+ "format, continue with next check ...", ipv4);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
c = ipv4[i];
|
|
|
|
|
|
@@ -201,6 +212,7 @@ int add_ipv4_to_acl(char *ipv4) {
|
|
|
break;
|
|
|
default:
|
|
|
/* Bad states */
|
|
|
+ syslog(LOG_INFO, "add_ipv4_to_acl: Error, ip-address >%s< bad state", ipv4);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -247,6 +259,10 @@ int add_ipv4_to_acl(char *ipv4) {
|
|
|
ip_acl_prev->next = ip_acl_curr;
|
|
|
}
|
|
|
ip_acl_prev = ip_acl_curr;
|
|
|
+
|
|
|
+ if(debug == TRUE)
|
|
|
+ syslog(LOG_INFO, "add_ipv4_to_acl: ip-address >%s< correct, adding.", ipv4);
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
@@ -387,8 +403,12 @@ int add_domain_to_acl(char *domain) {
|
|
|
|
|
|
struct dns_acl *dns_acl_curr;
|
|
|
|
|
|
- if (len > 63)
|
|
|
+ if (len > 63) {
|
|
|
+ syslog(LOG_INFO,
|
|
|
+ "ADD_DOMAIN_TO_ACL: Error, did not add >%s< to acl list, too long!",
|
|
|
+ domain);
|
|
|
return 0;
|
|
|
+ }
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
c = domain[i];
|
|
|
@@ -426,7 +446,10 @@ int add_domain_to_acl(char *domain) {
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
- /* Not valid chars */
|
|
|
+ syslog(LOG_INFO,
|
|
|
+ "ADD_DOMAIN_TO_ACL: Error, did not add >%s< to acl list, "
|
|
|
+ "invalid chars!", domain);
|
|
|
+ /* Not valid chars */
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
@@ -448,8 +471,13 @@ int add_domain_to_acl(char *domain) {
|
|
|
dns_acl_prev->next = dns_acl_curr;
|
|
|
|
|
|
dns_acl_prev = dns_acl_curr;
|
|
|
+ if(debug == TRUE)
|
|
|
+ syslog(LOG_INFO, "ADD_DOMAIN_TO_ACL: added >%s< to acl list!", domain);
|
|
|
return 1;
|
|
|
default:
|
|
|
+ syslog(LOG_INFO,
|
|
|
+ "ADD_DOMAIN_TO_ACL: ERROR, did not add >%s< to acl list, "
|
|
|
+ "check allowed_host in config file!", domain);
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
@@ -470,14 +498,23 @@ int is_an_allowed_host(int family, void *host)
|
|
|
struct sockaddr_in *addr;
|
|
|
struct sockaddr_in6 addr6;
|
|
|
struct addrinfo *res, *ai;
|
|
|
+ struct in_addr tmp;
|
|
|
|
|
|
while (ip_acl_curr != NULL) {
|
|
|
if(ip_acl_curr->family == family) {
|
|
|
switch(ip_acl_curr->family) {
|
|
|
case AF_INET:
|
|
|
+ if (debug == TRUE) {
|
|
|
+ tmp.s_addr = ((struct in_addr*)host)->s_addr;
|
|
|
+ syslog(LOG_INFO, "is_an_allowed_host (AF_INET): is host >%s< "
|
|
|
+ "an allowed host >%s<\n",
|
|
|
+ inet_ntoa(tmp), inet_ntoa(ip_acl_curr->addr));
|
|
|
+ }
|
|
|
if((((struct in_addr *)host)->s_addr &
|
|
|
ip_acl_curr->mask.s_addr) ==
|
|
|
ip_acl_curr->addr.s_addr) {
|
|
|
+ if (debug == TRUE)
|
|
|
+ syslog(LOG_INFO, "is_an_allowed_host (AF_INET): host is in allowed host list!");
|
|
|
return 1;
|
|
|
}
|
|
|
break;
|
|
|
@@ -509,9 +546,20 @@ int is_an_allowed_host(int family, void *host)
|
|
|
switch(ai->ai_family) {
|
|
|
|
|
|
case AF_INET:
|
|
|
+ if(debug == TRUE) {
|
|
|
+ tmp.s_addr=((struct in_addr *)host)->s_addr;
|
|
|
+ syslog(LOG_INFO, "is_an_allowed_host (AF_INET): is host >%s< "
|
|
|
+ "an allowed host >%s<\n",
|
|
|
+ inet_ntoa(tmp), dns_acl_curr->domain);
|
|
|
+ }
|
|
|
+
|
|
|
addr = (struct sockaddr_in*)(ai->ai_addr);
|
|
|
- if (addr->sin_addr.s_addr == ((struct in_addr*)host)->s_addr)
|
|
|
+ if (addr->sin_addr.s_addr == ((struct in_addr*)host)->s_addr) {
|
|
|
+ if (debug == TRUE)
|
|
|
+ syslog(LOG_INFO, "is_an_allowed_host (AF_INET): "
|
|
|
+ "host is in allowed host list!");
|
|
|
return 1;
|
|
|
+ }
|
|
|
break;
|
|
|
|
|
|
case AF_INET6:
|
|
|
@@ -559,19 +607,30 @@ void parse_allowed_hosts(char *allowed_hosts) {
|
|
|
const char *delim = ",";
|
|
|
char *trimmed_tok;
|
|
|
|
|
|
+ if (debug == TRUE)
|
|
|
+ syslog(LOG_INFO,
|
|
|
+ "parse_allowed_hosts: parsing the allowed host string >%s< to add to ACL list\n",
|
|
|
+ allowed_hosts);
|
|
|
+
|
|
|
#ifdef HAVE_STRTOK_R
|
|
|
tok = strtok_r(hosts, delim, &saveptr);
|
|
|
#else
|
|
|
+ if (debug == TRUE)
|
|
|
+ syslog(LOG_INFO,"parse_allowed_hosts: using strtok, this might lead to "
|
|
|
+ "problems in the allowed_hosts string determination!\n");
|
|
|
tok = strtok(hosts, delim);
|
|
|
#endif
|
|
|
while( tok) {
|
|
|
trimmed_tok = malloc( sizeof( char) * ( strlen( tok) + 1));
|
|
|
trim( tok, trimmed_tok);
|
|
|
+ if(debug == TRUE)
|
|
|
+ syslog(LOG_DEBUG, "parse_allowed_hosts: ADDING this record (%s) to ACL list!\n", trimmed_tok);
|
|
|
if( strlen( trimmed_tok) > 0) {
|
|
|
if (!add_ipv4_to_acl(trimmed_tok) && !add_ipv6_to_acl(trimmed_tok)
|
|
|
&& !add_domain_to_acl(trimmed_tok)) {
|
|
|
syslog(LOG_ERR,"Can't add to ACL this record (%s). Check allowed_hosts option!\n",trimmed_tok);
|
|
|
- }
|
|
|
+ } else if (debug == TRUE)
|
|
|
+ syslog(LOG_DEBUG,"parse_allowed_hosts: Record added to ACL list!\n");
|
|
|
}
|
|
|
free( trimmed_tok);
|
|
|
#ifdef HAVE_STRTOK_R
|
|
|
@@ -606,17 +665,21 @@ unsigned int prefix_from_mask(struct in_addr mask) {
|
|
|
* It shows all hosts in ACL lists
|
|
|
*/
|
|
|
|
|
|
-void show_acl_lists(void) {
|
|
|
- struct ip_acl *ip_acl_curr = ip_acl_head;
|
|
|
- struct dns_acl *dns_acl_curr = dns_acl_head;
|
|
|
+void show_acl_lists(void)
|
|
|
+{
|
|
|
+ struct ip_acl *ip_acl_curr = ip_acl_head;
|
|
|
+ struct dns_acl *dns_acl_curr = dns_acl_head;
|
|
|
|
|
|
- while (ip_acl_curr != NULL) {
|
|
|
- printf(" IP ACL: %s/%u %u\n", inet_ntoa(ip_acl_curr->addr), prefix_from_mask(ip_acl_curr->mask), ip_acl_curr->addr.s_addr);
|
|
|
- ip_acl_curr = ip_acl_curr->next;
|
|
|
- }
|
|
|
+ syslog(LOG_INFO, "Showing ACL lists for both IP and DOMAIN acl's:\n" );
|
|
|
|
|
|
- while (dns_acl_curr != NULL) {
|
|
|
- printf("DNS ACL: %s\n", dns_acl_curr->domain);
|
|
|
- dns_acl_curr = dns_acl_curr->next;
|
|
|
- }
|
|
|
+ while (ip_acl_curr != NULL) {
|
|
|
+ syslog(LOG_INFO, " IP ACL: %s/%u %u\n", inet_ntoa(ip_acl_curr->addr),
|
|
|
+ prefix_from_mask(ip_acl_curr->mask), ip_acl_curr->addr.s_addr);
|
|
|
+ ip_acl_curr = ip_acl_curr->next;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (dns_acl_curr != NULL) {
|
|
|
+ syslog(LOG_INFO, " DNS ACL: %s\n", dns_acl_curr->domain);
|
|
|
+ dns_acl_curr = dns_acl_curr->next;
|
|
|
+ }
|
|
|
}
|