mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 06:00:13 +01:00
added verification to the bulk export
This commit is contained in:
parent
b95919c574
commit
16abfa4266
17
src/digest.c
17
src/digest.c
@ -14,22 +14,24 @@
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
int make_body_digest(struct session_data *sdata, struct __config *cfg){
|
||||
int make_digests(struct session_data *sdata, struct __config *cfg){
|
||||
int i=0, n, fd, offset=3;
|
||||
char *p, *body=NULL;
|
||||
unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH];
|
||||
SHA256_CTX context;
|
||||
|
||||
//if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: digesting", sdata->ttmpfile);
|
||||
unsigned char buf[BIGBUFSIZE], md[DIGEST_LENGTH], md2[DIGEST_LENGTH];
|
||||
SHA256_CTX context, context2;
|
||||
|
||||
memset(sdata->bodydigest, 0, 2*DIGEST_LENGTH+1);
|
||||
memset(sdata->digest, 0, 2*DIGEST_LENGTH+1);
|
||||
SHA256_Init(&context);
|
||||
SHA256_Init(&context2);
|
||||
|
||||
fd = open(sdata->ttmpfile, O_RDONLY);
|
||||
if(fd == -1) return -1;
|
||||
|
||||
while((n = read(fd, buf, sizeof(buf))) > 0){
|
||||
|
||||
SHA256_Update(&context2, buf, n);
|
||||
|
||||
body = (char *)&buf[0];
|
||||
|
||||
if(i == 0){
|
||||
@ -62,9 +64,12 @@ int make_body_digest(struct session_data *sdata, struct __config *cfg){
|
||||
close(fd);
|
||||
|
||||
SHA256_Final(md, &context);
|
||||
SHA256_Final(md2, &context2);
|
||||
|
||||
for(i=0;i<DIGEST_LENGTH;i++)
|
||||
for(i=0;i<DIGEST_LENGTH;i++){
|
||||
snprintf(sdata->bodydigest + i*2, 2*DIGEST_LENGTH, "%02x", md[i]);
|
||||
snprintf(sdata->digest + i*2, 2*DIGEST_LENGTH, "%02x", md2[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ int read_key(struct __config *cfg);
|
||||
|
||||
int do_av_check(struct session_data *sdata, char *rcpttoemail, char *fromemail, char *virusinfo, struct __data *data, struct __config *cfg);
|
||||
|
||||
int make_body_digest(struct session_data *sdata, struct __config *cfg);
|
||||
int make_digests(struct session_data *sdata, struct __config *cfg);
|
||||
void digest_file(char *filename, char *digest);
|
||||
|
||||
int processMessage(struct session_data *sdata, struct _state *sstate, struct __config *cfg);
|
||||
|
@ -274,9 +274,88 @@ int retrieve_email_from_archive(struct session_data *sdata, FILE *dest, struct _
|
||||
}
|
||||
|
||||
|
||||
uint64 get_id_by_piler_id(struct session_data *sdata, char *digest, char *bodydigest, struct __config *cfg){
|
||||
char s[SMALLBUFSIZE];
|
||||
MYSQL_STMT *stmt;
|
||||
MYSQL_BIND bind[3];
|
||||
unsigned long len=0;
|
||||
uint64 id=0;
|
||||
|
||||
memset(digest, 0, 2*DIGEST_LENGTH+1);
|
||||
memset(bodydigest, 0, 2*DIGEST_LENGTH+1);
|
||||
|
||||
stmt = mysql_stmt_init(&(sdata->mysql));
|
||||
if(!stmt){
|
||||
goto ENDE;
|
||||
}
|
||||
|
||||
snprintf(s, SMALLBUFSIZE-1, "SELECT `id`,`digest`,`bodydigest` FROM %s WHERE piler_id=?", SQL_METADATA_TABLE);
|
||||
|
||||
|
||||
if(mysql_stmt_prepare(stmt, s, strlen(s))){
|
||||
goto ENDE;
|
||||
}
|
||||
|
||||
memset(bind, 0, sizeof(bind));
|
||||
|
||||
bind[0].buffer_type = MYSQL_TYPE_STRING;
|
||||
bind[0].buffer = sdata->ttmpfile;
|
||||
bind[0].is_null = 0;
|
||||
len = strlen(sdata->ttmpfile); bind[0].length = &len;
|
||||
|
||||
|
||||
if(mysql_stmt_bind_param(stmt, bind)){
|
||||
goto ENDE;
|
||||
}
|
||||
|
||||
|
||||
if(mysql_stmt_execute(stmt)){
|
||||
goto ENDE;
|
||||
}
|
||||
|
||||
|
||||
memset(bind, 0, sizeof(bind));
|
||||
|
||||
bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
|
||||
bind[0].buffer = (char *)&id;
|
||||
bind[0].is_null = 0;
|
||||
bind[0].length = 0;
|
||||
|
||||
bind[1].buffer_type = MYSQL_TYPE_STRING;
|
||||
bind[1].buffer = digest;
|
||||
bind[1].buffer_length = 2*DIGEST_LENGTH+1;
|
||||
bind[1].is_null = 0;
|
||||
bind[1].length = &len;
|
||||
|
||||
bind[2].buffer_type = MYSQL_TYPE_STRING;
|
||||
bind[2].buffer = bodydigest;
|
||||
bind[2].buffer_length = 2*DIGEST_LENGTH+1;
|
||||
bind[2].is_null = 0;
|
||||
bind[2].length = &len;
|
||||
|
||||
if(mysql_stmt_bind_result(stmt, bind)){
|
||||
goto ENDE;
|
||||
}
|
||||
|
||||
|
||||
if(mysql_stmt_store_result(stmt)){
|
||||
goto ENDE;
|
||||
}
|
||||
|
||||
mysql_stmt_fetch(stmt);
|
||||
|
||||
mysql_stmt_close(stmt);
|
||||
|
||||
ENDE:
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int rc;
|
||||
char filename[SMALLBUFSIZE];
|
||||
uint64 id;
|
||||
char filename[SMALLBUFSIZE], digest[2*DIGEST_LENGTH+1], bodydigest[2*DIGEST_LENGTH+1];
|
||||
FILE *f;
|
||||
struct session_data sdata;
|
||||
struct __config cfg;
|
||||
@ -312,14 +391,29 @@ int main(int argc, char **argv){
|
||||
|
||||
while((rc = read(0, sdata.ttmpfile, RND_STR_LEN+1)) > 0){
|
||||
trimBuffer(sdata.ttmpfile);
|
||||
snprintf(filename, sizeof(filename)-1, "%s.eml", sdata.ttmpfile);
|
||||
|
||||
id = get_id_by_piler_id(&sdata, &digest[0], &bodydigest[0], &cfg);
|
||||
|
||||
if(id > 0){
|
||||
snprintf(filename, sizeof(filename)-1, "%llu.eml", id);
|
||||
f = fopen(filename, "w");
|
||||
if(f){
|
||||
rc = retrieve_email_from_archive(&sdata, f, &cfg);
|
||||
fclose(f);
|
||||
|
||||
snprintf(sdata.ttmpfile, sizeof(sdata.ttmpfile)-1, "%s", filename);
|
||||
make_digests(&sdata, &cfg);
|
||||
|
||||
if(strcmp(digest, sdata.digest) == 0 && strcmp(bodydigest, sdata.bodydigest) == 0)
|
||||
printf("exported %s, verification: OK\n", sdata.ttmpfile);
|
||||
else
|
||||
printf("exported %s, verification: FAILED\n", sdata.ttmpfile);
|
||||
}
|
||||
else printf("cannot open: %s\n", filename);
|
||||
}
|
||||
else printf("%s was not found in archive\n", sdata.ttmpfile);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
@ -149,8 +149,7 @@ void handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
|
||||
|
||||
sdata.need_scan = 1;
|
||||
|
||||
digest_file(sdata.ttmpfile, sdata.digest);
|
||||
make_body_digest(&sdata, cfg);
|
||||
make_digests(&sdata, cfg);
|
||||
|
||||
#ifdef HAVE_ANTIVIRUS
|
||||
if(cfg->use_antivirus == 1){
|
||||
|
@ -74,7 +74,7 @@ int main(int argc, char **argv){
|
||||
printf("subject: *%s*\n", state.b_subject);
|
||||
//printf("body: *%s*\n", state.b_body);
|
||||
|
||||
make_body_digest(&sdata, &cfg);
|
||||
make_digests(&sdata, &cfg);
|
||||
|
||||
printf("hdr len: %d\n", sdata.hdr_len);
|
||||
|
||||
|
@ -61,7 +61,7 @@ create index `rcpt_idx2` on `rcpt`(`to`);
|
||||
|
||||
|
||||
drop view if exists `messages`;
|
||||
create view `messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`rcpt`.`to` AS `to`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`);
|
||||
create view `messages` AS select `metadata`.`id` AS `id`,`metadata`.`piler_id` AS `piler_id`,`metadata`.`from` AS `from`,`rcpt`.`to` AS `to`,`metadata`.`subject` AS `subject`, `metadata`.`size` AS `size`, `metadata`.`arrived` AS `arrived` from (`metadata` join `rcpt`) where (`metadata`.`id` = `rcpt`.`id`);
|
||||
|
||||
drop table if exists `attachment`;
|
||||
create table if not exists `attachment` (
|
||||
|
Loading…
Reference in New Issue
Block a user