cppcheck refactoring

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2020-08-10 20:58:34 +02:00
parent 47838a059f
commit 345fd715f5
42 changed files with 169 additions and 524 deletions

2
configure vendored
View File

@ -4854,7 +4854,7 @@ echo; echo
CFLAGS="$static -std=c99 -O2 -fPIC -Wall -Wextra -Wuninitialized -Wno-format-truncation -g" CFLAGS="$static -std=c99 -O2 -fPIC -Wall -Wextra -Wuninitialized -Wno-format-truncation -g"
LIBS="$antispam_libs $sunos_libs " LIBS="$antispam_libs $sunos_libs "
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs" OBJS="dirs.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs"
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile systemd/Makefile unit_tests/Makefile webui/Makefile contrib/imap/Makefile" ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile systemd/Makefile unit_tests/Makefile webui/Makefile contrib/imap/Makefile"

View File

@ -537,7 +537,7 @@ echo; echo
CFLAGS="$static -std=c99 -O2 -fPIC -Wall -Wextra -Wuninitialized -Wno-format-truncation -g" CFLAGS="$static -std=c99 -O2 -fPIC -Wall -Wextra -Wuninitialized -Wno-format-truncation -g"
LIBS="$antispam_libs $sunos_libs " LIBS="$antispam_libs $sunos_libs "
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs" OBJS="dirs.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o bdat.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o imap.o pop3.o extract.o mydomains.o tokenizer.o $objs"
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile systemd/Makefile unit_tests/Makefile webui/Makefile contrib/imap/Makefile]) AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile systemd/Makefile unit_tests/Makefile webui/Makefile contrib/imap/Makefile])
AC_OUTPUT AC_OUTPUT

7
cppcheck.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
cppcheck -DHAVE_PDFTOTEXT -DHAVE_PPTHTML -DHAVE_TNEF -DHAVE_UNRTF -DHAVE_XLS2CSV -DHAVE_CATPPT -DHAVE_CATDOC -DHAVE_ZIP -D_GNU_SOURCE -DHAVE_DAEMON -DHAVE_TRE -DHAVE_CLAMD -DHAVE_LIBCLAMAV -DNEED_MYSQL --error-exitcode=1 --enable=all --suppressions-list=suppressions.txt --force src/ unit_tests/

View File

@ -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,8 @@ 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);

View File

