* include/mailutils/cfg.h (mu_offsetof): Move mu_offsetof to
types.hin. * include/mailutils/types.hin (mu_offsetof): New macro. * mailbox/acl.c (MU_S_UN_NAME): New macro. (debug_sockaddr, mu_sockaddr_to_str, _acl_match) (_run_entry): Take into account salen for AF_UNIX.
Showing
4 changed files
with
39 additions
and
15 deletions
1 | 2008-01-16 Sergey Poznyakoff <gray@gnu.org.ua> | ||
2 | |||
3 | * include/mailutils/cfg.h (mu_offsetof): Move mu_offsetof to | ||
4 | types.hin. | ||
5 | * include/mailutils/types.hin (mu_offsetof): New macro. | ||
6 | * mailbox/acl.c (MU_S_UN_NAME): New macro. | ||
7 | (debug_sockaddr, mu_sockaddr_to_str, _acl_match) | ||
8 | (_run_entry): Take into account salen for AF_UNIX. | ||
9 | |||
1 | 2008-01-14 Sergey Poznyakoff <gray@gnu.org.ua> | 10 | 2008-01-14 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 11 | ||
3 | * include/mailutils/gocs.h (log_facility): Remove. | 12 | * include/mailutils/gocs.h (log_facility): Remove. | ... | ... |
... | @@ -135,8 +135,6 @@ struct mu_cfg_param | ... | @@ -135,8 +135,6 @@ struct mu_cfg_param |
135 | const char *argname; | 135 | const char *argname; |
136 | }; | 136 | }; |
137 | 137 | ||
138 | #define mu_offsetof(s,f) ((size_t)&((s*)0)->f) | ||
139 | |||
140 | #define MU_TARGET_REF(f) &f, 0 | 138 | #define MU_TARGET_REF(f) &f, 0 |
141 | #define MU_TARGET_OFF(s,f) NULL, mu_offsetof(s,f) | 139 | #define MU_TARGET_OFF(s,f) NULL, mu_offsetof(s,f) |
142 | 140 | ... | ... |
... | @@ -116,6 +116,8 @@ typedef struct _mu_m_server *mu_m_server_t; | ... | @@ -116,6 +116,8 @@ typedef struct _mu_m_server *mu_m_server_t; |
116 | 116 | ||
117 | #define MU_FOLDER_ATTRIBUTE_ALL \ | 117 | #define MU_FOLDER_ATTRIBUTE_ALL \ |
118 | (MU_FOLDER_ATTRIBUTE_DIRECTORY|MU_FOLDER_ATTRIBUTE_FILE) | 118 | (MU_FOLDER_ATTRIBUTE_DIRECTORY|MU_FOLDER_ATTRIBUTE_FILE) |
119 | |||
120 | #define mu_offsetof(s,f) ((size_t)&((s*)0)->f) | ||
119 | 121 | ||
120 | #ifdef __cplusplus | 122 | #ifdef __cplusplus |
121 | } | 123 | } | ... | ... |
... | @@ -91,8 +91,8 @@ prepare_sa (struct sockaddr *sa) | ... | @@ -91,8 +91,8 @@ prepare_sa (struct sockaddr *sa) |
91 | 91 | ||
92 | int | 92 | int |
93 | mu_acl_entry_create (struct _mu_acl_entry **pent, | 93 | mu_acl_entry_create (struct _mu_acl_entry **pent, |
94 | mu_acl_action_t action, void *data, | 94 | mu_acl_action_t action, void *data, |
95 | struct sockaddr *sa, int salen, unsigned long netmask) | 95 | struct sockaddr *sa, int salen, unsigned long netmask) |
96 | { | 96 | { |
97 | struct _mu_acl_entry *p = malloc (mu_acl_entry_size (salen)); | 97 | struct _mu_acl_entry *p = malloc (mu_acl_entry_size (salen)); |
98 | if (!p) | 98 | if (!p) |
... | @@ -307,8 +307,12 @@ mu_acl_string_to_action (const char *str, mu_acl_action_t *pres) | ... | @@ -307,8 +307,12 @@ mu_acl_string_to_action (const char *str, mu_acl_action_t *pres) |
307 | return rc; | 307 | return rc; |
308 | } | 308 | } |
309 | 309 | ||
310 | #define MU_S_UN_NAME(sa, salen) \ | ||
311 | ((salen < mu_offsetof (struct sockaddr_un,sun_path)) ? "" : (sa)->sun_path) | ||
312 | |||
310 | static void | 313 | static void |
311 | debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa) | 314 | debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa, |
315 | int salen) | ||
312 | { | 316 | { |
313 | switch (sa->sa_family) | 317 | switch (sa->sa_family) |
314 | { | 318 | { |
... | @@ -324,7 +328,10 @@ debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa) | ... | @@ -324,7 +328,10 @@ debug_sockaddr (mu_debug_t dbg, mu_log_level_t lvl, struct sockaddr *sa) |
324 | case AF_UNIX: | 328 | case AF_UNIX: |
325 | { | 329 | { |
326 | struct sockaddr_un *s_un = (struct sockaddr_un *)sa; | 330 | struct sockaddr_un *s_un = (struct sockaddr_un *)sa; |
327 | mu_debug_printf (dbg, lvl, "{AF_UNIX %s}", s_un->sun_path); | 331 | if (MU_S_UN_NAME(s_un, salen)[0] == 0) |
332 | mu_debug_printf (dbg, lvl, "{AF_UNIX}"); | ||
333 | else | ||
334 | mu_debug_printf (dbg, lvl, "{AF_UNIX %s}", s_un->sun_path); | ||
328 | break; | 335 | break; |
329 | } | 336 | } |
330 | 337 | ||
... | @@ -378,14 +385,20 @@ mu_sockaddr_to_str (struct sockaddr *sa, int salen, | ... | @@ -378,14 +385,20 @@ mu_sockaddr_to_str (struct sockaddr *sa, int salen, |
378 | case AF_UNIX: | 385 | case AF_UNIX: |
379 | { | 386 | { |
380 | struct sockaddr_un *s_un = (struct sockaddr_un *)sa; | 387 | struct sockaddr_un *s_un = (struct sockaddr_un *)sa; |
381 | len += mu_stpcpy (&bufptr, &buflen, "socket "); | 388 | if (MU_S_UN_NAME(s_un, salen)[0] == 0) |
382 | len += mu_stpcpy (&bufptr, &buflen, s_un->sun_path); | 389 | len += mu_stpcpy (&bufptr, &buflen, "anonymous socket"); |
390 | else | ||
391 | { | ||
392 | len += mu_stpcpy (&bufptr, &buflen, "socket "); | ||
393 | len += mu_stpcpy (&bufptr, &buflen, s_un->sun_path); | ||
394 | } | ||
383 | break; | 395 | break; |
384 | } | 396 | } |
385 | 397 | ||
386 | default: | 398 | default: |
387 | len += mu_stpcpy (&bufptr, &buflen, "{Unsupported family: "); | 399 | len += mu_stpcpy (&bufptr, &buflen, "{Unsupported family: "); |
388 | len += mu_stpcpy (&bufptr, &buflen, umaxtostr (sa->sa_family, buf)); | 400 | len += mu_stpcpy (&bufptr, &buflen, umaxtostr (sa->sa_family, buf)); |
401 | len += mu_stpcpy (&bufptr, &buflen, "}"); | ||
389 | } | 402 | } |
390 | if (plen) | 403 | if (plen) |
391 | *plen = len + 1; | 404 | *plen = len + 1; |
... | @@ -405,7 +418,8 @@ mu_sockaddr_to_astr (struct sockaddr *sa, int salen) | ... | @@ -405,7 +418,8 @@ mu_sockaddr_to_astr (struct sockaddr *sa, int salen) |
405 | } | 418 | } |
406 | 419 | ||
407 | int | 420 | int |
408 | _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa) | 421 | _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa, |
422 | int salen) | ||
409 | { | 423 | { |
410 | #define RESMATCH(word) \ | 424 | #define RESMATCH(word) \ |
411 | if (mu_debug_check_level (debug, MU_DEBUG_TRACE0)) \ | 425 | if (mu_debug_check_level (debug, MU_DEBUG_TRACE0)) \ |
... | @@ -416,9 +430,9 @@ _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa) | ... | @@ -416,9 +430,9 @@ _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa) |
416 | struct in_addr a; | 430 | struct in_addr a; |
417 | 431 | ||
418 | __MU_DEBUG1 (debug, MU_DEBUG_TRACE0, "%s", "Does "); | 432 | __MU_DEBUG1 (debug, MU_DEBUG_TRACE0, "%s", "Does "); |
419 | debug_sockaddr (debug, MU_DEBUG_TRACE0, sa); | 433 | debug_sockaddr (debug, MU_DEBUG_TRACE0, sa, salen); |
420 | mu_debug_printf (debug, MU_DEBUG_TRACE0, " match "); | 434 | mu_debug_printf (debug, MU_DEBUG_TRACE0, " match "); |
421 | debug_sockaddr (debug, MU_DEBUG_TRACE0, ent->sa); | 435 | debug_sockaddr (debug, MU_DEBUG_TRACE0, ent->sa, salen); |
422 | a.s_addr = ent->netmask; | 436 | a.s_addr = ent->netmask; |
423 | a.s_addr = htonl (a.s_addr); | 437 | a.s_addr = htonl (a.s_addr); |
424 | mu_debug_printf (debug, MU_DEBUG_TRACE0, " netmask %s? ", inet_ntoa (a)); | 438 | mu_debug_printf (debug, MU_DEBUG_TRACE0, " netmask %s? ", inet_ntoa (a)); |
... | @@ -458,7 +472,8 @@ _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa) | ... | @@ -458,7 +472,8 @@ _acl_match (mu_debug_t debug, struct _mu_acl_entry *ent, struct sockaddr *sa) |
458 | struct sockaddr_un *sun_ent = (struct sockaddr_un *)ent->sa; | 472 | struct sockaddr_un *sun_ent = (struct sockaddr_un *)ent->sa; |
459 | struct sockaddr_un *sun_item = (struct sockaddr_un *)sa; | 473 | struct sockaddr_un *sun_item = (struct sockaddr_un *)sa; |
460 | 474 | ||
461 | if (sun_ent->sun_path[0] && sun_item->sun_path[0] | 475 | if (MU_S_UN_NAME (sun_ent, ent->salen)[0] |
476 | && MU_S_UN_NAME (sun_item, salen)[0] | ||
462 | && strcmp (sun_ent->sun_path, sun_item->sun_path)) | 477 | && strcmp (sun_ent->sun_path, sun_item->sun_path)) |
463 | { | 478 | { |
464 | RESMATCH ("no"); | 479 | RESMATCH ("no"); |
... | @@ -619,7 +634,7 @@ _run_entry (void *item, void *data) | ... | @@ -619,7 +634,7 @@ _run_entry (void *item, void *data) |
619 | __MU_DEBUG2 (rp->debug, MU_DEBUG_TRACE0, "%d:%s: ", rp->idx, s); | 634 | __MU_DEBUG2 (rp->debug, MU_DEBUG_TRACE0, "%d:%s: ", rp->idx, s); |
620 | } | 635 | } |
621 | 636 | ||
622 | if (_acl_match (rp->debug, ent, rp->sa) == 0) | 637 | if (_acl_match (rp->debug, ent, rp->sa, rp->salen) == 0) |
623 | { | 638 | { |
624 | switch (ent->action) | 639 | switch (ent->action) |
625 | { | 640 | { |
... | @@ -645,7 +660,7 @@ _run_entry (void *item, void *data) | ... | @@ -645,7 +660,7 @@ _run_entry (void *item, void *data) |
645 | } | 660 | } |
646 | else | 661 | else |
647 | { | 662 | { |
648 | debug_sockaddr (dbg, MU_DIAG_INFO, rp->sa); | 663 | debug_sockaddr (dbg, MU_DIAG_INFO, rp->sa, rp->salen); |
649 | mu_debug_printf (dbg, MU_DIAG_INFO, "\n"); | 664 | mu_debug_printf (dbg, MU_DIAG_INFO, "\n"); |
650 | } | 665 | } |
651 | } | 666 | } |
... | @@ -707,7 +722,7 @@ mu_acl_check_sockaddr (mu_acl_t acl, struct sockaddr *sa, int salen, | ... | @@ -707,7 +722,7 @@ mu_acl_check_sockaddr (mu_acl_t acl, struct sockaddr *sa, int salen, |
707 | if (mu_debug_check_level (acl->debug, MU_DEBUG_TRACE0)) | 722 | if (mu_debug_check_level (acl->debug, MU_DEBUG_TRACE0)) |
708 | { | 723 | { |
709 | __MU_DEBUG1 (acl->debug, MU_DEBUG_TRACE0, "%s", "Checking sockaddr "); | 724 | __MU_DEBUG1 (acl->debug, MU_DEBUG_TRACE0, "%s", "Checking sockaddr "); |
710 | debug_sockaddr (acl->debug, MU_DEBUG_TRACE0, r.sa); | 725 | debug_sockaddr (acl->debug, MU_DEBUG_TRACE0, r.sa, r.salen); |
711 | mu_debug_printf (acl->debug, MU_DEBUG_TRACE0, "\n"); | 726 | mu_debug_printf (acl->debug, MU_DEBUG_TRACE0, "\n"); |
712 | } | 727 | } |
713 | 728 | ... | ... |
-
Please register or sign in to post a comment