comparison 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
comparison
equal deleted inserted replaced
316:d596ac8b5afb 317:55b7bde95d37
236 } 236 }
237 } 237 }
238 } 238 }
239 239
240 static gint 240 static gint
241 _g_list_addrcmp(gconstpointer a, gconstpointer b) 241 _g_list_addrcmp(gconstpointer pattern, gconstpointer addr)
242 { 242 {
243 return addr_match((address *) a, (address *) b); 243 int res;
244 address* patternaddr = (address*) pattern;
245 address* stringaddr = (address*) addr;
246
247 DEBUG(6) debugf("_g_list_addrcmp: pattern `%s' `%s' on string `%s' `%s'\n",
248 patternaddr->local_part, patternaddr->domain,
249 stringaddr->local_part, stringaddr->domain);
250 /* TODO: check if we should match here dependent on caseless_matching */
251 res = fnmatch(patternaddr->local_part, stringaddr->local_part, 0);
252 if (res != 0) {
253 DEBUG(6) debugf("_g_list_addrcmp: ... failed on local_part\n");
254 return res;
255 }
256 res = fnmatch(patternaddr->domain, stringaddr->domain, FNM_CASEFOLD);
257 DEBUG(6) debugf("_g_list_addrcmp: ... %s\n", (res==0) ? "matched" : "failed on domain");
258 return res;
244 } 259 }
245 260
246 gboolean 261 gboolean
247 route_is_allowed_return_path(connect_route * route, address * ret_path) 262 route_sender_is_allowed(connect_route * route, address * ret_path)
248 { 263 {
249 if (route->not_allowed_return_paths != NULL) { 264 if (route->denied_senders && g_list_find_custom(route->denied_senders, ret_path, _g_list_addrcmp)) {
250 if (g_list_find_custom(route->not_allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) { 265 return FALSE;
251 return FALSE; 266 }
252 } 267 if (route->allowed_senders) {
253 } 268 if (g_list_find_custom(route->allowed_senders, ret_path, _g_list_addrcmp)) {
254 if (route->allowed_return_paths != NULL) {
255 if (g_list_find_custom(route->allowed_return_paths, ret_path, _g_list_addrcmp) != NULL) {
256 return TRUE; 269 return TRUE;
257 } else { 270 } else {
258 return FALSE; 271 return FALSE;
259 } 272 }
260 }
261 return TRUE;
262 }
263
264 static gint
265 _g_list_strcmp(gconstpointer a, gconstpointer b)
266 {
267 return (gint) strcmp(a, b);
268 }
269
270 gboolean
271 route_is_allowed_mail_local(connect_route * route, address * ret_path)
272 {
273 gchar *loc_part = ret_path->local_part;
274
275 if (route->not_allowed_mail_locals != NULL) {
276 if (g_list_find_custom(route->not_allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
277 return FALSE;
278 }
279 if (route->allowed_mail_locals != NULL) {
280 if (g_list_find_custom(route->allowed_mail_locals, loc_part, _g_list_strcmp) != NULL)
281 return TRUE;
282 else
283 return FALSE;
284 } 273 }
285 return TRUE; 274 return TRUE;
286 } 275 }
287 276
288 /* 277 /*
289 Make lists of matching/not matching rcpts. 278 Make lists of matching/not matching rcpts.
290 Local domains are NOT regared here, these should be sorted out previously 279 Local domains are NOT regared here, these should be sorted out previously
291 */ 280 */
292 void 281 void
293 msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list) 282 route_split_rcpts(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list)
294 { 283 {
295 GList *tmp_list = NULL; 284 GList *tmp_list = NULL;
296 /* sort out those domains that can be sent over this connection: */ 285 /* sort out those domains that can be sent over this connection: */
297 if (route->allowed_rcpt_domains) { 286 if (route->allowed_recipients) {
298 DEBUG(5) debugf("testing for route->allowed_rcpt_domains\n"); 287 DEBUG(5) debugf("testing for route->allowed_recipients\n");
299 split_rcpts(rcpt_list, route->allowed_rcpt_domains, NULL, &tmp_list, p_non_rcpt_list); 288 split_rcpts(rcpt_list, route->allowed_recipients, NULL, &tmp_list, p_non_rcpt_list);
300 } else { 289 } else {
301 DEBUG(5) debugf("route->allowed_rcpt_domains == NULL\n"); 290 DEBUG(5) debugf("route->allowed_recipients == NULL\n");
302 tmp_list = g_list_copy(rcpt_list); 291 tmp_list = g_list_copy(rcpt_list);
303 } 292 }
304 293
305 /* sort out those domains that cannot be sent over this connection: */ 294 /* sort out those domains that cannot be sent over this connection: */
306 split_rcpts(tmp_list, route->not_allowed_rcpt_domains, NULL, p_non_rcpt_list, p_rcpt_list); 295 split_rcpts(tmp_list, route->denied_recipients, NULL, p_non_rcpt_list, p_rcpt_list);
307 g_list_free(tmp_list); 296 g_list_free(tmp_list);
308 } 297 }
309 298
310 msg_out* 299 msg_out*
311 route_prepare_msgout(connect_route * route, msg_out * msgout) 300 route_prepare_msgout(connect_route * route, msg_out * msgout)