X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fspam.c;h=6954bee32ada2ee5819f37d93fdec1ae58ce5871;hb=691ca88ca06899e02e77cb28fbf075de450607bc;hp=6451ba2cb91872e2d7c3b3cc75e750b8556091ca;hpb=149b0e8a479aa1bbd9b2fb8281313edc487e6cec;p=exim.git diff --git a/src/src/spam.c b/src/src/spam.c index 6451ba2cb..6954bee32 100644 --- a/src/src/spam.c +++ b/src/src/spam.c @@ -30,6 +30,7 @@ static int spamd_param_init(spamd_address_container *spamd) { /* default spamd server weight, time and priority value */ +spamd->is_rspamd = FALSE; spamd->is_failed = FALSE; spamd->weight = SPAMD_WEIGHT; spamd->timeout = SPAMD_TIMEOUT; @@ -136,7 +137,7 @@ spamd_get_server(spamd_address_container ** spamds, int num_servers) { unsigned int i; spamd_address_container * sd; -long rnd, weights; +long weights; unsigned pri; static BOOL srandomed = FALSE; @@ -169,7 +170,7 @@ for (weights = 0, i = 0; i < num_servers; i++) if (weights == 0) /* all servers failed */ return -1; -for (rnd = random() % weights, i = 0; i < num_servers; i++) +for (long rnd = random() % weights, i = 0; i < num_servers; i++) { sd = spamds[i]; if (!sd->is_failed && sd->priority == pri) @@ -292,7 +293,7 @@ start = time(NULL); uschar * s; DEBUG(D_acl) debug_printf_indent("spamd: addr entry '%s'\n", address); - sd = (spamd_address_container *)store_get(sizeof(spamd_address_container)); + sd = store_get(sizeof(spamd_address_container), FALSE); for (sublist = address, args = 0, spamd_param_init(sd); (s = string_nextinlist(&sublist, &sublist_sep, NULL, 0)); @@ -343,7 +344,7 @@ start = time(NULL); for (;;) { /*XXX could potentially use TFO early-data here */ - if ( (spamd_cctx.sock = ip_streamsocket(sd->hostspec, &errstr, 5)) >= 0 + if ( (spamd_cctx.sock = ip_streamsocket(sd->hostspec, &errstr, 5, NULL)) >= 0 || sd->retry <= 0 ) break; @@ -369,26 +370,28 @@ start = time(NULL); (void)fcntl(spamd_cctx.sock, F_SETFL, O_NONBLOCK); /* now we are connected to spamd on spamd_cctx.sock */ if (sd->is_rspamd) - { /* rspamd variant */ - uschar *req_str; - const uschar * helo; - const uschar * fcrdns; - const uschar * authid; - - req_str = string_sprintf("CHECK RSPAMC/1.3\r\nContent-length: %lu\r\n" - "Queue-Id: %s\r\nFrom: <%s>\r\nRecipient-Number: %d\r\n", - mbox_size, message_id, sender_address, recipients_count); - for (i = 0; i < recipients_count; i ++) - req_str = string_sprintf("%sRcpt: <%s>\r\n", req_str, recipients_list[i].address); - if ((helo = expand_string(US"$sender_helo_name")) != NULL && *helo != '\0') - req_str = string_sprintf("%sHelo: %s\r\n", req_str, helo); - if ((fcrdns = expand_string(US"$sender_host_name")) != NULL && *fcrdns != '\0') - req_str = string_sprintf("%sHostname: %s\r\n", req_str, fcrdns); - if (sender_host_address != NULL) - req_str = string_sprintf("%sIP: %s\r\n", req_str, sender_host_address); - if ((authid = expand_string(US"$authenticated_id")) != NULL && *authid != '\0') - req_str = string_sprintf("%sUser: %s\r\n", req_str, authid); - req_str = string_sprintf("%s\r\n", req_str); + { + gstring * req_str; + const uschar * s; + + req_str = string_append(NULL, 8, + "CHECK RSPAMC/1.3\r\nContent-length: ", string_sprintf("%lu\r\n", mbox_size), + "Queue-Id: ", message_id, + "\r\nFrom: <", sender_address, + ">\r\nRecipient-Number: ", string_sprintf("%d\r\n", recipients_count)); + + for (int i = 0; i < recipients_count; i++) + req_str = string_append(req_str, 3, + "Rcpt: <", recipients_list[i].address, ">\r\n"); + if ((s = expand_string(US"$sender_helo_name")) && *s) + req_str = string_append(req_str, 3, "Helo: ", s, "\r\n"); + if ((s = expand_string(US"$sender_host_name")) && *s) + req_str = string_append(req_str, 3, "Hostname: ", s, "\r\n"); + if (sender_host_address) + req_str = string_append(req_str, 3, "IP: ", sender_host_address, "\r\n"); + if ((s = expand_string(US"$authenticated_id")) && *s) + req_str = string_append(req_str, 3, "User: ", s, "\r\n"); + req_str = string_catn(req_str, US"\r\n", 2); wrote = send(spamd_cctx.sock, req_str->s, req_str->ptr, 0); } else @@ -492,7 +495,7 @@ if (ferror(mbox_file)) /* we're done sending, close socket for writing */ if (!sd->is_rspamd) - shutdown(spamd_cctx.sock, SHUT_WR); + shutdown(spamd_cctx.sock,SHUT_WR); /* read spamd response using what's left of the timeout. */ memset(spamd_buffer, 0, sizeof(spamd_buffer)); @@ -500,7 +503,7 @@ offset = 0; while ((i = ip_recv(&spamd_cctx, spamd_buffer + offset, sizeof(spamd_buffer) - offset - 1, - sd->timeout - time(NULL) + start)) > 0) + sd->timeout + start)) > 0) offset += i; spamd_buffer[offset] = '\0'; /* guard byte */ @@ -562,7 +565,7 @@ else } Ustrcpy(spam_action_buffer, - spamd_score >= spamd_threshold ? "reject" : "no action"); + spamd_score >= spamd_threshold ? US"reject" : US"no action"); } /* Create report. Since this is a multiline string,