You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

patch-exim-src_spam.c.diff 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. --- src/spam.c.orig 2011-01-20 19:29:51.179597017 +0300
  2. +++ src/spam.c 2011-02-21 21:17:15.051230555 +0300
  3. @@ -21,6 +21,9 @@
  4. int spam_ok = 0;
  5. int spam_rc = 0;
  6. +/* push formatted line into vector */
  7. +static int push_line(struct iovec *iov, int i, const char *fmt, ...);
  8. +
  9. int spam(uschar **listptr) {
  10. int sep = 0;
  11. uschar *list = *listptr;
  12. @@ -211,14 +214,26 @@
  13. }
  14. /* now we are connected to spamd on spamd_sock */
  15. - (void)string_format(spamd_buffer,
  16. - sizeof(spamd_buffer),
  17. - "REPORT SPAMC/1.2\r\nUser: %s\r\nContent-length: %ld\r\n\r\n",
  18. - user_name,
  19. - mbox_size);
  20. + int r, request_p = 0;
  21. + const char *helo;
  22. + struct iovec request_v[64];
  23. +
  24. + r = 0;
  25. + r += push_line(request_v, request_p++, "REPORT SPAMC/1.2\r\n");
  26. + r += push_line(request_v, request_p++, "Content-length: %lu\r\n", mbox_size);
  27. + r += push_line(request_v, request_p++, "Queue-Id: %s\r\n", message_id);
  28. + r += push_line(request_v, request_p++, "From: <%s>\r\n", sender_address);
  29. + r += push_line(request_v, request_p++, "Recipient-Number: %d\r\n", recipients_count);
  30. + for (i = 0; i < recipients_count; i ++)
  31. + r += push_line(request_v, request_p++, "Rcpt: <%s>\r\n", recipients_list[i].address);
  32. + if ((helo = expand_string(US"$sender_helo_name")) != NULL && *helo != '\0')
  33. + r += push_line(request_v, request_p++, "Helo: %s\r\n", helo);
  34. + if (sender_host_address != NULL)
  35. + r += push_line(request_v, request_p++, "IP: %s\r\n", sender_host_address);
  36. + r += push_line(request_v, request_p++, "\r\n");
  37. /* send our request */
  38. - if (send(spamd_sock, spamd_buffer, Ustrlen(spamd_buffer), 0) < 0) {
  39. + if (writev(spamd_sock, request_v, request_p) < 0) {
  40. (void)close(spamd_sock);
  41. log_write(0, LOG_MAIN|LOG_PANIC,
  42. "spam acl condition: spamd send failed: %s", strerror(errno));
  43. @@ -329,7 +344,7 @@
  44. (void)close(spamd_sock);
  45. /* dig in the spamd output and put the report in a multiline header, if requested */
  46. - if( sscanf(CS spamd_buffer,"SPAMD/%7s 0 EX_OK\r\nContent-length: %*u\r\n\r\n%lf/%lf\r\n%n",
  47. + if( sscanf(CS spamd_buffer,"SPAMD/%7s 0 EX_OK\r\n\r\nSpam: %*s ; %lf / %lf\r\nContent-length: %*u\r\n\r\n%n",
  48. spamd_version,&spamd_score,&spamd_threshold,&spamd_report_offset) != 3 ) {
  49. /* try to fall back to pre-2.50 spamd output */
  50. @@ -420,4 +435,31 @@
  51. };
  52. }
  53. +static int
  54. +push_line(struct iovec *iov, const int i, const char *fmt, ...)
  55. +{
  56. + va_list ap;
  57. + size_t len;
  58. + char buf[512];
  59. +
  60. + if (i >= 64) {
  61. + log_write(0, LOG_MAIN, "rspam: %s: index out of bounds", __FUNCTION__);
  62. + return (-1);
  63. + }
  64. +
  65. + va_start(ap, fmt);
  66. + len = vsnprintf(buf, sizeof(buf), fmt, ap);
  67. + va_end(ap);
  68. +
  69. + iov[i].iov_base = string_copy(US buf);
  70. + iov[i].iov_len = len;
  71. +
  72. + if (len >= sizeof(buf)) {
  73. + log_write(0, LOG_MAIN, "rspam: %s: error, string was longer than %d", __FUNCTION__, sizeof(buf));
  74. + return (-1);
  75. + }
  76. +
  77. + return 0;
  78. +}
  79. +
  80. #endif