do { \
if ((rec)->nested > SPF_MAX_NESTING || \
(rec)->dns_requests > SPF_MAX_DNS_REQUESTS) { \
+ msg_info ("<%s> spf recursion limit %d is reached, domain: %s", \
+ (rec)->task->message_id, (rec)->dns_requests, \
+ (rec)->sender_domain); \
return FALSE; \
} \
} while (0) \
}
static gboolean
-parse_spf_ipmask (const gchar *begin, struct spf_addr *addr)
+parse_spf_ipmask (const gchar *begin, struct spf_addr *addr, struct spf_record *rec)
{
const gchar *pos;
gchar mask_buf[5] = {'\0'}, *p;
case 0:
/* Require ':' */
if (*pos != ':') {
+ msg_info ("<%s>: spf error for domain %s: semicolon missing",
+ rec->task->message_id, rec->sender_domain);
return FALSE;
}
state = 1;
}
else {
/* Invalid character */
+ msg_info ("<%s>: spf error for domain %s: invalid ip address",
+ rec->task->message_id, rec->sender_domain);
return FALSE;
}
break;
case 2:
/* Parse mask */
if (p - mask_buf >= (gint)sizeof (mask_buf)) {
+ msg_info ("<%s>: spf error for domain %s: too long mask",
+ rec->task->message_id, rec->sender_domain);
return FALSE;
}
if (g_ascii_isdigit (*pos)) {
addr->data.normal.ipv6 = TRUE;
}
else {
+ msg_info ("<%s>: spf error for domain %s: invalid ip address",
+ rec->task->message_id, rec->sender_domain);
return FALSE;
}
}
if (!addr->data.normal.ipv6) {
addr->data.normal.mask = strtoul (mask_buf, NULL, 10);
if (addr->data.normal.mask > 32) {
- msg_info ("bad ipmask value: '%s'", begin);
+ msg_info ("<%s>: spf error for domain %s: bad ipmask value: '%s'",
+ rec->task->message_id, rec->sender_domain, begin);
return FALSE;
}
}
else {
addr->data.normal.mask = strtoul (mask_buf, NULL, 10);
if (addr->data.normal.mask > 128) {
- msg_info ("bad ipmask value: '%s'", begin);
+ msg_info ("<%s>: spf error for domain %s: bad ipmask value: '%s'",
+ rec->task->message_id, rec->sender_domain, begin);
return FALSE;
}
}
rspamd_strlcpy (mask_buf, p + 1, sizeof (mask_buf));
addr->data.normal.mask = mask_buf[0] * 10 + mask_buf[1];
if (addr->data.normal.mask > 32) {
+ msg_info ("<%s>: spf error for domain %s: too long mask",
+ rec->task->message_id, rec->sender_domain);
return FALSE;
}
if (host == NULL) {
cb->rec->addrs = g_list_insert_before (cb->rec->addrs, tmp, new_addr);
}
else {
- msg_info ("wrong address list");
+ msg_info ("<%s>: spf error for domain %s: addresses mismatch",
+ task->message_id, cb->rec->sender_domain);
}
}
cb->rec->addrs = g_list_insert_before (cb->rec->addrs, tmp, new_addr);
}
else {
- msg_info ("wrong address list");
+ msg_info ("<%s>: spf error for domain %s: addresses mismatch",
+ task->message_id, cb->rec->sender_domain);
}
}
switch (cb->cur_action) {
case SPF_RESOLVE_MX:
if (reply->type == DNS_REQUEST_MX) {
- msg_info ("cannot find MX record for %s", cb->rec->cur_domain);
+ msg_info ("<%s>: spf error for domain %s: cannot find MX record for %s",
+ task->message_id, cb->rec->sender_domain, cb->rec->cur_domain);
cb->addr->data.normal.d.in4.s_addr = INADDR_NONE;
cb->addr->data.normal.mask = 32;
}
else if (reply->type != DNS_REQUEST_MX) {
- msg_info ("cannot resolve MX record for %s", cb->rec->cur_domain);
+ msg_info ("<%s>: spf error for domain %s: cannot resolve MX record for %s",
+ task->message_id, cb->rec->sender_domain, cb->rec->cur_domain);
cb->addr->data.normal.d.in4.s_addr = INADDR_NONE;
cb->addr->data.normal.mask = 32;
}
case SPF_RESOLVE_PTR:
break;
case SPF_RESOLVE_REDIRECT:
- msg_info ("cannot resolve TXT record for redirect action");
+ msg_info ("<%s>: spf error for domain %s: cannot resolve TXT record for %s",
+ task->message_id, cb->rec->sender_domain, cb->rec->cur_domain);
break;
case SPF_RESOLVE_INCLUDE:
- msg_info ("cannot resolve TXT record for include action");
+ msg_info ("<%s>: spf error for domain %s: cannot resolve TXT record for %s",
+ task->message_id, cb->rec->sender_domain, cb->rec->cur_domain);
break;
case SPF_RESOLVE_EXP:
break;
cb->addr = addr;
cb->cur_action = SPF_RESOLVE_A;
cb->in_include = rec->in_include;
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, DNS_REQUEST_A, host)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ spf_record_dns_callback, (void *)cb, DNS_REQUEST_A, host)) {
task->dns_requests ++;
rec->requests_inflight ++;
return TRUE;
{
CHECK_REC (rec);
- msg_info ("ptr parsing is unimplemented");
+ msg_info ("<%s>: spf error for domain %s: ptr elements are not implemented",
+ rec->task->message_id, rec->sender_domain);
return FALSE;
}
memset (&addr->data.normal, 0, sizeof (addr->data.normal));
cb->cur_action = SPF_RESOLVE_MX;
cb->in_include = rec->in_include;
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, DNS_REQUEST_MX, host)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ spf_record_dns_callback, (void *)cb, DNS_REQUEST_MX, host)) {
task->dns_requests ++;
rec->requests_inflight ++;
/* ip4:addr[/mask] */
CHECK_REC (rec);
- return parse_spf_ipmask (begin, addr);
+ return parse_spf_ipmask (begin, addr, rec);
}
#ifdef HAVE_INET_PTON
/* ip6:addr[/mask] */
CHECK_REC (rec);
- return parse_spf_ipmask (begin, addr);
+ return parse_spf_ipmask (begin, addr, rec);
}
#endif
addr->is_list = TRUE;
addr->data.list = NULL;
domain = memory_pool_strdup (task->task_pool, begin);
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, DNS_REQUEST_TXT, domain)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ spf_record_dns_callback, (void *)cb, DNS_REQUEST_TXT, domain)) {
task->dns_requests ++;
rec->requests_inflight ++;
cb->cur_action = SPF_RESOLVE_REDIRECT;
cb->in_include = rec->in_include;
domain = memory_pool_strdup (task->task_pool, begin);
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, DNS_REQUEST_TXT, domain)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ spf_record_dns_callback, (void *)cb, DNS_REQUEST_TXT, domain)) {
task->dns_requests ++;
rec->requests_inflight ++;
cb->in_include = rec->in_include;
host = memory_pool_strdup (task->task_pool, begin);
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_record_dns_callback, (void *)cb, DNS_REQUEST_A, host)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ spf_record_dns_callback, (void *)cb, DNS_REQUEST_A, host)) {
task->dns_requests ++;
rec->requests_inflight ++;
}
else {
/* Something unknown */
- msg_info ("bad spf element: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: unknown spf element",
+ task->message_id, rec->sender_domain);
return begin;
}
p ++;
}
break;
default:
- msg_info ("unknown or unsupported spf macro %c in %s", *p, begin);
+ msg_info ("<%s>: spf error for domain %s: unknown or unsupported spf macro %c in %s",
+ task->message_id, rec->sender_domain, *p, begin);
return begin;
}
p ++;
need_expand = TRUE;
}
else if (*p != 'r' && !g_ascii_isdigit (*p)) {
- msg_info ("unknown or unsupported spf modifier %c in %s", *p, begin);
+ msg_info ("<%s>: spf error for domain %s: unknown or unsupported spf modifier %c in %s",
+ task->message_id, rec->sender_domain, *p, begin);
return begin;
}
p ++;
}
else {
/* Something unknown */
- msg_info ("bad spf element: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: unknown spf element",
+ task->message_id, rec->sender_domain);
return begin;
}
p ++;
}
break;
default:
- msg_info ("unknown or unsupported spf macro %c in %s", *p, begin);
+ msg_info ("<%s>: spf error for domain %s: unknown or unsupported spf macro %c in %s",
+ task->message_id, rec->sender_domain, *p, begin);
return begin;
}
p ++;
/*XXX: try to implement domain strimming */
}
else {
- msg_info ("unknown or unsupported spf modifier %c in %s", *p, begin);
+ msg_info ("<%s>: spf error for domain %s: unknown or unsupported spf macro %c in %s",
+ task->message_id, rec->sender_domain, *p, begin);
return begin;
}
p ++;
}
/* Null terminate */
*c = '\0';
- msg_info ("%s", new);
+
return new;
}
res = parse_spf_a (task, begin, rec, new);
}
else {
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
}
break;
case 'i':
#endif
}
else {
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
}
break;
case 'm':
res = parse_spf_mx (task, begin, rec, new);
}
else {
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
}
break;
case 'p':
res = parse_spf_ptr (task, begin, rec, new);
}
else {
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
}
break;
case 'e':
res = parse_spf_exists (task, begin, rec, new);
}
else {
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
}
break;
case 'r':
res = parse_spf_redirect (task, begin, rec, NULL);
}
else {
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
}
break;
case 'v':
}
break;
default:
- msg_info ("bad spf command: %s", begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf command %s",
+ task->message_id, rec->sender_domain, begin);
break;
}
if (res) {
/* Skip one number of record, so no we are here spf2.0/ */
begin += sizeof (SPF_VER2_STR);
if (*begin != '/') {
- msg_info ("sender id string has invalid scope");
+ msg_info ("<%s>: spf error for domain %s: sender id is invalid",
+ rec->task->message_id, rec->sender_domain);
}
else {
begin ++;
}
}
else {
- msg_info ("bad spf record version: %*s", sizeof (SPF_VER1_STR) - 1, begin);
+ msg_info ("<%s>: spf error for domain %s: bad spf record version: %*s",
+ rec->task->message_id, rec->sender_domain, sizeof (SPF_VER1_STR) - 1, begin);
}
}
}
rec->sender_domain = rec->cur_domain;
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_dns_callback, (void *)rec, DNS_REQUEST_TXT, rec->cur_domain)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool, spf_dns_callback,
+ (void *)rec, DNS_REQUEST_TXT, rec->cur_domain)) {
task->dns_requests ++;
rec->requests_inflight ++;
return TRUE;
*domain = '\0';
}
rec->sender_domain = rec->cur_domain;
- if (make_dns_request (task->resolver, task->s, task->task_pool, spf_dns_callback, (void *)rec, DNS_REQUEST_TXT, rec->cur_domain)) {
+ if (make_dns_request (task->resolver, task->s, task->task_pool,
+ spf_dns_callback, (void *)rec, DNS_REQUEST_TXT, rec->cur_domain)) {
task->dns_requests ++;
rec->requests_inflight ++;
return TRUE;