changeset 242:bc9d9cd9ee8e

made addr_isequal() and addr_isequal_parent() more flexible refactored various bits of this stuff. addr_isequal_alias() had become needless now and was removed. In fail_msg.c: postmaster is now matched caseless, like required by RFC.
author markus schnalke <meillo@marmaro.de>
date Mon, 25 Oct 2010 17:42:48 -0300 (2010-10-25)
parents 87df0aa99cc7
children e758296de02d
files man/masqmail.conf.5 src/address.c src/alias.c src/fail_msg.c src/masqmail.h
diffstat 5 files changed, 21 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/man/masqmail.conf.5	Mon Oct 25 15:41:48 2010 -0300
+++ b/man/masqmail.conf.5	Mon Oct 25 17:42:48 2010 -0300
@@ -251,7 +251,11 @@
 .TP
 \fBalias_local_caseless = \fIboolean\fR
 
-If this is set, local parts in the alias file will be matched disregarding upper/lower case.
+If this is set, aliasing and the matching for \fBlocal_addresses\fP and
+\fBnot_local_addresses\fP will be done caseless.
+
+Note: Be sure to change this option only if the queue is empty as
+correct processing of queued messages is not guaranteed otherwise.
 
 Default: false
 
--- a/src/address.c	Mon Oct 25 15:41:48 2010 -0300
+++ b/src/address.c	Mon Oct 25 17:42:48 2010 -0300
@@ -102,20 +102,20 @@
 }
 
 gboolean
-addr_isequal(address * addr1, address * addr2)
+addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*))
 {
-	return (strcmp(addr1->local_part, addr2->local_part) == 0)
+	return (cmpfunc(addr1->local_part, addr2->local_part) == 0)
 	       && (strcasecmp(addr1->domain, addr2->domain) == 0);
 }
 
 /* searches in ancestors of addr1 */
 gboolean
-addr_isequal_parent(address * addr1, address * addr2)
+addr_isequal_parent(address* addr1, address* addr2, int (*cmpfunc) (const char*, const char*))
 {
 	address *addr;
 
 	for (addr = addr1; addr; addr = addr->parent)
-		if (addr_isequal(addr, addr2))
+		if (addr_isequal(addr, addr2, cmpfunc))
 			return TRUE;
 
 	return FALSE;
--- a/src/alias.c	Mon Oct 25 15:41:48 2010 -0300
+++ b/src/alias.c	Mon Oct 25 17:42:48 2010 -0300
@@ -40,7 +40,7 @@
 			a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
 			DEBUG(6) debugf("not_local_addresses: addr_node->data=%s a->address=%s\n",
 			                addr_node->data, a->address);
-			if (addr_isequal(a, addr)) {
+			if (addr_isequal(a, addr, conf.alias_local_cmp)) {
 				destroy_address(a);
 				/* in local_hosts but also in not_local_addresses */
 				return FALSE;
@@ -54,7 +54,7 @@
 		a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
 		DEBUG(6) debugf("local_addresses: addr_node->data=%s a->address=%s\n",
 		                addr_node->data, a->address);
-		if (addr_isequal(a, addr)) {
+		if (addr_isequal(a, addr, conf.alias_local_cmp)) {
 			destroy_address(a);
 			/* in local_addresses */
 			return TRUE;
@@ -64,13 +64,6 @@
 	return FALSE;
 }
 
-static gboolean
-addr_isequal_alias(address * addr1, address * addr2)
-{
-	return (conf.alias_local_cmp(addr1->local_part, addr2->local_part) == 0)
-	       && (strcasecmp(addr1->domain, addr2->domain) == 0);
-}
-
 static GList*
 parse_list(gchar * line)
 {
@@ -180,18 +173,12 @@
 			continue;
 		}
 
-		/* addr is local, so let's go into recursion and expand again,
-		   but first ...  search in parents for loops: */
-		for (addr_parent=addr; addr_parent; addr_parent=addr_parent->parent) {
-			if (addr_isequal_alias(alias_addr, addr_parent)) {
-				break;
-			}
-		}
-		if (addr_parent) {
+		/* addr is local and to expand at this point */
+		/* but first ... search in parents for loops: */
+		if (addr_isequal_parent(addr, alias_addr, conf.alias_local_cmp)) {
 			/* loop detected, ignore this path */
-			logwrite(LOG_ALERT,
-			         "alias: detected loop (%s -> %s), hence ignoring\n",
-			         addr_parent->local_part, addr->local_part);
+			logwrite(LOG_ALERT, "alias: detected loop, hence ignoring '%s'\n",
+			         alias_addr->local_part);
 			continue;
 		}
 		alias_addr->parent = addr;
@@ -251,7 +238,7 @@
 		rcpt_node_next = g_list_next(rcpt_node);
 		foreach(non_rcpt_list, non_node) {
 			address *non_addr = (address *) (non_node->data);
-			if (addr_isequal(addr, non_addr)) {
+			if (addr_isequal(addr, non_addr, conf.alias_local_cmp)) {
 				done_list = g_list_remove_link(done_list, rcpt_node);
 				g_list_free_1(rcpt_node);
 				/* this address is still in the children lists
--- a/src/fail_msg.c	Mon Oct 25 15:41:48 2010 -0300
+++ b/src/fail_msg.c	Mon Oct 25 17:42:48 2010 -0300
@@ -35,7 +35,8 @@
 		ret_path = create_address_qualified("postmaster", TRUE, conf.host_name);
 		foreach(failed_rcpts, node) {
 			address *addr = (address *) (node->data);
-			if (addr_isequal_parent(addr, ret_path)) {
+
+			if (addr_isequal_parent(addr, ret_path, strcasecmp)) {
 				logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n", msg->uid, addr_string(ret_path));
 				return FALSE;
 			}
--- a/src/masqmail.h	Mon Oct 25 15:41:48 2010 -0300
+++ b/src/masqmail.h	Mon Oct 25 17:42:48 2010 -0300
@@ -390,8 +390,8 @@
 void destroy_address(address * addr);
 address *copy_modify_address(const address * orig, gchar * l_part, gchar * dom);
 #define copy_address(addr) copy_modify_address(addr, NULL, NULL)
-gboolean addr_isequal(address * addr1, address * addr2);
-gboolean addr_isequal_parent(address * addr1, address * addr2);
+gboolean addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*));
+gboolean addr_isequal_parent(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*));
 address *addr_find_ancestor(address * addr);
 gboolean addr_is_delivered_children(address * addr);
 gboolean addr_is_finished_children(address * addr);