upas/smtp: generate 128-bit random message id (was 32 bit), use dBprint(), cleanup unused variables

This commit is contained in:
cinap_lenrek 2017-03-23 00:36:57 +01:00
parent 04c7d5d8f6
commit 9b848903e6

View file

@ -136,6 +136,7 @@ main(int argc, char **argv)
mailfmtinstall(); /* 2047 encoding */ mailfmtinstall(); /* 2047 encoding */
fmtinstall('D', Dfmt); fmtinstall('D', Dfmt);
fmtinstall('[', encodefmt); fmtinstall('[', encodefmt);
fmtinstall('H', encodefmt);
errs = malloc(argc*sizeof(char*)); errs = malloc(argc*sizeof(char*));
reply = s_new(); reply = s_new();
host = 0; host = 0;
@ -496,7 +497,6 @@ doauth(char *methods)
static char buf[1024]; static char buf[1024];
char *s, *se, *err; char *s, *se, *err;
UserPasswd *p; UserPasswd *p;
int n;
DS ds; DS ds;
dialstringparse(farend, &ds); dialstringparse(farend, &ds);
@ -677,16 +677,14 @@ rcptto(char *to)
return 0; return 0;
} }
static char hex[] = "0123456789abcdef";
/* /*
* send the damn thing * send the damn thing
*/ */
char * char *
data(String *from, Biobuf *b, Mx *mx) data(String *from, Biobuf *b, Mx *mx)
{ {
char *buf, *cp, errmsg[ERRMAX], id[40]; char *buf, *cp, errmsg[ERRMAX];
int i, n, nbytes, bufsize, eof, r; int n, nbytes, bufsize, eof;
String *fromline; String *fromline;
/* /*
@ -751,35 +749,23 @@ data(String *from, Biobuf *b, Mx *mx)
fromline = convertheader(from); fromline = convertheader(from);
uneaten = buf; uneaten = buf;
srand(truerand());
if(messageid == 0){ if(messageid == 0){
for(i = 0; i < 16; i++){ uchar id[16];
r = rand() & 0xff;
id[2*i] = hex[r & 0xf]; genrandom(id, sizeof(id));
id[2*i + 1] = hex[(r>>4) & 0xf]; nbytes += dBprint("Message-ID: <%.*H@%s>\r\n",
} sizeof(id), id, hostdomain);
id[2*i] = '\0';
nbytes += Bprint(&bout, "Message-ID: <%s@%s>\r\n", id, hostdomain);
if(debug)
Bprint(&berr, "Message-ID: <%s@%s>\r\n", id, hostdomain);
} }
if(originator == 0){ if(originator == 0)
nbytes += Bprint(&bout, "From: %s\r\n", s_to_c(fromline)); nbytes += dBprint("From: %s\r\n", s_to_c(fromline));
if(debug)
Bprint(&berr, "From: %s\r\n", s_to_c(fromline));
}
s_free(fromline); s_free(fromline);
if(destination == 0 && toline) if(destination == 0 && toline){
if(*s_to_c(toline) == '@'){ /* route addr */ if(*s_to_c(toline) == '@') /* route addr */
nbytes += Bprint(&bout, "To: <%s>\r\n", s_to_c(toline)); nbytes += dBprint("To: <%s>\r\n", s_to_c(toline));
if(debug) else
Bprint(&berr, "To: <%s>\r\n", s_to_c(toline)); nbytes += dBprint("To: %s\r\n", s_to_c(toline));
} else {
nbytes += Bprint(&bout, "To: %s\r\n", s_to_c(toline));
if(debug)
Bprint(&berr, "To: %s\r\n", s_to_c(toline));
} }
if(date == 0 && udate) if(date == 0 && udate)