#include "newconf.h"
#include "ircd_defs.h"
-#include "common.h"
#include "logger.h"
#include "s_conf.h"
#include "s_user.h"
#include "cache.h"
#include "ircd.h"
#include "snomask.h"
-#include "blacklist.h"
#include "sslproc.h"
#include "privilege.h"
#include "chmode.h"
static char *yy_blacklist_host = NULL;
static char *yy_blacklist_reason = NULL;
-static int yy_blacklist_ipv4 = 1;
-static int yy_blacklist_ipv6 = 0;
-static rb_dlink_list yy_blacklist_filters;
+static uint8_t yy_blacklist_iptype = 0;
+static rb_dlink_list yy_blacklist_filters = { NULL, NULL, 0 };
static char *yy_privset_extends = NULL;
/* XXX for below */
static void conf_set_blacklist_reason(void *data);
+#define IPTYPE_IPV4 1
+#define IPTYPE_IPV6 2
+
static void
conf_set_blacklist_host(void *data)
{
return;
}
- yy_blacklist_ipv4 = 1;
- yy_blacklist_ipv6 = 0;
+ yy_blacklist_iptype |= IPTYPE_IPV4;
yy_blacklist_host = rb_strdup(data);
}
conf_parm_t *args = data;
/* Don't assume we have either if we got here */
- yy_blacklist_ipv4 = 0;
- yy_blacklist_ipv6 = 0;
+ yy_blacklist_iptype = 0;
for (; args; args = args->next)
{
if (!strcasecmp(args->v.string, "ipv4"))
- yy_blacklist_ipv4 = 1;
+ yy_blacklist_iptype |= IPTYPE_IPV4;
else if (!strcasecmp(args->v.string, "ipv6"))
- yy_blacklist_ipv6 = 1;
+ yy_blacklist_iptype |= IPTYPE_IPV6;
else
conf_report_error("blacklist::type has unknown address family %s",
args->v.string);
}
/* If we have neither, just default to IPv4 */
- if (!yy_blacklist_ipv4 && !yy_blacklist_ipv6)
+ if (!yy_blacklist_iptype)
{
- conf_report_error("blacklist::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
- yy_blacklist_ipv4 = 1;
+ conf_report_warning("blacklist::type has neither IPv4 nor IPv6 (defaulting to IPv4)");
+ yy_blacklist_iptype = IPTYPE_IPV4;
}
}
conf_set_blacklist_matches(void *data)
{
conf_parm_t *args = data;
+ enum filter_t { FILTER_NONE, FILTER_ALL, FILTER_LAST };
for (; args; args = args->next)
{
- struct BlacklistFilter *filter;
char *str = args->v.string;
char *p;
- int type = BLACKLIST_FILTER_LAST;
+ enum filter_t type = FILTER_LAST;
if (CF_TYPE(args->type) != CF_QSTRING)
{
{
/* Check for validity */
if (*p == '.')
- type = BLACKLIST_FILTER_ALL;
- else if (!isalnum((unsigned char)*p))
+ type = FILTER_ALL;
+ else if (!isdigit((unsigned char)*p))
{
conf_report_error("blacklist::matches has invalid IP match entry %s",
str);
- type = 0;
+ type = FILTER_NONE;
break;
}
}
- if (type == BLACKLIST_FILTER_ALL)
+ if (type == FILTER_ALL)
{
/* Basic IP sanity check */
struct rb_sockaddr_storage tmp;
continue;
}
}
- else if (type == BLACKLIST_FILTER_LAST)
+ else if (type == FILTER_LAST)
{
/* Verify it's the correct length */
if (strlen(str) > 3)
continue; /* Invalid entry */
}
- filter = rb_malloc(sizeof(struct BlacklistFilter));
- filter->type = type;
- rb_strlcpy(filter->filterstr, str, sizeof(filter->filterstr));
-
- rb_dlinkAdd(filter, &filter->node, &yy_blacklist_filters);
+ rb_dlinkAddAlloc(rb_strdup(str), &yy_blacklist_filters);
}
}
if (yy_blacklist_host && data)
{
yy_blacklist_reason = rb_strdup(data);
- if (yy_blacklist_ipv6)
+ if (yy_blacklist_iptype & IPTYPE_IPV6)
{
- /* Make sure things fit (64 = alnum count + dots) */
+ /* Make sure things fit (magic number 64 = alnum count + dots)
+ * Example: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
+ */
if ((64 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN)
{
conf_report_error("blacklist::host %s results in IPv6 queries that are too long",
}
}
/* Avoid doing redundant check, IPv6 is bigger than IPv4 --Elizabeth */
- if (yy_blacklist_ipv4 && !yy_blacklist_ipv6)
+ if ((yy_blacklist_iptype & IPTYPE_IPV4) && !(yy_blacklist_iptype & IPTYPE_IPV6))
{
- /* Make sure things fit (16 = number of nums + dots) */
+ /* Make sure things fit for worst case (magic number 16 = number of nums + dots)
+ * Example: 127.127.127.127.in-addr.arpa
+ */
if ((16 + strlen(yy_blacklist_host)) > IRCD_RES_HOSTLEN)
{
conf_report_error("blacklist::host %s results in IPv4 queries that are too long",
}
}
- new_blacklist(yy_blacklist_host, yy_blacklist_reason, yy_blacklist_ipv4, yy_blacklist_ipv6,
- &yy_blacklist_filters);
+ add_blacklist(yy_blacklist_host, yy_blacklist_reason, yy_blacklist_iptype, &yy_blacklist_filters);
}
cleanup_bl:
- if (data == NULL)
- {
- RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_blacklist_filters.head)
- {
- rb_dlinkDelete(ptr, &yy_blacklist_filters);
- rb_free(ptr);
- }
- }
- else
+ RB_DLINK_FOREACH_SAFE(ptr, nptr, yy_blacklist_filters.head)
{
- yy_blacklist_filters = (rb_dlink_list){ NULL, NULL, 0 };
+ rb_free(ptr->data);
+ rb_dlinkDestroy(ptr, &yy_blacklist_filters);
}
+ yy_blacklist_filters = (rb_dlink_list){ NULL, NULL, 0 };
+
rb_free(yy_blacklist_host);
rb_free(yy_blacklist_reason);
yy_blacklist_host = NULL;
yy_blacklist_reason = NULL;
- yy_blacklist_ipv4 = 1;
- yy_blacklist_ipv6 = 0;
+ yy_blacklist_iptype = 0;
}
/* public functions */
conf_report_error(const char *fmt, ...)
{
va_list ap;
- char msg[IRCD_BUFSIZE + 1] = { 0 };
+ char msg[BUFSIZE + 1] = { 0 };
va_start(ap, fmt);
- vsnprintf(msg, IRCD_BUFSIZE, fmt, ap);
+ vsnprintf(msg, BUFSIZE, fmt, ap);
va_end(ap);
if (testing_conf)
conf_report_warning(const char *fmt, ...)
{
va_list ap;
- char msg[IRCD_BUFSIZE + 1] = { 0 };
+ char msg[BUFSIZE + 1] = { 0 };
va_start(ap, fmt);
- vsnprintf(msg, IRCD_BUFSIZE, fmt, ap);
+ vsnprintf(msg, BUFSIZE, fmt, ap);
va_end(ap);
if (testing_conf)