masqmail

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
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 diff
     1.1 --- a/man/masqmail.conf.5	Mon Oct 25 15:41:48 2010 -0300
     1.2 +++ b/man/masqmail.conf.5	Mon Oct 25 17:42:48 2010 -0300
     1.3 @@ -251,7 +251,11 @@
     1.4  .TP
     1.5  \fBalias_local_caseless = \fIboolean\fR
     1.6  
     1.7 -If this is set, local parts in the alias file will be matched disregarding upper/lower case.
     1.8 +If this is set, aliasing and the matching for \fBlocal_addresses\fP and
     1.9 +\fBnot_local_addresses\fP will be done caseless.
    1.10 +
    1.11 +Note: Be sure to change this option only if the queue is empty as
    1.12 +correct processing of queued messages is not guaranteed otherwise.
    1.13  
    1.14  Default: false
    1.15  
     2.1 --- a/src/address.c	Mon Oct 25 15:41:48 2010 -0300
     2.2 +++ b/src/address.c	Mon Oct 25 17:42:48 2010 -0300
     2.3 @@ -102,20 +102,20 @@
     2.4  }
     2.5  
     2.6  gboolean
     2.7 -addr_isequal(address * addr1, address * addr2)
     2.8 +addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*))
     2.9  {
    2.10 -	return (strcmp(addr1->local_part, addr2->local_part) == 0)
    2.11 +	return (cmpfunc(addr1->local_part, addr2->local_part) == 0)
    2.12  	       && (strcasecmp(addr1->domain, addr2->domain) == 0);
    2.13  }
    2.14  
    2.15  /* searches in ancestors of addr1 */
    2.16  gboolean
    2.17 -addr_isequal_parent(address * addr1, address * addr2)
    2.18 +addr_isequal_parent(address* addr1, address* addr2, int (*cmpfunc) (const char*, const char*))
    2.19  {
    2.20  	address *addr;
    2.21  
    2.22  	for (addr = addr1; addr; addr = addr->parent)
    2.23 -		if (addr_isequal(addr, addr2))
    2.24 +		if (addr_isequal(addr, addr2, cmpfunc))
    2.25  			return TRUE;
    2.26  
    2.27  	return FALSE;
     3.1 --- a/src/alias.c	Mon Oct 25 15:41:48 2010 -0300
     3.2 +++ b/src/alias.c	Mon Oct 25 17:42:48 2010 -0300
     3.3 @@ -40,7 +40,7 @@
     3.4  			a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
     3.5  			DEBUG(6) debugf("not_local_addresses: addr_node->data=%s a->address=%s\n",
     3.6  			                addr_node->data, a->address);
     3.7 -			if (addr_isequal(a, addr)) {
     3.8 +			if (addr_isequal(a, addr, conf.alias_local_cmp)) {
     3.9  				destroy_address(a);
    3.10  				/* in local_hosts but also in not_local_addresses */
    3.11  				return FALSE;
    3.12 @@ -54,7 +54,7 @@
    3.13  		a = create_address_qualified(addr_node->data, TRUE, conf.host_name);
    3.14  		DEBUG(6) debugf("local_addresses: addr_node->data=%s a->address=%s\n",
    3.15  		                addr_node->data, a->address);
    3.16 -		if (addr_isequal(a, addr)) {
    3.17 +		if (addr_isequal(a, addr, conf.alias_local_cmp)) {
    3.18  			destroy_address(a);
    3.19  			/* in local_addresses */
    3.20  			return TRUE;
    3.21 @@ -64,13 +64,6 @@
    3.22  	return FALSE;
    3.23  }
    3.24  
    3.25 -static gboolean
    3.26 -addr_isequal_alias(address * addr1, address * addr2)
    3.27 -{
    3.28 -	return (conf.alias_local_cmp(addr1->local_part, addr2->local_part) == 0)
    3.29 -	       && (strcasecmp(addr1->domain, addr2->domain) == 0);
    3.30 -}
    3.31 -
    3.32  static GList*
    3.33  parse_list(gchar * line)
    3.34  {
    3.35 @@ -180,18 +173,12 @@
    3.36  			continue;
    3.37  		}
    3.38  
    3.39 -		/* addr is local, so let's go into recursion and expand again,
    3.40 -		   but first ...  search in parents for loops: */
    3.41 -		for (addr_parent=addr; addr_parent; addr_parent=addr_parent->parent) {
    3.42 -			if (addr_isequal_alias(alias_addr, addr_parent)) {
    3.43 -				break;
    3.44 -			}
    3.45 -		}
    3.46 -		if (addr_parent) {
    3.47 +		/* addr is local and to expand at this point */
    3.48 +		/* but first ... search in parents for loops: */
    3.49 +		if (addr_isequal_parent(addr, alias_addr, conf.alias_local_cmp)) {
    3.50  			/* loop detected, ignore this path */
    3.51 -			logwrite(LOG_ALERT,
    3.52 -			         "alias: detected loop (%s -> %s), hence ignoring\n",
    3.53 -			         addr_parent->local_part, addr->local_part);
    3.54 +			logwrite(LOG_ALERT, "alias: detected loop, hence ignoring '%s'\n",
    3.55 +			         alias_addr->local_part);
    3.56  			continue;
    3.57  		}
    3.58  		alias_addr->parent = addr;
    3.59 @@ -251,7 +238,7 @@
    3.60  		rcpt_node_next = g_list_next(rcpt_node);
    3.61  		foreach(non_rcpt_list, non_node) {
    3.62  			address *non_addr = (address *) (non_node->data);
    3.63 -			if (addr_isequal(addr, non_addr)) {
    3.64 +			if (addr_isequal(addr, non_addr, conf.alias_local_cmp)) {
    3.65  				done_list = g_list_remove_link(done_list, rcpt_node);
    3.66  				g_list_free_1(rcpt_node);
    3.67  				/* this address is still in the children lists
     4.1 --- a/src/fail_msg.c	Mon Oct 25 15:41:48 2010 -0300
     4.2 +++ b/src/fail_msg.c	Mon Oct 25 17:42:48 2010 -0300
     4.3 @@ -35,7 +35,8 @@
     4.4  		ret_path = create_address_qualified("postmaster", TRUE, conf.host_name);
     4.5  		foreach(failed_rcpts, node) {
     4.6  			address *addr = (address *) (node->data);
     4.7 -			if (addr_isequal_parent(addr, ret_path)) {
     4.8 +
     4.9 +			if (addr_isequal_parent(addr, ret_path, strcasecmp)) {
    4.10  				logwrite(LOG_ALERT, "%s == %s: postmaster address failed\n", msg->uid, addr_string(ret_path));
    4.11  				return FALSE;
    4.12  			}
     5.1 --- a/src/masqmail.h	Mon Oct 25 15:41:48 2010 -0300
     5.2 +++ b/src/masqmail.h	Mon Oct 25 17:42:48 2010 -0300
     5.3 @@ -390,8 +390,8 @@
     5.4  void destroy_address(address * addr);
     5.5  address *copy_modify_address(const address * orig, gchar * l_part, gchar * dom);
     5.6  #define copy_address(addr) copy_modify_address(addr, NULL, NULL)
     5.7 -gboolean addr_isequal(address * addr1, address * addr2);
     5.8 -gboolean addr_isequal_parent(address * addr1, address * addr2);
     5.9 +gboolean addr_isequal(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*));
    5.10 +gboolean addr_isequal_parent(address * addr1, address * addr2, int (*cmpfunc) (const char*, const char*));
    5.11  address *addr_find_ancestor(address * addr);
    5.12  gboolean addr_is_delivered_children(address * addr);
    5.13  gboolean addr_is_finished_children(address * addr);