introduced the server_id variable

This commit is contained in:
SJ 2013-01-06 21:04:58 +01:00
parent 28d12e9a52
commit 1d2ac1c117
13 changed files with 28 additions and 19 deletions

View File

@ -7,6 +7,11 @@
; 5: debug
verbosity=1
; unique server id. If you have more than 1 piler hosts combined,
; then assign a unique value to each host. Possible values: 0-255
server_id=0
; piler daemon will use this user (and its group)
; it it was started by root
username=piler

View File

@ -91,6 +91,7 @@ struct _parse_rule config_parse_rules[] =
{ "pidfile", "string", (void*) string_parser, offsetof(struct __config, pidfile), PIDFILE, MAXVAL-1},
{ "piler_header_field", "string", (void*) string_parser, offsetof(struct __config, piler_header_field), "", MAXVAL-1},
{ "queuedir", "string", (void*) string_parser, offsetof(struct __config, queuedir), QUEUE_DIR, MAXVAL-1},
{ "server_id", "integer", (void*) int_parser, offsetof(struct __config, server_id), "0", sizeof(int)},
{ "session_timeout", "integer", (void*) int_parser, offsetof(struct __config, session_timeout), "420", sizeof(int)},
{ "spam_header_line", "string", (void*) string_parser, offsetof(struct __config, spam_header_line), "", MAXVAL-1},
{ "tls_enable", "integer", (void*) int_parser, offsetof(struct __config, tls_enable), "0", sizeof(int)},

View File

@ -8,6 +8,7 @@
#include "config.h"
struct __config {
int server_id;
char username[MAXVAL];
char hostid[MAXVAL];

View File

@ -26,7 +26,7 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
struct __counters counters;
init_session_data(sdata);
init_session_data(sdata, cfg->server_id);
if(cfg->verbosity > 1) printf("processing: %s\n", filename);

View File

@ -211,13 +211,13 @@ int extractEmail(char *rawmail, char *email){
}
void create_id(char *id){
void create_id(char *id, unsigned char server_id){
int i;
unsigned char buf[RND_STR_LEN/2];
memset(id, 0, SMALLBUFSIZE);
get_random_bytes(buf, RND_STR_LEN/2);
get_random_bytes(buf, RND_STR_LEN/2, server_id);
for(i=0; i < RND_STR_LEN/2; i++){
sprintf(id, "%02x", buf[i]);
@ -231,7 +231,7 @@ void create_id(char *id){
* reading from pool
*/
int get_random_bytes(unsigned char *buf, int len){
int get_random_bytes(unsigned char *buf, int len, unsigned char server_id){
int fd, ret=0;
struct taia now;
char nowpack[TAIA_PACK];
@ -246,7 +246,9 @@ int get_random_bytes(unsigned char *buf, int len){
fd = open(RANDOM_POOL, O_RDONLY);
if(fd == -1) return ret;
if(readFromEntropyPool(fd, buf+12, len-12) != len-12){
*(buf + 12) = server_id;
if(readFromEntropyPool(fd, buf+12+1, len-12-1) != len-12-1){
syslog(LOG_PRIORITY, "%s: %s", ERR_CANNOT_READ_FROM_POOL, RANDOM_POOL);
}
@ -447,13 +449,13 @@ int is_email_address_on_my_domains(char *email, struct __config *cfg){
}
void init_session_data(struct session_data *sdata){
void init_session_data(struct session_data *sdata, unsigned char server_id){
int i;
sdata->fd = -1;
create_id(&(sdata->ttmpfile[0]));
create_id(&(sdata->ttmpfile[0]), server_id);
unlink(sdata->ttmpfile);
snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", sdata->ttmpfile);

View File

@ -24,8 +24,8 @@ char *split(char *row, int ch, char *s, int size);
char *split_str(char *row, char *what, char *s, int size);
int trimBuffer(char *s);
int extractEmail(char *rawmail, char *email);
void create_id(char *id);
int get_random_bytes(unsigned char *buf, int len);
void create_id(char *id, unsigned char server_id);
int get_random_bytes(unsigned char *buf, int len, unsigned char server_id);
int readFromEntropyPool(int fd, void *_s, size_t n);
int recvtimeout(int s, char *buf, int len, int timeout);
int write1(int sd, char *buf, int use_ssl, SSL *ssl);
@ -35,7 +35,7 @@ void write_pid_file(char *pidfile);
int drop_privileges(struct passwd *pwd);
int is_email_address_on_my_domains(char *email, struct __config *cfg);
void init_session_data(struct session_data *sdata);
void init_session_data(struct session_data *sdata, unsigned char server_id);
int read_from_stdin(struct session_data *sdata);
void strtolower(char *s);

View File

@ -400,7 +400,7 @@ int main(int argc, char **argv){
if(read_key(&cfg)) p_clean_exit(ERR_READING_KEY, 1);
init_session_data(&sdata);
init_session_data(&sdata, cfg.server_id);
mysql_init(&(sdata.mysql));

View File

@ -348,7 +348,7 @@ int main(int argc, char **argv){
setlocale(LC_CTYPE, cfg.locale);
init_session_data(&sdata);
init_session_data(&sdata, cfg.server_id);
i = is_purge_allowed(&sdata, &cfg);
if(i == 1){

View File

@ -212,7 +212,7 @@ int main(int argc, char **argv){
}
}
init_session_data(&sdata);
init_session_data(&sdata, cfg.server_id);
mysql_init(&(sdata.mysql));

View File

@ -54,7 +54,7 @@ int handle_smtp_session(int new_sd, struct __data *data, struct __config *cfg){
state = SMTP_STATE_INIT;
init_session_data(&sdata);
init_session_data(&sdata, cfg->server_id);
sdata.tls = 0;
bzero(&counters, sizeof(counters));
@ -370,7 +370,7 @@ AFTER_PERIOD:
unlink(sdata.ttmpfile);
unlink(sdata.tmpframe);
init_session_data(&sdata);
init_session_data(&sdata, cfg->server_id);
}
state = SMTP_STATE_MAIL_FROM;
@ -476,7 +476,7 @@ AFTER_PERIOD:
unlink(sdata.ttmpfile);
unlink(sdata.tmpframe);
init_session_data(&sdata);
init_session_data(&sdata, cfg->server_id);
state = SMTP_STATE_HELO;

View File

@ -60,7 +60,7 @@ int main(int argc, char **argv){
load_rules(&sdata, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
load_rules(&sdata, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
init_session_data(&sdata);
init_session_data(&sdata, cfg.server_id);
sdata.sent = 0;
sdata.delivered = 0;

View File

@ -33,7 +33,7 @@ int main(int argc, char **argv){
cfg = read_config(CONFIG_FILE);
init_session_data(&sdata);
init_session_data(&sdata, cfg.server_id);
sdata.sent = 0;
sdata.tot_len = st.st_size;

View File

@ -40,7 +40,7 @@ int parse_it(char *filename, struct session_data *sdata, struct __data *data, st
struct _state state;
init_session_data(sdata);
init_session_data(sdata, cfg->server_id);
if(stat(filename, &st) != 0){
printf("cannot stat() %s\n", filename);