diff -urp mixmaster-3.0rc1.orig/Src/chain1.c mixmaster-3.0rc1/Src/chain1.c --- mixmaster-3.0rc1.orig/Src/chain1.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/chain1.c 2007-11-29 23:29:57.058782174 +0200 @@ -176,7 +176,7 @@ int t1_encrypt(int type, BUFFER *message goto end; } if (chain_rand(remailer, badchains, maxrem, chain, chainlen, 1, 0) == -1) { - clienterr(feedback, "No reliable remailers!"); + clienterr(feedback, "No reliable v1 remailers!"); err = -1; goto end; } diff -urp mixmaster-3.0rc1.orig/Src/chain2.c mixmaster-3.0rc1/Src/chain2.c --- mixmaster-3.0rc1.orig/Src/chain2.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/chain2.c 2007-11-29 23:30:15.835279476 +0200 @@ -274,7 +274,7 @@ static int send_packet(int numcopies, BU israndom = chain_rand(remailer, badchains, maxrem, thischain, chainlen, 0, ignore_constraints_if_necessary); if (israndom == -1) { err = -1; - clienterr(feedback, "No reliable remailers!"); + clienterr(feedback, "No reliable v2 remailers!"); } if ((numcopies > 1 || numpackets > 1) && !israndom && (chainlen != 1)) { clienterr(feedback, @@ -595,7 +595,7 @@ int mix2_encrypt(int type, BUFFER *messa chain[0] = chain_randfinal(type, remailer, badchains, maxrem, 0, chain, chainlen, ignore_constraints_if_necessary); if (chain[0] == -1) { - clienterr(feedback, "No reliable remailers!"); + clienterr(feedback, "No reliable v2 remailers!"); err = -1; goto end; } diff -urp mixmaster-3.0rc1.orig/Src/mail.c mixmaster-3.0rc1/Src/mail.c --- mixmaster-3.0rc1.orig/Src/mail.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/mail.c 2007-10-02 19:15:19.794715809 +0300 @@ -269,7 +269,7 @@ int sendmail(BUFFER *message, char *from #endif /* else not SHORTNAMES */ if (f != NULL) { err = buf_write(head, f); - err = buf_write(message, f); + err |= buf_write(message, f); fclose(f); } else errlog(ERRORMSG, "Can't create %s!\n", path); @@ -280,8 +280,12 @@ int sendmail(BUFFER *message, char *from f = openpipe(SENDMAIL); if (f != NULL) { err = buf_write(head, f); - err = buf_write(message, f); - closepipe(f); + err |= buf_write(message, f); + if (closepipe(f) != 0) { + err = 1; + } + } else { + err = 1; } } if (err != 0) { diff -urp mixmaster-3.0rc1.orig/Src/maildir.c mixmaster-3.0rc1/Src/maildir.c --- mixmaster-3.0rc1.orig/Src/maildir.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/maildir.c 2007-10-02 19:15:19.840716428 +0300 @@ -23,6 +23,7 @@ */ #include "mix3.h" +#include "rdtscl.h" #ifdef WIN32 #include @@ -33,6 +34,7 @@ #else /* end of WIN32 */ #include #endif /* else not WIN32 */ +#include #include #include #include @@ -86,6 +88,7 @@ int maildirWrite(char *maildir, BUFFER * int count; int returnValue; char hostname[64]; + char *hostp; struct stat statbuf; char basename[MAX_BASENAME]; char tmpname[MAX_SUBNAME]; @@ -93,6 +96,7 @@ int maildirWrite(char *maildir, BUFFER * int messagesize; char olddirectory[PATHMAX] = ""; char normalizedmaildir[PATHMAX]; + struct timespec tsp; /* Declare a handler for SIGALRM so we can time out. */ /* set_handler(SIGALRM, alarm_handler); */ @@ -101,6 +105,12 @@ int maildirWrite(char *maildir, BUFFER * hostname[0] = '\0'; gethostname(hostname, 63); hostname[63] = '\0'; + hostp = hostname; + while(*hostp) { + if (*hostp == '/') *hostp = '_'; + if (*hostp == ':') *hostp = '_'; + hostp++; + } mixfile(normalizedmaildir, maildir); if ((checkDirectory(normalizedmaildir, NULL, create) != 0) || @@ -128,22 +138,21 @@ int maildirWrite(char *maildir, BUFFER * for (count = 0;; count++) { tmpname[0] = '\0'; newname[0] = '\0'; - snprintf(basename, MAX_BASENAME, "%lu.%u_%lu.%s,S=%u", - time(NULL), getpid(), namecounter++, hostname, messagesize); + if (clock_gettime(CLOCK_REALTIME, &tsp) == -1) { + tsp.tv_sec = time(NULL); + tsp.tv_nsec = 0; + } + snprintf(basename, MAX_BASENAME, "%lu.#%" PRIu64 ".M%lu.P%lu.Q%lu.S%u.%s", + tsp.tv_sec, rdtscl(), tsp.tv_nsec, (unsigned long)getpid(), namecounter++, messagesize, hostname); basename[MAX_BASENAME-1] = '\0'; strcatn(tmpname, "tmp" DIRSEPSTR, MAX_SUBNAME); strcatn(tmpname, basename, MAX_SUBNAME); strcatn(newname, "new" DIRSEPSTR, MAX_SUBNAME); strcatn(newname, basename, MAX_SUBNAME); - if (stat(tmpname, &statbuf) == 0) - errno = EEXIST; - else if (errno == ENOENT) { - /* Step 4: create the file (at least try) */ - fd = open(tmpname, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR); - if (fd >= 0) - break; /* we managed to open the file */ - } + fd = open(tmpname, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR); + if (fd >= 0) + break; /* we managed to open the file */ if (count > 5) { /* Too many retries - give up */ @@ -153,22 +162,39 @@ int maildirWrite(char *maildir, BUFFER * } /* Step 3: sleep and retry */ - sleep(2); + sleep(1); } /* Step 5: write file */ if(write(fd, message->data, message->length) != message->length) { returnValue = -1; + close(fd); + unlink(tmpname); + goto functionExit; + } + + if (fstat(fd, &statbuf) == -1) { + returnValue = -1; + close(fd); + unlink(tmpname); goto functionExit; } /* on NFS this could fail */ #ifndef WIN32 - if((fsync(fd) != 0) || (close(fd) != 0)) { + if(fsync(fd) != 0) { #else /* end of not WIN32 */ - if((_commit(fd) != 0) || (close(fd) != 0)) { + if(_commit(fd) != 0) { #endif /* else if WIN32 */ returnValue = -1; + close(fd); + unlink(tmpname); + goto functionExit; + } + + if (close(fd) != 0) { + returnValue = -1; + unlink(tmpname); goto functionExit; } @@ -209,10 +235,11 @@ int maildirWrite(char *maildir, BUFFER * goto functionExit; } - sleep(2); + sleep(1); newname[0] = '\0'; - snprintf(basename, MAX_BASENAME, "%lu.%u_%lu.%s,S=%u", - time(NULL), getpid(), namecounter++, hostname, messagesize); + snprintf(basename, MAX_BASENAME, "%lu.#%" PRIu64 ".I%" PRIu64 ".M%lu.P%lu.Q%lu.S%u.%s", + tsp.tv_sec, rdtscl(), (uint64_t)statbuf.st_ino, tsp.tv_nsec, + (unsigned long)getpid(), namecounter++, messagesize, hostname); basename[MAX_BASENAME-1] = '\0'; strcatn(newname, "new" DIRSEPSTR, MAX_SUBNAME); strcatn(newname, basename, MAX_SUBNAME); @@ -284,7 +311,7 @@ int main() /* write messages to maildir */ for(i = 0; i < count; i++) - assert(maildirWrite("Maildir.test_maildir", message, 1) == 0); + assert(maildirWrite("Maildir.test_maildir", &message, 1) == 0); /* read them back */ assert((d = opendir("Maildir.test_maildir/new")) != NULL); diff -urp mixmaster-3.0rc1.orig/Src/main.c mixmaster-3.0rc1/Src/main.c --- mixmaster-3.0rc1.orig/Src/main.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/main.c 2007-10-02 19:49:05.293113459 +0300 @@ -62,8 +62,12 @@ int main(int argc, char *argv[]) FILE *f; char pingpath[PATHMAX]; - /* Check if parse_yearmonthday works */ - assert(parse_yearmonthday("2003-04-01") == 1049155200); +#ifdef HAVE_SETENV + setenv("TZ", "GMT", 1); +#else /* end of HAVE_SETENV */ + putenv("TZ=GMT"); +#endif /* else if not HAVE_SETENV */ + tzset(); mix_init(NULL); diff -urp mixmaster-3.0rc1.orig/Src/menusend.c mixmaster-3.0rc1/Src/menusend.c --- mixmaster-3.0rc1.orig/Src/menusend.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/menusend.c 2007-10-02 19:15:23.006759037 +0300 @@ -293,8 +293,8 @@ redraw: edit: linecount = 1; - sprintf(path, "%s%cx%02x%02x%02x%02x.txt", POOLDIR, DIRSEP, - rnd_byte(), rnd_byte(), rnd_byte(), rnd_byte()); + snprintf(path, sizeof(path), "%s%cx%02x%02x%02x%02x.txt", + POOLDIR, DIRSEP, rnd_byte(), rnd_byte(), rnd_byte(), rnd_byte()); f = fopen(path, "w"); if (f == NULL) { #ifdef USE_NCURSES diff -urp mixmaster-3.0rc1.orig/Src/pool.c mixmaster-3.0rc1/Src/pool.c --- mixmaster-3.0rc1.orig/Src/pool.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/pool.c 2007-10-02 19:15:23.056759710 +0300 @@ -67,14 +67,14 @@ static void mv(char *name, char *newtype { char old[PATHMAX], new[PATHMAX]; - sprintf(old, "%s%c%s", POOLDIR, DIRSEP, name); + snprintf(old, sizeof(old), "%s%c%s", POOLDIR, DIRSEP, name); #ifdef SHORTNAMES assert(strlen(name) > 4); strcpy(name + strlen(name) - 3, newtype); #else /* end of SHORTNAMES */ name[0] = newtype[0]; #endif /* else if not SHORTNAMES */ - sprintf(new, "%s%c%s", POOLDIR, DIRSEP, name); + snprintf(new, sizeof(new), "%s%c%s", POOLDIR, DIRSEP, name); rename(old, new); } @@ -95,7 +95,7 @@ int latent_read(void) if (e == NULL) break; if (is(e->d_name, "lat")) { - sprintf(path, "%s%c%s", POOLDIR, DIRSEP, e->d_name); + snprintf(path, sizeof(path), "%s%c%s", POOLDIR, DIRSEP, e->d_name); f = fopen(path, "rb"); if (f != NULL) { fscanf(f, "%*d %ld\n", &then); @@ -127,7 +127,7 @@ int infile_read(void) break; if (is(e->d_name, "inf")) { mv(e->d_name, "tmp"); - sprintf(path, "%s%c%s", POOLDIR, DIRSEP, e->d_name); + snprintf(path, sizeof(path), "%s%c%s", POOLDIR, DIRSEP, e->d_name); f = fopen(path, "rb"); if (f != NULL) { buf_clear(msg); @@ -169,8 +169,7 @@ int mailin_maildir_one(char *dir) if (e == NULL) break; if (e->d_name[0] != '.') { - sprintf(path, "%s%c%s", dir, DIRSEP, e->d_name); - path[PATHMAX-1]='\0'; + snprintf(path, sizeof(path), "%s%c%s", dir, DIRSEP, e->d_name); f = fopen(path, "rb"); if (f != NULL) { buf_clear(msg); @@ -201,11 +200,9 @@ int mailin_maildir(char *maildir) char path[PATHMAX]; mixfile(normalized, maildir); - sprintf(path, "%s%c%s", normalized, DIRSEP, "new"); - path[PATHMAX-1]='\0'; + snprintf(path, sizeof(path), "%s%c%s", normalized, DIRSEP, "new"); mailin_maildir_one(path); - sprintf(path, "%s%c%s", normalized, DIRSEP, "cur"); - path[PATHMAX-1]='\0'; + snprintf(path, sizeof(path), "%s%c%s", normalized, DIRSEP, "cur"); mailin_maildir_one(path); return (0); } @@ -334,25 +331,22 @@ int pool_add(BUFFER *msg, char *type) FILE *pool_new(char *type, char *tmpname, char *path) { FILE *f; - struct stat buf; int err; assert(strlen(type) == 3); #ifdef SHORTNAMES - sprintf(tmpname, "%s%c%02x%02x%02x%02x.tmp", POOLDIR, DIRSEP, rnd_byte(), rnd_byte(), - rnd_byte(), rnd_byte()); + snprintf(tmpname, PATHMAX, "%s%c%02x%02x%02x%02x.tmp", POOLDIR, DIRSEP, + rnd_byte(), rnd_byte(), rnd_byte(), rnd_byte()); strcpy(path, tmpname); memcpy(path + strlen(path) - 3, type, 3); #else /* end of SHORTNAMES */ - sprintf(tmpname, "%s%ct%02x%02x%02x%02x%02x%02x%01x", POOLDIR, DIRSEP, rnd_byte(), - rnd_byte(), rnd_byte(), rnd_byte(), rnd_byte(), - rnd_byte(), rnd_byte() & 15); + snprintf(tmpname, PATHMAX, "%s%ct%02x%02x%02x%02x%02x%02x%01x", POOLDIR, DIRSEP, + rnd_byte(), rnd_byte(), rnd_byte(), rnd_byte(), rnd_byte(), + rnd_byte(), rnd_byte() & 15); strcpy(path, tmpname); strrchr(path, DIRSEP)[1] = type[0]; #endif /* else if not SHORTNAMES */ - err = stat(tmpname, &buf); - if (err == 0) - errlog(WARNING, "Overwriting file %s\n", tmpname); + unlink(tmpname); f = fopen(tmpname, "wb"); if (f == NULL) errlog(ERRORMSG, "Error creating temporary file %s\n", tmpname); @@ -400,9 +394,9 @@ void pool_dosend(void) if (is(e->d_name, "snd")) { sendmail_begin(); mv(e->d_name, "tmp"); - sprintf(path, "%s%c%s", POOLDIR, DIRSEP, e->d_name); + snprintf(path, sizeof(path), "%s%c%s", POOLDIR, DIRSEP, e->d_name); if (msg_send(path) == 1) - mv(e->d_name, "err"); + mv(e->d_name, "msg"); } } closedir(d); Only in mixmaster-3.0rc1/Src: pool.c.bak diff -urp mixmaster-3.0rc1.orig/Src/random.c mixmaster-3.0rc1/Src/random.c --- mixmaster-3.0rc1.orig/Src/random.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/random.c 2007-10-02 19:19:26.943054135 +0300 @@ -25,6 +25,8 @@ #include #include +#include "rdtscl.h" + int rnd_state = RND_NOTSEEDED; #ifdef USE_OPENSSL @@ -79,25 +81,13 @@ int rnd_add(byte *b, int l) void rnd_time(void) { - int pid; - -#ifdef WIN32 - SYSTEMTIME t; -#endif /* WIN32 */ - -#ifdef HAVE_GETTIMEOFDAY - struct timeval tv; + struct timespec tsp; + uint64_t ticks; - gettimeofday(&tv, 0); - rnd_add((byte *) &tv, sizeof(tv)); -#elif defined(WIN32) /* end of HAVE_GETTIMEOFDAY */ - GetSystemTime(&t); - rnd_add((byte *) &t, sizeof(t)); -#else /* end of defined(WIN32) */ - rnd_add((byte *) time(NULL), sizeof(time_t)); -#endif /* else if not defined(WIN32), HAVE_GETTIMEOFDAY */ - pid = getpid(); - rnd_add((byte *) &pid, sizeof(pid)); + clock_gettime(CLOCK_REALTIME, &tsp); + rnd_add((byte *) &tsp, sizeof(tsp)); + ticks = rdtscl(); + rnd_add((byte *) &ticks, sizeof(ticks)); } void rnd_update(byte *seed, int l) diff -urp mixmaster-3.0rc1.orig/Src/service.c mixmaster-3.0rc1/Src/service.c --- mixmaster-3.0rc1.orig/Src/service.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/service.c 2007-10-02 19:15:23.073759938 +0300 @@ -315,11 +315,11 @@ static char *GetLastErrorText() /* supplied buffer is not long enough */ if (!dwRet || (256 < (long)dwRet+14)) - sprintf(error_buf, "Error (0x%x)", err); + snprintf(error_buf, sizeof(error_buf), "Error (0x%x)", err); else { lpszTemp[lstrlen(lpszTemp)-2] = '\0'; /* remove cr and newline character */ - sprintf(error_buf, "%s (0x%x)", lpszTemp, err); + snprintf(error_buf, sizeof(error_buf), "%s (0x%x)", lpszTemp, err); } if (lpszTemp) diff -urp mixmaster-3.0rc1.orig/Src/util.c mixmaster-3.0rc1/Src/util.c --- mixmaster-3.0rc1.orig/Src/util.c 2006-06-24 16:40:39.000000000 +0300 +++ mixmaster-3.0rc1/Src/util.c 2007-10-02 19:47:11.957580259 +0300 @@ -8,8 +8,13 @@ Utility functions $Id: util.c 934 2006-06-24 13:40:39Z rabbi $ */ +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE +#endif + #include "mix3.h" #include +#include #include #include #include @@ -150,7 +155,6 @@ FILE *openpipe(const char *prog) #ifdef _MSC p = _popen(prog, "w"); #endif /* _MSC */ - if (p == NULL) errlog(ERRORMSG, "Unable to open pipe to %s\n", prog); return p; @@ -176,9 +180,9 @@ file_to_out(const char *filename) int closepipe(FILE *p) { #ifdef POSIX - return (pclose(p)); + return pclose(p); #elif defined(_MSC) /* end of POSIX */ - return (_pclose(p)); + return _pclose(p); #else /* end of defined(_MSC) */ return -1; #endif /* else if not defined(_MSC), POSIX */ @@ -608,42 +612,14 @@ int clear_pidfile(char *pidfile) time_t parse_yearmonthday(char* str) { - time_t date; - int day, month, year; + time_t date = -1; + struct tm timestruct = {0}; - if (sscanf( str, "%d-%d-%d", &year, &month, &day) == 3 ) { - struct tm timestruct; - char *tz; - - tz = getenv("TZ"); -#ifdef HAVE_SETENV - setenv("TZ", "GMT", 1); -#else /* end of HAVE_SETENV */ - putenv("TZ=GMT"); -#endif /* else if not HAVE_SETENV */ - tzset(); - memset(×truct, 0, sizeof(timestruct)); - timestruct.tm_mday = day; - timestruct.tm_mon = month - 1; - timestruct.tm_year = year - 1900; + if (strptime( str, "%Y-%m-%d", ×truct)) { date = mktime(×truct); -#ifdef HAVE_SETENV - if (tz) - setenv("TZ", tz, 1); - else - unsetenv("TZ"); -#else /* end of HAVE_SETENV */ - if (tz) { - char envstr[LINELEN]; - snprintf(envstr, LINELEN, "TZ=%s", tz); - putenv(envstr); - } else - putenv("TZ="); -#endif /* else if not HAVE_SETENV */ - tzset(); - return date; - } else - return -1; + } + + return date; } /* functions missing on some systems *************************************/ @@ -666,7 +642,7 @@ DIR *opendir(const char *name) dir = malloc(sizeof(HANDLE)); - sprintf(path, "%s%c*", name, DIRSEP); + snprintf(path, sizeof(path), "%s%c*", name, DIRSEP); *dir = FindFirstFile(path, &d); /* first file found is "." -- can be safely ignored here */ --- /dev/null 2008-03-03 12:31:35.402810776 +0200 +++ mixmaster-3.0rc1/Src/rdtscl.h 2007-10-02 19:15:26.280803099 +0300 @@ -0,0 +1,45 @@ +#ifndef _RDTSCL_H_ +#define _RDTSCL_H_ + +#include + +static inline uint64_t rdtscl(void) +{ + uint64_t val; + uint32_t valhigh, vallow; + +#if defined(__GNUC__) +#if defined(__i386__) + __asm__ volatile ( "rdtsc" : "=A" (val)); +#elif defined(__x86_64__) + asm volatile("rdtsc" : "=a" (valhigh), "=d" (vallow)); + val = ((unsigned long)valhigh) | (((unsigned long)vallow)<<32); +#elif defined(__ia64__) + __asm__ volatile ("mov %0=ar.itc" : "=r" (val)); +#elif defined(__alpha__) + __asm__ volatile ("rpcc %0" : "=r" (val)); +#elif defined(__mips__) + __asm__ volatile (".set noreorder\n\t" + "mfc0 %0, $9\n\t" ".set reorder" + : "=r" (val)); +#elif defined(__parisc__) + __asm__ volatile ("mfctl 16, %0" : "=r" (val)); +#elif defined(__powerpc__) + __asm__ volatile ("mftb %0" : "=r" (val)); +#elif defined(__s390__) || defined(__s390x__) + __asm__ volatile ("stck 0(%0)" : : "a" (&(val)) + :"memory", "cc"); + /* add "-Wa,-Av9a" or "-Wa,-xarch=v8plus" to cc flags */ +#elif defined(__sparc__) + __asm__ volatile ("rd %%tick, %0; clruw %0, %1; srlx %0, 32, %0" + : "=r" (valhigh), "=r" (vallow)); + val = (uint64_t)((uint64_t)valhigh << 32 | vallow); +#else + val = 0; +#endif +#endif + return val; +} + +#endif +