masqmail

diff src/route.c @ 317:55b7bde95d37

reworked allowed and denied addrs for routes The following refactorings had been made: - allowed_mail_locals + allowed_return_paths -> allowed_senders - not_allowed_mail_locals + not_allowed_return_paths -> denied_senders - allowed_rcpt_domains -> allowed_recipients - not_allowed_rcpt_domains -> denied_recipients The new options allow more consistent and more flexible matching.
author meillo@marmaro.de
date Thu, 28 Apr 2011 09:55:06 +0200
parents 87df0aa99cc7
children 257ffce6c1cd
line diff
     1.1 --- a/src/route.c	Mon Apr 25 15:17:30 2011 +0200
     1.2 +++ b/src/route.c	Thu Apr 28 09:55:06 2011 +0200
     1.3 @@ -238,21 +238,34 @@
     1.4  }
     1.5  
     1.6  static gint
     1.7 -_g_list_addrcmp(gconstpointer a, gconstpointer b)
     1.8 +_g_list_addrcmp(gconstpointer pattern, gconstpointer addr)
     1.9  {
    1.10 -	return addr_match((address *) a, (address *) b);
    1.11 +	int res;
    1.12 +	address* patternaddr = (address*) pattern;
    1.13 +	address* stringaddr = (address*) addr;
    1.14 +
    1.15 +	DEBUG(6) debugf("_g_list_addrcmp: pattern `%s' `%s' on string `%s' `%s'\n",
    1.16 +	                patternaddr->local_part, patternaddr->domain,
    1.17 +	                stringaddr->local_part, stringaddr->domain);
    1.18 +	/* TODO: check if we should match here dependent on caseless_matching */
    1.19 +	res = fnmatch(patternaddr->local_part, stringaddr->local_part, 0);
    1.20 +	if (res != 0) {
    1.21 +		DEBUG(6) debugf("_g_list_addrcmp: ... failed on local_part\n");
    1.22 +		return res;
    1.23 +	}
    1.24 +	res = fnmatch(patternaddr->domain, stringaddr->domain, FNM_CASEFOLD);
    1.25 +	DEBUG(6) debugf("_g_list_addrcmp: ... %s\n", (res==0) ? "matched" : "failed on domain");
    1.26 +	return res;
    1.27  }
    1.28  
    1.29  gboolean
    1.30 -route_is_allowed_return_path(connect_route * route, address * ret_path)
    1.31 +route_sender_is_allowed(connect_route * route, address * ret_path)
    1.32  {
    1.33 -	if (route->not_allowed_return_paths != NULL) {
    1.34 -		if (g_list_find_custom(route->not_allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
    1.35 -			return FALSE;
    1.36 -		}
    1.37 +	if (route->denied_senders && g_list_find_custom(route->denied_senders, ret_path, _g_list_addrcmp)) {
    1.38 +		return FALSE;
    1.39  	}
    1.40 -	if (route->allowed_return_paths != NULL) {
    1.41 -		if (g_list_find_custom(route->allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
    1.42 +	if (route->allowed_senders) {
    1.43 +		if (g_list_find_custom(route->allowed_senders, ret_path, _g_list_addrcmp)) {
    1.44  			return TRUE;
    1.45  		} else {
    1.46  			return FALSE;
    1.47 @@ -261,49 +274,25 @@
    1.48  	return TRUE;
    1.49  }
    1.50  
    1.51 -static gint
    1.52 -_g_list_strcmp(gconstpointer a, gconstpointer b)
    1.53 -{
    1.54 -	return (gint) strcmp(a, b);
    1.55 -}
    1.56 -
    1.57 -gboolean
    1.58 -route_is_allowed_mail_local(connect_route * route, address * ret_path)
    1.59 -{
    1.60 -	gchar *loc_part = ret_path->local_part;
    1.61 -
    1.62 -	if (route->not_allowed_mail_locals != NULL) {
    1.63 -		if (g_list_find_custom(route->not_allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
    1.64 -			return FALSE;
    1.65 -	}
    1.66 -	if (route->allowed_mail_locals != NULL) {
    1.67 -		if (g_list_find_custom(route->allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
    1.68 -			return TRUE;
    1.69 -		else
    1.70 -			return FALSE;
    1.71 -	}
    1.72 -	return TRUE;
    1.73 -}
    1.74 -
    1.75  /*
    1.76     Make lists of matching/not matching rcpts.
    1.77     Local domains are NOT regared here, these should be sorted out previously
    1.78  */
    1.79  void
    1.80 -msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
    1.81 +route_split_rcpts(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
    1.82  {
    1.83  	GList *tmp_list = NULL;
    1.84  	/* sort out those domains that can be sent over this connection: */
    1.85 -	if (route->allowed_rcpt_domains) {
    1.86 -		DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n");
    1.87 -		split_rcpts(rcpt_list, route->allowed_rcpt_domains, NULL, &tmp_list, p_non_rcpt_list);
    1.88 +	if (route->allowed_recipients) {
    1.89 +		DEBUG(5) debugf("testing for route->allowed_recipients\n");
    1.90 +		split_rcpts(rcpt_list, route->allowed_recipients, NULL, &tmp_list, p_non_rcpt_list);
    1.91  	} else {
    1.92 -		DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n");
    1.93 +		DEBUG(5) debugf("route->allowed_recipients == NULL\n");
    1.94  		tmp_list = g_list_copy(rcpt_list);
    1.95  	}
    1.96  
    1.97  	/* sort out those domains that cannot be sent over this connection: */
    1.98 -	split_rcpts(tmp_list, route->not_allowed_rcpt_domains, NULL, p_non_rcpt_list, p_rcpt_list);
    1.99 +	split_rcpts(tmp_list, route->denied_recipients, NULL, p_non_rcpt_list, p_rcpt_list);
   1.100  	g_list_free(tmp_list);
   1.101  }
   1.102