/* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* WIN32 */ #endif /* POSIX */ #else /* not DEBUG */ #endif /* else not DEBUG */ #endif /* BUFFER_MAX */ #endif /* WIN32 */ #endif /* POSIX */ #else /* end of 1 */ #endif /* else if not 1 */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* 0 */ #else /* end of 0 */ #endif /* else not 0 */ if (len >= 20) { /* array passed in is has length 20 */ (remailer[i].info[t].latency <= MAXLAT || constraints_ignored ) && /* remailer has low enough latency */ (remailer[i].info[t].latency >= MINLAT || constraints_ignored ) && /* remailer has high enough latency */ (remailer[i].info[t].latency <= MAXLAT || constraints_ignored ) && /* remailer has low enough latency */ (remailer[i].info[t].latency >= MINLAT || constraints_ignored ) && /* remailer has high enough latency */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* USE_PGP */ #endif /* DEBUG */ #endif /* USE_PGP */ buf_appendf(b, "%s: %s\n", ek ? "::\nAnon-To" : "To", #endif /* USE_PGP */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. * if a chain can not be constructed otherwhise, maxlat, minlat, * and minrel are ignored. maxlat, minlat, and minrel are ignored. /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of USE_ZLIB */ #endif /* else not USE_ZLIB */ /* Mixmaster version 3.0 -- (C) 1999 - 2008 Anonymizer Inc. and others. #define DEV_RANDOM "/dev/arandom" #if defined(WIN32) && !defined(_USRDLL) #define DLLIMPORT __declspec(dllimport) #else #define DLLIMPORT #endif #define DEFAULT_MIXCONF "mix.cfg" /* change to mix.ini eventually */ #ifdef WIN32 #define DEFAULT_POP3CONF "pop3.cfg" /* change to pop3.ini eventually */ #else #endif #define DEFAULT_PIDFILE "mixmaster.pid" DLLIMPORT extern char NYMSECRING[]; #define mixmaster_protocol "2" extern int INDUMMYP; extern int OUTDUMMYP; DLLIMPORT extern int VERBOSE; extern long MINLAT; DLLIMPORT extern char PGPPUBRING[]; DLLIMPORT extern char PGPSECRING[]; /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. buf_appends(ek, PASSPHRASE); #ifdef USE_AES int buf_aescrypt(BUFFER *buf, BUFFER *key, BUFFER *iv, int enc) { int n = 0; AES_KEY ks; if (key == NULL || key->length == 0) return (-1); assert(enc == ENCRYPT || enc == DECRYPT); assert((key->length == 16 || key->length == 24 || key->length == 32) && iv->length == 16); AES_set_encrypt_key(key->data, key->length<<3, &ks); AES_cfb128_encrypt(buf->data, buf->data, buf->length, &ks, iv->data, &n, enc == ENCRYPT ? AES_ENCRYPT : AES_DECRYPT); return (0); } #endif /* USE_AES */ #endif /* USE_OPENSSL */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #error "This version of OpenSSL is not supported. Please get a more current version from http://www.openssl.org" #endif /* version check */ #endif /* USE_IDEA */ #ifdef USE_AES #include #endif /* USE_AES */ #else /* end of USE_OPENSSL */ #endif /* else not USE_OPENSSL */ #endif /* ifndef _CRYPTO_H */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. if(!is_nt_service()) { rnd_state = RND_WILLSEED; mix_init(NULL); if (rnd_state == RND_WILLSEED) } if(!is_nt_service()) mix_exit(); #endif /* WIN32 */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. int getv2seckey(byte keyid[], BUFFER *key); if (getv2seckey(keyid, key) == -1) if (getv2pubkey(keyid, key) == -1) /* now accepts NULL keyid too, with NULL keyid any key * will be matched, with valid passphrase of course */ int getv2seckey(byte keyid[], BUFFER *key) int err = -1; if (keyid) id_encode(keyid, idstr); else idstr[0] = 0; errlog(ERRORMSG, "Key is not valid yet (creation date in the future): %s", idstr); break; } } errlog(ERRORMSG, "No such public key: %s\n", idstr); errlog(ERRORMSG, "Corrupt public key %s\n", idstr); * is the key with the latest expiration date (keys with no expiration date * are always considered newer if they appear later in the secret mix file * - key creation appends keys). fprintf(f, "%s %s %s %s:%s %s%s", SHORTNAME, REMAILERADDR, line, mixmaster_protocol, VERSION, #endif /* USE_PGP */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* defined(UNIX) && defined(USE_SOCK) */ #else /* end of SHORTNAMES */ #endif /* else not SHORTNAMES */ if (err != 0) { errlog(ERRORMSG, "Unable to execute sendmail. Check path!\n"); } #endif /* WIN32 */ #endif /* ifndef WIN32 */ #else /* end of USE_SOCK */ #endif /* else not USE_SOCK */ #endif /* USE_SOCK */ #endif /* USE_SOCK */ #ifdef BROKEN_MTA #endif /* BROKEN_MTA */ rfc822_addr(content, rcpt); #ifdef BROKEN_MTA #endif /* BROKEN_MTA */ rfc822_addr(content, rcpt); #endif /* USE_SOCK */ server = INVALID_SOCKET; closesocket(server); closesocket(server); if (f != NULL) fclose(f); #endif /* USE_SOCK */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. Mixmaster may be redistributed and modified under certain conditions. This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the file COPYRIGHT for details. Maildir support routines $Id: $ */ Added by and (C) 2001 Doobee R. Tzeck drt@un.bewaff.net - http://c0re.jp/ #else /* end of WIN32 */ #endif /* else not WIN32 */ #endif /* defined(S_IFDIR) && !defined(S_ISDIR) */ #else /* end of not POSIX */ #endif /* else if POSIX */ #else /* end of not WIN32 */ #endif /* else if WIN32 */ #else /* end of POSIX */ #endif /* else if not POSIX */ #else /* end of SHORTNAMES */ #endif /* else if not SHORTNAMES */ #endif /* NDEBUG */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #include "pgp.h" #else /* end of POSIX */ #endif /* else if not POSIX */ #ifdef WIN32SERVICE int mix_main(int argc, char *argv[]) #else #endif /* WIN32SERVICE */ redirect_mail = 0, about=0, version=0; #endif /* USE_SOCK */ #endif /* USE_NCURSES */ #endif /* USE_SOCK */ #endif /* USE_PGP */ #endif /* USE_SOCK */ #endif /* USE_PGP */ if (version) { printf("Mixmaster %s\n", VERSION); goto end; } if (help ||about ||(isatty(fileno(stdin)) && isatty(fileno(stdout)))) fprintf(stderr, "Mixmaster %s\n", VERSION); if (help ||about) printf("\n\n"); if (about) { printf("Many people have contributed to the source code for Mixmaster.\n"); printf("These contributors include:\n\n"); printf("Lance Cottrell\n"); printf("Janis Jagars\n"); printf("Ulf Moeller\n"); printf("Peter Palfrader\n"); printf("Len Sassaman\n"); printf("\nand others. For full information on copyright and license issues,\n"); printf("read the bundled file COPYRIGHT.\n\n"); ret = 0; } -V, --version print version information\n\ --about print authorship information\n\ #endif /* USE_PGP */ #endif /* USE_PGP */ #endif /* USE_NCURSES */ #endif /* USE_SOCK */ #ifdef WIN32SERVICE "\n\ WinNT service:\n\ \n\ --install-svc install the service\n\ --remove-svc remove the service\n\ --run-svc run as a service\n" #endif /* WIN32SERVICE */ ); #endif /* else not UNIX */ #endif /* USE_PGP */ #endif /* USE_PGP */ #endif /* USE_SOCK */ #ifdef UNIX int pid; #endif /* UNIX */ #endif /* UNIX */ * if force != 0 passphrase must match with some key */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #ifdef USE_NCURSES #else /* end of USE_NCURSES */ char path[PATHMAX] = "stdin", l[LINELEN]; #endif /* else if not USE_NCURSES */ #ifdef USE_NCURSES #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ mix_status("Can't read %s.\n", path); #endif /* USE_PGP */ #endif /* USE_NCURSES */ mix_status("%s is empty.\n", path); #endif /* USE_NCURSES */ mix_status("%s is not a mail folder.\n", path); #endif /* not USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ int space; #if 0 #endif for (space = 0; space < (COLS - 10 - sizeof(VERSION)); space++) { printw(" "); }; } #endif /* USE_NCURSES */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of HAVE_NCURSES_H */ #endif /* else if not HAVE_NCURSES_H */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* not _MENU_H */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* POSIX */ #endif /* USE_PGP */ #endif /* USE_PGP */ #endif /* USE_NCURSES */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* USE_PGP */ char reliability[9]; #endif /* USE_NCURSES */ #else /* end of not USE_NCURSES */ #endif /* else if USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_PGP */ #endif /* USE_NCURSES */ sprintf(path, "%s%cx%02x%02x%02x%02x.txt", POOLDIR, DIRSEP, #endif /* USE_NCURSES */ #else /* end of USE_NCURSES */ #endif /* else if not USE_NCURSES */ #else /* end of not USE_NCURSES */ #endif /* else if USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_PGP */ #endif /* USE_NCURSES */ #else /* end of USE_NCURSES */ #endif /* else if not USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_PGP */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_PGP */ #endif /* USE_NCURSES */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ #endif /* USE_NCURSES */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* WIN32 */ #endif /* USE_SOCK */ int INDUMMYP; int OUTDUMMYP; int INDUMMYMAXP; int OUTDUMMYMAXP; int LISTSUPPORTED; /* list supported remailers in remailer-conf reply? */ long PACKETEXP; /* Expiration time for old packets */ long IDEXP; /* 0 = no ID log !! */ long MINLAT; #endif /* defined(S_IFDIR) && !defined(S_ISDIR) */ if (MIXDIR[strlen(MIXDIR) - 1] == DIRSEP) #else /* end of not POSIX */ #endif /* else if POSIX */ strcatn(MIXDIR, DIRSEPSTR, PATHMAX); #endif /* defined(HAVE_GETDOMAINNAME) || [...] */ #endif /* HAVE_UNAME */ #endif /* POSIX */ #elif defined(HAVE_GETHOSTNAME) /* end of HAVE_UNAME */ #endif /* defined(HAVE_GETHOSTNAME) */ #endif /* HAVE_GETDOMAINNAME */ #else /* end of WIN32 */ #endif /* else if not WIN32 */ #endif /* USE_SOCK */ INDUMMYP = 3; /* add dummy messages with probability p for each message added to the pool */ OUTDUMMYP = 10; /* add dummy messages with probability p each time we send from the pool */ INDUMMYMAXP = 84; /* for both of the above: while (rnd < p) { senddummy(); } */ MIDDLEMAN = 0; /* be generated on average. More than this is insane. */ SENDPOOLTIME = 0; /* frequency for sending pool messages */ KEYLIFETIME = 13 * 30 * 24 * 60 * 60; /* validity period for keys. */ KEYOVERLAPPERIOD = 1 * 30 * 24 * 60 * 60; /* when keys have this amount of time */ /* new ones when ./mix -K is run.*/ KEYGRACEPERIOD = 7 * 24 * 60 * 60; /* accept mail to the old key for this */ /* amount of time after it has expired. */ MINLAT = 5 * 60; #else /* end of COMPILEDPASS */ #endif /* else if not COMPILEDPASS */ #else /* end of WIN32 */ #endif /* else if not WIN32 */ #endif /* USE_SOCK */ read_conf_i(OUTDUMMYP) || read_conf_t(MINLAT) || #endif /* USE_SOCK */ #endif /* POSIX */ #endif /* HAVE_UNAME */ #endif /* WIN32 */ #endif /* POSIX */ #endif /* WIN32 */ #endif /* SPOOL */ if (line[strlen(line) - 1] != DIRSEP) strcatn(line, DIRSEPSTR, PATHMAX); #endif /* POSIX */ #endif /* GLOBALMIXCONF */ if (INDUMMYP > INDUMMYMAXP) INDUMMYP = INDUMMYMAXP; if (OUTDUMMYP > OUTDUMMYMAXP) OUTDUMMYP = OUTDUMMYMAXP; #elif defined(HAVE_GETHOSTNAME) /* end of HAVE_UNAME */ #endif /* defined(HAVE_GETHOSTNAME) */ #endif /* HAVE_GECOS */ #endif /* not USE_PGP */ #endif /* WIN32 */ #endif /* not GLOBALMIXCONF */ #endif /* defined(USE_SOCK) && defined(WIN32) */ #endif /* defined(USE_SOCK) && defined(WIN32) */ #endif /* USE_SOCK */ #endif /* USE_SOCK */ #endif /* POSIX */ #ifdef WIN32 seems there is no easy reliable way */ int is_nt_service(void) static int issvc = -1; #ifdef WIN32SERVICE STARTUPINFO StartupInfo; OSVERSIONINFO VersionInfo; DWORD dwsize; if (issvc != -1) /* do it only once */ VersionInfo.dwOSVersionInfoSize = sizeof(VersionInfo); if (GetVersionEx(&VersionInfo)) GetStartupInfo(&StartupInfo); if (StartupInfo.lpDesktop[0] == 0) #endif /* WIN32SERVICE */ return issvc = 0; /* assume not the service */ } /* is_nt_service */ HANDLE hMustTerminate = NULL; void set_nt_exit_event(HANDLE h_svc_exit_event) { hMustTerminate = h_svc_exit_event; } /* set_nt_exit_event */ #endif /* WIN32 */ #endif /* USE_SOCK */ #endif /* USE_SOCK */ #else /* end of WIN32 */ #endif /* else if not WIN32 */ #else /* end of _MSC */ #endif /* else if not _MSC */ #endif /* USE_NCURSES */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. This function initializes internal data of the Mixmaster library, signaled success. *chain is a string consisting of a comma-separated list of remailer "Newsgroups:", "Null:", "Latency:", "Chain:" and arbitrary header lines Lower-Level Remailer Functions This function encrypts and signs a message according to OpenPGP (RFC 2440). mode is the bitwise or of one of PGP_ENCRYPT, PGP_CONVENTIONAL and PGP_SIGN, It sig is NULL, the message will be decrypted without signature signer's user ID or the key ID of the unknown signature key to sig. gets length information, then p from buf. This function sets the read counter of buf to the start of the buffer #endif /* WIN32 */ #endif /* WIN32 */ #endif /* USE_PGP */ #endif /* not _MIXLIB_H */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #define COPYRIGHT "Copyright Anonymizer Inc. et al." #endif /* not USE_SOCK */ #ifdef _MSC #define snprintf _snprintf #endif /* _MSC */ #define DIRSEP '\\' #define DIRSEPSTR "\\" #else /* end of WIN32 */ #define DIRSEP '/' #define DIRSEPSTR "/" #endif /* else if not WIN32 */ #endif /* USE_IDEA */ #ifdef USE_AES int buf_aescrypt(BUFFER *b, BUFFER *key, BUFFER *iv, int enc); #endif /* USE_AES */ typedef struct { /* added for binary id.log change */ char id[16]; long time; } idlog_t; #endif /* _MSC */ #else /* end of defined(WIN32) && defined(USE_SOCK) */ #endif /* else if not defined(WIN32) && defined(USE_SOCK) */ #ifdef WIN32 int is_nt_service(void); void set_nt_exit_event(); #endif /* WIN32 */ #else /* end of __GNUC__ >= 2 */ #endif /* else if not __GNUC__ >= 2 */ #endif /* not _MIX3_H */ /* mpgp -- (C) 2000 - 2006 Ulf Moeller and others. mpgp may be redistributed and modified under certain conditions. This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF details. Test application for OpenPGP features #endif /* POSIX */ #endif /* HAVE_TERMIOS */ #else /* end of HAVE_TERMIOS */ #endif /* else if not HAVE_TERMIOS */ fprintf(stderr, " %s -C [-b]\n", n); /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of not USE_PGP */ #endif /* DEBUG */ #endif /* DEBUG */ #endif /* else if USE_PGP */ #else /* end of not USE_PGP */ #endif /* DEBUG */ #endif /* else if USE_PGP */ #else /* end of not USE_PGP */ #endif /* 0 */ #endif /* else if USE_PGP */ #endif /* USE_PGP */ #endif /* USE_PGP */ #endif /* USE_PGP */ #endif /* USE_PGP */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of 1 */ #endif /* not 1 */ #else /* end of 1 */ #endif /* else if not 1 */ #endif /* USE_IDEA */ #endif /* USE_IDEA */ pgp_symmetric(in, dek, mdc); */ #ifdef CLOAK buf_appends(out, "Version: N/A\n"); else #elif MIMIC /* end of CLOAK */ #endif /* MIMIC */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* USE_OPENSSL */ versions of Mixmaster to prevent anonymity set division. */ #define CLOAK #define PGP_ENCRYPTEDMDC 18 #define PGP_MDC 19 #define PGP_K_AES128 7 #define PGP_K_AES192 8 #define PGP_K_AES256 9 #define PGP_SUB_FEATURES 30 int pgp_blocklen(int symalgo); int pgp_getsymmetric(BUFFER *buf, BUFFER *key, int algo, int type); int pgp_symmetric(BUFFER *buf, BUFFER *key, int mdc); #endif /* not _PGP_H */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. if (type > 15) { ctb = 0xC0 | type; /* make v4 packet */ buf_setc(out, ctb); if (in->length > 8383) { buf_appendc(out, 0xFF); buf_appendl(out, in->length); } else if (in->length > 191) { #if 0 buf_appendc(out, ((in->length-192) >> 8) + 192); buf_appendc(out, (in->length-192) & 0xFF); #else /* end of 0 */ buf_appendi(out, in->length - 0xC0 + 0xC000); #endif /* else if not 0 */ } else { buf_appendc(out, in->length); } } else { #endif /* MIMIC */ #endif /* else if MIMIC */ } #else /* end of MIMIC */ #endif /* else if not MIMIC */ static int pgp_ideaencrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; if (mdc) { mdc = 1; out->data[0] = 1; } rnd_bytes(out->data + mdc, 8); out->data[8 + mdc] = out->data[6 + mdc], out->data[9 + mdc] = out->data[7 + mdc]; if (mdc) { SHA1_Init(&c); SHA1_Update(&c, out->data + 1, 10); SHA1_Update(&c, in->data, in->length); } idea_cfb64_encrypt(out->data + mdc, out->data + mdc, 10, &ks, iv, &n, IDEA_ENCRYPT); if (!mdc) { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, out->data + 2, 6); n = 0; } idea_cfb64_encrypt(in->data, out->data + 10 + mdc, in->length, &ks, iv, &n, if (mdc) { SHA1_Update(&c, "\xD3\x14", 2); /* 0xD3 = 0xC0 | PGP_MDC */ idea_cfb64_encrypt("\xD3\x14", out->data + 11 + in->length, 2, &ks, iv, &n, IDEA_ENCRYPT); SHA1_Final(out->data + 13 + in->length, &c); idea_cfb64_encrypt(out->data + 13 + in->length, out->data + 13 + in->length, 20, &ks, iv, &n, IDEA_ENCRYPT); } #endif /* USE_IDEA */ static int pgp_3desencrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; if (mdc) { mdc = 1; out->data[0] = 1; } rnd_bytes(out->data + mdc, 8); out->data[8 + mdc] = out->data[6 + mdc], out->data[9 + mdc] = out->data[7 + mdc]; if (mdc) { SHA1_Init(&c); SHA1_Update(&c, out->data + 1, 10); SHA1_Update(&c, in->data, in->length); } des_ede3_cfb64_encrypt(out->data + mdc, out->data + mdc, 10, ks1, ks2, ks3, &iv, &n, if (!mdc) { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, out->data + 2, 6); n = 0; } des_ede3_cfb64_encrypt(in->data, out->data + 10 + mdc, in->length, ks1, ks2, ks3, if (mdc) { SHA1_Update(&c, "\xD3\x14", 2); /* 0xD3 = 0xC0 | PGP_MDC */ des_ede3_cfb64_encrypt("\xD3\x14", out->data + 11 + in->length, 2, ks1, ks2, ks3, &iv, &n, ENCRYPT); SHA1_Final(out->data + 13 + in->length, &c); des_ede3_cfb64_encrypt(out->data + 13 + in->length, out->data + 13 + in->length, 20, ks1, ks2, ks3, &iv, &n, ENCRYPT); } static int pgp_castencrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; if (mdc) { mdc = 1; out->data[0] = 1; } rnd_bytes(out->data + mdc, 8); out->data[8 + mdc] = out->data[6 + mdc], out->data[9 + mdc] = out->data[7 + mdc]; if (mdc) { SHA1_Init(&c); SHA1_Update(&c, out->data + 1, 10); SHA1_Update(&c, in->data, in->length); } CAST_cfb64_encrypt(out->data + mdc, out->data + mdc, 10, &ks, iv, &n, CAST_ENCRYPT); if (!mdc) { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, out->data + 2, 6); n = 0; } CAST_cfb64_encrypt(in->data, out->data + 10 + mdc, in->length, &ks, iv, &n, if (mdc) { SHA1_Update(&c, "\xD3\x14", 2); /* 0xD3 = 0xC0 | PGP_MDC */ CAST_cfb64_encrypt("\xD3\x14", out->data + 11 + in->length, 2, &ks, iv, &n, CAST_ENCRYPT); SHA1_Final(out->data + 13 + in->length, &c); CAST_cfb64_encrypt(out->data + 13 + in->length, out->data + 13 + in->length, 20, &ks, iv, &n, CAST_ENCRYPT); } return (0); } static int pgp_bfencrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) { byte iv[8]; int i, n = 0; BF_KEY ks; SHA_CTX c; assert(key->length == 17); for (i = 0; i < 8; i++) iv[i] = 0; BF_set_key(&ks, 16, key->data + 1); if (mdc) { mdc = 1; out->data[0] = 1; } rnd_bytes(out->data + mdc, 8); out->data[8 + mdc] = out->data[6 + mdc], out->data[9 + mdc] = out->data[7 + mdc]; if (mdc) { SHA1_Init(&c); SHA1_Update(&c, out->data + 1, 10); SHA1_Update(&c, in->data, in->length); } n = 0; BF_cfb64_encrypt(out->data + mdc, out->data + mdc, 10, &ks, iv, &n, BF_ENCRYPT); if (!mdc) { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, out->data + 2, 6); n = 0; } BF_cfb64_encrypt(in->data, out->data + 10 + mdc, in->length, &ks, iv, &n, BF_ENCRYPT); if (mdc) { SHA1_Update(&c, "\xD3\x14", 2); /* 0xD3 = 0xC0 | PGP_MDC */ BF_cfb64_encrypt("\xD3\x14", out->data + 11 + in->length, 2, &ks, iv, &n, BF_ENCRYPT); SHA1_Final(out->data + 13 + in->length, &c); BF_cfb64_encrypt(out->data + 13 + in->length, out->data + 13 + in->length, 20, &ks, iv, &n, BF_ENCRYPT); } #ifdef USE_AES static int pgp_aesencrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) { byte iv[16]; int i, n = 0; AES_KEY ks; SHA_CTX c; assert(key->length == 17 || key->length == 25 || key->length == 33); for (i = 0; i < 16; i++) iv[i] = 0; AES_set_encrypt_key(key->data + 1, (key->length-1)<<3, &ks); if (mdc) { mdc = 1; out->data[0] = 1; } rnd_bytes(out->data + mdc, 16); out->data[16 + mdc] = out->data[14 + mdc], out->data[17 + mdc] = out->data[15 + mdc]; if (mdc) { SHA1_Init(&c); SHA1_Update(&c, out->data + 1, 18); SHA1_Update(&c, in->data, in->length); } n = 0; AES_cfb128_encrypt(out->data + mdc, out->data + mdc, 18, &ks, iv, &n, AES_ENCRYPT); if (!mdc) { iv[14] = iv[0], iv[15] = iv[1]; memcpy(iv, out->data + 2, 14); n = 0; } AES_cfb128_encrypt(in->data, out->data + 18 + mdc, in->length, &ks, iv, &n, AES_ENCRYPT); if (mdc) { SHA1_Update(&c, "\xD3\x14", 2); /* 0xD3 = 0xC0 | PGP_MDC */ AES_cfb128_encrypt("\xD3\x14", out->data + 19 + in->length, 2, &ks, iv, &n, AES_ENCRYPT); SHA1_Final(out->data + 21 + in->length, &c); AES_cfb128_encrypt(out->data + 21 + in->length, out->data + 21 + in->length, 20, &ks, iv, &n, AES_ENCRYPT); } return (0); } #endif /* USE_AES */ int pgp_symmetric(BUFFER *in, BUFFER *key, int mdc) int sym; if (pgp_blocklen(sym = buf_getc(key)) > 8) mdc = 1; /* force MDC for AES */ buf_prepare(out, in->length + (mdc?(1+2+22):2) + pgp_blocklen(sym)); switch (sym) { pgp_ideaencrypt(in, out, key, mdc); break; #endif /* USE_IDEA */ #ifdef USE_AES case PGP_K_AES128: case PGP_K_AES192: case PGP_K_AES256: pgp_aesencrypt(in, out, key, mdc); #endif /* USE_AES */ pgp_3desencrypt(in, out, key, mdc); pgp_castencrypt(in, out, key, mdc); break; case PGP_K_BF: pgp_bfencrypt(in, out, key, mdc); pgp_packet(out, mdc?PGP_ENCRYPTEDMDC:PGP_ENCRYPTED); #else /* end of MIMICPGP5 */ #endif /* else if not MIMICPGP5 */ int type1; type1 = pgp_getpacket(msg, d) == PGP_PUBKEY; assert (type1); type1 = pgp_getpacket(msg, d) == PGP_PUBKEY; assert (type1); type1 = pgp_getpacket(msg2, d) == PGP_PUBSUBKEY; assert (type1); buf_setc(d, PGP_K_CAST5); buf_appendc(d, PGP_K_AES128); #endif /* USE_AES */ buf_appendc(d, PGP_K_3DES); pgp_subpacket(d, PGP_SUB_FEATURES); buf_cat(sub, d); /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #ifdef USE_AES case PGP_K_AES256: return (32); case PGP_K_AES192: return (24); case PGP_K_AES128: #endif /* USE_AES */ return (0); } } int pgp_blocklen(int symalgo) { switch (symalgo) { #ifdef USE_AES case PGP_K_AES256: case PGP_K_AES192: case PGP_K_AES128: return (16); #endif /* USE_AES */ case PGP_K_IDEA: case PGP_K_CAST5: case PGP_K_BF: case PGP_K_3DES: return (8); default: return (16); while (!mpi->data[0] && mpi->length) /* remove leading zeros from mpi */ #endif /* USE_IDEA */ #ifdef USE_AES case PGP_K_AES128: case PGP_K_AES192: case PGP_K_AES256: return (buf_aescrypt(data, key, iv, enc)); #endif /* USE_AES */ #endif /* 1 */ #endif /* 0 */ buf_get(p, iv, pgp_blocklen(skalgo)); buf_setrnd(iv, pgp_blocklen(PGP_K_CAST5)); int needsym = 0, symfound = 0, mdcfound = 0; int ivlen; if ((a == PGP_K_3DES || a == PGP_K_CAST5 || a == PGP_K_BF #endif /* USE_IDEA */ #ifdef USE_AES || a == PGP_K_AES128 || a == PGP_K_AES192 || a == PGP_K_AES256 #endif /* USE_AES */ break; /* while ((a = buf_getc(i)) != -1) */ } /* if ((a == PGP_K_3DES)... */ if ((a = buf_getc(i)) != -1) if (a & 0x01) } /* while (p1->ptr < j) */ break; /* switch (type) */ ivlen = pgp_blocklen(skalgo); unsigned char lastb[16]; assert(ivlen <= 16); memcpy(lastb, i->data+i->length-ivlen, ivlen); buf_clear(iv); buf_append(iv, lastb, ivlen); } /* switch (type) */ } /* while ((type = pgp_getpacket(keypacket, p1)) > 0) */ if (pmdc) *pmdc = mdcfound; buf_setrnd(iv, pgp_blocklen(skalgo)); #endif /* USE_IDEA */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* if 0 */ #endif /* DEBUG */ buf_sets(pass, PASSPHRASE); #endif /* USE_IDEA */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. case PGP_ENCRYPTEDMDC: err = pgp_getsymmetric(p, key, algo, type==PGP_ENCRYPTEDMDC); #else /* end of 0 */ #endif /* else if not 0 */ while(partial && len > 0) { #else /* end of 0 */ #endif /* else if not 0 */ static int pgp_ideadecrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; char md[20]; /* we could make hdr 20 bytes long and reuse it for md */ if (key->length != 16 || in->length <= (mdc?(1+10+22):10)) if (mdc) { mdc = 1; if (in->data[0] != 1) return (-1); } buf_prepare(out, in->length - 10 - mdc); idea_cfb64_encrypt(in->data + mdc, hdr, 10, &ks, iv, &n, IDEA_DECRYPT); if (mdc) { SHA1_Init(&c); SHA1_Update(&c, hdr, 10); } else { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, in->data + 2, 6); n = 0; } idea_cfb64_encrypt(in->data + 10 + mdc, out->data, in->length - 10 - mdc, &ks, iv, &n, if (mdc) { if (out->length > 22) { out->length -= 22; if (out->data[out->length] == 0xD3 && out->data[out->length + 1] == 0x14) { } else } else err = -1; } #endif /* USE_IDEA */ static int pgp_3desdecrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; char md[20]; /* we could make hdr 20 bytes long and reuse it for md */ if (key->length != 24 || in->length <= (mdc?(1+10+22):10)) if (mdc) { mdc = 1; if (in->data[0] != 1) return (-1); } buf_prepare(out, in->length - 10 - mdc); des_ede3_cfb64_encrypt(in->data + mdc, hdr, 10, ks1, ks2, ks3, &iv, &n, DECRYPT); if (mdc) { SHA1_Init(&c); SHA1_Update(&c, hdr, 10); } else { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, in->data + 2, 6); n = 0; } des_ede3_cfb64_encrypt(in->data + 10 + mdc, out->data, in->length - 10 + mdc, ks1, if (mdc) { if (out->length > 22) { out->length -= 22; if (out->data[out->length] == 0xD3 && out->data[out->length + 1] == 0x14) { } else } else err = -1; } static int pgp_castdecrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; char md[20]; /* we could make hdr 20 bytes long and reuse it for md */ if (key->length != 16 || in->length <= (mdc?(1+10+22):10)) if (mdc) { mdc = 1; if (in->data[0] != 1) return (-1); } buf_prepare(out, in->length - 10 - mdc); CAST_cfb64_encrypt(in->data + mdc, hdr, 10, &ks, iv, &n, CAST_DECRYPT); if (mdc) { SHA1_Init(&c); SHA1_Update(&c, hdr, 10); } else { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, in->data + 2, 6); n = 0; } CAST_cfb64_encrypt(in->data + 10 + mdc, out->data, in->length - 10 - mdc, &ks, if (mdc) { if (out->length > 22) { out->length -= 22; if (out->data[out->length] == 0xD3 && out->data[out->length + 1] == 0x14) { } else } else err = -1; } static int pgp_bfdecrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) SHA_CTX c; char md[20]; /* we could make hdr 20 bytes long and reuse it for md */ if (key->length != 16 || in->length <= (mdc?(1+10+22):10)) if (mdc) { mdc = 1; if (in->data[0] != 1) return (-1); } buf_prepare(out, in->length - 10 - mdc); BF_cfb64_encrypt(in->data + mdc, hdr, 10, &ks, iv, &n, BF_DECRYPT); if (mdc) { SHA1_Init(&c); SHA1_Update(&c, hdr, 10); } else { iv[6] = iv[0], iv[7] = iv[1]; memcpy(iv, in->data + 2, 6); n = 0; } BF_cfb64_encrypt(in->data + 10 + mdc, out->data, in->length - 10 - mdc, &ks, if (mdc) { if (out->length > 22) { out->length -= 22; if (out->data[out->length] == 0xD3 && out->data[out->length + 1] == 0x14) { } else } else err = -1; } #ifdef USE_AES static int pgp_aesdecrypt(BUFFER *in, BUFFER *out, BUFFER *key, int mdc) { int err = 0; byte iv[16]; byte hdr[18]; int i, n; SHA_CTX c; char md[20]; /* we could make hdr 20 bytes long and reuse it for md */ AES_KEY ks; if ((key->length != 16 && key->length != 24 && key->length != 32) || in->length <= (mdc?(1+18+22):18)) return (-1); if (mdc) { mdc = 1; if (in->data[0] != 1) return (-1); } buf_prepare(out, in->length - 18 - mdc); for (i = 0; i < 16; i++) iv[i] = 0; AES_set_encrypt_key(key->data, key->length<<3, &ks); n = 0; AES_cfb128_encrypt(in->data + mdc, hdr, 18, &ks, iv, &n, AES_DECRYPT); if (n != 2 || hdr[16] != hdr[14] || hdr[17] != hdr[15]) { err = -1; goto end; } if (mdc) { SHA1_Init(&c); SHA1_Update(&c, hdr, 18); } else { iv[14] = iv[0], iv[15] = iv[1]; memcpy(iv, in->data + 2, 14); n = 0; } AES_cfb128_encrypt(in->data + 18 + mdc, out->data, in->length - 18 - mdc, &ks, iv, &n, AES_DECRYPT); if (mdc) { if (out->length > 22) { out->length -= 22; if (out->data[out->length] == 0xD3 && out->data[out->length + 1] == 0x14) { } else } else err = -1; } end: return (err); } #endif /* USE_AES */ int pgp_getsymmetric(BUFFER *in, BUFFER *key, int algo, int mdc) #ifdef USE_AES case PGP_K_AES128: case PGP_K_AES192: case PGP_K_AES256: err = pgp_aesdecrypt(in, out, key, mdc); break; #endif /* USE_AES */ err = pgp_ideadecrypt(in, out, key, mdc); #endif /* USE_IDEA */ err = pgp_3desdecrypt(in, out, key, mdc); err = pgp_castdecrypt(in, out, key, mdc); err = pgp_bfdecrypt(in, out, key, mdc); buf_appendzero(iv, pgp_blocklen(algo)); /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* not _MSC */ #endif /* USE_PCRE */ * error messages: e* *.err * outgoing messages: out *.txt (to be used by external program) #else /* end of SHORTNAMES */ #endif /* else if not SHORTNAMES */ sprintf(old, "%s%c%s", POOLDIR, DIRSEP, name); #else /* end of SHORTNAMES */ #endif /* else if not SHORTNAMES */ sprintf(new, "%s%c%s", POOLDIR, DIRSEP, name); sprintf(path, "%s%c%s", POOLDIR, DIRSEP, e->d_name); sprintf(path, "%s%c%s", POOLDIR, DIRSEP, e->d_name); #if 0 buf_appends(msg, line); #endif /* 0 */ #else /* end of not WIN32 */ #endif /* else if WIN32 */ sprintf(tmpname, "%s%c%02x%02x%02x%02x.tmp", POOLDIR, DIRSEP, rnd_byte(), rnd_byte(), #else /* end of SHORTNAMES */ sprintf(tmpname, "%s%ct%02x%02x%02x%02x%02x%02x%01x", POOLDIR, DIRSEP, rnd_byte(), strrchr(path, DIRSEP)[1] = type[0]; #endif /* else if not SHORTNAMES */ sprintf(path, "%s%c%s", POOLDIR, DIRSEP, e->d_name); int create_dummy_mailout() { while (rnd_number(100) < OUTDUMMYP) { errlog(DEBUGINFO, "Generating dummy message with outgoing mail.\n"); if (mix_encrypt(MSG_NULL, NULL, NULL, 1, NULL) == -1) return -1; } return 0; } create_dummy_mailout(); #endif /* 0 */ #endif /* USE_PCRE */ #endif /* not USE_PCRE_OLD */ #endif /* (PCRE_MAJOR == 2 && PCRE_MINOR >= 06) */ #endif /* (PCRE_MAJOR >= 3) */ #else /* end of USE_PCRE */ #endif /* else if not USE_PCRE */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* WIN32 */ #endif /* USE_OPENSSL */ #endif /* WIN32 */ #elif defined(WIN32) /* end of HAVE_GETTIMEOFDAY */ #else /* end of defined(WIN32) */ #endif /* else if not defined(WIN32), HAVE_GETTIMEOFDAY */ #endif /* DEV_URANDOM */ #endif /* WIN32 */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* not _MSC */ int create_dummy_mailin(); } else create_dummy_mailin(); } else create_dummy_mailin(); int create_dummy_mailin() { while (rnd_number(100) < INDUMMYP) { errlog(DEBUGINFO, "Generating dummy message with incoming mail.\n"); if (mix_encrypt(MSG_NULL, NULL, NULL, 1, NULL) == -1) return -1; } return 0; } sprintf(fname, "%s%cp%02x%02x%02x%01x.%02x", POOLDIR, DIRSEP, #else /* end of SHORTNAMES */ sprintf(fname, "%s%cp%02x%02x%02x%02x%02x%02x%01x", POOLDIR, DIRSEP, #endif /* else if not SHORTNAMES */ char *path; if (e->d_name[0] == 'p' || e->d_name[0] == 'e' || e->d_name[0] == 't') { errlog(DEBUGINFO, "Piping message to %s.\n", mailbox + 1); in the subject line work too (we process the body a few lines down) */ } if (addr->length == 0) { rfc822_addr (from, addr); buf_chop(addr); } if (line->length == 0) { errlog(LOG, "Nothing to block after rfc822_addr().\n"); if (bufleft(line, "/")) { errlog(LOG, "Ignoring blocking request: %b is a regex.\n", addr); } else { if (strchr(line->data, '@') && strchr(strchr(line->data, '@'), '.')) { if (f != NULL) { lock(f); buf_chop(line); sendinfofile(BLOCKFILE, NULL, line, NULL); if (line->length) { fprintf(f, "%s\n", line->data); } else errlog(NOTICE, "%b already blocked.\n", addr); unlock(f); fclose(f); } else errlog(ERRORMSG, "Can't write to %s.\n", DESTBLOCK); } else errlog(WARNING, "Invalid address not added to %s: %b\n", DESTBLOCK, addr); } idlog_t idbuf; long fpi = sizeof(idlog_t), fpo = sizeof(idlog_t); f = mix_openfile(IDLOG, "rb+"); if (fread(&idbuf, 1, sizeof(idlog_t), f) != sizeof(idlog_t)) { /* replace first line */ fclose(f); unlockfile(i); return (-1); } then = idbuf.time; memset(idbuf.id,0,sizeof(idbuf.id)); idbuf.time = now - IDEXP; fseek(f,0,SEEK_SET); fwrite(&idbuf,1,sizeof(idlog_t),f); fseek(f,fpi,SEEK_SET); /* this fseek does nothing, but MSVC CRT happilly reads past EOF (!!!) if we do not fseek here :-/ */ while (fread(&idbuf, 1, sizeof(idlog_t), f) == sizeof(idlog_t)) { fpi+=sizeof(idlog_t); then = idbuf.time; { fseek(f,fpo,SEEK_SET); fwrite(&idbuf,1,sizeof(idlog_t),f); fpo += sizeof(idlog_t); fseek(f,fpi,SEEK_SET); } #ifdef _MSC chsize(fileno(f),fpo); #else /* end of _MSC */ ftruncate(fileno(f),fpo); #endif /* else if not _MSC */ buf_free(b); /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #endif /* USE_IDEA */ #endif /* USE_NSUB */ buf_sets(pass, PASSPHRASE); #endif /* USE_PGP */ #endif /* 0 */ #endif /* USE_IDEA */ #endif /* 0 */ #else /* end of USE_PGP */ #endif /* Else if not USE_PGP */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* not _MSC */ idlog_t idbuf; if ((f = mix_openfile(IDLOG, "rb+")) != NULL) { fread(&idbuf,1,sizeof(idlog_t),f); old = idbuf.time; } else { if ((f = mix_openfile(IDLOG, "wb")) != NULL) { memset(idbuf.id,0,sizeof(idbuf.id)); idbuf.time = now; fwrite(&idbuf,1,sizeof(idlog_t),f); memcpy(idbuf.id,id->data,sizeof(idbuf.id)); idbuf.time = now; fwrite(&idbuf,1,sizeof(idlog_t),f); while (fread(&idbuf, 1, sizeof(idlog_t), f) == sizeof(idlog_t)) { if (!memcmp(idbuf.id, id->data, sizeof(idbuf.id))) { errlog(LOG, "Ignoring message with future timestamp.\n"); if (ftell(f)%sizeof(idlog_t)) fseek(f,0-(ftell(f)%sizeof(idlog_t)),SEEK_CUR); /* make sure that we're on sizeof(idlog_t) byte boundary */ memcpy(idbuf.id,id->data,sizeof(idbuf.id)); idbuf.time = now; fwrite(&idbuf,1,sizeof(idlog_t),f); /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* defined(WIN32) || defined(MSDOS) */ #endif /* WIN32 */ #endif /* not O_NDELAY */ #endif /* HAVE_TERMIOS */ #endif /* HAVE_TERMIOS */ #endif /* DEV_RANDOM */ #else /* end of 1 */ #endif /* else if not 1 */ #else /* end of HAVE_GETKEY */ #endif /* else if not HAVE_GETKEY */ #endif /* DEV_RANDOM */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. Mixmaster may be redistributed and modified under certain conditions. This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the file COPYRIGHT for details. Win32 Service support $Id$ */ #include #include #include #include #include #include "mix3.h" #define SVCNAME "Mixmaster" #define SVCDISPLAYNAME "Mixmaster Service" /* internal variables */ static SERVICE_STATUS ssStatus; static SERVICE_STATUS_HANDLE sshStatusHandle; static BOOL not_service = FALSE; static HANDLE hThread = NULL; static HANDLE hMustTerminate = NULL; /* internal function prototypes */ VOID WINAPI service_ctrl(DWORD ctrl_code); VOID WINAPI service_main(DWORD argc, LPSTR *argv); static DWORD service_run(void); static void service_stop(); static int set_stdfiles(); static int install_service(); static int remove_service(); static int run_notservice(int argc, char **argv); BOOL WINAPI console_ctrl_handler(DWORD ctrl_type); static char *GetLastErrorText(); static BOOL send_status(DWORD current_state, DWORD exit_code, DWORD wait_hint, DWORD id); static void event_log(DWORD id, char *eventmsg); int mix_main(int argc, char *argv[]); int main(int argc, char *argv[]) { SERVICE_TABLE_ENTRY dispatchTable[] = { if ((argc > 1) && ((argv[1][0] == '-') && (argv[1][1] == '-'))) { } else if (!is_nt_service()) { } printf("mix --install-svc install the service\n"); printf("mix --remove-svc remove the service\n"); printf("mix --run-svc run as a service\n"); printf("mix -h view a summary of the command line options.\n"); printf("\nStartServiceCtrlDispatcher being called.\n" ); printf("This may take several seconds. Please wait.\n" ); if (!StartServiceCtrlDispatcher(dispatchTable)) { } return 0; } /* main */ VOID WINAPI service_main(DWORD argc, LPSTR *argv) { DWORD err = 0; if (!(sshStatusHandle = RegisterServiceCtrlHandler(SVCNAME, service_ctrl))) ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ssStatus.dwServiceSpecificExitCode = 0; if (send_status(SERVICE_START_PENDING, NO_ERROR, 1000, 1020)) send_status(SERVICE_STOPPED, err, 0, err ? 1030 : 30); } /* service_main */ VOID WINAPI service_ctrl(DWORD ctrl_code) { /* Handle the requested control code. */ if (ctrl_code == SERVICE_CONTROL_STOP || ctrl_code == SERVICE_CONTROL_SHUTDOWN) else } /* service_ctrl */ static DWORD service_run(void) { char filename[_MAX_PATH+1]; char home[_MAX_PATH+1], *p; char *svc_argv[2] = {filename, "-D"}; if (!hMustTerminate) set_nt_exit_event(hMustTerminate); DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), GetModuleFileName(NULL , filename, _MAX_PATH); strcpy(home, filename); if (p = strrchr(home, '\\')) { } if (!set_stdfiles()) { } send_status(SERVICE_RUNNING, NO_ERROR, 0, 1060); event_log(10, "Mixmaster Service started"); mix_main(2, svc_argv); return 0; } /* service_run */ static void service_stop(void) { send_status(SERVICE_STOP_PENDING, NO_ERROR, 5000, 1070); if (hMustTerminate) { } else if (hThread) hThread = NULL; ssStatus.dwCurrentState = SERVICE_STOPPED; } /* service_stop */ static int set_stdfiles() { /* needed for _popen() */ static DWORD std_handles[]={STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE}; FILE *stdfile[]={stdin, stdout, stderr}; HANDLE hStd; int fh, stf_fileno; FILE *fl; AllocConsole(); for (stf_fileno=0; stf_fileno<=2; stf_fileno++) { } return 1; } /* set_stdfiles */ static BOOL send_status(DWORD current_state, DWORD exit_code, DWORD wait_hint, DWORD id) { static DWORD dwCheckPoint = 1; BOOL ret_val; if (not_service) ssStatus.dwCurrentState = current_state; ssStatus.dwWin32ExitCode = exit_code; ssStatus.dwWaitHint = wait_hint; ssStatus.dwControlsAccepted = (current_state == SERVICE_START_PENDING) ? ssStatus.dwCheckPoint = ((current_state == SERVICE_RUNNING) || (current_state == SERVICE_STOPPED)) ? if (!(ret_val = SetServiceStatus(sshStatusHandle, &ssStatus))) return ret_val; } /* send_status */ static void event_log(DWORD id, char *eventmsg) { HANDLE hEventSource; char *pStrings[2] = {"", eventmsg}; if (not_service) if (id > 1000) if (!(hEventSource = RegisterEventSource(NULL, SVCNAME))) ReportEvent(hEventSource, (WORD)((id < 1000) ? EVENTLOG_SUCCESS : EVENTLOG_ERROR_TYPE), DeregisterEventSource(hEventSource); } /* event_log */ static int run_notservice(int argc, char ** argv) { not_service = TRUE; return mix_main(argc, argv); } /* run_notservice */ static int install_service() { SC_HANDLE schService, schSCManager; char filename[_MAX_PATH+10]; if (GetModuleFileName(NULL, filename, _MAX_PATH) == 0) { } strcat(filename, " --run-svc"); if (!(schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) { } schService = CreateService(schSCManager, SVCNAME, SVCDISPLAYNAME, if (schService) { } else { } CloseServiceHandle(schSCManager); return 0; } /* install_service */ static int remove_service() { SC_HANDLE schService, schSCManager; int ret_val = 0; if (!(schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) { } if (!(schService = OpenService(schSCManager, SVCNAME, SERVICE_ALL_ACCESS))) { } /* try to stop the service */ if (ControlService(schService, SERVICE_CONTROL_STOP, &ssStatus)) { } /* now remove the service */ if (!DeleteService(schService)) { } else CloseServiceHandle(schService); CloseServiceHandle(schSCManager); return ret_val; } /* remove_service */ static char *GetLastErrorText() { static char error_buf[256]; DWORD dwRet, err; LPSTR lpszTemp = NULL; dwRet = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, /* supplied buffer is not long enough */ if (!dwRet || (256 < (long)dwRet+14)) else { } if (lpszTemp) return error_buf; } /* GetLastErrorText */ #endif /* WIN32SERVICE */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. idlog_t idbuf; f = mix_openfile(IDLOG, "rb"); while (fread(&idbuf, 1, sizeof(idlog_t), f) == sizeof(idlog_t)) { then = idbuf.time; #endif /* 0 */ #endif /* 0 */ /* display destinations to which delivery is explicitly permitted if (PGP && REPGP) { #endif /* USE_IDEA */ #endif /* USE_IDEA */ #else /* end of USE_NSUB */ #endif /* else if not USE_NSUB */ #endif /* 0 */ /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others. #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* HAVE_GETKEY */ #endif /* POSIX */ #endif /* POSIX */ #ifdef _MSC p = _popen(prog, "w"); #endif /* _MSC */ #elif defined(_MSC) /* end of POSIX */ return (_pclose(p)); #else /* end of defined(_MSC) */ #endif /* else if not defined(_MSC), POSIX */ #endif /* 1 */ if (strchr(filename, DIRSEP)) strcatn(name, strrchr(filename, DIRSEP), LINELEN); #else /* end of WIN32 */ #endif /* else if not WIN32 */ #else /* end of not WIN32 */ #endif /* else if WIN32 */ #endif /* HAVE_TERMIOS */ #else /* end of HAVE_GETKEY */ #endif /* else if not HAVE_GETKEY */ #else /* end of not UNIX */ #endif /* else if UNIX */ #endif /* POSIX */ #else /* end of POSIX */ #endif /* else if not POSIX */ #endif /* __RSXNT__ */ WIN32_FIND_DATA d; char path[PATHMAX]; sprintf(path, "%s%c*", name, DIRSEP); *dir = FindFirstFile(path, &d); WIN32_FIND_DATA d; ok = FindNextFile(*dir, &d); strncpy(e.d_name, d.cFileName, PATHMAX); #endif /* _MSC */ #define VERSION "3.0"