int open_locked(const char *, int, ...);
char *rfc822date(void);
int strprefixcmp(const char *, const char *);
+void init_random(void);
#endif
*/
#include <errno.h>
+#include <inttypes.h>
+#include <signal.h>
#include <syslog.h>
#include <unistd.h>
had_date = 1;
snprintf(line, sizeof(line), "Date: %s\n", rfc822date());
} else if (!had_messagid) {
- /* XXX better msgid, assign earlier and log? */
+ /* XXX msgid, assign earlier and log? */
had_messagid = 1;
- snprintf(line, sizeof(line), "Message-Id: <%s@%s>\n",
- queue->id, hostname());
+ snprintf(line, sizeof(line), "Message-Id: <%"PRIxMAX".%s.%"PRIxMAX"@%s>\n",
+ (uintmax_t)time(NULL),
+ queue->id,
+ random(),
+ hostname());
} else if (!had_from) {
had_from = 1;
snprintf(line, sizeof(line), "From: <%s>\n", queue->sender);
return (strncasecmp(str, prefix, strlen(prefix)));
}
+void
+init_random(void)
+{
+ unsigned int seed;
+ int rf;
+
+ rf = open("/dev/urandom", O_RDONLY);
+ if (rf == -1)
+ rf = open("/dev/random", O_RDONLY);
+
+ if (!(rf != -1 && read(rf, &seed, sizeof(seed)) == sizeof(seed)))
+ seed = (time(NULL) ^ getpid()) + (uintptr_t)&seed;
+
+ srandom(seed);
+
+ if (rf != -1)
+ close(rf);
+}