dovecot-2.0-sslstream: config: Renamed remote/local_ip to just r...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Feb 13 02:55:50 EET 2010
details: http://hg.dovecot.org/dovecot-2.0-sslstream/rev/a90d9bb6fec3
changeset: 10221:a90d9bb6fec3
user: Timo Sirainen <tss at iki.fi>
date: Wed Oct 28 18:35:29 2009 -0400
description:
config: Renamed remote/local_ip to just remote/local and added support for hostnames.
diffstat:
5 files changed, 80 insertions(+), 17 deletions(-)
src/config/config-connection.c | 4 ++
src/config/config-filter.c | 25 +++++++++++++--
src/config/config-filter.h | 1
src/config/config-parser.c | 63 +++++++++++++++++++++++++++++++---------
src/config/doveconf.c | 4 ++
diffs (197 lines):
diff -r 55b60c79c54c -r a90d9bb6fec3 src/config/config-connection.c
--- a/src/config/config-connection.c Wed Oct 28 17:04:24 2009 -0400
+++ b/src/config/config-connection.c Wed Oct 28 18:35:29 2009 -0400
@@ -75,6 +75,10 @@ static int config_connection_request(str
filter.service = *args + 8;
else if (strncmp(*args, "module=", 7) == 0)
module = *args + 7;
+ else if (strncmp(*args, "lhost=", 6) == 0)
+ filter.local_host = *args + 6;
+ else if (strncmp(*args, "rhost=", 6) == 0)
+ filter.remote_host = *args + 6;
else if (strncmp(*args, "lip=", 4) == 0) {
if (net_addr2ip(*args + 4, &filter.local_net) == 0) {
filter.local_bits =
diff -r 55b60c79c54c -r a90d9bb6fec3 src/config/config-filter.c
--- a/src/config/config-filter.c Wed Oct 28 17:04:24 2009 -0400
+++ b/src/config/config-filter.c Wed Oct 28 18:35:29 2009 -0400
@@ -17,18 +17,30 @@ bool config_filter_match(const struct co
if (mask->service != NULL) {
if (filter->service == NULL)
return FALSE;
- if (strcasecmp(filter->service, mask->service) != 0)
+ if (strcmp(filter->service, mask->service) != 0)
+ return FALSE;
+ }
+ if (mask->local_host != NULL) {
+ if (filter->local_host == NULL)
+ return FALSE;
+ if (strcmp(filter->local_host, mask->local_host) != 0)
+ return FALSE;
+ }
+ if (mask->remote_host != NULL) {
+ if (filter->remote_host == NULL)
+ return FALSE;
+ if (strcmp(filter->remote_host, mask->remote_host) != 0)
return FALSE;
}
/* FIXME: it's not comparing full masks */
- if (mask->remote_bits != 0) {
+ if (mask->remote_bits != 0 && mask->remote_host == NULL) {
if (filter->remote_bits == 0)
return FALSE;
if (!net_is_in_network(&filter->remote_net, &mask->remote_net,
mask->remote_bits))
return FALSE;
}
- if (mask->local_bits != 0) {
+ if (mask->local_bits != 0 && mask->local_host == NULL) {
if (filter->local_bits == 0)
return FALSE;
if (!net_is_in_network(&filter->local_net, &mask->local_net,
@@ -52,6 +64,11 @@ bool config_filters_equal(const struct c
if (f1->local_bits != f2->local_bits)
return FALSE;
if (!net_ip_compare(&f1->local_net, &f2->local_net))
+ return FALSE;
+
+ if (null_strcmp(f1->remote_host, f2->remote_host) != 0)
+ return FALSE;
+ if (null_strcmp(f1->local_host, f2->local_host) != 0)
return FALSE;
return TRUE;
@@ -90,7 +107,7 @@ config_filter_parser_cmp(struct config_f
{
const struct config_filter *f1 = &(*p1)->filter, *f2 = &(*p2)->filter;
- /* remote_ip and local_ips are first, although it doesn't really
+ /* remote and local are first, although it doesn't really
matter which one comes first */
if (f1->local_bits > f2->local_bits)
return -1;
diff -r 55b60c79c54c -r a90d9bb6fec3 src/config/config-filter.h
--- a/src/config/config-filter.h Wed Oct 28 17:04:24 2009 -0400
+++ b/src/config/config-filter.h Wed Oct 28 18:35:29 2009 -0400
@@ -5,6 +5,7 @@
struct config_filter {
const char *service;
+ const char *local_host, *remote_host;
struct ip_addr local_net, remote_net;
unsigned int local_bits, remote_bits;
};
diff -r 55b60c79c54c -r a90d9bb6fec3 src/config/config-parser.c
--- a/src/config/config-parser.c Wed Oct 28 17:04:24 2009 -0400
+++ b/src/config/config-parser.c Wed Oct 28 18:35:29 2009 -0400
@@ -12,6 +12,7 @@
#include "config-filter.h"
#include "config-parser.h"
+#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_GLOB_H
@@ -209,6 +210,40 @@ config_filter_parser_find(struct parser_
return NULL;
}
+static int
+config_parse_net(struct parser_context *ctx, const char *value,
+ const char **host_r, struct ip_addr *ip_r,
+ unsigned int *bits_r, const char **error_r)
+{
+ struct ip_addr *ips;
+ const char *p;
+ unsigned int ip_count;
+ int ret;
+
+ if (net_parse_range(value, ip_r, bits_r) == 0)
+ return 0;
+
+ p = strchr(value, '/');
+ if (p != NULL) {
+ value = t_strdup_until(value, p);
+ p++;
+ }
+
+ ret = net_gethostbyname(value, &ips, &ip_count);
+ if (ret != 0) {
+ *error_r = t_strdup_printf("gethostbyname(%s) failed: %s",
+ value, net_gethosterror(ret));
+ return -1;
+ }
+ *host_r = p_strdup(ctx->pool, value);
+ *ip_r = ips[0];
+ if (p != NULL && is_numeric(p, '\0'))
+ *bits_r = atoi(p);
+ else
+ *bits_r = IPADDR_IS_V4(&ips[0]) ? 32 : 128;
+ return 0;
+}
+
static bool
config_filter_add_new_filter(struct parser_context *ctx,
const char *key, const char *value,
@@ -223,32 +258,34 @@ config_filter_add_new_filter(struct pars
*error_r = "protocol must not be under protocol";
else
filter->service = p_strdup(ctx->pool, value);
- } else if (strcmp(key, "local_ip") == 0) {
+ } else if (strcmp(key, "local") == 0) {
if (parent->remote_bits > 0)
- *error_r = "local_ip must not be under remote_ip";
+ *error_r = "local must not be under remote";
else if (parent->service != NULL)
- *error_r = "local_ip must not be under protocol";
- else if (net_parse_range(value, &filter->local_net,
- &filter->local_bits) < 0)
- *error_r = "Invalid network mask";
+ *error_r = "local must not be under protocol";
+ else if (config_parse_net(ctx, value, &filter->local_host,
+ &filter->local_net,
+ &filter->local_bits, error_r) < 0)
+ ;
else if (parent->local_bits > filter->local_bits ||
(parent->local_bits > 0 &&
!net_is_in_network(&filter->local_net,
&parent->local_net,
parent->local_bits)))
- *error_r = "local_ip not a subset of parent local_ip";
- } else if (strcmp(key, "remote_ip") == 0) {
+ *error_r = "local not a subset of parent local";
+ } else if (strcmp(key, "remote") == 0) {
if (parent->service != NULL)
- *error_r = "remote_ip must not be under protocol";
- else if (net_parse_range(value, &filter->remote_net,
- &filter->remote_bits) < 0)
- *error_r = "Invalid network mask";
+ *error_r = "remote must not be under protocol";
+ else if (config_parse_net(ctx, value, &filter->remote_host,
+ &filter->remote_net,
+ &filter->remote_bits, error_r) < 0)
+ ;
else if (parent->remote_bits > filter->remote_bits ||
(parent->remote_bits > 0 &&
!net_is_in_network(&filter->remote_net,
&parent->remote_net,
parent->remote_bits)))
- *error_r = "remote_ip not a subset of parent remote_ip";
+ *error_r = "remote not a subset of parent remote";
} else {
return FALSE;
}
diff -r 55b60c79c54c -r a90d9bb6fec3 src/config/doveconf.c
--- a/src/config/doveconf.c Wed Oct 28 17:04:24 2009 -0400
+++ b/src/config/doveconf.c Wed Oct 28 18:35:29 2009 -0400
@@ -285,6 +285,10 @@ static void filter_parse_arg(struct conf
filter->service = arg + 8;
else if (strncmp(arg, "protocol=", 9) == 0)
filter->service = arg + 9;
+ else if (strncmp(arg, "lhost=", 6) == 0)
+ filter->local_host = arg + 6;
+ else if (strncmp(arg, "rhost=", 6) == 0)
+ filter->remote_host = arg + 6;
else if (strncmp(arg, "lip=", 4) == 0) {
if (net_parse_range(arg + 4, &filter->local_net,
&filter->local_bits) < 0)
More information about the dovecot-cvs
mailing list