mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 01:41:59 +01:00
Refactored make_random_string()
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
5380196325
commit
ce193974f1
@ -164,7 +164,7 @@ int extract_tnef(struct session_data *sdata, struct parser_state *state, char *f
|
||||
struct dirent **namelist;
|
||||
|
||||
memset(tmpdir, 0, sizeof(tmpdir));
|
||||
make_random_string(&tmpdir[0], sizeof(tmpdir)-3);
|
||||
make_random_string((unsigned char *)&tmpdir[0], sizeof(tmpdir)-3);
|
||||
|
||||
memcpy(&tmpdir[sizeof(tmpdir)-3], ".d", 2);
|
||||
|
||||
|
11
src/misc.c
11
src/misc.c
@ -269,19 +269,18 @@ int extractEmail(char *rawmail, char *email){
|
||||
* using the rand() function if not possible
|
||||
*/
|
||||
|
||||
void make_random_string(char *buf, int buflen){
|
||||
void make_random_string(unsigned char *buf, int buflen){
|
||||
int i, len, fd;
|
||||
int urandom=0;
|
||||
static char alphanum[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
unsigned char s[QUEUE_ID_LEN];
|
||||
|
||||
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];
|
||||
if(readFromEntropyPool(fd, buf, buflen) == buflen){
|
||||
for(i=0; i<buflen; i++){
|
||||
*(buf+i) = alphanum[*(buf+i) % len];
|
||||
}
|
||||
|
||||
urandom = 1;
|
||||
@ -338,7 +337,7 @@ int get_random_bytes(unsigned char *buf, int len, unsigned char 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);
|
||||
}
|
||||
|
||||
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ char *split_str(char *row, char *what, char *s, int size);
|
||||
int trimBuffer(char *s);
|
||||
int extractEmail(char *rawmail, char *email);
|
||||
int extract_verp_address(char *email);
|
||||
void make_random_string(char *buf, int buflen);
|
||||
void make_random_string(unsigned 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);
|
||||
int readFromEntropyPool(int fd, void *_s, ssize_t n);
|
||||
|
@ -208,7 +208,7 @@ void process_command_mail_from(struct smtp_session *session, char *buf){
|
||||
}
|
||||
else {
|
||||
memset(&(session->ttmpfile[0]), 0, SMALLBUFSIZE);
|
||||
make_random_string(&(session->ttmpfile[0]), QUEUE_ID_LEN);
|
||||
make_random_string((unsigned char*)&(session->ttmpfile[0]), QUEUE_ID_LEN);
|
||||
session->protocol_state = SMTP_STATE_MAIL_FROM;
|
||||
|
||||
extractEmail(buf, session->mailfrom);
|
||||
|
Loading…
Reference in New Issue
Block a user