From b7e61f27eff42865ce247e47c0fa5be99c9e7cfc Mon Sep 17 00:00:00 2001 From: SJ Date: Sun, 27 Apr 2014 10:59:59 +0200 Subject: [PATCH] fixed handling enrypted zip files --- src/config.h | 2 +- src/extract.c | 50 ++++++++++++++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/config.h b/src/config.h index a2079abd..e0446633 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 868 +#define BUILD 869 #define HOSTID "mailarchiver" diff --git a/src/extract.c b/src/extract.c index 3853ceb9..097592ca 100644 --- a/src/extract.c +++ b/src/extract.c @@ -58,7 +58,7 @@ int extract_opendocument(struct session_data *sdata, struct _state *state, char memset(buf, 0, sizeof(buf)); while(zip_stat_index(z, i, 0, &sb) == 0){ - if(strncmp(sb.name, prefix, strlen(prefix)) == 0 && (int)sb.size > 0){ + if(ZIP_EM_NONE == sb.encryption_method && strncmp(sb.name, prefix, strlen(prefix)) == 0 && (int)sb.size > 0){ zf = zip_fopen_index(z, i, 0); if(zf){ @@ -106,35 +106,41 @@ int unzip_file(struct session_data *sdata, struct _state *state, char *filename, while(zip_stat_index(z, i, 0, &sb) == 0){ //printf("processing file inside the zip: %s, index: %d, size: %d\n", sb.name, sb.index, (int)sb.size); - p = strrchr(sb.name, '.'); + if(ZIP_EM_NONE == sb.encryption_method) { - if((int)sb.size > 0 && p && strcmp(get_attachment_extractor_by_filename((char*)sb.name), "other")){ + p = strrchr(sb.name, '.'); - snprintf(extracted_filename, sizeof(extracted_filename)-1, "%s-%d-%d%s", sdata->ttmpfile, *rec, i, p); + if((int)sb.size > 0 && p && strcmp(get_attachment_extractor_by_filename((char*)sb.name), "other")){ - fd = open(extracted_filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); - if(fd != -1){ - zf = zip_fopen_index(z, i, 0); - if(zf){ - while((len = zip_fread(zf, buf, sizeof(buf))) > 0){ - write(fd, buf, len); + snprintf(extracted_filename, sizeof(extracted_filename)-1, "%s-%d-%d%s", sdata->ttmpfile, *rec, i, p); + + fd = open(extracted_filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + if(fd != -1){ + zf = zip_fopen_index(z, i, 0); + if(zf){ + while((len = zip_fread(zf, buf, sizeof(buf))) > 0){ + write(fd, buf, len); + } + zip_fclose(zf); } - zip_fclose(zf); + else syslog(LOG_PRIORITY, "%s: cannot extract '%s' from '%s'", sdata->ttmpfile, sb.name, extracted_filename); + + close(fd); + + extract_attachment_content(sdata, state, extracted_filename, get_attachment_extractor_by_filename(extracted_filename), rec); + + unlink(extracted_filename); + + } + else { + syslog(LOG_PRIORITY, "%s: cannot open '%s'", sdata->ttmpfile, extracted_filename); } - else syslog(LOG_PRIORITY, "%s: cannot extract '%s' from '%s'", sdata->ttmpfile, sb.name, extracted_filename); - - close(fd); - - extract_attachment_content(sdata, state, extracted_filename, get_attachment_extractor_by_filename(extracted_filename), rec); - - unlink(extracted_filename); - - } - else { - syslog(LOG_PRIORITY, "%s: cannot open '%s'", sdata->ttmpfile, extracted_filename); } } + else { + syslog(LOG_PRIORITY, "ERR: attachment ('%s') is in encrypted zip file", sb.name); + } i++; }