|
Lines 1-4
Link Here
|
| 1 |
/* $Id: client.c,v 1.685 2010/05/13 22:38:45 sbajic Exp $ */ |
1 |
/* $Id: client.c,v 1.689 2011/03/02 21:16:28 sbajic Exp $ */ |
| 2 |
|
2 |
|
| 3 |
/* |
3 |
/* |
| 4 |
DSPAM |
4 |
DSPAM |
|
Lines 140-154
int client_process(AGENT_CTX *ATX, buffer *message) {
Link Here
|
| 140 |
i = 0; |
140 |
i = 0; |
| 141 |
msglen = strlen(message->data); |
141 |
msglen = strlen(message->data); |
| 142 |
while(i<msglen) { |
142 |
while(i<msglen) { |
| 143 |
int r = send(TTX.sockfd, message->data+i, msglen - i, 0); |
143 |
int r; |
| 144 |
if (r <= 0) { |
144 |
int t; |
| 145 |
STATUS(ERR_CLIENT_SEND_FAILED); |
145 |
int buflen; |
| 146 |
goto BAIL; |
146 |
|
|
|
147 |
/* |
| 148 |
* fill buf with partial msg, replacing \n with \r\n |
| 149 |
* and do dot stuffing, if needed. |
| 150 |
*/ |
| 151 |
buflen = 0; |
| 152 |
while ((size_t)buflen < (sizeof(buf) - 4) && i < msglen) { |
| 153 |
if (i > 0) { |
| 154 |
if (message->data[i] == '\n') { |
| 155 |
/* only replace \n and not \r\n */ |
| 156 |
if (message->data[i - 1] != '\r') { |
| 157 |
buf[buflen] = '\r'; |
| 158 |
buflen++; |
| 159 |
} |
| 160 |
/* take care of dot stuffing \n */ |
| 161 |
if (message->data[i + 1] && message->data[i + 1] == '.') { |
| 162 |
buf[buflen] = '\n'; |
| 163 |
buflen++; |
| 164 |
buf[buflen] = '.'; |
| 165 |
buflen++; |
| 166 |
buf[buflen] = '.'; |
| 167 |
buflen++; |
| 168 |
i += 2; |
| 169 |
continue; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
buf[buflen] = message->data[i]; |
| 175 |
buflen++; |
| 176 |
i++; |
| 177 |
} |
| 178 |
|
| 179 |
/* send buf */ |
| 180 |
t = 0; |
| 181 |
while (t < buflen) { |
| 182 |
r = send(TTX.sockfd, buf+t, buflen - t, 0); |
| 183 |
if (r <= 0) { |
| 184 |
LOG(LOG_ERR, ERR_CLIENT_SEND_FAILED); |
| 185 |
STATUS(ERR_CLIENT_SEND_FAILED); |
| 186 |
goto BAIL; |
| 187 |
} |
| 188 |
t += r; |
| 147 |
} |
189 |
} |
| 148 |
i += r; |
|
|
| 149 |
} |
190 |
} |
| 150 |
|
191 |
|
| 151 |
if (message->data[strlen(message->data)-1]!= '\n') { |
192 |
if (message->data[msglen-1]!= '\n') { |
| 152 |
if (send_socket(&TTX, "")<=0) { |
193 |
if (send_socket(&TTX, "")<=0) { |
| 153 |
STATUS(ERR_CLIENT_SEND_FAILED); |
194 |
STATUS(ERR_CLIENT_SEND_FAILED); |
| 154 |
goto BAIL; |
195 |
goto BAIL; |
|
Lines 685-690
int deliver_socket(AGENT_CTX *ATX, const char *msg, int proto) {
Link Here
|
| 685 |
int buflen; |
726 |
int buflen; |
| 686 |
char *inp; |
727 |
char *inp; |
| 687 |
int i; |
728 |
int i; |
|
|
729 |
int size_extension = 0; |
| 688 |
|
730 |
|
| 689 |
err[0] = 0; |
731 |
err[0] = 0; |
| 690 |
|
732 |
|
|
Lines 720-728
int deliver_socket(AGENT_CTX *ATX, const char *msg, int proto) {
Link Here
|
| 720 |
goto BAIL; |
762 |
goto BAIL; |
| 721 |
} |
763 |
} |
| 722 |
|
764 |
|
| 723 |
/* MAIL FROM */ |
765 |
/* Check for SIZE extension */ |
| 724 |
|
766 |
|
| 725 |
inp = client_expect(&TTX, LMTP_OK, err, sizeof(err)); |
767 |
if (proto == DDP_LMTP) { |
|
|
768 |
char *dup, *ptr, *ptrptr; |
| 769 |
inp = client_getline(&TTX, 300); |
| 770 |
while(inp != NULL) { |
| 771 |
code = 0; |
| 772 |
dup = strdup(inp); |
| 773 |
if (!dup) { |
| 774 |
free(inp); |
| 775 |
LOG(LOG_CRIT, ERR_MEM_ALLOC); |
| 776 |
LOG(LOG_ERR, ERR_CLIENT_INVALID_RESPONSE, "LHLO", ERR_MEM_ALLOC); |
| 777 |
STATUS("LHLO: %s", ERR_MEM_ALLOC); |
| 778 |
goto QUIT; |
| 779 |
} |
| 780 |
if (!strcmp(dup, "250-SIZE") || (!strncmp(dup, "250-SIZE", 8) && strlen(dup)>=8 && isspace(dup[8]))) { |
| 781 |
free(inp); |
| 782 |
free(dup); |
| 783 |
size_extension = 1; |
| 784 |
inp = client_expect(&TTX, LMTP_OK, err, sizeof(err)); |
| 785 |
break; |
| 786 |
} else if (strncmp(dup, "250-", 4)) { |
| 787 |
ptr = strtok_r(dup, " ", &ptrptr); |
| 788 |
if (ptr) |
| 789 |
code = atoi(ptr); |
| 790 |
if (code == LMTP_OK) { |
| 791 |
ptr = strtok_r(NULL, " ", &ptrptr); |
| 792 |
if (ptr && !strcmp(ptr, "SIZE")) |
| 793 |
size_extension = 1; |
| 794 |
} |
| 795 |
free(dup); |
| 796 |
if (code == LMTP_OK) { |
| 797 |
err[0] = 0; |
| 798 |
break; |
| 799 |
} |
| 800 |
LOG(LOG_WARNING, ERR_CLIENT_RESPONSE_CODE, code, inp); |
| 801 |
} |
| 802 |
strlcpy(err, inp, sizeof(err)); |
| 803 |
free(inp); |
| 804 |
inp = client_getline(&TTX, 300); |
| 805 |
} |
| 806 |
} else { |
| 807 |
inp = client_expect(&TTX, LMTP_OK, err, sizeof(err)); |
| 808 |
} |
| 726 |
if (inp == NULL) { |
809 |
if (inp == NULL) { |
| 727 |
LOG(LOG_ERR, ERR_CLIENT_INVALID_RESPONSE, |
810 |
LOG(LOG_ERR, ERR_CLIENT_INVALID_RESPONSE, |
| 728 |
(proto == DDP_LMTP) ? "LHLO" : "HELO", err); |
811 |
(proto == DDP_LMTP) ? "LHLO" : "HELO", err); |
|
Lines 731-738
int deliver_socket(AGENT_CTX *ATX, const char *msg, int proto) {
Link Here
|
| 731 |
} |
814 |
} |
| 732 |
free(inp); |
815 |
free(inp); |
| 733 |
|
816 |
|
| 734 |
if (proto == DDP_LMTP) { |
817 |
/* MAIL FROM */ |
| 735 |
snprintf(buf, sizeof(buf), "MAIL FROM:<%s> SIZE=%ld", |
818 |
|
|
|
819 |
if (proto == DDP_LMTP && size_extension == 1) { |
| 820 |
snprintf(buf, sizeof(buf), "MAIL FROM:<%s> SIZE=%ld", |
| 736 |
ATX->mailfrom, (long) strlen(msg)); |
821 |
ATX->mailfrom, (long) strlen(msg)); |
| 737 |
} else { |
822 |
} else { |
| 738 |
snprintf(buf, sizeof(buf), "MAIL FROM:<%s>", ATX->mailfrom); |
823 |
snprintf(buf, sizeof(buf), "MAIL FROM:<%s>", ATX->mailfrom); |