mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-26 07:30:13 +01:00
Heavy refactoring based on ccpcheck
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
4f0dda34c2
commit
e7d57df751
@ -54,7 +54,6 @@ void zerr(int ret){
|
|||||||
|
|
||||||
int inf(unsigned char *in, int len, int mode, char **buffer, FILE *dest){
|
int inf(unsigned char *in, int len, int mode, char **buffer, FILE *dest){
|
||||||
int ret, pos=0;
|
int ret, pos=0;
|
||||||
unsigned have;
|
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
char *new_ptr;
|
char *new_ptr;
|
||||||
unsigned char out[REALLYBIGBUFSIZE];
|
unsigned char out[REALLYBIGBUFSIZE];
|
||||||
@ -96,7 +95,7 @@ int inf(unsigned char *in, int len, int mode, char **buffer, FILE *dest){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
have = REALLYBIGBUFSIZE - strm.avail_out;
|
unsigned have = REALLYBIGBUFSIZE - strm.avail_out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* write the uncompressed result either to stdout
|
* write the uncompressed result either to stdout
|
||||||
@ -235,8 +234,8 @@ CLEANUP:
|
|||||||
|
|
||||||
|
|
||||||
int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct config *cfg){
|
int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct config *cfg){
|
||||||
int i, attachments;
|
int attachments;
|
||||||
char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE], pointer[SMALLBUFSIZE];
|
char *buffer=NULL, *saved_buffer, *p, filename[SMALLBUFSIZE];
|
||||||
struct ptr_array ptr_arr[MAX_ATTACHMENTS];
|
struct ptr_array ptr_arr[MAX_ATTACHMENTS];
|
||||||
#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT
|
#ifdef HAVE_SUPPORT_FOR_COMPAT_STORAGE_LAYOUT
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -270,7 +269,9 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct c
|
|||||||
if(buffer){
|
if(buffer){
|
||||||
saved_buffer = buffer;
|
saved_buffer = buffer;
|
||||||
|
|
||||||
for(i=1; i<=attachments; i++){
|
for(int i=1; i<=attachments; i++){
|
||||||
|
char pointer[SMALLBUFSIZE];
|
||||||
|
|
||||||
snprintf(pointer, sizeof(pointer)-1, "ATTACHMENT_POINTER_%s.a%d_XXX_PILER", sdata->ttmpfile, i);
|
snprintf(pointer, sizeof(pointer)-1, "ATTACHMENT_POINTER_%s.a%d_XXX_PILER", sdata->ttmpfile, i);
|
||||||
|
|
||||||
p = strstr(buffer, pointer);
|
p = strstr(buffer, pointer);
|
||||||
|
79
src/base64.c
79
src/base64.c
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* base64.c, SJ
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
|
||||||
char base64_value(char c){
|
|
||||||
static const char *base64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
||||||
|
|
||||||
if((int)c > 63) return '=';
|
|
||||||
|
|
||||||
return base64_table[(int)c];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void base64_encode_block(unsigned char *in, int inlen, char *out){
|
|
||||||
char a, b, c, d, fragment;
|
|
||||||
|
|
||||||
sprintf(out, "====");
|
|
||||||
|
|
||||||
if(inlen <= 0) return;
|
|
||||||
|
|
||||||
fragment = *in & 0x3;
|
|
||||||
|
|
||||||
a = *in >> 2;
|
|
||||||
|
|
||||||
out[0] = base64_value(a);
|
|
||||||
|
|
||||||
b = fragment << 4;
|
|
||||||
|
|
||||||
if(inlen > 1)
|
|
||||||
b += *(in+1) >> 4;
|
|
||||||
|
|
||||||
out[1] = base64_value(b);
|
|
||||||
|
|
||||||
if(inlen == 1) return;
|
|
||||||
|
|
||||||
|
|
||||||
c = *(in+1) & 0xf;
|
|
||||||
c = c << 2;
|
|
||||||
|
|
||||||
if(inlen > 2){
|
|
||||||
fragment = *(in+2) & 0xfc;
|
|
||||||
c += fragment >> 6;
|
|
||||||
|
|
||||||
d = *(in+2) & 0x3f;
|
|
||||||
out[3] = base64_value(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
out[2] = base64_value(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void base64_encode(unsigned char *in, int inlen, char *out, int outlen){
|
|
||||||
int i=0, j, pos=0;
|
|
||||||
unsigned char buf[3];
|
|
||||||
|
|
||||||
memset(buf, 0, 3);
|
|
||||||
memset(out, 0, outlen);
|
|
||||||
|
|
||||||
for(j=0; j<inlen; j++){
|
|
||||||
|
|
||||||
if(i == 3){
|
|
||||||
base64_encode_block(buf, 3, &out[pos]); pos += 4;
|
|
||||||
|
|
||||||
memset(buf, 0, 3);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[i] = *(in+j);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
base64_encode_block(buf, i, &out[pos]);
|
|
||||||
}
|
|
||||||
|
|
@ -54,8 +54,6 @@ void get_bdat_size_to_read(struct smtp_session *session, char *buf){
|
|||||||
|
|
||||||
|
|
||||||
void process_bdat(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg){
|
void process_bdat(struct smtp_session *session, char *readbuf, int readlen, struct config *cfg){
|
||||||
char buf[SMALLBUFSIZE];
|
|
||||||
|
|
||||||
if(readlen <= 0) return;
|
if(readlen <= 0) return;
|
||||||
|
|
||||||
if(session->fd == -1){
|
if(session->fd == -1){
|
||||||
@ -106,6 +104,7 @@ void process_bdat(struct smtp_session *session, char *readbuf, int readlen, stru
|
|||||||
|
|
||||||
move_email(session);
|
move_email(session);
|
||||||
|
|
||||||
|
char buf[SMALLBUFSIZE];
|
||||||
snprintf(buf, sizeof(buf)-1, "250 OK <%s>\r\n", session->ttmpfile);
|
snprintf(buf, sizeof(buf)-1, "250 OK <%s>\r\n", session->ttmpfile);
|
||||||
send_smtp_response(session, buf);
|
send_smtp_response(session, buf);
|
||||||
syslog(LOG_PRIORITY, "received: %s, from=%s, size=%d, client=%s, fd=%d", session->ttmpfile, session->mailfrom, session->tot_len, session->remote_host, session->net.socket);
|
syslog(LOG_PRIORITY, "received: %s, from=%s, size=%d, client=%s, fd=%d", session->ttmpfile, session->mailfrom, session->tot_len, session->remote_host, session->net.socket);
|
||||||
|
@ -35,13 +35,6 @@ int int_parser(char *src, int *target){
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int float_parser(char *src, float *target){
|
|
||||||
*target = strtof(src, (char **) NULL);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct _parse_rule {
|
struct _parse_rule {
|
||||||
char *name;
|
char *name;
|
||||||
char *type;
|
char *type;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
int clamd_scan(char *tmpfile, struct config *cfg){
|
int clamd_scan(char *tmpfile, struct config *cfg){
|
||||||
int s, n;
|
int s, n;
|
||||||
char *p, *q, buf[MAXBUFSIZE], scan_cmd[SMALLBUFSIZE];
|
char buf[MAXBUFSIZE], scan_cmd[SMALLBUFSIZE];
|
||||||
struct sockaddr_un server;
|
struct sockaddr_un server;
|
||||||
|
|
||||||
chmod(tmpfile, 0644);
|
chmod(tmpfile, 0644);
|
||||||
@ -58,9 +58,9 @@ int clamd_scan(char *tmpfile, struct config *cfg){
|
|||||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: CLAMD DEBUG: %d %s", tmpfile, n, buf);
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: CLAMD DEBUG: %d %s", tmpfile, n, buf);
|
||||||
|
|
||||||
if(strcasestr(buf, CLAMD_RESP_INFECTED)){
|
if(strcasestr(buf, CLAMD_RESP_INFECTED)){
|
||||||
p = strchr(buf, ' ');
|
char *p = strchr(buf, ' ');
|
||||||
if(p){
|
if(p){
|
||||||
q = strrchr(p, ' ');
|
char *q = strrchr(p, ' ');
|
||||||
if(q){
|
if(q){
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
p++;
|
p++;
|
||||||
|
@ -51,19 +51,18 @@ struct counters load_counters(struct session_data *sdata){
|
|||||||
void update_counters(struct session_data *sdata, struct counters *counters, struct config *cfg){
|
void update_counters(struct session_data *sdata, struct counters *counters, struct config *cfg){
|
||||||
char buf[MAXBUFSIZE];
|
char buf[MAXBUFSIZE];
|
||||||
#ifdef HAVE_MEMCACHED
|
#ifdef HAVE_MEMCACHED
|
||||||
unsigned long long mc, rcvd;
|
unsigned long long mc;
|
||||||
struct counters c;
|
struct counters c;
|
||||||
char key[MAX_MEMCACHED_KEY_LEN];
|
|
||||||
unsigned int flags=0;
|
unsigned int flags=0;
|
||||||
|
|
||||||
if(counters->c_virus + counters->c_duplicate + counters->c_ignore + counters->c_size + counters->c_stored_size <= 0) return;
|
if(counters->c_virus + counters->c_duplicate + counters->c_ignore + counters->c_size + counters->c_stored_size < 1) return;
|
||||||
|
|
||||||
if(cfg->update_counters_to_memcached == 1){
|
if(cfg->update_counters_to_memcached == 1){
|
||||||
|
|
||||||
/* increment counters to memcached */
|
/* increment counters to memcached */
|
||||||
|
|
||||||
if(memcached_increment(&(data->memc), MEMCACHED_MSGS_RCVD, strlen(MEMCACHED_MSGS_RCVD), counters->c_rcvd, &mc) == MEMCACHED_SUCCESS){
|
if(memcached_increment(&(data->memc), MEMCACHED_MSGS_RCVD, strlen(MEMCACHED_MSGS_RCVD), counters->c_rcvd, &mc) == MEMCACHED_SUCCESS){
|
||||||
rcvd = mc;
|
unsigned long long rcvd = mc;
|
||||||
|
|
||||||
if(counters->c_virus > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_VIRUS, strlen(MEMCACHED_MSGS_VIRUS), counters->c_virus, &mc);
|
if(counters->c_virus > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_VIRUS, strlen(MEMCACHED_MSGS_VIRUS), counters->c_virus, &mc);
|
||||||
if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, strlen(MEMCACHED_MSGS_DUPLICATE), counters->c_duplicate, &mc);
|
if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, strlen(MEMCACHED_MSGS_DUPLICATE), counters->c_duplicate, &mc);
|
||||||
@ -77,6 +76,8 @@ void update_counters(struct session_data *sdata, struct counters *counters, stru
|
|||||||
snprintf(buf, MAXBUFSIZE-1, "%s %s %s %s %s %s %s", MEMCACHED_MSGS_RCVD, MEMCACHED_MSGS_VIRUS, MEMCACHED_MSGS_DUPLICATE, MEMCACHED_MSGS_IGNORE, MEMCACHED_MSGS_SIZE, MEMCACHED_MSGS_STORED_SIZE, MEMCACHED_COUNTERS_LAST_UPDATE);
|
snprintf(buf, MAXBUFSIZE-1, "%s %s %s %s %s %s %s", MEMCACHED_MSGS_RCVD, MEMCACHED_MSGS_VIRUS, MEMCACHED_MSGS_DUPLICATE, MEMCACHED_MSGS_IGNORE, MEMCACHED_MSGS_SIZE, MEMCACHED_MSGS_STORED_SIZE, MEMCACHED_COUNTERS_LAST_UPDATE);
|
||||||
|
|
||||||
if(memcached_mget(&(data->memc), buf) == MEMCACHED_SUCCESS){
|
if(memcached_mget(&(data->memc), buf) == MEMCACHED_SUCCESS){
|
||||||
|
char key[MAX_MEMCACHED_KEY_LEN];
|
||||||
|
|
||||||
while((memcached_fetch_result(&(data->memc), &key[0], &buf[0], &flags))){
|
while((memcached_fetch_result(&(data->memc), &key[0], &buf[0], &flags))){
|
||||||
if(!strcmp(key, MEMCACHED_MSGS_RCVD)) c.c_rcvd = strtoull(buf, NULL, 10);
|
if(!strcmp(key, MEMCACHED_MSGS_RCVD)) c.c_rcvd = strtoull(buf, NULL, 10);
|
||||||
else if(!strcmp(key, MEMCACHED_MSGS_VIRUS)) c.c_virus = strtoull(buf, NULL, 10);
|
else if(!strcmp(key, MEMCACHED_MSGS_VIRUS)) c.c_virus = strtoull(buf, NULL, 10);
|
||||||
@ -117,7 +118,7 @@ void update_counters(struct session_data *sdata, struct counters *counters, stru
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#endif
|
#endif
|
||||||
if(counters->c_virus + counters->c_duplicate + counters->c_ignore + counters->c_size + counters->c_stored_size <= 0) return;
|
if(counters->c_virus + counters->c_duplicate + counters->c_ignore + counters->c_size + counters->c_stored_size < 1) return;
|
||||||
|
|
||||||
snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=`rcvd`+%llu, `virus`=`virus`+%llu, `duplicate`=`duplicate`+%llu, `ignore`=`ignore`+%llu, `size`=`size`+%llu, `stored_size`=`stored_size`+%llu", SQL_COUNTER_TABLE, counters->c_rcvd, counters->c_virus, counters->c_duplicate, counters->c_ignore, counters->c_size, counters->c_stored_size);
|
snprintf(buf, SMALLBUFSIZE-1, "UPDATE `%s` SET `rcvd`=`rcvd`+%llu, `virus`=`virus`+%llu, `duplicate`=`duplicate`+%llu, `ignore`=`ignore`+%llu, `size`=`size`+%llu, `stored_size`=`stored_size`+%llu", SQL_COUNTER_TABLE, counters->c_rcvd, counters->c_virus, counters->c_duplicate, counters->c_ignore, counters->c_size, counters->c_stored_size);
|
||||||
p_query(sdata, buf);
|
p_query(sdata, buf);
|
||||||
|
@ -98,20 +98,6 @@ inline void utf8_encode_char(unsigned char c, unsigned char *buf, int buflen, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void sanitiseBase64(char *s){
|
|
||||||
char *p1;
|
|
||||||
|
|
||||||
if(s == NULL) return;
|
|
||||||
|
|
||||||
for(; *s; s++){
|
|
||||||
if(b64[(unsigned int)(*s & 0xFF)] == 255){
|
|
||||||
for(p1 = s; p1[0] != '\0'; p1++)
|
|
||||||
p1[0] = p1[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline static void pack_4_into_3(char *s, char *s2){
|
inline static void pack_4_into_3(char *s, char *s2){
|
||||||
int j, n[4], k1, k2;
|
int j, n[4], k1, k2;
|
||||||
|
|
||||||
@ -157,7 +143,7 @@ int decodeBase64(char *p){
|
|||||||
|
|
||||||
|
|
||||||
int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){
|
int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){
|
||||||
int i, len=0, decodedlen;
|
int i, len=0;
|
||||||
char s[5], s2[3];
|
char s[5], s2[3];
|
||||||
|
|
||||||
if(plen < 4 || plen > blen)
|
if(plen < 4 || plen > blen)
|
||||||
@ -166,7 +152,7 @@ int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){
|
|||||||
for(i=0; i<plen; i+=4){
|
for(i=0; i<plen; i+=4){
|
||||||
memcpy(s, p+i, 4);
|
memcpy(s, p+i, 4);
|
||||||
s[4] = '\0';
|
s[4] = '\0';
|
||||||
decodedlen = 3;
|
int decodedlen = 3;
|
||||||
|
|
||||||
/* safety check against abnormally long lines */
|
/* safety check against abnormally long lines */
|
||||||
|
|
||||||
@ -191,12 +177,11 @@ int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen){
|
|||||||
void decodeQP(char *p){
|
void decodeQP(char *p){
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int k=0, a, b;
|
int k=0, a, b;
|
||||||
char c;
|
|
||||||
|
|
||||||
if(p == NULL) return;
|
if(p == NULL) return;
|
||||||
|
|
||||||
for(i=0; i<strlen((char*)p); i++){
|
for(i=0; i<strlen((char*)p); i++){
|
||||||
c = p[i];
|
char c = p[i];
|
||||||
|
|
||||||
if(p[i] == '=' && isxdigit(p[i+1]) && isxdigit(p[i+2])){
|
if(p[i] == '=' && isxdigit(p[i+1]) && isxdigit(p[i+2])){
|
||||||
a = p[i+1];
|
a = p[i+1];
|
||||||
|
@ -5,9 +5,6 @@
|
|||||||
#ifndef _DECODER_H
|
#ifndef _DECODER_H
|
||||||
#define _DECODER_H
|
#define _DECODER_H
|
||||||
|
|
||||||
void base64_encode(unsigned char *in, int inlen, char *out, int outlen);
|
|
||||||
|
|
||||||
void sanitiseBase64(char *s);
|
|
||||||
int decodeBase64(char *p);
|
int decodeBase64(char *p);
|
||||||
int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen);
|
int decode_base64_to_buffer(char *p, int plen, unsigned char *b, int blen);
|
||||||
void decodeQP(char *p);
|
void decodeQP(char *p);
|
||||||
|
@ -240,10 +240,6 @@ struct session_data {
|
|||||||
#ifdef NEED_MYSQL
|
#ifdef NEED_MYSQL
|
||||||
MYSQL mysql;
|
MYSQL mysql;
|
||||||
#endif
|
#endif
|
||||||
#ifdef NEED_PSQL
|
|
||||||
PGconn *psql;
|
|
||||||
char conninfo[SMALLBUFSIZE];
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ int remove_xml(char *src, char *dest, int destlen, int *html){
|
|||||||
|
|
||||||
#ifdef HAVE_ZIP
|
#ifdef HAVE_ZIP
|
||||||
int extract_opendocument(struct session_data *sdata, struct parser_state *state, char *filename, char *prefix){
|
int extract_opendocument(struct session_data *sdata, struct parser_state *state, char *filename, char *prefix){
|
||||||
int errorp, i=0, len=0, html=0;
|
int errorp, i=0, html=0;
|
||||||
int len2;
|
int len2;
|
||||||
char buf[4*MAXBUFSIZE], puf[4*MAXBUFSIZE];
|
char buf[4*MAXBUFSIZE], puf[4*MAXBUFSIZE];
|
||||||
struct zip *z;
|
struct zip *z;
|
||||||
@ -60,6 +60,8 @@ int extract_opendocument(struct session_data *sdata, struct parser_state *state,
|
|||||||
|
|
||||||
zf = zip_fopen_index(z, i, 0);
|
zf = zip_fopen_index(z, i, 0);
|
||||||
if(zf){
|
if(zf){
|
||||||
|
int len;
|
||||||
|
|
||||||
while((len = zip_fread(zf, buf, sizeof(buf)-2)) > 0){
|
while((len = zip_fread(zf, buf, sizeof(buf)-2)) > 0){
|
||||||
|
|
||||||
len2 = remove_xml(buf, puf, sizeof(puf), &html);
|
len2 = remove_xml(buf, puf, sizeof(puf), &html);
|
||||||
@ -206,9 +208,8 @@ void kill_helper(){
|
|||||||
|
|
||||||
|
|
||||||
void extract_attachment_content(struct session_data *sdata, struct parser_state *state, char *filename, char *type, int *rec, struct config *cfg){
|
void extract_attachment_content(struct session_data *sdata, struct parser_state *state, char *filename, char *type, int *rec, struct config *cfg){
|
||||||
int link[2], n;
|
int link[2];
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char outbuf[MAXBUFSIZE];
|
|
||||||
|
|
||||||
if(strcmp(type, "other") == 0 || strcmp(type, "text") == 0) return;
|
if(strcmp(type, "other") == 0 || strcmp(type, "text") == 0) return;
|
||||||
|
|
||||||
@ -302,6 +303,9 @@ void extract_attachment_content(struct session_data *sdata, struct parser_state
|
|||||||
die("execl");
|
die("execl");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
int n;
|
||||||
|
char outbuf[MAXBUFSIZE];
|
||||||
|
|
||||||
close(link[1]);
|
close(link[1]);
|
||||||
while((n = read(link[0], outbuf, sizeof(outbuf))) > 0){
|
while((n = read(link[0], outbuf, sizeof(outbuf))) > 0){
|
||||||
if(state->bodylen < BIGBUFSIZE-n-1){
|
if(state->bodylen < BIGBUFSIZE-n-1){
|
||||||
|
@ -91,10 +91,7 @@ END:
|
|||||||
|
|
||||||
|
|
||||||
int connect_to_imap_server(struct data *data){
|
int connect_to_imap_server(struct data *data){
|
||||||
int n;
|
|
||||||
char buf[MAXBUFSIZE];
|
char buf[MAXBUFSIZE];
|
||||||
X509* server_cert;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
data->import->cap_uidplus = 0;
|
data->import->cap_uidplus = 0;
|
||||||
|
|
||||||
@ -113,15 +110,15 @@ int connect_to_imap_server(struct data *data){
|
|||||||
CHK_NULL(data->net->ssl, "internal ssl error");
|
CHK_NULL(data->net->ssl, "internal ssl error");
|
||||||
|
|
||||||
SSL_set_fd(data->net->ssl, data->net->socket);
|
SSL_set_fd(data->net->ssl, data->net->socket);
|
||||||
n = SSL_connect(data->net->ssl);
|
int n = SSL_connect(data->net->ssl);
|
||||||
CHK_SSL(n, "internal ssl error");
|
CHK_SSL(n, "internal ssl error");
|
||||||
|
|
||||||
printf("Cipher: %s\n", SSL_get_cipher(data->net->ssl));
|
printf("Cipher: %s\n", SSL_get_cipher(data->net->ssl));
|
||||||
|
|
||||||
server_cert = SSL_get_peer_certificate(data->net->ssl);
|
X509 *server_cert = SSL_get_peer_certificate(data->net->ssl);
|
||||||
CHK_NULL(server_cert, "server cert error");
|
CHK_NULL(server_cert, "server cert error");
|
||||||
|
|
||||||
str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0);
|
char *str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0);
|
||||||
CHK_NULL(str, "error in server cert");
|
CHK_NULL(str, "error in server cert");
|
||||||
printf("server cert:\n\t subject: %s\n", str);
|
printf("server cert:\n\t subject: %s\n", str);
|
||||||
OPENSSL_free(str);
|
OPENSSL_free(str);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
int import_message(struct session_data *sdata, struct data *data, struct config *cfg){
|
int import_message(struct session_data *sdata, struct data *data, struct config *cfg){
|
||||||
int rc=ERR;
|
int rc=ERR;
|
||||||
char *p, *rule, newpath[SMALLBUFSIZE];
|
char *rule;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct parser_state state;
|
struct parser_state state;
|
||||||
struct counters counters;
|
struct counters counters;
|
||||||
@ -130,12 +130,14 @@ int import_message(struct session_data *sdata, struct data *data, struct config
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(rc != OK && data->import->failed_folder){
|
if(rc != OK && data->import->failed_folder){
|
||||||
p = strrchr(data->import->filename, '/');
|
char *p = strrchr(data->import->filename, '/');
|
||||||
if(p)
|
if(p)
|
||||||
p++;
|
p++;
|
||||||
else
|
else
|
||||||
p = data->import->filename;
|
p = data->import->filename;
|
||||||
|
|
||||||
|
char newpath[SMALLBUFSIZE];
|
||||||
|
|
||||||
snprintf(newpath, sizeof(newpath)-2, "%s/%s", data->import->failed_folder, p);
|
snprintf(newpath, sizeof(newpath)-2, "%s/%s", data->import->failed_folder, p);
|
||||||
|
|
||||||
if(rename(data->import->filename, newpath))
|
if(rename(data->import->filename, newpath))
|
||||||
|
@ -73,7 +73,7 @@ int import_from_imap_server(struct session_data *sdata, struct data *data, struc
|
|||||||
q = data->imapfolders[i];
|
q = data->imapfolders[i];
|
||||||
while(q != NULL){
|
while(q != NULL){
|
||||||
|
|
||||||
if(q && q->str && strlen(q->str) > 1){
|
if(q->str && strlen(q->str) > 1){
|
||||||
|
|
||||||
skipmatch = 0;
|
skipmatch = 0;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
int import_from_mailbox(char *mailbox, struct session_data *sdata, struct data *data, struct config *cfg){
|
int import_from_mailbox(char *mailbox, struct session_data *sdata, struct data *data, struct config *cfg){
|
||||||
FILE *F, *f=NULL;
|
FILE *F, *f=NULL;
|
||||||
int rc=ERR, tot_msgs=0, ret=OK;
|
int rc=ERR, ret=OK;
|
||||||
char buf[MAXBUFSIZE];
|
char buf[MAXBUFSIZE];
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
@ -40,7 +40,6 @@ int import_from_mailbox(char *mailbox, struct session_data *sdata, struct data *
|
|||||||
while(fgets(buf, sizeof(buf)-1, F)){
|
while(fgets(buf, sizeof(buf)-1, F)){
|
||||||
|
|
||||||
if(buf[0] == 'F' && buf[1] == 'r' && buf[2] == 'o' && buf[3] == 'm' && buf[4] == ' '){
|
if(buf[0] == 'F' && buf[1] == 'r' && buf[2] == 'o' && buf[3] == 'm' && buf[4] == ' '){
|
||||||
tot_msgs++;
|
|
||||||
if(f){
|
if(f){
|
||||||
fclose(f);
|
fclose(f);
|
||||||
f = NULL;
|
f = NULL;
|
||||||
|
97
src/list.c
97
src/list.c
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* list.c, SJ
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "list.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
|
|
||||||
int append_list(struct list **list, char *p){
|
|
||||||
struct list *q, *t, *u=NULL;
|
|
||||||
|
|
||||||
q = *list;
|
|
||||||
|
|
||||||
while(q){
|
|
||||||
if(strcmp(q->s, p) == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
u = q;
|
|
||||||
q = q->r;
|
|
||||||
}
|
|
||||||
|
|
||||||
t = create_list_item(p);
|
|
||||||
if(t){
|
|
||||||
if(*list == NULL)
|
|
||||||
*list = t;
|
|
||||||
else if(u)
|
|
||||||
u->r = t;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct list *create_list_item(char *s){
|
|
||||||
struct list *h=NULL;
|
|
||||||
|
|
||||||
if((h = malloc(sizeof(struct list))) == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
snprintf(h->s, SMALLBUFSIZE-1, "%s", s);
|
|
||||||
h->r = NULL;
|
|
||||||
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int is_string_on_list(struct list *list, char *s){
|
|
||||||
struct list *p;
|
|
||||||
|
|
||||||
p = list;
|
|
||||||
|
|
||||||
while(p != NULL){
|
|
||||||
if(strcmp(p->s, s) == 0) return 1;
|
|
||||||
p = p->r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int is_item_on_string(struct list *list, char *s){
|
|
||||||
struct list *p;
|
|
||||||
|
|
||||||
p = list;
|
|
||||||
|
|
||||||
while(p != NULL){
|
|
||||||
if(strstr(s, p->s)) return 1;
|
|
||||||
p = p->r;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void free_list(struct list *list){
|
|
||||||
struct list *p, *q;
|
|
||||||
|
|
||||||
p = list;
|
|
||||||
|
|
||||||
while(p != NULL){
|
|
||||||
q = p->r;
|
|
||||||
|
|
||||||
if(p)
|
|
||||||
free(p);
|
|
||||||
|
|
||||||
p = q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
17
src/list.h
17
src/list.h
@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
* list.h, SJ
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _LIST_H
|
|
||||||
#define _LIST_H
|
|
||||||
|
|
||||||
#include "defs.h"
|
|
||||||
|
|
||||||
int append_list(struct list **list, char *p);
|
|
||||||
struct list *create_list_item(char *s);
|
|
||||||
int is_string_on_list(struct list *list, char *s);
|
|
||||||
int is_item_on_string(struct list *list, char *s);
|
|
||||||
void free_list(struct list *list);
|
|
||||||
|
|
||||||
#endif /* _LIST_H */
|
|
||||||
|
|
@ -59,7 +59,7 @@ void memcached_init(struct memcached_server *ptr, char *server_ip, int server_po
|
|||||||
|
|
||||||
|
|
||||||
int set_socket_options(struct memcached_server *ptr){
|
int set_socket_options(struct memcached_server *ptr){
|
||||||
int error, flag=1, flags, rval;
|
int error, flag=1, flags;
|
||||||
struct timeval waittime;
|
struct timeval waittime;
|
||||||
struct linger linger;
|
struct linger linger;
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ int set_socket_options(struct memcached_server *ptr){
|
|||||||
|
|
||||||
|
|
||||||
if((flags & O_NONBLOCK) == 0){
|
if((flags & O_NONBLOCK) == 0){
|
||||||
rval = fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK);
|
int rval = fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK);
|
||||||
if(rval == -1) return MEMCACHED_FAILURE;
|
if(rval == -1) return MEMCACHED_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ int memcached_add(struct memcached_server *ptr, char *key, unsigned int keylen,
|
|||||||
|
|
||||||
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE;
|
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE;
|
||||||
|
|
||||||
snprintf(ptr->buf, MAXBUFSIZE-1, "add %s %d %ld %d \r\n", key, flags, expiry, valuelen);
|
snprintf(ptr->buf, MAXBUFSIZE-1, "add %s %u %lu %u \r\n", key, flags, expiry, valuelen);
|
||||||
len = strlen(ptr->buf);
|
len = strlen(ptr->buf);
|
||||||
|
|
||||||
strncat(ptr->buf, value, MAXBUFSIZE-strlen(ptr->buf)-1);
|
strncat(ptr->buf, value, MAXBUFSIZE-strlen(ptr->buf)-1);
|
||||||
@ -245,7 +245,7 @@ int memcached_set(struct memcached_server *ptr, char *key, unsigned int keylen,
|
|||||||
|
|
||||||
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE;
|
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE;
|
||||||
|
|
||||||
snprintf(ptr->buf, MAXBUFSIZE-1, "set %s %d %ld %d \r\n", key, flags, expiry, valuelen);
|
snprintf(ptr->buf, MAXBUFSIZE-1, "set %s %u %lu %u \r\n", key, flags, expiry, valuelen);
|
||||||
len = strlen(ptr->buf);
|
len = strlen(ptr->buf);
|
||||||
|
|
||||||
strncat(ptr->buf, value, MAXBUFSIZE-strlen(ptr->buf)-1);
|
strncat(ptr->buf, value, MAXBUFSIZE-strlen(ptr->buf)-1);
|
||||||
|
64
src/misc.c
64
src/misc.c
@ -84,43 +84,6 @@ long tvdiff(struct timeval a, struct timeval b){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* count a character in buffer
|
|
||||||
*/
|
|
||||||
|
|
||||||
int countCharacterInBuffer(char *p, char c){
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
for(; *p; p++){
|
|
||||||
if(*p == c)
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void replaceCharacterInBuffer(char *p, char from, char to){
|
|
||||||
int i, k=0;
|
|
||||||
|
|
||||||
for(i=0; i<strlen(p); i++){
|
|
||||||
if(p[i] == from){
|
|
||||||
if(to > 0){
|
|
||||||
p[k] = to;
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
p[k] = p[i];
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
p[k] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* split a string by a character as delimiter
|
* split a string by a character as delimiter
|
||||||
*/
|
*/
|
||||||
@ -157,7 +120,8 @@ char *split_str(char *row, char *what, char *s, int size){
|
|||||||
char *r;
|
char *r;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
memset(s, 0, size);
|
if(s) memset(s, 0, size);
|
||||||
|
else return NULL;
|
||||||
|
|
||||||
if(row == NULL)
|
if(row == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -176,10 +140,8 @@ char *split_str(char *row, char *what, char *s, int size){
|
|||||||
r += strlen(what);
|
r += strlen(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(s != NULL){
|
|
||||||
strncpy(s, row, len);
|
strncpy(s, row, len);
|
||||||
s[len] = '\0';
|
s[len] = '\0';
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -210,8 +172,7 @@ int trimBuffer(char *s){
|
|||||||
|
|
||||||
|
|
||||||
int extract_verp_address(char *email){
|
int extract_verp_address(char *email){
|
||||||
char *p, *p1, *p2;
|
char *p1;
|
||||||
char puf[SMALLBUFSIZE];
|
|
||||||
|
|
||||||
// a VERP address is like archive+user=domain.com@myarchive.local
|
// a VERP address is like archive+user=domain.com@myarchive.local
|
||||||
|
|
||||||
@ -221,13 +182,15 @@ int extract_verp_address(char *email){
|
|||||||
|
|
||||||
p1 = strchr(email, '+');
|
p1 = strchr(email, '+');
|
||||||
if(p1){
|
if(p1){
|
||||||
p2 = strchr(p1, '@');
|
char *p2 = strchr(p1, '@');
|
||||||
if(p2 && p2 > p1 + 2){
|
if(p2 && p2 > p1 + 2){
|
||||||
if(strchr(p1+1, '=')){
|
if(strchr(p1+1, '=')){
|
||||||
|
char puf[SMALLBUFSIZE];
|
||||||
|
|
||||||
memset(puf, 0, sizeof(puf));
|
memset(puf, 0, sizeof(puf));
|
||||||
|
|
||||||
memcpy(&puf[0], p1+1, p2-p1-1);
|
memcpy(&puf[0], p1+1, p2-p1-1);
|
||||||
p = strchr(puf, '=');
|
char *p = strchr(puf, '=');
|
||||||
if(p) *p = '@';
|
if(p) *p = '@';
|
||||||
strcpy(email, puf);
|
strcpy(email, puf);
|
||||||
}
|
}
|
||||||
@ -268,12 +231,13 @@ void make_random_string(char *buf, int buflen){
|
|||||||
int i, len, fd;
|
int i, len, fd;
|
||||||
int urandom=0;
|
int urandom=0;
|
||||||
static char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
static char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||||
unsigned char s[QUEUE_ID_LEN];
|
|
||||||
|
|
||||||
len = strlen(alphanum);
|
len = strlen(alphanum);
|
||||||
|
|
||||||
fd = open(RANDOM_POOL, O_RDONLY);
|
fd = open(RANDOM_POOL, O_RDONLY);
|
||||||
if(fd != -1){
|
if(fd != -1){
|
||||||
|
unsigned char s[QUEUE_ID_LEN];
|
||||||
|
|
||||||
if(readFromEntropyPool(fd, s, sizeof(s)) == sizeof(s)){
|
if(readFromEntropyPool(fd, s, sizeof(s)) == sizeof(s)){
|
||||||
for(i=0; i<QUEUE_ID_LEN; i++){
|
for(i=0; i<QUEUE_ID_LEN; i++){
|
||||||
*(buf+i) = alphanum[s[i] % len];
|
*(buf+i) = alphanum[s[i] % len];
|
||||||
@ -345,10 +309,10 @@ int get_random_bytes(unsigned char *buf, int len, unsigned char server_id){
|
|||||||
|
|
||||||
int readFromEntropyPool(int fd, void *_s, ssize_t n){
|
int readFromEntropyPool(int fd, void *_s, ssize_t n){
|
||||||
char *s = _s;
|
char *s = _s;
|
||||||
ssize_t res, pos = 0;
|
ssize_t pos = 0;
|
||||||
|
|
||||||
while(n > pos){
|
while(n > pos){
|
||||||
res = read(fd, s + pos, n - pos);
|
ssize_t res = read(fd, s + pos, n - pos);
|
||||||
switch(res){
|
switch(res){
|
||||||
case -1: continue;
|
case -1: continue;
|
||||||
case 0: return res;
|
case 0: return res;
|
||||||
@ -601,12 +565,6 @@ void strtolower(char *s){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *get_in_addr(struct sockaddr *sa){
|
|
||||||
if(sa->sa_family == AF_INET) return &(((struct sockaddr_in*)sa)->sin_addr);
|
|
||||||
return &(((struct sockaddr_in6*)sa)->sin6_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int make_socket_non_blocking(int fd){
|
int make_socket_non_blocking(int fd){
|
||||||
int flags, s;
|
int flags, s;
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ int get_build();
|
|||||||
void get_extractor_list();
|
void get_extractor_list();
|
||||||
void __fatal(char *s);
|
void __fatal(char *s);
|
||||||
long tvdiff(struct timeval a, struct timeval b);
|
long tvdiff(struct timeval a, struct timeval b);
|
||||||
int countCharacterInBuffer(char *p, char c);
|
|
||||||
void replaceCharacterInBuffer(char *p, char from, char to);
|
|
||||||
char *split(char *str, int ch, char *buf, int buflen, int *result);
|
char *split(char *str, int ch, char *buf, int buflen, int *result);
|
||||||
char *split_str(char *row, char *what, char *s, int size);
|
char *split_str(char *row, char *what, char *s, int size);
|
||||||
int trimBuffer(char *s);
|
int trimBuffer(char *s);
|
||||||
@ -42,7 +40,6 @@ void init_session_data(struct session_data *sdata, struct config *cfg);
|
|||||||
int read_from_stdin(struct session_data *sdata);
|
int read_from_stdin(struct session_data *sdata);
|
||||||
void strtolower(char *s);
|
void strtolower(char *s);
|
||||||
|
|
||||||
void *get_in_addr(struct sockaddr *sa);
|
|
||||||
int make_socket_non_blocking(int fd);
|
int make_socket_non_blocking(int fd);
|
||||||
int create_and_bind(char *listen_addr, int listen_port);
|
int create_and_bind(char *listen_addr, int listen_port);
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
|
|
||||||
void load_mydomains(struct session_data *sdata, struct data *data, struct config *cfg){
|
void load_mydomains(struct session_data *sdata, struct data *data, struct config *cfg){
|
||||||
int rc;
|
|
||||||
char s[SMALLBUFSIZE];
|
char s[SMALLBUFSIZE];
|
||||||
struct sql sql;
|
struct sql sql;
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ void load_mydomains(struct session_data *sdata, struct data *data, struct config
|
|||||||
p_store_results(&sql);
|
p_store_results(&sql);
|
||||||
|
|
||||||
while(p_fetch_results(&sql) == OK){
|
while(p_fetch_results(&sql) == OK){
|
||||||
rc = addnode(data->mydomains, s);
|
int rc = addnode(data->mydomains, s);
|
||||||
|
|
||||||
if(rc == 0) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s);
|
if(rc == 0) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s);
|
||||||
else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s);
|
else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s);
|
||||||
|
15
src/parser.c
15
src/parser.c
@ -61,8 +61,6 @@ struct parser_state parse_message(struct session_data *sdata, int take_into_piec
|
|||||||
|
|
||||||
void post_parse(struct session_data *sdata, struct parser_state *state, struct config *cfg){
|
void post_parse(struct session_data *sdata, struct parser_state *state, struct config *cfg){
|
||||||
int i, rec=0;
|
int i, rec=0;
|
||||||
unsigned int len;
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
clearhash(state->boundaries);
|
clearhash(state->boundaries);
|
||||||
clearhash(state->rcpt);
|
clearhash(state->rcpt);
|
||||||
@ -92,8 +90,8 @@ void post_parse(struct session_data *sdata, struct parser_state *state, struct c
|
|||||||
|
|
||||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: attachment list: i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s", sdata->ttmpfile, i, state->attachments[i].filename, state->attachments[i].type, state->attachments[i].size, state->attachments[i].internalname, state->attachments[i].digest);
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: attachment list: i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s", sdata->ttmpfile, i, state->attachments[i].filename, state->attachments[i].type, state->attachments[i].size, state->attachments[i].internalname, state->attachments[i].digest);
|
||||||
|
|
||||||
p = determine_attachment_type(state->attachments[i].filename, state->attachments[i].type);
|
char *p = determine_attachment_type(state->attachments[i].filename, state->attachments[i].type);
|
||||||
len = strlen(p);
|
unsigned int len = strlen(p);
|
||||||
if(strlen(sdata->attachments) < SMALLBUFSIZE-len-1 && !strstr(sdata->attachments, p)) memcpy(&(sdata->attachments[strlen(sdata->attachments)]), p, len);
|
if(strlen(sdata->attachments) < SMALLBUFSIZE-len-1 && !strstr(sdata->attachments, p)) memcpy(&(sdata->attachments[strlen(sdata->attachments)]), p, len);
|
||||||
|
|
||||||
if(state->attachments[i].dumped == 1){
|
if(state->attachments[i].dumped == 1){
|
||||||
@ -142,8 +140,7 @@ void storno_attachment(struct parser_state *state){
|
|||||||
int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct data *data, struct config *cfg){
|
int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct data *data, struct config *cfg){
|
||||||
char *p, *q, puf[SMALLBUFSIZE];
|
char *p, *q, puf[SMALLBUFSIZE];
|
||||||
unsigned char b64buffer[MAXBUFSIZE];
|
unsigned char b64buffer[MAXBUFSIZE];
|
||||||
char tmpbuf[MAXBUFSIZE];
|
int n64, boundary_line=0, result;
|
||||||
int n64, writelen, boundary_line=0, result;
|
|
||||||
unsigned int len, domainlen;
|
unsigned int len, domainlen;
|
||||||
|
|
||||||
if(cfg->debug == 1) printf("line: %s", buf);
|
if(cfg->debug == 1) printf("line: %s", buf);
|
||||||
@ -261,7 +258,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
snprintf(puf, sizeof(puf)-1, "ATTACHMENT_POINTER_%s.a%d_XXX_PILER", sdata->ttmpfile, state->n_attachments);
|
snprintf(puf, sizeof(puf)-1, "ATTACHMENT_POINTER_%s.a%d_XXX_PILER", sdata->ttmpfile, state->n_attachments);
|
||||||
writelen = strlen(puf);
|
int writelen = strlen(puf);
|
||||||
if(writelen + state->writebufpos > writebuffersize-1){
|
if(writelen + state->writebufpos > writebuffersize-1){
|
||||||
if(write(state->mfd, writebuffer, state->writebufpos) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__);
|
if(write(state->mfd, writebuffer, state->writebufpos) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__);
|
||||||
state->writebufpos = 0;
|
state->writebufpos = 0;
|
||||||
@ -631,6 +628,8 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
|||||||
|
|
||||||
/* encode the body if it's not utf-8 encoded */
|
/* encode the body if it's not utf-8 encoded */
|
||||||
if(state->message_state == MSG_BODY && state->utf8 != 1){
|
if(state->message_state == MSG_BODY && state->utf8 != 1){
|
||||||
|
char tmpbuf[MAXBUFSIZE];
|
||||||
|
|
||||||
result = utf8_encode(buf, strlen(buf), &tmpbuf[0], sizeof(tmpbuf), state->charset);
|
result = utf8_encode(buf, strlen(buf), &tmpbuf[0], sizeof(tmpbuf), state->charset);
|
||||||
if(result == OK) snprintf(buf, MAXBUFSIZE-1, "%s", tmpbuf);
|
if(result == OK) snprintf(buf, MAXBUFSIZE-1, "%s", tmpbuf);
|
||||||
}
|
}
|
||||||
@ -652,8 +651,6 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
|
|||||||
|
|
||||||
degenerateToken((unsigned char*)puf);
|
degenerateToken((unsigned char*)puf);
|
||||||
|
|
||||||
if(puf[0] == '\0') continue;
|
|
||||||
|
|
||||||
strncat(puf, " ", sizeof(puf)-strlen(puf)-1);
|
strncat(puf, " ", sizeof(puf)-strlen(puf)-1);
|
||||||
|
|
||||||
if(strncasecmp(puf, "http://", 7) == 0 || strncasecmp(puf, "https://", 8) == 0) fixURL(puf, sizeof(puf)-1);
|
if(strncasecmp(puf, "http://", 7) == 0 || strncasecmp(puf, "https://", 8) == 0) fixURL(puf, sizeof(puf)-1);
|
||||||
|
@ -113,7 +113,6 @@ long get_local_timezone_offset(){
|
|||||||
|
|
||||||
|
|
||||||
time_t parse_date_header(char *datestr){
|
time_t parse_date_header(char *datestr){
|
||||||
int n=0, len;
|
|
||||||
long offset=0;
|
long offset=0;
|
||||||
time_t ts=0;
|
time_t ts=0;
|
||||||
char *p, *q, *r, *tz, s[SMALLBUFSIZE], tzh[4], tzm[3];
|
char *p, *q, *r, *tz, s[SMALLBUFSIZE], tzh[4], tzm[3];
|
||||||
@ -149,11 +148,9 @@ time_t parse_date_header(char *datestr){
|
|||||||
do {
|
do {
|
||||||
p = split_str(p, " ", s, sizeof(s)-1);
|
p = split_str(p, " ", s, sizeof(s)-1);
|
||||||
|
|
||||||
len = strlen(s);
|
int len = strlen(s);
|
||||||
|
|
||||||
if(len > 0){
|
if(len > 0){
|
||||||
n++;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A proper Date: header should look like this:
|
* A proper Date: header should look like this:
|
||||||
*
|
*
|
||||||
@ -263,7 +260,7 @@ time_t parse_date_header(char *datestr){
|
|||||||
|
|
||||||
|
|
||||||
int extract_boundary(char *p, struct parser_state *state){
|
int extract_boundary(char *p, struct parser_state *state){
|
||||||
char *q, *q2;
|
char *q;
|
||||||
|
|
||||||
p += strlen("boundary");
|
p += strlen("boundary");
|
||||||
|
|
||||||
@ -290,7 +287,7 @@ int extract_boundary(char *p, struct parser_state *state){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
q2 = strchr(p, ';');
|
char *q2 = strchr(p, ';');
|
||||||
if(q2) *q2 = '\0';
|
if(q2) *q2 = '\0';
|
||||||
|
|
||||||
q = strrchr(p, '"');
|
q = strrchr(p, '"');
|
||||||
@ -314,7 +311,7 @@ int extract_boundary(char *p, struct parser_state *state){
|
|||||||
|
|
||||||
|
|
||||||
void fixupEncodedHeaderLine(char *buf, int buflen){
|
void fixupEncodedHeaderLine(char *buf, int buflen){
|
||||||
char *p, *q, *r, *s, *e, *end;
|
char *q, *r, *s, *e, *end;
|
||||||
/*
|
/*
|
||||||
* I thought SMALLBUFSIZE would be enough for v, encoding and tmpbuf(2*),
|
* I thought SMALLBUFSIZE would be enough for v, encoding and tmpbuf(2*),
|
||||||
* but then I saw a 6-7000 byte long subject line, so I've switched to MAXBUFSIZE
|
* but then I saw a 6-7000 byte long subject line, so I've switched to MAXBUFSIZE
|
||||||
@ -332,7 +329,7 @@ void fixupEncodedHeaderLine(char *buf, int buflen){
|
|||||||
do {
|
do {
|
||||||
q = split_str(q, " ", v, sizeof(v)-1);
|
q = split_str(q, " ", v, sizeof(v)-1);
|
||||||
|
|
||||||
p = v;
|
char *p = v;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
memset(u, 0, sizeof(u));
|
memset(u, 0, sizeof(u));
|
||||||
@ -443,9 +440,10 @@ void fixupEncodedHeaderLine(char *buf, int buflen){
|
|||||||
|
|
||||||
void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){
|
void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){
|
||||||
int i=0;
|
int i=0;
|
||||||
char *p, puf[MAXBUFSIZE];
|
|
||||||
|
|
||||||
if(strlen(state->qpbuf) > 0){
|
if(strlen(state->qpbuf) > 0){
|
||||||
|
char puf[MAXBUFSIZE];
|
||||||
|
|
||||||
memset(puf, 0, sizeof(puf));
|
memset(puf, 0, sizeof(puf));
|
||||||
snprintf(puf, sizeof(puf)-1, "%s%s", state->qpbuf, buf);
|
snprintf(puf, sizeof(puf)-1, "%s%s", state->qpbuf, buf);
|
||||||
snprintf(buf, MAXBUFSIZE-1, "%s", puf);
|
snprintf(buf, MAXBUFSIZE-1, "%s", puf);
|
||||||
@ -458,7 +456,7 @@ void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(i == 1){
|
if(i == 1){
|
||||||
p = strrchr(buf, ' ');
|
char *p = strrchr(buf, ' ');
|
||||||
if(p){
|
if(p){
|
||||||
memset(state->qpbuf, 0, MAX_TOKEN_LEN);
|
memset(state->qpbuf, 0, MAX_TOKEN_LEN);
|
||||||
if(strlen(p) < MAX_TOKEN_LEN-1){
|
if(strlen(p) < MAX_TOKEN_LEN-1){
|
||||||
@ -472,9 +470,10 @@ void fixupSoftBreakInQuotedPritableLine(char *buf, struct parser_state *state){
|
|||||||
|
|
||||||
|
|
||||||
void fixupBase64EncodedLine(char *buf, struct parser_state *state){
|
void fixupBase64EncodedLine(char *buf, struct parser_state *state){
|
||||||
char *p, puf[MAXBUFSIZE];
|
|
||||||
|
|
||||||
if(strlen(state->miscbuf) > 0){
|
if(strlen(state->miscbuf) > 0){
|
||||||
|
char puf[MAXBUFSIZE];
|
||||||
|
|
||||||
memset(puf, 0, sizeof(puf));
|
memset(puf, 0, sizeof(puf));
|
||||||
strncpy(puf, state->miscbuf, sizeof(puf)-strlen(puf)-1);
|
strncpy(puf, state->miscbuf, sizeof(puf)-strlen(puf)-1);
|
||||||
strncat(puf, buf, sizeof(puf)-strlen(puf)-1);
|
strncat(puf, buf, sizeof(puf)-strlen(puf)-1);
|
||||||
@ -486,7 +485,7 @@ void fixupBase64EncodedLine(char *buf, struct parser_state *state){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(buf[strlen(buf)-1] != '\n'){
|
if(buf[strlen(buf)-1] != '\n'){
|
||||||
p = strrchr(buf, ' ');
|
char *p = strrchr(buf, ' ');
|
||||||
if(p){
|
if(p){
|
||||||
memcpy(&(state->miscbuf[0]), p+1, MAX_TOKEN_LEN-1);
|
memcpy(&(state->miscbuf[0]), p+1, MAX_TOKEN_LEN-1);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
@ -573,7 +572,7 @@ void markHTML(char *buf, struct parser_state *state){
|
|||||||
|
|
||||||
|
|
||||||
int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state){
|
int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state){
|
||||||
char *p, html[SMALLBUFSIZE];
|
char html[SMALLBUFSIZE];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if(pos == 0 && strncmp(htmlbuf, "style ", 6) == 0) state->style = 1;
|
if(pos == 0 && strncmp(htmlbuf, "style ", 6) == 0) state->style = 1;
|
||||||
@ -591,7 +590,7 @@ int appendHTMLTag(char *buf, char *htmlbuf, int pos, struct parser_state *state)
|
|||||||
len = strlen(html);
|
len = strlen(html);
|
||||||
|
|
||||||
if(len > 8 && strchr(html, '=')){
|
if(len > 8 && strchr(html, '=')){
|
||||||
p = strstr(html, "cid:");
|
char *p = strstr(html, "cid:");
|
||||||
if(p){
|
if(p){
|
||||||
*(p+3) = '\0';
|
*(p+3) = '\0';
|
||||||
strncat(html, " ", SMALLBUFSIZE-1);
|
strncat(html, " ", SMALLBUFSIZE-1);
|
||||||
@ -779,8 +778,7 @@ void fixURL(char *buf, int buflen){
|
|||||||
|
|
||||||
|
|
||||||
void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultbuflen){
|
void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultbuflen){
|
||||||
int extended=0;
|
char buf[SMALLBUFSIZE], *p, *q;
|
||||||
char buf[SMALLBUFSIZE], puf[SMALLBUFSIZE], *p, *q, *encoding;
|
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf)-1, "%s", s);
|
snprintf(buf, sizeof(buf)-1, "%s", s);
|
||||||
|
|
||||||
@ -788,6 +786,7 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb
|
|||||||
|
|
||||||
p = strstr(buf, name);
|
p = strstr(buf, name);
|
||||||
if(p){
|
if(p){
|
||||||
|
int extended=0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@ -843,7 +842,7 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb
|
|||||||
|
|
||||||
|
|
||||||
if(extended == 1){
|
if(extended == 1){
|
||||||
encoding = p;
|
char *encoding = p;
|
||||||
q = strchr(p, '\'');
|
q = strchr(p, '\'');
|
||||||
if(q){
|
if(q){
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
@ -860,6 +859,8 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb
|
|||||||
snprintf(resultbuf, resultbuflen-2, "%s", p);
|
snprintf(resultbuf, resultbuflen-2, "%s", p);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
char puf[SMALLBUFSIZE];
|
||||||
|
|
||||||
snprintf(puf, sizeof(puf)-1, "%s", p);
|
snprintf(puf, sizeof(puf)-1, "%s", p);
|
||||||
fixupEncodedHeaderLine(puf, sizeof(puf));
|
fixupEncodedHeaderLine(puf, sizeof(puf));
|
||||||
|
|
||||||
@ -873,8 +874,6 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb
|
|||||||
|
|
||||||
|
|
||||||
char *determine_attachment_type(char *filename, char *type){
|
char *determine_attachment_type(char *filename, char *type){
|
||||||
char *p;
|
|
||||||
|
|
||||||
if(strncasecmp(type, "text/", strlen("text/")) == 0) return "text,";
|
if(strncasecmp(type, "text/", strlen("text/")) == 0) return "text,";
|
||||||
if(strncasecmp(type, "image/", strlen("image/")) == 0) return "image,";
|
if(strncasecmp(type, "image/", strlen("image/")) == 0) return "image,";
|
||||||
if(strncasecmp(type, "audio/", strlen("audio/")) == 0) return "audio,";
|
if(strncasecmp(type, "audio/", strlen("audio/")) == 0) return "audio,";
|
||||||
@ -905,7 +904,7 @@ char *determine_attachment_type(char *filename, char *type){
|
|||||||
|
|
||||||
if(strncasecmp(type, "application/", 12) == 0){
|
if(strncasecmp(type, "application/", 12) == 0){
|
||||||
|
|
||||||
p = strrchr(filename, '.');
|
char *p = strrchr(filename, '.');
|
||||||
if(p){
|
if(p){
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
@ -967,14 +966,13 @@ char *get_attachment_extractor_by_filename(char *filename){
|
|||||||
|
|
||||||
|
|
||||||
void parse_reference(struct parser_state *state, char *s){
|
void parse_reference(struct parser_state *state, char *s){
|
||||||
int len;
|
|
||||||
char puf[SMALLBUFSIZE];
|
char puf[SMALLBUFSIZE];
|
||||||
|
|
||||||
if(strlen(state->reference) > 10) return;
|
if(strlen(state->reference) > 10) return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
s = split_str(s, " ", puf, sizeof(puf)-1);
|
s = split_str(s, " ", puf, sizeof(puf)-1);
|
||||||
len = strlen(puf);
|
int len = strlen(puf);
|
||||||
|
|
||||||
if(len > 10 && len < SMALLBUFSIZE-1){
|
if(len > 10 && len < SMALLBUFSIZE-1){
|
||||||
memcpy(&(state->reference[strlen(state->reference)]), puf, len);
|
memcpy(&(state->reference[strlen(state->reference)]), puf, len);
|
||||||
@ -1000,12 +998,11 @@ int base64_decode_attachment_buffer(char *p, unsigned char *b, int blen){
|
|||||||
|
|
||||||
|
|
||||||
void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len){
|
void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len){
|
||||||
int n;
|
|
||||||
char *r;
|
char *r;
|
||||||
|
|
||||||
r = strchr(puf, '+');
|
r = strchr(puf, '+');
|
||||||
if(r){
|
if(r){
|
||||||
n = strlen(*at_sign);
|
int n = strlen(*at_sign);
|
||||||
memmove(r, *at_sign, n);
|
memmove(r, *at_sign, n);
|
||||||
*(r+n) = '\0';
|
*(r+n) = '\0';
|
||||||
*len = strlen(puf);
|
*len = strlen(puf);
|
||||||
|
@ -53,14 +53,12 @@ void usage(){
|
|||||||
|
|
||||||
|
|
||||||
void p_clean_exit(int sig){
|
void p_clean_exit(int sig){
|
||||||
int i;
|
|
||||||
|
|
||||||
if(sig > 0) syslog(LOG_PRIORITY, "got signal: %d, %s", sig, strsignal(sig));
|
if(sig > 0) syslog(LOG_PRIORITY, "got signal: %d, %s", sig, strsignal(sig));
|
||||||
|
|
||||||
if(listenerfd != -1) close(listenerfd);
|
if(listenerfd != -1) close(listenerfd);
|
||||||
|
|
||||||
if(sessions){
|
if(sessions){
|
||||||
for(i=0; i<cfg.max_connections; i++){
|
for(int i=0; i<cfg.max_connections; i++){
|
||||||
if(sessions[i]) free_smtp_session(sessions[i]);
|
if(sessions[i]) free_smtp_session(sessions[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +83,11 @@ void fatal(char *s){
|
|||||||
|
|
||||||
void check_for_client_timeout(){
|
void check_for_client_timeout(){
|
||||||
time_t now;
|
time_t now;
|
||||||
int i;
|
|
||||||
|
|
||||||
if(num_connections > 0){
|
if(num_connections > 0){
|
||||||
time(&now);
|
time(&now);
|
||||||
|
|
||||||
for(i=0; i<cfg.max_connections; i++){
|
for(int i=0; i<cfg.max_connections; i++){
|
||||||
if(sessions[i] && now - sessions[i]->lasttime >= cfg.smtp_timeout){
|
if(sessions[i] && now - sessions[i]->lasttime >= cfg.smtp_timeout){
|
||||||
syslog(LOG_PRIORITY, "client %s timeout", sessions[i]->remote_host);
|
syslog(LOG_PRIORITY, "client %s timeout", sessions[i]->remote_host);
|
||||||
tear_down_session(sessions, sessions[i]->slot, &num_connections);
|
tear_down_session(sessions, sessions[i]->slot, &num_connections);
|
||||||
@ -128,7 +125,7 @@ void initialise_configuration(){
|
|||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int listenerfd, client_sockfd;
|
int listenerfd, client_sockfd;
|
||||||
int i, n, daemonise=0;
|
int i, daemonise=0;
|
||||||
int client_len = sizeof(struct sockaddr_storage);
|
int client_len = sizeof(struct sockaddr_storage);
|
||||||
ssize_t readlen;
|
ssize_t readlen;
|
||||||
struct sockaddr_storage client_address;
|
struct sockaddr_storage client_address;
|
||||||
@ -212,14 +209,14 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
syslog(LOG_PRIORITY, "%s %s, build %d starting", PROGNAME, VERSION, get_build());
|
syslog(LOG_PRIORITY, "%s %s, build %d starting", PROGNAME, VERSION, get_build());
|
||||||
|
|
||||||
#if HAVE_DAEMON == 1
|
#if HAVE_DAEMON
|
||||||
if(daemonise == 1 && daemon(1, 0) == -1) fatal(ERR_DAEMON);
|
if(daemonise == 1 && daemon(1, 0) == -1) fatal(ERR_DAEMON);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
alarm(timeout);
|
alarm(timeout);
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
n = epoll_wait(efd, events, cfg.max_connections, -1);
|
int n = epoll_wait(efd, events, cfg.max_connections, -1);
|
||||||
for(i=0; i<n; i++){
|
for(i=0; i<n; i++){
|
||||||
|
|
||||||
// Office365 sometimes behaves oddly: when it receives the 250 OK
|
// Office365 sometimes behaves oddly: when it receives the 250 OK
|
||||||
|
@ -106,7 +106,6 @@ int process_email(char *filename, struct session_data *sdata, struct data *data,
|
|||||||
char tmpbuf[SMALLBUFSIZE];
|
char tmpbuf[SMALLBUFSIZE];
|
||||||
char *status=S_STATUS_UNDEF;
|
char *status=S_STATUS_UNDEF;
|
||||||
char *arule;
|
char *arule;
|
||||||
char *rcpt;
|
|
||||||
char *p;
|
char *p;
|
||||||
struct timezone tz;
|
struct timezone tz;
|
||||||
struct timeval tv1, tv2;
|
struct timeval tv1, tv2;
|
||||||
@ -134,6 +133,8 @@ int process_email(char *filename, struct session_data *sdata, struct data *data,
|
|||||||
post_parse(sdata, &parser_state, cfg);
|
post_parse(sdata, &parser_state, cfg);
|
||||||
|
|
||||||
if(cfg->syslog_recipients == 1){
|
if(cfg->syslog_recipients == 1){
|
||||||
|
char *rcpt;
|
||||||
|
|
||||||
rcpt = parser_state.b_to;
|
rcpt = parser_state.b_to;
|
||||||
do {
|
do {
|
||||||
rcpt = split_str(rcpt, " ", tmpbuf, sizeof(tmpbuf)-1);
|
rcpt = split_str(rcpt, " ", tmpbuf, sizeof(tmpbuf)-1);
|
||||||
@ -467,7 +468,7 @@ void initialise_configuration(){
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int i, daemonise=0, dedupfd;
|
int i, daemonise=0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
|
||||||
@ -520,7 +521,7 @@ int main(int argc, char **argv){
|
|||||||
if(stat(cfg.pidfile, &st) == 0) fatal(ERR_PID_FILE_EXISTS);
|
if(stat(cfg.pidfile, &st) == 0) fatal(ERR_PID_FILE_EXISTS);
|
||||||
|
|
||||||
if(cfg.mmap_dedup_test == 1){
|
if(cfg.mmap_dedup_test == 1){
|
||||||
dedupfd = open(MESSAGE_ID_DEDUP_FILE, O_RDWR);
|
int dedupfd = open(MESSAGE_ID_DEDUP_FILE, O_RDWR);
|
||||||
if(dedupfd == -1) fatal(ERR_OPEN_DEDUP_FILE);
|
if(dedupfd == -1) fatal(ERR_OPEN_DEDUP_FILE);
|
||||||
|
|
||||||
data.dedup = mmap(NULL, MAXCHILDREN*DIGEST_LENGTH*2, PROT_READ|PROT_WRITE, MAP_SHARED, dedupfd, 0);
|
data.dedup = mmap(NULL, MAXCHILDREN*DIGEST_LENGTH*2, PROT_READ|PROT_WRITE, MAP_SHARED, dedupfd, 0);
|
||||||
@ -531,7 +532,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
syslog(LOG_PRIORITY, "%s %s, build %d starting", PROGNAME, VERSION, get_build());
|
syslog(LOG_PRIORITY, "%s %s, build %d starting", PROGNAME, VERSION, get_build());
|
||||||
|
|
||||||
#if HAVE_DAEMON == 1
|
#if HAVE_DAEMON
|
||||||
if(daemonise == 1 && daemon(1, 0) == -1) fatal(ERR_DAEMON);
|
if(daemonise == 1 && daemon(1, 0) == -1) fatal(ERR_DAEMON);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ unsigned long convert_time(char *yyyymmdd, int h, int m, int s){
|
|||||||
|
|
||||||
|
|
||||||
int append_email_to_buffer(char **buffer, char *email){
|
int append_email_to_buffer(char **buffer, char *email){
|
||||||
int len, arglen;
|
int arglen;
|
||||||
char *s=NULL, emailaddress[SMALLBUFSIZE];
|
char *s=NULL, emailaddress[SMALLBUFSIZE];
|
||||||
|
|
||||||
snprintf(emailaddress, sizeof(emailaddress)-1, "'%s'", email);
|
snprintf(emailaddress, sizeof(emailaddress)-1, "'%s'", email);
|
||||||
@ -107,7 +107,7 @@ int append_email_to_buffer(char **buffer, char *email){
|
|||||||
memcpy(*buffer, emailaddress, arglen);
|
memcpy(*buffer, emailaddress, arglen);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len = strlen(*buffer);
|
int len = strlen(*buffer);
|
||||||
s = realloc(*buffer, len + arglen+2);
|
s = realloc(*buffer, len + arglen+2);
|
||||||
if(!s){
|
if(!s){
|
||||||
printf("malloc problem!\n");
|
printf("malloc problem!\n");
|
||||||
@ -126,7 +126,7 @@ int append_email_to_buffer(char **buffer, char *email){
|
|||||||
|
|
||||||
|
|
||||||
int append_string_to_buffer(char **buffer, char *str){
|
int append_string_to_buffer(char **buffer, char *str){
|
||||||
int len, arglen;
|
int arglen;
|
||||||
char *s=NULL;
|
char *s=NULL;
|
||||||
|
|
||||||
arglen = strlen(str);
|
arglen = strlen(str);
|
||||||
@ -137,7 +137,7 @@ int append_string_to_buffer(char **buffer, char *str){
|
|||||||
memcpy(*buffer, str, arglen);
|
memcpy(*buffer, str, arglen);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len = strlen(*buffer);
|
int len = strlen(*buffer);
|
||||||
s = realloc(*buffer, len + arglen+1);
|
s = realloc(*buffer, len + arglen+1);
|
||||||
if(!s) return 1;
|
if(!s) return 1;
|
||||||
|
|
||||||
@ -152,8 +152,6 @@ int append_string_to_buffer(char **buffer, char *str){
|
|||||||
|
|
||||||
|
|
||||||
uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *where_condition, uint64 last_id, int *num, struct config *cfg){
|
uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *where_condition, uint64 last_id, int *num, struct config *cfg){
|
||||||
MYSQL_RES *res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
int rc=0;
|
int rc=0;
|
||||||
uint64 id=0;
|
uint64 id=0;
|
||||||
char s[SMALLBUFSIZE];
|
char s[SMALLBUFSIZE];
|
||||||
@ -168,8 +166,9 @@ uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *
|
|||||||
snprintf(s, sizeof(s)-1, "SELECT id FROM %s WHERE %s AND id > %llu ORDER BY id ASC LIMIT 0,%d", index_list, where_condition, last_id, max_matches);
|
snprintf(s, sizeof(s)-1, "SELECT id FROM %s WHERE %s AND id > %llu ORDER BY id ASC LIMIT 0,%d", index_list, where_condition, last_id, max_matches);
|
||||||
|
|
||||||
if(mysql_real_query(&(sdata2->mysql), s, strlen(s)) == 0){
|
if(mysql_real_query(&(sdata2->mysql), s, strlen(s)) == 0){
|
||||||
res = mysql_store_result(&(sdata2->mysql));
|
MYSQL_RES *res = mysql_store_result(&(sdata2->mysql));
|
||||||
if(res != NULL){
|
if(res != NULL){
|
||||||
|
MYSQL_ROW row;
|
||||||
while((row = mysql_fetch_row(res))){
|
while((row = mysql_fetch_row(res))){
|
||||||
id = strtoull(row[0], NULL, 10);
|
id = strtoull(row[0], NULL, 10);
|
||||||
(*num)++;
|
(*num)++;
|
||||||
@ -194,13 +193,12 @@ uint64 run_query(struct session_data *sdata, struct session_data *sdata2, char *
|
|||||||
|
|
||||||
|
|
||||||
uint64 get_total_found(struct session_data *sdata){
|
uint64 get_total_found(struct session_data *sdata){
|
||||||
MYSQL_RES *res;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
uint64 total_found=0;
|
uint64 total_found=0;
|
||||||
|
|
||||||
if(mysql_real_query(&(sdata->mysql), "SHOW META LIKE 'total_found'", 28) == 0){
|
if(mysql_real_query(&(sdata->mysql), "SHOW META LIKE 'total_found'", 28) == 0){
|
||||||
res = mysql_store_result(&(sdata->mysql));
|
MYSQL_RES *res = mysql_store_result(&(sdata->mysql));
|
||||||
if(res != NULL){
|
if(res != NULL){
|
||||||
|
MYSQL_ROW row;
|
||||||
while((row = mysql_fetch_row(res))){
|
while((row = mysql_fetch_row(res))){
|
||||||
total_found = strtoull(row[1], NULL, 10);
|
total_found = strtoull(row[1], NULL, 10);
|
||||||
}
|
}
|
||||||
@ -313,7 +311,7 @@ int build_query_from_args(char *from, char *to, char *fromdomain, char *todomain
|
|||||||
|
|
||||||
if(startdate > 0){
|
if(startdate > 0){
|
||||||
if(where_condition) rc = append_string_to_buffer(&query, " AND ");
|
if(where_condition) rc = append_string_to_buffer(&query, " AND ");
|
||||||
snprintf(s, sizeof(s)-1, " `sent` >= %ld", startdate);
|
snprintf(s, sizeof(s)-1, " `sent` >= %lu", startdate);
|
||||||
rc += append_string_to_buffer(&query, s);
|
rc += append_string_to_buffer(&query, s);
|
||||||
|
|
||||||
where_condition++;
|
where_condition++;
|
||||||
@ -322,7 +320,7 @@ int build_query_from_args(char *from, char *to, char *fromdomain, char *todomain
|
|||||||
|
|
||||||
if(stopdate > 0){
|
if(stopdate > 0){
|
||||||
if(where_condition) rc = append_string_to_buffer(&query, " AND ");
|
if(where_condition) rc = append_string_to_buffer(&query, " AND ");
|
||||||
snprintf(s, sizeof(s)-1, " `sent` <= %ld", stopdate);
|
snprintf(s, sizeof(s)-1, " `sent` <= %lu", stopdate);
|
||||||
rc += append_string_to_buffer(&query, s);
|
rc += append_string_to_buffer(&query, s);
|
||||||
|
|
||||||
where_condition++;
|
where_condition++;
|
||||||
@ -410,7 +408,7 @@ ENDE:
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int c, minsize=0, maxsize=0;
|
int minsize=0, maxsize=0;
|
||||||
size_t nmatch=0;
|
size_t nmatch=0;
|
||||||
unsigned long startdate=0, stopdate=0;
|
unsigned long startdate=0, stopdate=0;
|
||||||
char *configfile=CONFIG_FILE;
|
char *configfile=CONFIG_FILE;
|
||||||
@ -451,9 +449,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?", long_options, &option_index);
|
int c = getopt_long(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?", long_options, &option_index);
|
||||||
#else
|
#else
|
||||||
c = getopt(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?");
|
int c = getopt(argc, argv, "c:s:S:f:r:F:R:a:b:w:m:i:Adhv?");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(c == -1) break;
|
if(c == -1) break;
|
||||||
|
@ -62,7 +62,7 @@ void usage(){
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int i, c, n_mbox=0;
|
int i, n_mbox=0;
|
||||||
char *configfile=CONFIG_FILE, *mbox[MBOX_ARGS], *directory=NULL;
|
char *configfile=CONFIG_FILE, *mbox[MBOX_ARGS], *directory=NULL;
|
||||||
char *imapserver=NULL, *pop3server=NULL;
|
char *imapserver=NULL, *pop3server=NULL;
|
||||||
struct session_data sdata;
|
struct session_data sdata;
|
||||||
@ -145,9 +145,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:DRroqh?", long_options, &option_index);
|
int c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:DRroqh?", long_options, &option_index);
|
||||||
#else
|
#else
|
||||||
c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:DRroqh?");
|
int c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:j:DRroqh?");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(c == -1) break;
|
if(c == -1) break;
|
||||||
|
14
src/pop3.c
14
src/pop3.c
@ -34,11 +34,7 @@ int is_last_complete_pop3_packet(char *s, int len){
|
|||||||
|
|
||||||
|
|
||||||
int connect_to_pop3_server(struct data *data){
|
int connect_to_pop3_server(struct data *data){
|
||||||
int n;
|
|
||||||
char buf[MAXBUFSIZE];
|
char buf[MAXBUFSIZE];
|
||||||
X509* server_cert;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
|
|
||||||
if(data->net->use_ssl == 1){
|
if(data->net->use_ssl == 1){
|
||||||
|
|
||||||
@ -56,15 +52,15 @@ int connect_to_pop3_server(struct data *data){
|
|||||||
CHK_NULL(data->net->ssl, "internal ssl error");
|
CHK_NULL(data->net->ssl, "internal ssl error");
|
||||||
|
|
||||||
SSL_set_fd(data->net->ssl, data->net->socket);
|
SSL_set_fd(data->net->ssl, data->net->socket);
|
||||||
n = SSL_connect(data->net->ssl);
|
int n = SSL_connect(data->net->ssl);
|
||||||
CHK_SSL(n, "internal ssl error");
|
CHK_SSL(n, "internal ssl error");
|
||||||
|
|
||||||
printf("Cipher: %s\n", SSL_get_cipher(data->net->ssl));
|
printf("Cipher: %s\n", SSL_get_cipher(data->net->ssl));
|
||||||
|
|
||||||
server_cert = SSL_get_peer_certificate(data->net->ssl);
|
X509 *server_cert = SSL_get_peer_certificate(data->net->ssl);
|
||||||
CHK_NULL(server_cert, "server cert error");
|
CHK_NULL(server_cert, "server cert error");
|
||||||
|
|
||||||
str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0);
|
char *str = X509_NAME_oneline(X509_get_subject_name(server_cert), 0, 0);
|
||||||
CHK_NULL(str, "error in server cert");
|
CHK_NULL(str, "error in server cert");
|
||||||
OPENSSL_free(str);
|
OPENSSL_free(str);
|
||||||
|
|
||||||
@ -99,7 +95,7 @@ int connect_to_pop3_server(struct data *data){
|
|||||||
|
|
||||||
|
|
||||||
void get_number_of_total_messages(struct data *data){
|
void get_number_of_total_messages(struct data *data){
|
||||||
char *p, buf[MAXBUFSIZE];
|
char buf[MAXBUFSIZE];
|
||||||
|
|
||||||
data->import->total_messages = 0;
|
data->import->total_messages = 0;
|
||||||
|
|
||||||
@ -109,7 +105,7 @@ void get_number_of_total_messages(struct data *data){
|
|||||||
recvtimeoutssl(data->net, buf, sizeof(buf));
|
recvtimeoutssl(data->net, buf, sizeof(buf));
|
||||||
|
|
||||||
if(strncmp(buf, "+OK ", 4) == 0){
|
if(strncmp(buf, "+OK ", 4) == 0){
|
||||||
p = strchr(&buf[4], ' ');
|
char *p = strchr(&buf[4], ' ');
|
||||||
if(p){
|
if(p){
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
data->import->total_messages = atoi(&buf[4]);
|
data->import->total_messages = atoi(&buf[4]);
|
||||||
|
@ -74,10 +74,7 @@ uint64 get_max_meta_id(struct session_data *sdata){
|
|||||||
|
|
||||||
|
|
||||||
uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *data, uint64 from_id, uint64 to_id, struct config *cfg){
|
uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *data, uint64 from_id, uint64 to_id, struct config *cfg){
|
||||||
FILE *f;
|
|
||||||
char filename[SMALLBUFSIZE];
|
|
||||||
char s[SMALLBUFSIZE];
|
char s[SMALLBUFSIZE];
|
||||||
int rc=0;
|
|
||||||
uint64 stored_id=0, reindexed=0, delta;
|
uint64 stored_id=0, reindexed=0, delta;
|
||||||
struct parser_state state;
|
struct parser_state state;
|
||||||
struct sql sql;
|
struct sql sql;
|
||||||
@ -111,12 +108,14 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *da
|
|||||||
while(p_fetch_results(&sql) == OK){
|
while(p_fetch_results(&sql) == OK){
|
||||||
|
|
||||||
if(stored_id > 0){
|
if(stored_id > 0){
|
||||||
|
FILE *f;
|
||||||
|
char filename[SMALLBUFSIZE];
|
||||||
|
|
||||||
snprintf(filename, sizeof(filename)-1, "%llu.eml", stored_id);
|
snprintf(filename, sizeof(filename)-1, "%llu.eml", stored_id);
|
||||||
|
|
||||||
f = fopen(filename, "w");
|
f = fopen(filename, "w");
|
||||||
if(f){
|
if(f){
|
||||||
rc = retrieve_email_from_archive(sdata, f, cfg);
|
int rc = retrieve_email_from_archive(sdata, f, cfg);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if(rc){
|
if(rc){
|
||||||
@ -162,7 +161,7 @@ uint64 retrieve_email_by_metadata_id(struct session_data *sdata, struct data *da
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int c, all=0;
|
int all=0;
|
||||||
uint64 from_id=0, to_id=0, n=0;
|
uint64 from_id=0, to_id=0, n=0;
|
||||||
char *configfile=CONFIG_FILE, *folder=NULL;
|
char *configfile=CONFIG_FILE, *folder=NULL;
|
||||||
struct session_data sdata;
|
struct session_data sdata;
|
||||||
@ -171,7 +170,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
c = getopt(argc, argv, "c:f:t:F:pahv?");
|
int c = getopt(argc, argv, "c:f:t:F:pahv?");
|
||||||
|
|
||||||
if(c == -1) break;
|
if(c == -1) break;
|
||||||
|
|
||||||
@ -211,7 +210,7 @@ int main(int argc, char **argv){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage();
|
if(all == 0 && (from_id < 1 || to_id < 1) ) usage();
|
||||||
|
|
||||||
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
|
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");
|
||||||
|
|
||||||
|
@ -408,14 +408,13 @@ int check_spam_rule(int is_spam, int spam){
|
|||||||
int check_attachment_rule(struct parser_state *state, struct rule *rule){
|
int check_attachment_rule(struct parser_state *state, struct rule *rule){
|
||||||
int i;
|
int i;
|
||||||
size_t nmatch=0;
|
size_t nmatch=0;
|
||||||
int ismatch = 0;
|
|
||||||
|
|
||||||
if(state->n_attachments == 0) return RULE_UNDEF;
|
if(state->n_attachments == 0) return RULE_UNDEF;
|
||||||
|
|
||||||
if(rule->emptyaname == 1 && rule->emptyatype == 1) return RULE_UNDEF;
|
if(rule->emptyaname == 1 && rule->emptyatype == 1) return RULE_UNDEF;
|
||||||
|
|
||||||
for(i=1; i<=state->n_attachments; i++){
|
for(i=1; i<=state->n_attachments; i++){
|
||||||
ismatch = 0;
|
int ismatch = 0;
|
||||||
|
|
||||||
if(rule->emptyaname == 0){
|
if(rule->emptyaname == 0){
|
||||||
if(regexec(&(rule->attachment_name), state->attachments[i].filename, nmatch, NULL, 0) == 0)
|
if(regexec(&(rule->attachment_name), state->attachments[i].filename, nmatch, NULL, 0) == 0)
|
||||||
@ -446,13 +445,13 @@ void initrules(struct node *xhash[]){
|
|||||||
|
|
||||||
|
|
||||||
void clearrules(struct node *xhash[]){
|
void clearrules(struct node *xhash[]){
|
||||||
struct node *p, *q;
|
struct node *q;
|
||||||
struct rule *rule;
|
struct rule *rule;
|
||||||
|
|
||||||
q = xhash[0];
|
q = xhash[0];
|
||||||
|
|
||||||
while(q != NULL){
|
while(q != NULL){
|
||||||
p = q;
|
struct node *p = q;
|
||||||
q = q->r;
|
q = q->r;
|
||||||
|
|
||||||
if(p){
|
if(p){
|
||||||
|
@ -29,7 +29,6 @@ int is_blocked_by_tcp_wrappers(int sd){
|
|||||||
|
|
||||||
|
|
||||||
int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct config *cfg){
|
int start_new_session(struct smtp_session **sessions, int socket, int *num_connections, struct config *cfg){
|
||||||
char smtp_banner[SMALLBUFSIZE];
|
|
||||||
int slot;
|
int slot;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -55,6 +54,8 @@ int start_new_session(struct smtp_session **sessions, int socket, int *num_conne
|
|||||||
if(slot >= 0 && sessions[slot] == NULL){
|
if(slot >= 0 && sessions[slot] == NULL){
|
||||||
sessions[slot] = malloc(sizeof(struct smtp_session));
|
sessions[slot] = malloc(sizeof(struct smtp_session));
|
||||||
if(sessions[slot]){
|
if(sessions[slot]){
|
||||||
|
char smtp_banner[SMALLBUFSIZE];
|
||||||
|
|
||||||
init_smtp_session(sessions[slot], slot, socket, cfg);
|
init_smtp_session(sessions[slot], slot, socket, cfg);
|
||||||
snprintf(smtp_banner, sizeof(smtp_banner)-1, SMTP_RESP_220_BANNER, cfg->hostid);
|
snprintf(smtp_banner, sizeof(smtp_banner)-1, SMTP_RESP_220_BANNER, cfg->hostid);
|
||||||
send(socket, smtp_banner, strlen(smtp_banner), 0);
|
send(socket, smtp_banner, strlen(smtp_banner), 0);
|
||||||
@ -228,12 +229,12 @@ void handle_data(struct smtp_session *session, char *readbuf, int readlen, struc
|
|||||||
|
|
||||||
void write_envelope_addresses(struct smtp_session *session, struct config *cfg){
|
void write_envelope_addresses(struct smtp_session *session, struct config *cfg){
|
||||||
int i;
|
int i;
|
||||||
char *p, s[SMALLBUFSIZE];
|
char s[SMALLBUFSIZE];
|
||||||
|
|
||||||
if(session->fd == -1) return;
|
if(session->fd == -1) return;
|
||||||
|
|
||||||
for(i=0; i<session->num_of_rcpt_to; i++){
|
for(i=0; i<session->num_of_rcpt_to; i++){
|
||||||
p = strchr(session->rcptto[i], '@');
|
char *p = strchr(session->rcptto[i], '@');
|
||||||
if(p && strncmp(p+1, cfg->hostid, cfg->hostid_len)){
|
if(p && strncmp(p+1, cfg->hostid, cfg->hostid_len)){
|
||||||
snprintf(s, sizeof(s)-1, "X-Piler-Envelope-To: %s\n", session->rcptto[i]);
|
snprintf(s, sizeof(s)-1, "X-Piler-Envelope-To: %s\n", session->rcptto[i]);
|
||||||
if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope to address", session->ttmpfile);
|
if(write(session->fd, s, strlen(s)) == -1) syslog(LOG_PRIORITY, "ERROR: %s: cannot write envelope to address", session->ttmpfile);
|
||||||
|
@ -89,7 +89,6 @@ void process_data(struct smtp_session *session, char *buf, int buflen){
|
|||||||
|
|
||||||
void wait_for_ssl_accept(struct smtp_session *session){
|
void wait_for_ssl_accept(struct smtp_session *session){
|
||||||
int rc;
|
int rc;
|
||||||
char ssl_error[SMALLBUFSIZE];
|
|
||||||
|
|
||||||
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "waiting for ssl handshake");
|
if(session->cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "waiting for ssl handshake");
|
||||||
|
|
||||||
@ -106,6 +105,8 @@ void wait_for_ssl_accept(struct smtp_session *session){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(session->cfg->verbosity >= _LOG_DEBUG || session->net.use_ssl == 0){
|
if(session->cfg->verbosity >= _LOG_DEBUG || session->net.use_ssl == 0){
|
||||||
|
char ssl_error[SMALLBUFSIZE];
|
||||||
|
|
||||||
ERR_error_string_n(ERR_get_error(), ssl_error, SMALLBUFSIZE);
|
ERR_error_string_n(ERR_get_error(), ssl_error, SMALLBUFSIZE);
|
||||||
syslog(LOG_PRIORITY, "SSL_accept() result, rc=%d, errorcode: %d, error text: %s",
|
syslog(LOG_PRIORITY, "SSL_accept() result, rc=%d, errorcode: %d, error text: %s",
|
||||||
rc, SSL_get_error(session->net.ssl, rc), ssl_error);
|
rc, SSL_get_error(session->net.ssl, rc), ssl_error);
|
||||||
|
@ -68,12 +68,11 @@ int query_counters(struct session_data *sdata, struct stats *stats){
|
|||||||
|
|
||||||
int get_last_email_archived_timestamp(struct session_data *sdata, struct stats *stats){
|
int get_last_email_archived_timestamp(struct session_data *sdata, struct stats *stats){
|
||||||
int rc=ERR;
|
int rc=ERR;
|
||||||
unsigned long arrived=86400;
|
|
||||||
struct sql sql;
|
struct sql sql;
|
||||||
|
|
||||||
// By default we haven't archived a mail a day ago, and this value should represent an error
|
// By default we haven't archived a mail a day ago, and this value should represent an error
|
||||||
time(&(sdata->now));
|
time(&(sdata->now));
|
||||||
arrived = sdata->now - 86400;
|
unsigned long arrived = sdata->now - 86400;
|
||||||
|
|
||||||
if(prepare_sql_statement(sdata, &sql, "select arrived from metadata order by id desc limit 1") == ERR) return rc;
|
if(prepare_sql_statement(sdata, &sql, "select arrived from metadata order by id desc limit 1") == ERR) return rc;
|
||||||
|
|
||||||
@ -134,12 +133,13 @@ void sphinx_queries(struct session_data *sdata, struct stats *stats){
|
|||||||
|
|
||||||
void count_error_emails(struct stats *stats){
|
void count_error_emails(struct stats *stats){
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *de;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char buf[SMALLBUFSIZE];
|
|
||||||
|
|
||||||
dir = opendir(ERROR_DIR);
|
dir = opendir(ERROR_DIR);
|
||||||
if(dir){
|
if(dir){
|
||||||
|
struct dirent *de;
|
||||||
|
char buf[SMALLBUFSIZE];
|
||||||
|
|
||||||
while((de = readdir(dir))){
|
while((de = readdir(dir))){
|
||||||
if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue;
|
||||||
|
|
||||||
|
@ -213,12 +213,10 @@ ENDE:
|
|||||||
|
|
||||||
|
|
||||||
int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct config *cfg){
|
int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct config *cfg){
|
||||||
int i;
|
|
||||||
char s[SMALLBUFSIZE];
|
char s[SMALLBUFSIZE];
|
||||||
|
|
||||||
if(state->n_attachments > 0){
|
if(state->n_attachments > 0){
|
||||||
|
for(int i=1; i<=state->n_attachments; i++){
|
||||||
for(i=1; i<=state->n_attachments; i++){
|
|
||||||
snprintf(s, sizeof(s)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, sdata->ttmpfile[8], sdata->ttmpfile[9], sdata->ttmpfile[10], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile, i);
|
snprintf(s, sizeof(s)-1, "%s/%02x/%c%c%c/%c%c/%c%c/%s.a%d", cfg->queuedir, cfg->server_id, sdata->ttmpfile[8], sdata->ttmpfile[9], sdata->ttmpfile[10], sdata->ttmpfile[RND_STR_LEN-4], sdata->ttmpfile[RND_STR_LEN-3], sdata->ttmpfile[RND_STR_LEN-2], sdata->ttmpfile[RND_STR_LEN-1], sdata->ttmpfile, i);
|
||||||
|
|
||||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s);
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: unlinking %s", sdata->ttmpfile, s);
|
||||||
|
20
src/tai.c
20
src/tai.c
@ -4,8 +4,6 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "tai.h"
|
#include "tai.h"
|
||||||
|
|
||||||
static char hex[16] = "0123456789abcdef";
|
|
||||||
|
|
||||||
|
|
||||||
void tai_pack(char *s, struct tai *t){
|
void tai_pack(char *s, struct tai *t){
|
||||||
uint64 x = t->x;
|
uint64 x = t->x;
|
||||||
@ -50,21 +48,3 @@ void taia_now(struct taia *t){
|
|||||||
t->nano = 1000 * now.tv_usec + 500;
|
t->nano = 1000 * now.tv_usec + 500;
|
||||||
t->atto = 0;
|
t->atto = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void tai_timestamp(char *s){
|
|
||||||
struct tai now;
|
|
||||||
char nowpack[TAI_PACK];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
now.x = 4611686018427387914ULL + (uint64)time((long *) 0);
|
|
||||||
|
|
||||||
tai_pack(nowpack, &now);
|
|
||||||
|
|
||||||
for (i = 0;i < 8;++i) {
|
|
||||||
*(s+i*2) = hex[(nowpack[i] >> 4) & 15];
|
|
||||||
*(s+i*2+1) = hex[nowpack[i] & 15];
|
|
||||||
}
|
|
||||||
|
|
||||||
*(s+2*TAI_PACK) = '\0';
|
|
||||||
}
|
|
||||||
|
@ -28,7 +28,7 @@ void usage(){
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int i, c;
|
int i;
|
||||||
time_t retention_seconds=0;
|
time_t retention_seconds=0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct session_data sdata;
|
struct session_data sdata;
|
||||||
@ -53,8 +53,7 @@ int main(int argc, char **argv){
|
|||||||
{0,0,0,0}
|
{0,0,0,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int option_index = 0;
|
int c, option_index = 0;
|
||||||
|
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "c:m:a:hv?", long_options, &option_index);
|
c = getopt_long(argc, argv, "c:m:a:hv?", long_options, &option_index);
|
||||||
#else
|
#else
|
||||||
|
7
suppressions.txt
Normal file
7
suppressions.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
unusedFunction:src/cfg.c:20
|
||||||
|
unusedFunction:src/memc.c:288
|
||||||
|
unusedFunction:src/message.c:138
|
||||||
|
unreadVariable:src/pilerexport.c:326
|
||||||
|
unusedFunction:src/sig.c:33
|
||||||
|
unusedFunction:src/sig.c:38
|
||||||
|
unusedFunction:src/sig.c:44
|
@ -123,7 +123,7 @@ static void test_create_id(){
|
|||||||
static void test_split(){
|
static void test_split(){
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int result;
|
int result;
|
||||||
char *p, buf[SMALLBUFSIZE];
|
char buf[SMALLBUFSIZE];
|
||||||
|
|
||||||
struct test_data_s_s_i test_data_s_s_i[] = {
|
struct test_data_s_s_i test_data_s_s_i[] = {
|
||||||
{ "hello\nworld\n", "world\n", 1 },
|
{ "hello\nworld\n", "world\n", 1 },
|
||||||
@ -135,7 +135,7 @@ static void test_split(){
|
|||||||
TEST_HEADER();
|
TEST_HEADER();
|
||||||
|
|
||||||
for(i=0; i<sizeof(test_data_s_s_i)/sizeof(struct test_data_s_s_i); i++){
|
for(i=0; i<sizeof(test_data_s_s_i)/sizeof(struct test_data_s_s_i); i++){
|
||||||
p = split(test_data_s_s_i[i].s1, '\n', buf, sizeof(buf)-1, &result);
|
chat *p = split(test_data_s_s_i[i].s1, '\n', buf, sizeof(buf)-1, &result);
|
||||||
|
|
||||||
if(p){ ASSERT(strcmp(buf, "hello") == 0 && strcmp(p, test_data_s_s_i[i].s2) == 0 && result == test_data_s_s_i[i].result, test_data_s_s_i[i].s1); }
|
if(p){ ASSERT(strcmp(buf, "hello") == 0 && strcmp(p, test_data_s_s_i[i].s2) == 0 && result == test_data_s_s_i[i].result, test_data_s_s_i[i].s1); }
|
||||||
else { ASSERT(p == NULL && result == test_data_s_s_i[i].result, test_data_s_s_i[i].s1); }
|
else { ASSERT(p == NULL && result == test_data_s_s_i[i].result, test_data_s_s_i[i].s1); }
|
||||||
@ -147,7 +147,7 @@ static void test_split(){
|
|||||||
|
|
||||||
static void test_split_str(){
|
static void test_split_str(){
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
char *p, buf[SMALLBUFSIZE];
|
char buf[SMALLBUFSIZE];
|
||||||
|
|
||||||
struct test_data_s_s test_data_s_s[] = {
|
struct test_data_s_s test_data_s_s[] = {
|
||||||
{ "aaaXXbbbXX", "bbbXX" },
|
{ "aaaXXbbbXX", "bbbXX" },
|
||||||
@ -159,7 +159,7 @@ static void test_split_str(){
|
|||||||
TEST_HEADER();
|
TEST_HEADER();
|
||||||
|
|
||||||
for(i=0; i<sizeof(test_data_s_s)/sizeof(struct test_data_s_s); i++){
|
for(i=0; i<sizeof(test_data_s_s)/sizeof(struct test_data_s_s); i++){
|
||||||
p = split_str(test_data_s_s[i].s, "XX", buf, sizeof(buf)-1);
|
char *p = split_str(test_data_s_s[i].s, "XX", buf, sizeof(buf)-1);
|
||||||
|
|
||||||
if(p){ ASSERT(strcmp(buf, "aaa") == 0 && strcmp(test_data_s_s[i].result, p) == 0, test_data_s_s[i].s); }
|
if(p){ ASSERT(strcmp(buf, "aaa") == 0 && strcmp(test_data_s_s[i].result, p) == 0, test_data_s_s[i].s); }
|
||||||
else { ASSERT(strcmp(buf, "aaa") == 0 && p == NULL, test_data_s_s[i].s); }
|
else { ASSERT(strcmp(buf, "aaa") == 0 && p == NULL, test_data_s_s[i].s); }
|
||||||
|
@ -44,10 +44,10 @@ void connect_to_smtp_server(char *server, int port, struct data *data){
|
|||||||
char port_string[8], buf[MAXBUFSIZE];
|
char port_string[8], buf[MAXBUFSIZE];
|
||||||
struct addrinfo hints, *res;
|
struct addrinfo hints, *res;
|
||||||
|
|
||||||
data->net->socket = -1;
|
|
||||||
|
|
||||||
if(data == NULL) return;
|
if(data == NULL) return;
|
||||||
|
|
||||||
|
data->net->socket = -1;
|
||||||
|
|
||||||
snprintf(port_string, sizeof(port_string)-1, "%d", port);
|
snprintf(port_string, sizeof(port_string)-1, "%d", port);
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
@ -360,7 +360,7 @@ static void test_smtp_commands_period_command_in_its_own_packet(char *server, in
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
int c, port=25;
|
int port=25;
|
||||||
char *server=NULL;
|
char *server=NULL;
|
||||||
struct data data;
|
struct data data;
|
||||||
struct net net;
|
struct net net;
|
||||||
@ -384,9 +384,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "c:s:p:t:lh?", long_options, &option_index);
|
int c = getopt_long(argc, argv, "c:s:p:t:lh?", long_options, &option_index);
|
||||||
#else
|
#else
|
||||||
c = getopt(argc, argv, "c:s:p:t:lh?");
|
int c = getopt(argc, argv, "c:s:p:t:lh?");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user