@ -17,7 +17,6 @@
int store_attachments(struct session_data *sdata, struct parser_state *state, struct config *cfg){ int store_attachments(struct session_data *sdata, struct parser_state *state, struct config *cfg){
uint64 id=0;
int i, rc=1, found, affected_rows; int i, rc=1, found, affected_rows;
struct sql sql, sql2; struct sql sql, sql2;
@ -27,7 +26,7 @@ int store_attachments(struct session_data *sdata, struct parser_state *state, st
for(i=1; i<=state->n_attachments; i++){ for(i=1; i<=state->n_attachments; i++){
found = 0; found = 0;
id = 0; uint64 id = 0;
if(state->attachments[i].size > 0){ if(state->attachments[i].size > 0){

View File

@ -1,78 +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]);
}

View File

@ -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);

View File

@ -17,31 +17,12 @@ int string_parser(char *src, char *target, int limit){
return 0; return 0;
}; };
int multi_line_string_parser(char *src, char *target, unsigned int limit){
if(strlen(src) > 0 && strlen(target) + strlen(src) + 3 < limit){
strncat(target, src, limit-strlen(target));
strncat(target, "\r\n", limit-strlen(target));
return 0;
}
return 1;
};
int int_parser(char *src, int *target){ int int_parser(char *src, int *target){
*target = strtol(src, (char **) NULL, 10); *target = strtol(src, (char **) NULL, 10);
return 0; return 0;
}; };
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;

View File

@ -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++;

View File

@ -51,13 +51,12 @@ struct counters load_counters(struct session_data *sdata){
void update_counters(struct session_data *sdata, struct data *data, struct counters *counters, struct config *cfg){ void update_counters(struct session_data *sdata, struct data *data, 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;
#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 == 0) return;
#ifdef HAVE_MEMCACHED #ifdef HAVE_MEMCACHED
if(cfg->update_counters_to_memcached == 1){ if(cfg->update_counters_to_memcached == 1){
@ -65,7 +64,7 @@ void update_counters(struct session_data *sdata, struct data *data, struct count
/* increment counters to memcached */ /* increment counters to memcached */
if(memcached_increment(&(data->memc), MEMCACHED_MSGS_RCVD, counters->c_rcvd, &mc) == MEMCACHED_SUCCESS){ if(memcached_increment(&(data->memc), 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, counters->c_virus, &mc); if(counters->c_virus > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_VIRUS, counters->c_virus, &mc);
if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, counters->c_duplicate, &mc); if(counters->c_duplicate > 0) memcached_increment(&(data->memc), MEMCACHED_MSGS_DUPLICATE, counters->c_duplicate, &mc);
@ -79,6 +78,8 @@ void update_counters(struct session_data *sdata, struct data *data, struct count
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);

View File

@ -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];

View File

@ -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);

View File

@ -241,10 +241,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
}; };

View File

@ -34,7 +34,7 @@ int search_header_end(char *p, int n){
int make_digests(struct session_data *sdata, struct config *cfg){ int make_digests(struct session_data *sdata, struct config *cfg){
int i=0, n, fd, offset=3, hdr_len=0, len=0; int i=0, n, fd, offset=3, hdr_len=0;
char *body=NULL; char *body=NULL;
unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH], md2[DIGEST_LENGTH]; unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH], md2[DIGEST_LENGTH];
SHA256_CTX context, context2; SHA256_CTX context, context2;
@ -50,8 +50,6 @@ int make_digests(struct session_data *sdata, struct config *cfg){
while((n = read(fd, buf, sizeof(buf))) > 0){ while((n = read(fd, buf, sizeof(buf))) > 0){
len += n;
SHA256_Update(&context2, buf, n); SHA256_Update(&context2, buf, n);
body = (char *)&buf[0]; body = (char *)&buf[0];

View File

@ -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;
unsigned int len2; unsigned 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,7 @@ 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);
@ -89,7 +90,7 @@ int extract_opendocument(struct session_data *sdata, struct parser_state *state,
int unzip_file(struct session_data *sdata, struct parser_state *state, char *filename, int *rec, struct config *cfg){ int unzip_file(struct session_data *sdata, struct parser_state *state, char *filename, int *rec, struct config *cfg){
int errorp, i=0, len=0, fd; int errorp, i=0, fd;
char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE]; char *p, extracted_filename[SMALLBUFSIZE], buf[MAXBUFSIZE];
struct zip *z; struct zip *z;
struct zip_stat sb; struct zip_stat sb;
@ -120,6 +121,7 @@ int unzip_file(struct session_data *sdata, struct parser_state *state, char *fil
if(fd != -1){ if(fd != -1){
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))) > 0){ while((len = zip_fread(zf, buf, sizeof(buf))) > 0){
if(write(fd, buf, len) == -1) syslog(LOG_PRIORITY, "ERROR: error writing to fd in %s", __func__); if(write(fd, buf, len) == -1) syslog(LOG_PRIORITY, "ERROR: error writing to fd in %s", __func__);
} }
@ -207,9 +209,7 @@ 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]; int link[2];
ssize_t n;
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;
@ -304,6 +304,9 @@ void extract_attachment_content(struct session_data *sdata, struct parser_state
} }
else { else {
close(link[1]); close(link[1]);
ssize_t n;
char outbuf[MAXBUFSIZE];
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){
memcpy(&(state->b_body[state->bodylen]), outbuf, n); memcpy(&(state->b_body[state->bodylen]), outbuf, n);

View File

@ -33,12 +33,10 @@ void clearhash(struct node *xhash[]){
p = q; p = q;
q = q->r; q = q->r;
if(p){ if(p->str){
if(p->str){ free(p->str);
free(p->str);
}
free(p);
} }
free(p);
} }
xhash[i] = NULL; xhash[i] = NULL;
} }
@ -154,12 +152,12 @@ int is_substr_in_hash(struct node *xhash[], char *s){
unsigned int DJBHash(char* str, unsigned int len){ unsigned int DJBHash(char* str, unsigned int len){
unsigned int hash = 5381; unsigned int hashval = 5381;
unsigned int i = 0; unsigned int i = 0;
for(i=0; i < len; str++, i++){ for(i=0; i < len; str++, i++){
hash = ((hash << 5) + hash) + (*str); hashval = ((hashval << 5) + hashval) + (*str);
} }
return hash; return hashval;
} }

View File

@ -314,7 +314,7 @@ void imap_expunge_message(struct data *data){
int process_imap_folder(char *folder, struct session_data *sdata, struct data *data, struct config *cfg){ int process_imap_folder(char *folder, struct session_data *sdata, struct data *data, struct config *cfg){
int rc=ERR, i, messages=0; int i, messages=0;
messages = imap_select_cmd_on_folder(folder, data); messages = imap_select_cmd_on_folder(folder, data);
@ -330,7 +330,7 @@ int process_imap_folder(char *folder, struct session_data *sdata, struct data *d
if(data->quiet == 0){ printf("processed: %7d [%3d%%]\r", data->import->processed_messages, 100*i/messages); fflush(stdout); } if(data->quiet == 0){ printf("processed: %7d [%3d%%]\r", data->import->processed_messages, 100*i/messages); fflush(stdout); }
if(data->import->dryrun == 0){ if(data->import->dryrun == 0){
rc = import_message(sdata, data, cfg); int rc = import_message(sdata, data, cfg);
if(data->import->remove_after_import == 1 && rc == OK){ if(data->import->remove_after_import == 1 && rc == OK){
imap_delete_message(data, i); imap_delete_message(data, i);

View File

@ -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;
@ -127,12 +127,13 @@ 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))

View File

@ -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;

View File

@ -1,94 +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;
}
}

View File

@ -1,16 +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 */

View File

@ -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,8 +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); if(fcntl(ptr->fd, F_SETFL, flags | O_NONBLOCK) == -1) return MEMCACHED_FAILURE;
if(rval == -1) return MEMCACHED_FAILURE;
} }
return MEMCACHED_SUCCESS; return MEMCACHED_SUCCESS;
@ -223,7 +222,7 @@ int memcached_add(struct memcached_server *ptr, char *cmd, char *key, char *valu
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE; if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE;
// cmd could be either 'add' or 'set' // cmd could be either 'add' or 'set'
snprintf(ptr->buf, MAXBUFSIZE-1, "%s %s %d %ld %d \r\n", cmd, key, flags, expiry, valuelen); snprintf(ptr->buf, MAXBUFSIZE-1, "%s %s %u %lu %u \r\n", cmd, 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);
@ -263,52 +262,6 @@ int memcached_increment(struct memcached_server *ptr, char *key, unsigned long l
} }
char *memcached_get(struct memcached_server *ptr, char *key, unsigned int *len, unsigned int *flags){
char *p;
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return NULL;
snprintf(ptr->buf, MAXBUFSIZE, "get %s \r\n", key);
send(ptr->fd, ptr->buf, strlen(ptr->buf), 0);
ptr->last_read_bytes = __recvtimeout(ptr->fd, ptr->buf, MAXBUFSIZE, ptr->rcv_timeout);
if(ptr->last_read_bytes <= 0){
memcached_shutdown(ptr);
return NULL;
}
if(ptr->last_read_bytes < 10) return NULL;
if(strncmp("VALUE ", ptr->buf, 6)) return NULL;
p = strchr(ptr->buf, '\r');
if(!p) return NULL;
*p = '\0';
ptr->result = p + 2;
p = strrchr(ptr->buf + 6, ' ');
if(!p) return NULL;
*len = atoi(p+1);
*p = '\0';
p = strrchr(ptr->buf + 6, ' ');
if(!p) return NULL;
*flags = atoi(p+1);
*p = '\0';
p = strchr(ptr->result, '\r');
if(!p) return NULL;
*p = '\0';
return ptr->result;
}
int memcached_mget(struct memcached_server *ptr, char *key){ int memcached_mget(struct memcached_server *ptr, char *key){
if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE; if(memcached_connect(ptr) != MEMCACHED_SUCCESS) return MEMCACHED_FAILURE;

View File

@ -136,15 +136,6 @@ int store_recipients(struct session_data *sdata, char *to, uint64 id, struct con
} }
void remove_recipients(struct session_data *sdata, uint64 id){
char s[SMALLBUFSIZE];
snprintf(s, sizeof(s)-1, "DELETE FROM " SQL_RECIPIENT_TABLE " WHERE id=%llu", id);
p_query(sdata, s);
}
int store_folder_id(struct session_data *sdata, struct data *data, uint64 id, struct config *cfg){ int store_folder_id(struct session_data *sdata, struct data *data, uint64 id, struct config *cfg){
int rc=ERR; int rc=ERR;
struct sql sql; struct sql sql;

View File

@ -88,44 +88,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){
size_t i;
int 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
*/ */
@ -181,10 +143,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;
} }
@ -215,8 +175,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
@ -226,13 +185,14 @@ 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);
} }
@ -349,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;
@ -605,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;

View File

@ -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);

View File

@ -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,9 +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); if(addnode(data->mydomains, s) == 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);
memset(s, 0, sizeof(s)); memset(s, 0, sizeof(s));

View File

@ -73,9 +73,7 @@ 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;
unsigned int len;
char *p;
clearhash(state->boundaries); clearhash(state->boundaries);
clearhash(state->rcpt); clearhash(state->rcpt);
@ -105,12 +103,12 @@ 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){
rec = 0; int rec = 0;
if(cfg->extract_attachments == 1 && state->bodylen < BIGBUFSIZE-1024) extract_attachment_content(sdata, state, state->attachments[i].aname, get_attachment_extractor_by_filename(state->attachments[i].filename), &rec, cfg); if(cfg->extract_attachments == 1 && state->bodylen < BIGBUFSIZE-1024) extract_attachment_content(sdata, state, state->attachments[i].aname, get_attachment_extractor_by_filename(state->attachments[i].filename), &rec, cfg);
unlink(state->attachments[i].aname); unlink(state->attachments[i].aname);
@ -153,15 +151,13 @@ void storno_attachment(struct parser_state *state){
void flush_attachment_buffer(struct parser_state *state, char *abuffer, unsigned int abuffersize){ void flush_attachment_buffer(struct parser_state *state, char *abuffer, unsigned int abuffersize){
int n64;
unsigned char b64buffer[MAXBUFSIZE];
if(write(state->fd, abuffer, state->abufpos) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__); if(write(state->fd, abuffer, state->abufpos) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__);
if(state->b64fd != -1){ if(state->b64fd != -1){
abuffer[state->abufpos] = '\0'; abuffer[state->abufpos] = '\0';
if(state->base64 == 1){ if(state->base64 == 1){
n64 = base64_decode_attachment_buffer(abuffer, &b64buffer[0], sizeof(b64buffer)); unsigned char b64buffer[MAXBUFSIZE];
int n64 = base64_decode_attachment_buffer(abuffer, &b64buffer[0], sizeof(b64buffer));
if(write(state->b64fd, b64buffer, n64) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__); if(write(state->b64fd, b64buffer, n64) == -1) syslog(LOG_PRIORITY, "ERROR: write(), %s, %d, %s", __func__, __LINE__, __FILE__);
} }
else if(write(state->b64fd, abuffer, state->abufpos) == -1){ else if(write(state->b64fd, abuffer, state->abufpos) == -1){
@ -175,9 +171,8 @@ void flush_attachment_buffer(struct parser_state *state, char *abuffer, unsigned
int parse_line(char *buf, struct parser_state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, unsigned int writebuffersize, char *abuffer, unsigned 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, unsigned int writebuffersize, char *abuffer, unsigned int abuffersize, struct data *data, struct config *cfg){
char *p, puf[SMALLBUFSIZE]; char *p;
char tmpbuf[MAXBUFSIZE]; int boundary_line=0;
int writelen, boundary_line=0, result;
unsigned int len; unsigned int len;
if(cfg->debug == 1) printf("line: %s", buf); if(cfg->debug == 1) printf("line: %s", buf);
@ -284,8 +279,9 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
syslog(LOG_PRIORITY, "%s: error opening %s", sdata->ttmpfile, state->attachments[state->n_attachments].internalname); syslog(LOG_PRIORITY, "%s: error opening %s", sdata->ttmpfile, state->attachments[state->n_attachments].internalname);
} }
else { else {
char puf[SMALLBUFSIZE];
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;
@ -637,7 +633,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){
result = utf8_encode(buf, strlen(buf), &tmpbuf[0], sizeof(tmpbuf), state->charset); char tmpbuf[MAXBUFSIZE];
int 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);
} }

View File

@ -114,7 +114,7 @@ long get_local_timezone_offset(){
time_t parse_date_header(char *datestr){ time_t parse_date_header(char *datestr){
int n=0, len; int n=0;
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];
@ -150,7 +150,7 @@ 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++; n++;
@ -264,7 +264,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");
@ -291,7 +291,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, '"');
@ -315,14 +315,13 @@ 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
*/ */
char v[MAXBUFSIZE], u[MAXBUFSIZE], puf[MAXBUFSIZE], encoding[MAXBUFSIZE], tmpbuf[2*MAXBUFSIZE]; char v[MAXBUFSIZE], u[MAXBUFSIZE], puf[MAXBUFSIZE], encoding[MAXBUFSIZE], tmpbuf[2*MAXBUFSIZE];
int need_encoding, ret, prev_encoded=0, n_tokens=0; int need_encoding, ret, prev_encoded=0, n_tokens=0;
int b64=0, qp=0;
if(buflen < 5) return; if(buflen < 5) return;
@ -333,7 +332,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));
@ -349,7 +348,7 @@ void fixupEncodedHeaderLine(char *buf, int buflen){
* Happy New Year! =?utf-8?q?=F0=9F=8E=86?= * Happy New Year! =?utf-8?q?=F0=9F=8E=86?=
*/ */
b64 = qp = 0; int b64=0, qp=0;
memset(encoding, 0, sizeof(encoding)); memset(encoding, 0, sizeof(encoding));
r = strstr(p, "=?"); r = strstr(p, "=?");
@ -446,9 +445,9 @@ 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);
@ -461,7 +460,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){
@ -475,9 +474,8 @@ 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);
@ -489,7 +487,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';
@ -576,7 +574,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;
@ -594,7 +592,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);
@ -697,11 +695,9 @@ int does_it_seem_like_an_email_address(char *email){
void add_recipient(char *email, unsigned int len, struct session_data *sdata, struct parser_state *state, struct data *data, struct config *cfg){ void add_recipient(char *email, unsigned int len, struct session_data *sdata, struct parser_state *state, struct data *data, struct config *cfg){
char *q;
if(findnode(state->rcpt, email) == NULL){ if(findnode(state->rcpt, email) == NULL){
q = strchr(email, '@'); char *q = strchr(email, '@');
/* skip any address matching ...@cfg->hostid, 2013.10.29, SJ */ /* skip any address matching ...@cfg->hostid, 2013.10.29, SJ */
if(q && strncmp(q+1, cfg->hostid, cfg->hostid_len) == 0){ if(q && strncmp(q+1, cfg->hostid, cfg->hostid_len) == 0){
@ -769,7 +765,7 @@ void degenerateToken(unsigned char *p){
int i=1, d=0, dp=0; int i=1, d=0, dp=0;
unsigned char *s; unsigned char *s;
/* quit if this the string does not end with a punctuation character */ /* quit if the string does not end with a punctuation character */
if(!ispunct(*(p+strlen((char *)p)-1))) if(!ispunct(*(p+strlen((char *)p)-1)))
return; return;
@ -825,8 +821,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);
@ -862,6 +857,8 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb
* *
*/ */
int extended=0;
p += strlen(name); p += strlen(name);
if(*p == '*'){ if(*p == '*'){
extended = 1; extended = 1;
@ -889,7 +886,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';
@ -906,6 +903,7 @@ 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));
@ -919,8 +917,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,";
@ -951,7 +947,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++;
@ -1013,14 +1009,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);
@ -1046,12 +1041,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);

View File

@ -63,7 +63,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;
@ -73,7 +73,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]);
@ -86,7 +86,7 @@ void get_number_of_total_messages(struct data *data){
int pop3_download_email(struct data *data, int i){ int pop3_download_email(struct data *data, int i){
int n, fd, pos=0, readlen=0, lastpos=0, nreads=0; int n, fd, pos=0, lastpos=0, nreads=0;
char *p, buf[MAXBUFSIZE]; char *p, buf[MAXBUFSIZE];
char aggrbuf[3*MAXBUFSIZE]; char aggrbuf[3*MAXBUFSIZE];
@ -108,7 +108,6 @@ int pop3_download_email(struct data *data, int i){
while((n = recvtimeoutssl(data->net, buf, sizeof(buf))) > 0){ while((n = recvtimeoutssl(data->net, buf, sizeof(buf))) > 0){
nreads++; nreads++;
readlen += n;
if(nreads == 1){ if(nreads == 1){
@ -167,7 +166,6 @@ void pop3_delete_message(struct data *data, int i){
void process_pop3_emails(struct session_data *sdata, struct data *data, struct config *cfg){ void process_pop3_emails(struct session_data *sdata, struct data *data, struct config *cfg){
int i=0, rc=ERR;
char buf[MAXBUFSIZE]; char buf[MAXBUFSIZE];
data->import->processed_messages = 0; data->import->processed_messages = 0;
@ -178,12 +176,12 @@ void process_pop3_emails(struct session_data *sdata, struct data *data, struct c
if(data->import->total_messages <= 0) return; if(data->import->total_messages <= 0) return;
for(i=data->import->start_position; i<=data->import->total_messages; i++){ for(int i=data->import->start_position; i<=data->import->total_messages; i++){
if(pop3_download_email(data, i) == OK){ if(pop3_download_email(data, i) == OK){
if(data->quiet == 0){ printf("processed: %7d [%3d%%]\r", data->import->processed_messages, 100*i/data->import->total_messages); fflush(stdout); } if(data->quiet == 0){ printf("processed: %7d [%3d%%]\r", data->import->processed_messages, 100*i/data->import->total_messages); fflush(stdout); }
if(data->import->dryrun == 0){ if(data->import->dryrun == 0){
rc = import_message(sdata, data, cfg); int rc = import_message(sdata, data, cfg);
if(data->import->remove_after_import == 1 && rc == OK){ if(data->import->remove_after_import == 1 && rc == OK){
pop3_delete_message(data, i); pop3_delete_message(data, i);

View File

@ -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,12 @@ 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){
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"); FILE *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 +159,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 +168,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 +208,7 @@ int main(int argc, char **argv){
} }
if(all == 0 && (from_id <= 0 || to_id <= 0) ) usage(); if(all == 0 && (from_id == 0 || to_id == 0) ) usage();
if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!"); if(!can_i_write_directory(NULL)) __fatal("cannot write current directory!");

View File

@ -196,13 +196,14 @@ struct rule *create_rule_item(struct rule_cond *rule_cond){
int count_match(struct rule *p, struct parser_state *state, int size, int spam){ int count_match(struct rule *p, struct parser_state *state, int size, int spam){
int ismatch=0; int ismatch=0;
size_t nmatch=0;
ismatch += check_spam_rule(spam, p->spam); ismatch += check_spam_rule(spam, p->spam);
ismatch += check_size_rule(size, p->size, p->_size); ismatch += check_size_rule(size, p->size, p->_size);
ismatch += check_attachment_rule(state, p); ismatch += check_attachment_rule(state, p);
if(p->compiled == 1){ if(p->compiled == 1){
size_t nmatch=0;
if(p->emptyfrom == 1){ if(p->emptyfrom == 1){
ismatch += RULE_UNDEF; ismatch += RULE_UNDEF;
} }
@ -338,7 +339,6 @@ 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 no attachment rule, then return RULE_UNDEF // If no attachment rule, then return RULE_UNDEF
if(rule->emptyaname == 1 && rule->emptyatype == 1 && rule->attachment_size == 0) return RULE_UNDEF; if(rule->emptyaname == 1 && rule->emptyatype == 1 && rule->attachment_size == 0) return RULE_UNDEF;
@ -348,7 +348,7 @@ int check_attachment_rule(struct parser_state *state, struct rule *rule){
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)
@ -379,34 +379,32 @@ 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->str){
if(p->str){ rule = (struct rule*)p->str;
rule = (struct rule*)p->str;
regfree(&(rule->from)); regfree(&(rule->from));
regfree(&(rule->to)); regfree(&(rule->to));
regfree(&(rule->subject)); regfree(&(rule->subject));
regfree(&(rule->body)); regfree(&(rule->body));
regfree(&(rule->attachment_name)); regfree(&(rule->attachment_name));
regfree(&(rule->attachment_type)); regfree(&(rule->attachment_type));
free(rule->rulestr); free(rule->rulestr);
if(rule->domain) free(rule->domain); if(rule->domain) free(rule->domain);
free(rule); free(rule);
}
free(p);
} }
free(p);
} }
xhash[0] = NULL; xhash[0] = NULL;

View File

@ -30,7 +30,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;
/* /*
@ -57,6 +56,8 @@ int start_new_session(struct smtp_session **sessions, int socket, int *num_conne
sessions[slot] = malloc(sizeof(struct smtp_session)); sessions[slot] = malloc(sizeof(struct smtp_session));
if(sessions[slot]){ if(sessions[slot]){
init_smtp_session(sessions[slot], slot, socket, cfg); init_smtp_session(sessions[slot], slot, socket, cfg);
char smtp_banner[SMALLBUFSIZE];
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);
@ -233,14 +234,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;
char *p, s[SMALLBUFSIZE];
if(session->fd == -1) return; if(session->fd == -1) return;
for(i=0; i<session->num_of_rcpt_to; i++){ for(int 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)){
char s[SMALLBUFSIZE];
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);
} }

View File

@ -72,15 +72,15 @@ void process_smtp_command(struct smtp_session *session, char *buf, struct config
void process_data(struct smtp_session *session, char *buf, int buflen){ void process_data(struct smtp_session *session, char *buf, int buflen){
int len=0, written=0, n_writes=0;
if(session->last_data_char == '\n' && strcmp(buf, ".\r\n") == 0){ if(session->last_data_char == '\n' && strcmp(buf, ".\r\n") == 0){
process_command_period(session); process_command_period(session);
} }
else { else {
// write line to file // write line to file
int written=0, n_writes=0;
while(written < buflen) { while(written < buflen) {
len = write(session->fd, buf+written, buflen-written); int len = write(session->fd, buf+written, buflen-written);
n_writes++; n_writes++;
if(len > 0){ if(len > 0){
@ -98,7 +98,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");
@ -115,6 +114,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);

View File

@ -134,15 +134,15 @@ 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;
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;
char buf[SMALLBUFSIZE];
snprintf(buf, sizeof(buf)-1, "%s/%s", ERROR_DIR, de->d_name); snprintf(buf, sizeof(buf)-1, "%s/%s", ERROR_DIR, de->d_name);
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)){ if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)){

View File

@ -213,12 +213,11 @@ 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(i=1; i<=state->n_attachments; i++){ for(int 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);

View File

@ -4,7 +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){
@ -50,21 +49,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';
}

View File

@ -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;
@ -57,9 +57,9 @@ int main(int argc, char **argv){
int option_index = 0; int option_index = 0;
c = getopt_long(argc, argv, "c:m:a:hv?", long_options, &option_index); int c = getopt_long(argc, argv, "c:m:a:hv?", long_options, &option_index);
#else #else
c = getopt(argc, argv, "c:m:a:hv?"); int c = getopt(argc, argv, "c:m:a:hv?");
#endif #endif
if(c == -1) break; if(c == -1) break;

13
suppressions.txt Normal file
View File

@ -0,0 +1,13 @@
identicalConditionAfterEarlyExit:src/tokenizer.c:40
invalidPrintfArgType_s:src/extract.c:175
invalidPrintfArgType_s:src/misc.c:39
invalidPrintfArgType_s:src/misc.c:43
invalidPrintfArgType_s:src/misc.c:47
invalidPrintfArgType_s:src/misc.c:51
invalidPrintfArgType_s:src/misc.c:55
invalidPrintfArgType_s:src/misc.c:59
invalidPrintfArgType_s:src/misc.c:63
redundantAssignment:src/imap.c:47
unusedFunction:src/sig.c:33
unusedFunction:src/sig.c:38
unusedFunction:src/sig.c:44

View File

@ -5,7 +5,7 @@
#include "test.h" #include "test.h"
struct digest_test tests[] = { struct digest_test emls[] = {
{"1.eml", "7fa4f06f7085986007454b374f6685e4cf838d9e9f8878f3cba89cfe98e29f56", "bbbafb22e2d4c035584a5024e9d4feaf32172559b4d7cacc8b7af4bd548da53e"}, {"1.eml", "7fa4f06f7085986007454b374f6685e4cf838d9e9f8878f3cba89cfe98e29f56", "bbbafb22e2d4c035584a5024e9d4feaf32172559b4d7cacc8b7af4bd548da53e"},
{"2.eml", "668cb3b91b944af786667323442576b9813d65f3cd3bc33e9d5da303c79de038", "de90475409dd6ab24e80c1b7a987715c40fe8d28d91337b7f063b477159c7b3c"}, {"2.eml", "668cb3b91b944af786667323442576b9813d65f3cd3bc33e9d5da303c79de038", "de90475409dd6ab24e80c1b7a987715c40fe8d28d91337b7f063b477159c7b3c"},
{"3.eml", "0d546d4cb4a8ce74ea5fd4cc51dbb4ebeaa7542f1c691817579da7eeab8d4771", "f585d011340d292ee52ddedb07cda662a8f1e46329d14a2ce92dca0604387bab"}, {"3.eml", "0d546d4cb4a8ce74ea5fd4cc51dbb4ebeaa7542f1c691817579da7eeab8d4771", "f585d011340d292ee52ddedb07cda662a8f1e46329d14a2ce92dca0604387bab"},
@ -41,9 +41,9 @@ static void test_digest_file(){
unsigned int i; unsigned int i;
char digest[2*DIGEST_LENGTH+1]; char digest[2*DIGEST_LENGTH+1];
for(i=0; i<sizeof(tests)/sizeof(struct digest_test); i++){ for(i=0; i<sizeof(emls)/sizeof(struct digest_test); i++){
digest_file(tests[i].s, &digest[0]); digest_file(emls[i].s, &digest[0]);
assert(strcmp(digest, tests[i].digest2) == 0 && "test_digest_file()"); assert(strcmp(digest, emls[i].digest2) == 0 && "test_digest_file()");
} }
printf("test_digest_file() OK\n"); printf("test_digest_file() OK\n");
@ -64,8 +64,8 @@ static void test_make_digests(struct config *cfg){
} }
for(i=0; i<sizeof(tests)/sizeof(struct digest_test); i++){ for(i=0; i<sizeof(emls)/sizeof(struct digest_test); i++){
if(setup_and_parse_message(&sdata, &state, &data, tests[i].s, cfg) == 1){ if(setup_and_parse_message(&sdata, &state, &data, emls[i].s, cfg) == 1){
continue; continue;
} }
@ -79,8 +79,8 @@ static void test_make_digests(struct config *cfg){
unlink(sdata.tmpframe); unlink(sdata.tmpframe);
assert(strcmp(sdata.bodydigest, tests[i].digest1) == 0 && "test_make_digests()"); assert(strcmp(sdata.bodydigest, emls[i].digest1) == 0 && "test_make_digests()");
assert(strcmp(sdata.digest, tests[i].digest2) == 0 && "test_make_digests()"); assert(strcmp(sdata.digest, emls[i].digest2) == 0 && "test_make_digests()");
} }

View File

@ -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); char *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); }

View File

@ -25,7 +25,6 @@ struct str_pair {
static void test_parse_date_header(){ static void test_parse_date_header(){
unsigned int i; unsigned int i;
struct config cfg; struct config cfg;
time_t delta;
struct date_test date_test[] = { struct date_test date_test[] = {
{"Date: Mon, 02 Nov 2015 09:39:31 -0000", 1446457171}, {"Date: Mon, 02 Nov 2015 09:39:31 -0000", 1446457171},
{"Date: Mon, 2 Nov 2015 10:39:45 +0100", 1446457185}, {"Date: Mon, 2 Nov 2015 10:39:45 +0100", 1446457185},
@ -49,7 +48,7 @@ static void test_parse_date_header(){
TEST_HEADER(); TEST_HEADER();
for(i=0; i<sizeof(date_test)/sizeof(struct date_test); i++){ for(i=0; i<sizeof(date_test)/sizeof(struct date_test); i++){
delta = parse_date_header(date_test[i].date_str) - date_test[i].timestamp; time_t delta = parse_date_header(date_test[i].date_str) - date_test[i].timestamp;
ASSERT(delta <= 3600 && delta >= -3600, date_test[i].date_str); ASSERT(delta <= 3600 && delta >= -3600, date_test[i].date_str);
} }

View File

@ -27,10 +27,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));
@ -301,7 +301,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;
@ -325,9 +325,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