mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 18:50:12 +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;
|
struct dirent **namelist;
|
||||||
|
|
||||||
memset(tmpdir, 0, sizeof(tmpdir));
|
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);
|
memcpy(&tmpdir[sizeof(tmpdir)-3], ".d", 2);
|
||||||
|
|
||||||
|
@ -269,19 +269,18 @@ int extractEmail(char *rawmail, char *email){
|
|||||||
* using the rand() function if not possible
|
* 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 i, len, fd;
|
||||||
int urandom=0;
|
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);
|
fd = open(RANDOM_POOL, O_RDONLY);
|
||||||
if(fd != -1){
|
if(fd != -1){
|
||||||
if(readFromEntropyPool(fd, s, sizeof(s)) == sizeof(s)){
|
if(readFromEntropyPool(fd, buf, buflen) == buflen){
|
||||||
for(i=0; i<QUEUE_ID_LEN; i++){
|
for(i=0; i<buflen; i++){
|
||||||
*(buf+i) = alphanum[s[i] % len];
|
*(buf+i) = alphanum[*(buf+i) % len];
|
||||||
}
|
}
|
||||||
|
|
||||||
urandom = 1;
|
urandom = 1;
|
||||||
|
@ -26,7 +26,7 @@ char *split_str(char *row, char *what, char *s, int size);
|
|||||||
int trimBuffer(char *s);
|
int trimBuffer(char *s);
|
||||||
int extractEmail(char *rawmail, char *email);
|
int extractEmail(char *rawmail, char *email);
|
||||||
int extract_verp_address(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);
|
void create_id(char *id, unsigned char server_id);
|
||||||
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);
|
||||||
int readFromEntropyPool(int fd, void *_s, ssize_t n);
|
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 {
|
else {
|
||||||
memset(&(session->ttmpfile[0]), 0, SMALLBUFSIZE);
|
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;
|
session->protocol_state = SMTP_STATE_MAIL_FROM;
|
||||||
|
|
||||||
extractEmail(buf, session->mailfrom);
|
extractEmail(buf, session->mailfrom);
|
||||||
|
Loading…
Reference in New Issue
Block a user