-/* $Cambridge: exim/src/src/dcc.c,v 1.3 2009/10/13 15:08:03 tom Exp $ */
-
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
-/* Copyright (c) Wolfgang Breyha 2005-2009
+/* Copyright (c) Wolfgang Breyha 2005-2012
* Vienna University Computer Center
* wbreyha@gmx.net
* See the file NOTICE for conditions of use and distribution.
#include "unistd.h"
uschar dcc_header_str[256];
-uschar dcc_result_str[256];
int dcc_ok = 0;
int dcc_rc = 0;
int dcc_process(uschar **listptr) {
int sep = 0;
uschar *list = *listptr;
- uschar *user_name;
- uschar *body_begin;
- uschar user_name_buffer[128];
- unsigned long mbox_size;
FILE *data_file;
- int dcc_sock;
- uschar dcc_buffer[32600];
uschar *dcc_daemon_ip = US"";
- int dcc_daemon_port = 6276;
- uschar *dcc_request = US"header";
uschar *dcc_default_ip_option = US"127.0.0.1";
uschar *dcc_ip_option = US"";
uschar *dcc_helo_option = US"localhost";
uschar *xtra_hdrs = NULL;
/* from local_scan */
- int i, j, k, c, retval, sockfd, servlen, resp, portnr, line;
+ int i, j, k, c, retval, sockfd, resp, line;
+ unsigned int portnr;
struct sockaddr_un serv_addr;
struct sockaddr_in serv_addr_in;
struct hostent *ipaddress;
uschar rcpt[128], from[128];
uschar sendbuf[4096];
uschar recvbuf[4096];
- uschar xhdr[256];
uschar dcc_return_text[1024];
uschar mbox_path[1024];
uschar message_subdir[2];
struct header_line *dcchdr;
- struct recipient_item *dcc_rcpt = recipients_list;
uschar *dcc_acl_options;
uschar dcc_acl_options_buffer[10];
uschar dcc_xtra_hdrs[1024];
- int offset, result;
- uschar *p,*q;
- int override = 0;
- time_t start;
- struct sockaddr_un server;
-#ifndef NO_POLL_H
- struct pollfd pollfd;
-#endif
-
- /* stop compiler warning */
- result = result;
-
/* grep 1st option */
if ((dcc_acl_options = string_nextinlist(&list, &sep,
dcc_acl_options_buffer,
if (dccifd_address[0] == '/')
Ustrncpy(sockpath, dccifd_address, sizeof(sockpath));
else
- if( sscanf(CS dccifd_address, "%s %u", sockip, portnr) != 2) {
+ if( sscanf(CS dccifd_address, "%s %u", sockip, &portnr) != 2) {
log_write(0, LOG_MAIN,
"dcc acl condition: warning - invalid dccifd address: '%s'", dccifd_address);
(void)fclose(data_file);
retval = DEFER;
bzero(sendbuf,sizeof(sendbuf));
- bzero(xhdr,sizeof(xhdr));
+ bzero(dcc_header_str,sizeof(dcc_header_str));
bzero(rcpt,sizeof(rcpt));
bzero(from,sizeof(from));
bzero((char *)&serv_addr,sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
Ustrcpy(serv_addr.sun_path, sockpath);
- servlen = Ustrlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
if ((sockfd = socket(AF_UNIX, SOCK_STREAM,0)) < 0){
DEBUG(D_acl)
debug_printf("Creating socket failed: %s\n", strerror(errno));
return retval;
}
/* Now connecting the socket (UNIX) */
- if (connect(sockfd, (struct sockaddr *) &serv_addr, servlen) < 0){
+ if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0){
DEBUG(D_acl)
debug_printf("Connecting socket failed: %s\n", strerror(errno));
log_write(0,LOG_REJECT,"Connecting socket failed: %s\n", strerror(errno));
}
}
- /* a blank line separates header from body */
+ /* a blank line seperates header from body */
Ustrncat(sendbuf, "\n", sizeof(sendbuf)-Ustrlen(sendbuf)-1);
flushbuffer(sockfd, sendbuf);
DEBUG(D_acl)
- debug_printf("\n****************************\n", sendbuf);
+ debug_printf("\n****************************\n%s", sendbuf);
/* Clear the input buffer */
bzero(sendbuf, sizeof(sendbuf));
line = 1; /* we start at the first line of the output */
j = 0; /* will be used as index for the recipients list */
- k = 0; /* initializing the index of the X-DCC header: xhdr[k] */
+ k = 0; /* initializing the index of the X-DCC header: dcc_header_str[k] */
/* Let's read from the socket until there's nothing left to read */
bzero(recvbuf, sizeof(recvbuf));
- while(resp = read(sockfd, recvbuf, sizeof(recvbuf)-1) > 0) {
+ while((resp = read(sockfd, recvbuf, sizeof(recvbuf)-1)) > 0) {
/* How much did we get from the socket */
c = Ustrlen(recvbuf) + 1;
DEBUG(D_acl)
DEBUG(D_acl)
debug_printf("Overall result = A\treturning OK\n");
Ustrcpy(dcc_return_text, "Mail accepted by DCC");
- dcc_result = "A";
+ dcc_result = US"A";
retval = OK;
}
else if(recvbuf[i] == 'R') {
DEBUG(D_acl)
debug_printf("Overall result = R\treturning FAIL\n");
- dcc_result = "R";
+ dcc_result = US"R";
retval = FAIL;
if(sender_host_name) {
log_write(0, LOG_MAIN, "H=%s [%s] F=<%s>: rejected by DCC", sender_host_name, sender_host_address, sender_address);
Ustrcpy(dcc_return_text, "Not all recipients accepted by DCC");
/* Since we're in an ACL we want a global result
* so we accept for all */
- dcc_result = "A";
+ dcc_result = US"A";
retval = OK;
}
else if(recvbuf[i] == 'G') {
DEBUG(D_acl)
debug_printf("Overall result = G\treturning FAIL\n");
Ustrcpy(dcc_return_text, "Greylisted by DCC");
- dcc_result = "G";
+ dcc_result = US"G";
retval = FAIL;
}
else if(recvbuf[i] == 'T') {
retval = DEFER;
log_write(0,LOG_MAIN,"Temporary error with DCC: %s\n", recvbuf);
Ustrcpy(dcc_return_text, "Temporary error with DCC");
- dcc_result = "T";
+ dcc_result = US"T";
}
else {
DEBUG(D_acl)
retval = DEFER;
log_write(0,LOG_MAIN,"Unknown DCC response: %s\n", recvbuf);
Ustrcpy(dcc_return_text, "Unknown DCC response");
- dcc_result = "T";
+ dcc_result = US"T";
}
}
else {
}
else if(line == 2) {
/* On the second line we get a list of
- * answer for each recipient. We don't care about
- * it because we're in an acl and so just take the
+ * answers for each recipient. We don't care about
+ * it because we're in an acl and take the
* global result. */
}
else if(line > 2) {
- /* The third and following lines is the X-DCC header,
- * so we store it in xhdr. */
- /* check if we don't get more than what we can handle */
- if(k < sizeof(xhdr)) { /* xhdr has a length of 120 */
- xhdr[k] = recvbuf[i];
+ /* The third and following lines are the X-DCC header,
+ * so we store it in dcc_header_str. */
+ /* check if we don't get more than we can handle */
+ if(k < sizeof(dcc_header_str)) {
+ dcc_header_str[k] = recvbuf[i];
k++;
}
else {
}
/* We have read everything from the socket */
- /* We need the terminate the X-DCC header with a '\n' character. This needs to be k-1
- * for xhdr[k] contains '\0'. */
- xhdr[k-1] = '\n';
+ /* We need to terminate the X-DCC header with a '\n' character. This needs to be k-1
+ * since dcc_header_str[k] contains '\0'. */
+ dcc_header_str[k-1] = '\n';
/* Now let's sum up what we've got. */
DEBUG(D_acl)
- debug_printf("\n--------------------------\nOverall result = %d\nX-DCC header: %sReturn message: %s\ndcc_result: %s\n", retval, xhdr, dcc_return_text, dcc_result);
+ debug_printf("\n--------------------------\nOverall result = %d\nX-DCC header: %sReturn message: %s\ndcc_result: %s\n", retval, dcc_header_str, dcc_return_text, dcc_result);
/* We only add the X-DCC header if it starts with X-DCC */
- if(!(Ustrncmp(xhdr, "X-DCC", 5))){
- dcc_header = xhdr;
+ if(!(Ustrncmp(dcc_header_str, "X-DCC", 5))){
+ dcc_header = dcc_header_str;
if(dcc_direct_add_header) {
- header_add(' ' , "%s", xhdr);
+ header_add(' ' , "%s", dcc_header_str);
/* since the MIME ACL already writes the .eml file to disk without DCC Header we've to erase it */
unspool_mbox();
}
}
else {
DEBUG(D_acl)
- debug_printf("Wrong format of the X-DCC header: %s\n", xhdr);
+ debug_printf("Wrong format of the X-DCC header: %s\n", dcc_header_str);
}
/* check if we should add additional headers passed in acl_m_dcc_add_header */
if(dcc_direct_add_header) {
- if (((xtra_hdrs = expand_string("$acl_m_dcc_add_header")) != NULL) && (xtra_hdrs[0] != '\0')) {
+ if (((xtra_hdrs = expand_string(US"$acl_m_dcc_add_header")) != NULL) && (xtra_hdrs[0] != '\0')) {
Ustrncpy(dcc_xtra_hdrs, xtra_hdrs, sizeof(dcc_xtra_hdrs) - 2);
if (dcc_xtra_hdrs[Ustrlen(dcc_xtra_hdrs)-1] != '\n')
Ustrcat(dcc_xtra_hdrs, "\n");
debug_printf("Before returning to exim main process:\nreturn_text = %s - retval = %d\ndcc_result = %s\n", dcc_return_text, retval, dcc_result);
(void)fclose(data_file);
- return retval;
+ dcc_rc = retval;
+ return dcc_rc;
}
#endif