From d2cf3a4debcb7b1a33b0065b815442bb9f2e716f Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Fri, 10 Nov 2017 09:49:16 +0100 Subject: [PATCH] src: encode piler child serial to piler_id Signed-off-by: Janos SUTO --- src/defs.h | 2 +- src/import.c | 2 +- src/misc.c | 13 +++++++------ src/misc.h | 6 +++--- src/piler.c | 4 ++-- src/pilerexport.c | 4 ++-- src/pilerimport.c | 1 + src/reindex.c | 2 +- src/test.c | 2 +- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/defs.h b/src/defs.h index 0d7a11f5..40f119be 100644 --- a/src/defs.h +++ b/src/defs.h @@ -338,7 +338,7 @@ struct data { struct import *import; struct licence licence; char *dedup; - int child_serial; + unsigned char child_serial; int pos; #ifdef HAVE_TRE diff --git a/src/import.c b/src/import.c index 254a884a..7e8e185d 100644 --- a/src/import.c +++ b/src/import.c @@ -26,7 +26,7 @@ int import_message(struct session_data *sdata, struct data *data, struct config struct counters counters; - init_session_data(sdata, cfg); + init_session_data(sdata, 0, cfg); if(data->import->extra_recipient){ snprintf(sdata->rcptto[0], SMALLBUFSIZE-1, "%s", data->import->extra_recipient); diff --git a/src/misc.c b/src/misc.c index 9643acdc..3ed59a17 100644 --- a/src/misc.c +++ b/src/misc.c @@ -331,13 +331,13 @@ void make_random_string(char *buf, int buflen){ } -void create_id(char *id, unsigned char server_id){ +void create_id(char *id, unsigned char server_id, unsigned char child_serial){ int i; unsigned char buf[RND_STR_LEN/2]; memset(id, 0, SMALLBUFSIZE); - get_random_bytes(buf, RND_STR_LEN/2, server_id); + get_random_bytes(buf, RND_STR_LEN/2, server_id, child_serial); for(i=0; i < RND_STR_LEN/2; i++){ sprintf(id, "%02x", buf[i]); @@ -351,7 +351,7 @@ void create_id(char *id, unsigned char server_id){ * reading from pool */ -int get_random_bytes(unsigned char *buf, int len, unsigned char server_id){ +int get_random_bytes(unsigned char *buf, int len, unsigned char server_id, unsigned char child_serial){ int fd, ret=0; struct taia now; char nowpack[TAIA_PACK]; @@ -367,8 +367,9 @@ int get_random_bytes(unsigned char *buf, int len, unsigned char server_id){ if(fd == -1) return ret; *(buf + 12) = server_id; + *(buf + 14) = child_serial; - if(readFromEntropyPool(fd, buf+12+1, len-12-1) != len-12-1){ + if(readFromEntropyPool(fd, buf+14+1, len-14-1) != len-14-1){ syslog(LOG_PRIORITY, "%s: %s", ERR_CANNOT_READ_FROM_POOL, RANDOM_POOL); } @@ -544,13 +545,13 @@ int drop_privileges(struct passwd *pwd){ } -void init_session_data(struct session_data *sdata, struct config *cfg){ +void init_session_data(struct session_data *sdata, unsigned char child_serial, struct config *cfg){ int i; sdata->fd = -1; - create_id(&(sdata->ttmpfile[0]), cfg->server_id); + create_id(&(sdata->ttmpfile[0]), cfg->server_id, child_serial); unlink(sdata->ttmpfile); snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", sdata->ttmpfile); diff --git a/src/misc.h b/src/misc.h index ff58cdcb..c4a3f38f 100644 --- a/src/misc.h +++ b/src/misc.h @@ -28,8 +28,8 @@ char *split_str(char *row, char *what, char *s, int size); int trimBuffer(char *s); int extractEmail(char *rawmail, char *email); void make_random_string(char *buf, int buflen); -void create_id(char *id, unsigned char server_id); -int get_random_bytes(unsigned char *buf, int len, unsigned char server_id); +void create_id(char *id, unsigned char server_id, unsigned char child_serial); +int get_random_bytes(unsigned char *buf, int len, unsigned char server_id, unsigned char child_serial); int readFromEntropyPool(int fd, void *_s, ssize_t n); int recvtimeout(int s, char *buf, int len, int timeout); int write1(struct net *net, void *buf, int buflen); @@ -39,7 +39,7 @@ void close_connection(struct net *net); void write_pid_file(char *pidfile); int drop_privileges(struct passwd *pwd); -void init_session_data(struct session_data *sdata, struct config *cfg); +void init_session_data(struct session_data *sdata, unsigned char child_serial, struct config *cfg); int read_from_stdin(struct session_data *sdata); void strtolower(char *s); diff --git a/src/piler.c b/src/piler.c index 49b8e2a6..55d7c77e 100644 --- a/src/piler.c +++ b/src/piler.c @@ -110,7 +110,7 @@ int process_email(char *filename, struct session_data *sdata, struct data *data, } #endif - init_session_data(sdata, cfg); + init_session_data(sdata, data->child_serial, cfg); sdata->tot_len = size; @@ -247,7 +247,7 @@ void child_main(struct child *ptr){ if(cfg.verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "child (pid: %d, serial: %d) started main() working on '%s'", getpid(), ptr->serial, dir); - data.child_serial = ptr->serial; + data.child_serial = ptr->serial % 255; while(1){ if(received_sighup == 1){ diff --git a/src/pilerexport.c b/src/pilerexport.c index 92428da6..f24bf30e 100644 --- a/src/pilerexport.c +++ b/src/pilerexport.c @@ -571,7 +571,7 @@ int main(int argc, char **argv){ if(read_key(&cfg)) p_clean_exit(ERR_READING_KEY, 1); - init_session_data(&sdata, &cfg); + init_session_data(&sdata, 0, &cfg); if(open_database(&sdata, &cfg) == ERR){ @@ -581,7 +581,7 @@ int main(int argc, char **argv){ if(where_condition){ - init_session_data(&sdata2, &cfg); + init_session_data(&sdata2, 0, &cfg); strcpy(cfg.mysqlhost, "127.0.0.1"); cfg.mysqlport = 9306; diff --git a/src/pilerimport.c b/src/pilerimport.c index b648c366..b609f828 100644 --- a/src/pilerimport.c +++ b/src/pilerimport.c @@ -76,6 +76,7 @@ int main(int argc, char **argv){ srand(getpid()); data.folder = 0; + data.child_serial = 0; data.recursive_folder_names = 0; data.quiet = 0; diff --git a/src/reindex.c b/src/reindex.c index b42b5893..b1bfe8e3 100644 --- a/src/reindex.c +++ b/src/reindex.c @@ -234,7 +234,7 @@ int main(int argc, char **argv){ initrules(data.retention_rules); initrules(data.folder_rules); - init_session_data(&sdata, &cfg); + init_session_data(&sdata, 0, &cfg); if(open_database(&sdata, &cfg) == ERR){ diff --git a/src/test.c b/src/test.c index d10d98ed..3f22d354 100644 --- a/src/test.c +++ b/src/test.c @@ -73,7 +73,7 @@ int main(int argc, char **argv){ load_rules(&sdata, &data, data.folder_rules, SQL_FOLDER_RULE_TABLE); - init_session_data(&sdata, &cfg); + init_session_data(&sdata, 0, &cfg); sdata.delivered = 0; sdata.tot_len = st.st_size;