Lines 764-769
Link Here
|
764 |
{ |
764 |
{ |
765 |
char is_spam[6]; |
765 |
char is_spam[6]; |
766 |
char s_str[21], t_str[21]; |
766 |
char s_str[21], t_str[21]; |
|
|
767 |
char is_learned[4]; |
767 |
|
768 |
|
768 |
UNUSED_VARIABLE(len); |
769 |
UNUSED_VARIABLE(len); |
769 |
|
770 |
|
Lines 810-821
Link Here
|
810 |
} |
811 |
} |
811 |
return EX_OK; |
812 |
return EX_OK; |
812 |
} |
813 |
} |
|
|
814 |
else if (sscanf(buf, "Learned: %3s", is_learned) == 1) |
815 |
{ |
816 |
if(strcmp(is_learned,"yes")==0||strcmp(is_learned,"Yes")==0) |
817 |
{ |
818 |
m->is_learned = 1; |
819 |
} |
820 |
else if(strcmp(is_learned,"no")==0||strcmp(is_learned,"No")==0) |
821 |
{ |
822 |
m->is_learned = 0; |
823 |
} |
824 |
else |
825 |
{ |
826 |
libspamc_log(flags, LOG_ERR, "spamd responded with bad Learned-state '%s'", |
827 |
buf); |
828 |
return EX_PROTOCOL; |
829 |
} |
830 |
return EX_OK; |
831 |
} |
813 |
|
832 |
|
814 |
libspamc_log(flags, LOG_ERR, "spamd responded with bad header '%s'", buf); |
833 |
libspamc_log(flags, LOG_ERR, "spamd responded with bad header '%s'", buf); |
815 |
return EX_PROTOCOL; |
834 |
return EX_PROTOCOL; |
816 |
} |
835 |
} |
817 |
|
836 |
|
818 |
int message_filter(struct transport *tp, const char *username, |
837 |
int message_filter(struct transport *tp, const char *username, int learntype, |
819 |
int flags, struct message *m) |
838 |
int flags, struct message *m) |
820 |
{ |
839 |
{ |
821 |
char buf[8192]; |
840 |
char buf[8192]; |
Lines 824-829
Link Here
|
824 |
int sock = -1; |
843 |
int sock = -1; |
825 |
int rc; |
844 |
int rc; |
826 |
char versbuf[20]; |
845 |
char versbuf[20]; |
|
|
846 |
char strlearntype[1]; |
827 |
float version; |
847 |
float version; |
828 |
int response; |
848 |
int response; |
829 |
int failureval; |
849 |
int failureval; |
Lines 854-862
Link Here
|
854 |
m->out = m->outbuf; |
874 |
m->out = m->outbuf; |
855 |
m->out_len = 0; |
875 |
m->out_len = 0; |
856 |
|
876 |
|
|
|
877 |
/* Build spamd protocol header */ |
857 |
|
878 |
|
858 |
/* Build spamd protocol header */ |
879 |
if(flags & SPAMC_CHECK_ONLY) |
859 |
if (flags & SPAMC_CHECK_ONLY) |
|
|
860 |
strcpy(buf, "CHECK "); |
880 |
strcpy(buf, "CHECK "); |
861 |
else if (flags & SPAMC_REPORT_IFSPAM) |
881 |
else if (flags & SPAMC_REPORT_IFSPAM) |
862 |
strcpy(buf, "REPORT_IFSPAM "); |
882 |
strcpy(buf, "REPORT_IFSPAM "); |
Lines 864-870
Link Here
|
864 |
strcpy(buf, "REPORT "); |
884 |
strcpy(buf, "REPORT "); |
865 |
else if (flags & SPAMC_SYMBOLS) |
885 |
else if (flags & SPAMC_SYMBOLS) |
866 |
strcpy(buf, "SYMBOLS "); |
886 |
strcpy(buf, "SYMBOLS "); |
867 |
else |
887 |
else if (flags & SPAMC_LEARN ) |
|
|
888 |
{ |
889 |
strcpy(buf, "LEARN "); |
890 |
len = strlen(buf); |
891 |
} |
892 |
else |
868 |
strcpy(buf, "PROCESS "); |
893 |
strcpy(buf, "PROCESS "); |
869 |
|
894 |
|
870 |
len = strlen(buf); |
895 |
len = strlen(buf); |
Lines 877-882
Link Here
|
877 |
strcat(buf, "\r\n"); |
902 |
strcat(buf, "\r\n"); |
878 |
len = strlen(buf); |
903 |
len = strlen(buf); |
879 |
|
904 |
|
|
|
905 |
|
906 |
if (flags & SPAMC_LEARN) |
907 |
{ |
908 |
if ((learntype > 2) | (learntype < 0 )) |
909 |
{ |
910 |
free(m->out); |
911 |
m->out = m->msg; |
912 |
m->out_len = m->msg_len; |
913 |
return EX_OSERR; |
914 |
} |
915 |
sprintf(strlearntype,"%d",learntype); |
916 |
strcpy(buf + len, "Learn-type: "); |
917 |
strcat(buf + len, strlearntype); |
918 |
strcat(buf + len, "\r\n"); |
919 |
len += strlen(buf + len); |
920 |
} |
921 |
|
880 |
if (username != NULL) { |
922 |
if (username != NULL) { |
881 |
if (strlen(username) + 8 >= (bufsiz - len)) { |
923 |
if (strlen(username) + 8 >= (bufsiz - len)) { |
882 |
_use_msg_for_out(m); |
924 |
_use_msg_for_out(m); |
Lines 951-956
Link Here
|
951 |
m->score = 0; |
993 |
m->score = 0; |
952 |
m->threshold = 0; |
994 |
m->threshold = 0; |
953 |
m->is_spam = EX_TOOBIG; |
995 |
m->is_spam = EX_TOOBIG; |
|
|
996 |
m->is_learned = 0; |
954 |
while (1) { |
997 |
while (1) { |
955 |
failureval = |
998 |
failureval = |
956 |
_spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz); |
999 |
_spamc_read_full_line(m, flags, ssl, sock, buf, &len, bufsiz); |
Lines 963-969
Link Here
|
963 |
} |
1006 |
} |
964 |
|
1007 |
|
965 |
if (_handle_spamd_header(m, flags, buf, len) < 0) { |
1008 |
if (_handle_spamd_header(m, flags, buf, len) < 0) { |
966 |
failureval = EX_PROTOCOL; |
1009 |
failureval = EX_PROTOCOL; |
967 |
goto failure; |
1010 |
goto failure; |
968 |
} |
1011 |
} |
969 |
} |
1012 |
} |
Lines 980-989
Link Here
|
980 |
} |
1023 |
} |
981 |
return EX_OK; |
1024 |
return EX_OK; |
982 |
} |
1025 |
} |
|
|
1026 |
else if (flags & SPAMC_LEARN) |
1027 |
{ |
1028 |
shutdown(sock, SHUT_RD); |
1029 |
closesocket(sock); |
1030 |
sock = -1; |
1031 |
return EX_OK; |
1032 |
} |
983 |
else { |
1033 |
else { |
984 |
if (m->content_length < 0) { |
1034 |
if (m->content_length < 0) { |
985 |
/* should have got a length too. */ |
1035 |
/* should have got a length too. */ |
986 |
failureval = EX_PROTOCOL; |
1036 |
|
|
|
1037 |
failureval = EX_PROTOCOL; |
987 |
goto failure; |
1038 |
goto failure; |
988 |
} |
1039 |
} |
989 |
|
1040 |
|
Lines 1049-1055
Link Here
|
1049 |
} |
1100 |
} |
1050 |
|
1101 |
|
1051 |
|
1102 |
|
1052 |
int message_process(struct transport *trans, char *username, int max_size, |
1103 |
int message_process(struct transport *trans, char *username, int learntype, int max_size, |
1053 |
int in_fd, int out_fd, const int flags) |
1104 |
int in_fd, int out_fd, const int flags) |
1054 |
{ |
1105 |
{ |
1055 |
int ret; |
1106 |
int ret; |
Lines 1061-1067
Link Here
|
1061 |
ret = message_read(in_fd, flags, &m); |
1112 |
ret = message_read(in_fd, flags, &m); |
1062 |
if (ret != EX_OK) |
1113 |
if (ret != EX_OK) |
1063 |
goto FAIL; |
1114 |
goto FAIL; |
1064 |
ret = message_filter(trans, username, flags, &m); |
1115 |
ret = message_filter(trans, username, learntype, flags, &m); |
1065 |
if (ret != EX_OK) |
1116 |
if (ret != EX_OK) |
1066 |
goto FAIL; |
1117 |
goto FAIL; |
1067 |
if (message_write(out_fd, &m) < 0) |
1118 |
if (message_write(out_fd, &m) < 0) |
Lines 1086-1091
Link Here
|
1086 |
} |
1137 |
} |
1087 |
} |
1138 |
} |
1088 |
|
1139 |
|
|
|
1140 |
|
1089 |
void message_cleanup(struct message *m) |
1141 |
void message_cleanup(struct message *m) |
1090 |
{ |
1142 |
{ |
1091 |
if (m->outbuf) |
1143 |
if (m->outbuf) |
Lines 1098-1104
Link Here
|
1098 |
} |
1150 |
} |
1099 |
|
1151 |
|
1100 |
/* Aug 14, 2002 bj: Obsolete! */ |
1152 |
/* Aug 14, 2002 bj: Obsolete! */ |
1101 |
int process_message(struct transport *tp, char *username, int max_size, |
1153 |
int process_message(struct transport *tp, char *username, int learntype, int max_size, |
1102 |
int in_fd, int out_fd, const int my_check_only, |
1154 |
int in_fd, int out_fd, const int my_check_only, |
1103 |
const int my_safe_fallback) |
1155 |
const int my_safe_fallback) |
1104 |
{ |
1156 |
{ |
Lines 1110-1116
Link Here
|
1110 |
if (my_safe_fallback) |
1162 |
if (my_safe_fallback) |
1111 |
flags |= SPAMC_SAFE_FALLBACK; |
1163 |
flags |= SPAMC_SAFE_FALLBACK; |
1112 |
|
1164 |
|
1113 |
return message_process(tp, username, max_size, in_fd, out_fd, flags); |
1165 |
return message_process(tp, username, learntype, max_size, in_fd, out_fd, flags); |
1114 |
} |
1166 |
} |
1115 |
|
1167 |
|
1116 |
/* |
1168 |
/* |
Lines 1390-1393
Link Here
|
1390 |
exit(0); |
1442 |
exit(0); |
1391 |
} |
1443 |
} |
1392 |
|
1444 |
|
|
|
1445 |
|
1446 |
|
1447 |
|
1393 |
#endif /* LIBSPAMC_UNIT_TESTS */ |
1448 |
#endif /* LIBSPAMC_UNIT_TESTS */ |
|
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|