improved queue id generation

Change-Id: I8a0f91eabd3eaf6c074946f723147a3f6ef925d9
Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
SJ 2016-10-28 22:11:14 +02:00
parent 37d4babd38
commit cf1d7bdf45
2 changed files with 23 additions and 2 deletions

View File

@ -297,12 +297,33 @@ int extractEmail(char *rawmail, char *email){
} }
/*
* Generate a random string from /dev/urandom or
* using the rand() function if not possible
*/
void make_random_string(char *buf, int buflen){ void make_random_string(char *buf, int buflen){
int i, len; int i, len, fd;
int urandom=0;
static char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; static char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
unsigned char s[QUEUE_ID_LEN];
len = strlen(alphanum); len = strlen(alphanum);
fd = open(RANDOM_POOL, O_RDONLY);
if(fd != -1){
if(readFromEntropyPool(fd, s, sizeof(s)) == sizeof(s)){
for(i=0; i<QUEUE_ID_LEN; i++){
*(buf+i) = alphanum[s[i] % len];
}
urandom = 1;
}
close(fd);
}
if(urandom == 1) return;
for(i=0; i<buflen; i++){ for(i=0; i<buflen; i++){
*(buf+i) = alphanum[rand() % len]; *(buf+i) = alphanum[rand() % len];
} }

View File

@ -156,7 +156,7 @@ int process_email(char *filename, struct session_data *sdata, struct __data *dat
gettimeofday(&tv2, &tz); gettimeofday(&tv2, &tz);
syslog(LOG_PRIORITY, "%s: piler-id=%s, size=%d/%d, attachments=%d, reference=%s, " syslog(LOG_PRIORITY, "%s: %s, size=%d/%d, attachments=%d, reference=%s, "
"message-id=%s, retention=%d, folder=%d, delay=%.4f, status=%s", "message-id=%s, retention=%d, folder=%d, delay=%.4f, status=%s",
filename, sdata->ttmpfile, sdata->tot_len, sdata->stored_len, filename, sdata->ttmpfile, sdata->tot_len, sdata->stored_len,
parser_state.n_attachments, parser_state.reference, parser_state.message_id, parser_state.n_attachments, parser_state.reference, parser_state.message_id,