| 1 |
/* $Id: main.c,v 1.2 2002/08/29 19:54:47 rabbi Exp $
|
| 2 |
*
|
| 3 |
* $Log: main.c,v $
|
| 4 |
* Revision 1.2 2002/08/29 19:54:47 rabbi
|
| 5 |
* Fixed compilation error in main.c. The value of errlog is now assigned in
|
| 6 |
* main().
|
| 7 |
*
|
| 8 |
* Revision 1.1.1.1 2002/08/28 20:06:50 rabbi
|
| 9 |
* Mixmaster 2.0.4 source.
|
| 10 |
*
|
| 11 |
* Revision 2.13 1998/08/21 13:26:08 um
|
| 12 |
* *** empty log message ***
|
| 13 |
*
|
| 14 |
* Revision 2.12 1998/05/07 23:59:36 um
|
| 15 |
* Moved IDEXP and PACKETEXP to mixmaster.conf.
|
| 16 |
*
|
| 17 |
* Revision 2.11 1998/04/20 14:13:59 um
|
| 18 |
* Added support for type1 PGP-only remailers.
|
| 19 |
*
|
| 20 |
* Revision 2.9 1998/04/13 23:22:29 um
|
| 21 |
* re-indented.
|
| 22 |
*
|
| 23 |
* Revision 2.8 1998/04/06 21:58:29 um
|
| 24 |
* read_conf* macro bug fix by Johannes Kroeger.
|
| 25 |
*
|
| 26 |
* Revision 2.7 1998/03/02 16:37:21 um
|
| 27 |
* fuction getline() replaces fgets() + chop().
|
| 28 |
*
|
| 29 |
* Revision 2.6 1998/02/26 02:25:32 um
|
| 30 |
* Changes for BSAFEeay.
|
| 31 |
*
|
| 32 |
* Revision 2.4 1998/02/17 23:25:41 um
|
| 33 |
* Check for DecodePEM return value.
|
| 34 |
*
|
| 35 |
* Revision 2.2 1998/01/13 17:34:38 um
|
| 36 |
* Increased version number.
|
| 37 |
*
|
| 38 |
* main.c 1997-12-08 um
|
| 39 |
* bug fix by Andy Dustman.
|
| 40 |
*
|
| 41 |
* main.c 1997-11-10 um
|
| 42 |
* source block Reply-To and Sender address.
|
| 43 |
*
|
| 44 |
* main.c 1997-11-07 um
|
| 45 |
* mix server command line option -D1 for single protocol run.
|
| 46 |
* -GD to generate DH parameter.
|
| 47 |
*
|
| 48 |
* main.c 1997-10-10 um
|
| 49 |
* parse header lines without " " after the ":" correctly. bug fix from
|
| 50 |
* Johannes Kroeger.
|
| 51 |
*
|
| 52 |
* main.c 1997-10-07 um
|
| 53 |
* bug fix from Johannes Kroeger: skip blank lines in source.block.
|
| 54 |
* bug fix for opening mixmaster.conf under DOS.
|
| 55 |
* removed read_conf_wt macro.
|
| 56 |
*
|
| 57 |
* main.c 1997-09-23 um
|
| 58 |
* new mixmaster.conf entry VERBOSE.
|
| 59 |
*
|
| 60 |
* main.c 1997-09-18 um
|
| 61 |
* help/key/stats requests must be case-insensitive exact match.
|
| 62 |
*
|
| 63 |
* main.c 1997-09-15 um
|
| 64 |
* string size check for $HOME/Mix corrected.
|
| 65 |
*
|
| 66 |
* main.c 1997-09-07 um
|
| 67 |
* Win95: try opening mixmaste.con if mixmaster.conf doesn't exist.
|
| 68 |
*
|
| 69 |
* main.c 1997-09-02 um
|
| 70 |
* -Q takes additional destination as optional argument.
|
| 71 |
*
|
| 72 |
* main.c 1997-08-26 um
|
| 73 |
* bug fixes in init_mix().
|
| 74 |
*
|
| 75 |
* main.c 1997-08-20 JK
|
| 76 |
* bug fix in init_mix(), regexp source blocking.
|
| 77 |
*
|
| 78 |
* main.c 1997-08-17 JK
|
| 79 |
* support for additional type1 headers.
|
| 80 |
* improved configuration lines.
|
| 81 |
*
|
| 82 |
* main.c 1997-08-15 um
|
| 83 |
*
|
| 84 |
* main.c 1997-07-11 ad
|
| 85 |
* support for ANONNAME (long name for anonymous messages).
|
| 86 |
*
|
| 87 |
* main.c 1997-07-01 um
|
| 88 |
* middleman patch.
|
| 89 |
*
|
| 90 |
* main.c 1997-06-18 um
|
| 91 |
* new mixmaster.conf entries.
|
| 92 |
*
|
| 93 |
* main.c 1997-06-13 um
|
| 94 |
* use capital letters for remailer functions (-K, -X)
|
| 95 |
*
|
| 96 |
* main.c 1997-06-08 um
|
| 97 |
* call init_our_random also if mixmaster.conf can't be read.
|
| 98 |
*
|
| 99 |
* main.c 1996-12-11 um
|
| 100 |
* new option -k for key management.
|
| 101 |
*
|
| 102 |
* main.c 1996-10-26 um
|
| 103 |
* additional entries in mixmaster.conf
|
| 104 |
* remailer message: 1st non-empty line begins with ::
|
| 105 |
*
|
| 106 |
* main.c 1996-07-11 um
|
| 107 |
* new option -x to seed the random number generator
|
| 108 |
*
|
| 109 |
* modified for DOS. um
|
| 110 |
*
|
| 111 |
* main.c 1.4 11/9/95
|
| 112 |
* Mixmaster now chdir's to mix_dir rather than prepending
|
| 113 |
* That directory to every filename.
|
| 114 |
* Magic strings now defined here rather than in mixmaster.h
|
| 115 |
*
|
| 116 |
* -P prints out three lines,
|
| 117 |
* current mix_dir
|
| 118 |
* filename containing the list of remailers
|
| 119 |
* current version of Mixmaster.
|
| 120 |
*
|
| 121 |
* main.c 1.3 5/10/95
|
| 122 |
* -t and To: replaces destination on command line
|
| 123 |
*
|
| 124 |
* main.c 1.2 5/10/95
|
| 125 |
*
|
| 126 |
* (c) Copyright 1995 by Lance Cottrell. All right reserved.
|
| 127 |
* The author assumes no liability for damages resulting from the
|
| 128 |
* use of this software, even if the damage results from defects in
|
| 129 |
* this software. No warranty is expressed or implied.
|
| 130 |
*
|
| 131 |
* This software is being distributed under the GNU Public Licence,
|
| 132 |
* see the file GNU.license for more details.
|
| 133 |
*
|
| 134 |
* - Lance Cottrell (loki@obscura.com) 4/23/95
|
| 135 |
*
|
| 136 |
*/
|
| 137 |
|
| 138 |
#include "version.h"
|
| 139 |
|
| 140 |
#include "mix.h"
|
| 141 |
#include <stdio.h>
|
| 142 |
#include <string.h>
|
| 143 |
#include <stdlib.h>
|
| 144 |
#include <unistd.h>
|
| 145 |
#include <sys/stat.h>
|
| 146 |
#include <sys/types.h>
|
| 147 |
#include <ctype.h>
|
| 148 |
|
| 149 |
char remailer_type[] = "Remailer-Type: Mixmaster ";
|
| 150 |
char begin_remailer[] = "-----BEGIN REMAILER MESSAGE-----";
|
| 151 |
char end_remailer[] = "-----END REMAILER MESSAGE-----";
|
| 152 |
char begin_key[] = "-----Begin Mix Key-----";
|
| 153 |
char end_key[] = "-----End Mix Key-----";
|
| 154 |
char begin_cfg[] = "-----Begin Mix Config-----";
|
| 155 |
char end_cfg[] = "-----End Mix Config-----";
|
| 156 |
char begin_signed[] = "-----Begin Mix Signed Data-----";
|
| 157 |
char begin_signature[] = "-----Begin Mix Signature-----";
|
| 158 |
char end_signature[] = "-----End Mix Signature-----";
|
| 159 |
char intermed_hop[] = "-----Intermediate Hop-----";
|
| 160 |
char final_hop[] = "-----Final Hop-----";
|
| 161 |
|
| 162 |
char mix_dir[256] = "";
|
| 163 |
char cur_dir[256];
|
| 164 |
char KEYFILE[256] = "mix.key";
|
| 165 |
char HELPFILE[256] = "mix.help";
|
| 166 |
char KEYINFO[256] = "keyinfo.txt";
|
| 167 |
char REMAILERNAME[256] = "Anonymous Remailer";
|
| 168 |
char SHORTNAME[256] = "foo";
|
| 169 |
char REMAILERADDR[256] = "";
|
| 170 |
char ANONADDR[256] = "";
|
| 171 |
char ANONNAME[256] = "";
|
| 172 |
char COMPLAINTS[256] = "";
|
| 173 |
int POOLSIZE = 0;
|
| 174 |
int POOLTIMEOUT = 0;
|
| 175 |
int RATE = 100;
|
| 176 |
char REMAILERLIST[256] = "type2.list";
|
| 177 |
char IDLOG[256] = "id.log";
|
| 178 |
char STATS[256] = "stats.log";
|
| 179 |
char SECRING[256] = "secring.mix";
|
| 180 |
char PUBRING[256] = "pubring.mix";
|
| 181 |
char SOURCEBLOCK[256] = "source.block";
|
| 182 |
char DESTALLOW[256] = "destination.allow";
|
| 183 |
char DESTBLOCK[256] = "destination.block";
|
| 184 |
char HDRFILTER[256] = "headers.del";
|
| 185 |
char MIXRAND[256] = "mixrand.bin";
|
| 186 |
/* the -t option tells sendmail to expect a To: header in stdin */
|
| 187 |
char SENDMAIL[256] = "/usr/lib/sendmail -t";
|
| 188 |
char NEWS[256] = "";
|
| 189 |
char ORGANIZATION[256] = "";
|
| 190 |
char MAILtoNEWS[256] = "mail2news@nym.alias.net";
|
| 191 |
char TYPE1[256] = ""; /* Default is no Type 1 support */
|
| 192 |
int T1PGPONLY = 0;
|
| 193 |
char REJECT[256] = "M";
|
| 194 |
char REQUIRE[256] = "";
|
| 195 |
char CHAIN[256] = "";
|
| 196 |
int DISTANCE = 2;
|
| 197 |
char RELLIST[256] = "mix.list";
|
| 198 |
char FORWARDTO[256] = "0";
|
| 199 |
int MINREL = 98;
|
| 200 |
int RELFINAL = 99;
|
| 201 |
int MAXLAT = 24; /* in hours! Default: one day */
|
| 202 |
int MINREMAILERS = 1;
|
| 203 |
int NUMCOPIES = 1;
|
| 204 |
int VERBOSE = 0;
|
| 205 |
int CREATEKEYS = 0;
|
| 206 |
int KEYVALIDITY = 30;
|
| 207 |
int KEYOVERLAP = 5;
|
| 208 |
int MIDDLEMAN = 0;
|
| 209 |
/*Expiration time for old packets and id numbers in hours */
|
| 210 |
int PACKETEXP = 7 * 24;
|
| 211 |
int IDEXP = 7 * 24;
|
| 212 |
int ERRSTDOUT = 0;
|
| 213 |
FILE *errlog;
|
| 214 |
|
| 215 |
#ifdef USE_BSAFE
|
| 216 |
B_ALGORITHM_METHOD *CHOOSER[] =
|
| 217 |
{
|
| 218 |
&AM_DESX_CBC_DECRYPT,
|
| 219 |
&AM_DESX_CBC_ENCRYPT,
|
| 220 |
&AM_DES_CBC_DECRYPT,
|
| 221 |
&AM_DES_CBC_ENCRYPT,
|
| 222 |
&AM_DES_EDE3_CBC_DECRYPT,
|
| 223 |
&AM_DES_EDE3_CBC_ENCRYPT,
|
| 224 |
&AM_DH_KEY_AGREE,
|
| 225 |
&AM_DH_PARAM_GEN,
|
| 226 |
&AM_DSA_KEY_GEN,
|
| 227 |
&AM_DSA_PARAM_GEN,
|
| 228 |
&AM_DSA_SIGN,
|
| 229 |
&AM_DSA_VERIFY,
|
| 230 |
&AM_MAC,
|
| 231 |
&AM_MD,
|
| 232 |
&AM_MD2,
|
| 233 |
&AM_MD2_RANDOM,
|
| 234 |
&AM_MD5,
|
| 235 |
&AM_MD5_RANDOM,
|
| 236 |
&AM_RC2_CBC_DECRYPT,
|
| 237 |
&AM_RC2_CBC_ENCRYPT,
|
| 238 |
&AM_RC4_DECRYPT,
|
| 239 |
&AM_RC4_ENCRYPT,
|
| 240 |
&AM_RC4_WITH_MAC_DECRYPT,
|
| 241 |
&AM_RC4_WITH_MAC_ENCRYPT,
|
| 242 |
&AM_RC5_CBC_DECRYPT,
|
| 243 |
&AM_RC5_CBC_ENCRYPT,
|
| 244 |
&AM_RSA_CRT_DECRYPT,
|
| 245 |
&AM_RSA_CRT_ENCRYPT,
|
| 246 |
&AM_RSA_DECRYPT,
|
| 247 |
&AM_RSA_ENCRYPT,
|
| 248 |
&AM_RSA_KEY_GEN,
|
| 249 |
&AM_SHA,
|
| 250 |
NULL
|
| 251 |
};
|
| 252 |
#endif
|
| 253 |
|
| 254 |
#ifdef MSDOS
|
| 255 |
void
|
| 256 |
cdcurdir (void)
|
| 257 |
{
|
| 258 |
chdir (cur_dir);
|
| 259 |
}
|
| 260 |
|
| 261 |
#endif
|
| 262 |
|
| 263 |
/* read word from mixmaster.conf */
|
| 264 |
#define read_conf(t) \
|
| 265 |
if (strncmp (line, #t, sizeof (#t) - 1) == 0 && isspace (line[sizeof (#t) - 1]))\
|
| 266 |
sscanf (line, "%s %s", junk, t);
|
| 267 |
|
| 268 |
/* read line from mixmaster.conf, with whitespace */
|
| 269 |
#define read_conf_w(t) \
|
| 270 |
if (strncmp (line, #t, sizeof (#t) - 1) == 0 && isspace (line[sizeof (#t) - 1])) {\
|
| 271 |
foo = line;\
|
| 272 |
while (*foo > ' ') foo++; /* scan to first space */ \
|
| 273 |
while (*foo > '\0' && *foo <= ' ') foo++; /* scan to first non whitespace */ \
|
| 274 |
strcpy(t, foo);\
|
| 275 |
chop (t);}
|
| 276 |
|
| 277 |
/* read number from mixmaster.conf */
|
| 278 |
#define read_conf_i(t) \
|
| 279 |
if (strncmp (line, #t, sizeof (#t) - 1) == 0 && isspace (line[sizeof (#t) - 1]))\
|
| 280 |
sscanf (line, "%s %d", junk, &t);
|
| 281 |
|
| 282 |
int
|
| 283 |
init_mix (void)
|
| 284 |
{
|
| 285 |
FILE *fptr, *tmp;
|
| 286 |
char line[256], junk[256], *foo;
|
| 287 |
|
| 288 |
umask (077);
|
| 289 |
mix_dir[0] = 0;
|
| 290 |
strncat (mix_dir, SPOOL, sizeof (mix_dir) - 1);
|
| 291 |
/* environment variable replaces defined value */
|
| 292 |
if ((foo = getenv ("MIXPATH")) != NULL)
|
| 293 |
{
|
| 294 |
mix_dir[0] = 0;
|
| 295 |
strncat (mix_dir, foo, sizeof (mix_dir) - 1);
|
| 296 |
}
|
| 297 |
if (!getcwd (cur_dir, sizeof (cur_dir)))
|
| 298 |
{ /*could not get current dir */
|
| 299 |
fprintf (errlog, "Could not get current directory!\n");
|
| 300 |
strcpy (cur_dir, mix_dir);/* So set cur_dir to mix_dir */
|
| 301 |
}
|
| 302 |
if (cur_dir[strlen (cur_dir) - 1] != '/')
|
| 303 |
strcat (cur_dir, "/");
|
| 304 |
#ifdef MSDOS
|
| 305 |
atexit (cdcurdir);
|
| 306 |
#endif
|
| 307 |
if (mix_dir[0] == '\0')
|
| 308 |
{
|
| 309 |
if ((foo = getenv ("HOME")) != NULL) /* try ~/Mix */
|
| 310 |
{
|
| 311 |
strncat (mix_dir, foo, sizeof (mix_dir) - 1);
|
| 312 |
strncat (mix_dir, "/Mix", sizeof (mix_dir) - strlen (mix_dir) - 1);
|
| 313 |
}
|
| 314 |
}
|
| 315 |
if (!streq (SPOOL, mix_dir))
|
| 316 |
drop_mix_uid ();
|
| 317 |
if ((mix_dir[0] != '\0') && (chdir (mix_dir) != 0))
|
| 318 |
fprintf (errlog, "Error changing to directory %s.\n", mix_dir);
|
| 319 |
|
| 320 |
init_our_random ();
|
| 321 |
|
| 322 |
#ifdef MSDOS
|
| 323 |
strcpy (SENDMAIL, "outfile");
|
| 324 |
#endif
|
| 325 |
|
| 326 |
#ifdef SHORTNAMES
|
| 327 |
if ((fptr = (FILE *) try_open_mix_file ("mixmaster.conf", "r")) != NULL
|
| 328 |
|| (fptr = (FILE *) open_mix_file ("mixmaste.con", "r")) != NULL)
|
| 329 |
#else
|
| 330 |
if ((fptr = (FILE *) open_mix_file ("mixmaster.conf", "r")) != NULL)
|
| 331 |
#endif
|
| 332 |
{
|
| 333 |
while (getline (line, sizeof (line), fptr) != NULL)
|
| 334 |
{
|
| 335 |
if (line[0] != '#' && strlen (line) > 1)
|
| 336 |
{
|
| 337 |
if (strleft (line, "mix_dir"))
|
| 338 |
{
|
| 339 |
sscanf (line, "%s %s", junk, mix_dir);
|
| 340 |
if (chdir (mix_dir) != 0)
|
| 341 |
{
|
| 342 |
fprintf (errlog, "Error changing to mix_dir %s\n", mix_dir);
|
| 343 |
}
|
| 344 |
}
|
| 345 |
if (strncmp (line, "help", 4) == 0)
|
| 346 |
sscanf (line, "%s %s", junk, HELPFILE);
|
| 347 |
if (strncmp (line, "key", 3) == 0)
|
| 348 |
sscanf (line, "%s %s", junk, KEYFILE);
|
| 349 |
read_conf (KEYINFO);
|
| 350 |
read_conf (SHORTNAME);
|
| 351 |
read_conf (REMAILERADDR);
|
| 352 |
read_conf (ANONADDR);
|
| 353 |
read_conf_w (ANONNAME);
|
| 354 |
read_conf_w (REMAILERNAME);
|
| 355 |
read_conf_w (TYPE1);
|
| 356 |
read_conf_i (T1PGPONLY);
|
| 357 |
read_conf (COMPLAINTS);
|
| 358 |
read_conf_i (POOLSIZE);
|
| 359 |
read_conf_i (POOLTIMEOUT);
|
| 360 |
read_conf_i (RATE);
|
| 361 |
read_conf (REMAILERLIST);
|
| 362 |
read_conf (IDLOG);
|
| 363 |
read_conf (STATS);
|
| 364 |
read_conf (SECRING);
|
| 365 |
read_conf (PUBRING);
|
| 366 |
read_conf (SOURCEBLOCK);
|
| 367 |
read_conf (DESTALLOW);
|
| 368 |
read_conf (DESTBLOCK);
|
| 369 |
read_conf (HDRFILTER);
|
| 370 |
read_conf (MIXRAND);
|
| 371 |
read_conf (MAILtoNEWS);
|
| 372 |
read_conf_w (SENDMAIL);
|
| 373 |
read_conf_w (NEWS);
|
| 374 |
read_conf_w (ORGANIZATION);
|
| 375 |
read_conf (REQUIRE);
|
| 376 |
read_conf (REJECT);
|
| 377 |
read_conf_w (CHAIN);
|
| 378 |
read_conf_i (DISTANCE);
|
| 379 |
read_conf (RELLIST);
|
| 380 |
read_conf_w (FORWARDTO);
|
| 381 |
read_conf_i (MINREL);
|
| 382 |
read_conf_i (RELFINAL);
|
| 383 |
read_conf_i (MAXLAT);
|
| 384 |
read_conf_i (MINREMAILERS);
|
| 385 |
read_conf_i (NUMCOPIES);
|
| 386 |
read_conf_i (VERBOSE);
|
| 387 |
read_conf_i (CREATEKEYS);
|
| 388 |
read_conf_i (KEYVALIDITY);
|
| 389 |
read_conf_i (KEYOVERLAP);
|
| 390 |
read_conf_i (MIDDLEMAN);
|
| 391 |
read_conf_i (PACKETEXP);
|
| 392 |
read_conf_i (IDEXP);
|
| 393 |
read_conf_i (ERRSTDOUT);
|
| 394 |
} /* if not comment */
|
| 395 |
}
|
| 396 |
fclose (fptr);
|
| 397 |
}
|
| 398 |
if (ERRSTDOUT == 1)
|
| 399 |
errlog = stdout;
|
| 400 |
if (ANONNAME[0] == '\0')
|
| 401 |
strcpy (ANONNAME, REMAILERNAME);
|
| 402 |
if (ANONADDR[0] == '\0')
|
| 403 |
strcpy (ANONADDR, REMAILERADDR);
|
| 404 |
if (COMPLAINTS[0] == '\0')
|
| 405 |
strcpy (COMPLAINTS, REMAILERADDR);
|
| 406 |
if (strstr (NEWS, "mail-to-news"))
|
| 407 |
NEWS[0] = '\0';
|
| 408 |
else
|
| 409 |
MAILtoNEWS[0] = '\0';
|
| 410 |
/* middleman flag:
|
| 411 |
0 = normal remailer
|
| 412 |
1 = middle only remailer
|
| 413 |
2 = middleman (hidden remailer)
|
| 414 |
3 = middleman, remail intermediate hops */
|
| 415 |
if (MIDDLEMAN > 0)
|
| 416 |
MIDDLEMAN++;
|
| 417 |
else if ((tmp = try_open_mix_file (DESTALLOW, "r")) != NULL)
|
| 418 |
{
|
| 419 |
MIDDLEMAN = 1;
|
| 420 |
fclose (tmp);
|
| 421 |
}
|
| 422 |
if (IDEXP != 0 && IDEXP < 4 * 24)
|
| 423 |
IDEXP = 4 * 24;
|
| 424 |
return (0);
|
| 425 |
}
|
| 426 |
|
| 427 |
int
|
| 428 |
extract_type2_message (FILE * fptr, char *filename)
|
| 429 |
/* Fetch the next type2 message from the stream fptr.
|
| 430 |
* Place in a temporary file and return its file name in filename. */
|
| 431 |
{
|
| 432 |
char line[256];
|
| 433 |
FILE *temp_fptr;
|
| 434 |
|
| 435 |
strcpy (filename, "tmpM");
|
| 436 |
temp_fptr = tempfile (filename);
|
| 437 |
|
| 438 |
/* Find the first line of the type2 message */
|
| 439 |
while (getline (line, sizeof (line), fptr) != NULL)
|
| 440 |
{
|
| 441 |
if (streq (line, begin_remailer))
|
| 442 |
break;
|
| 443 |
}
|
| 444 |
|
| 445 |
if (!streq (line, begin_remailer))
|
| 446 |
{ /* did we find begin? */
|
| 447 |
fclose (temp_fptr);
|
| 448 |
unlink (filename);
|
| 449 |
return (0);
|
| 450 |
}
|
| 451 |
fprintf (temp_fptr, "%s\n", line); /* put begin remail line */
|
| 452 |
while (getline (line, sizeof (line), fptr) != NULL)
|
| 453 |
{
|
| 454 |
fprintf (temp_fptr, "%s\n", line);
|
| 455 |
if (streq (line, end_remailer))
|
| 456 |
break;
|
| 457 |
}
|
| 458 |
|
| 459 |
fclose (temp_fptr);
|
| 460 |
return 1;
|
| 461 |
}
|
| 462 |
|
| 463 |
void
|
| 464 |
help_files (int type, char *tmpfile)
|
| 465 |
{
|
| 466 |
char address[256], *outfile = "", line[256], *tmp;
|
| 467 |
FILE *fp, *pp;
|
| 468 |
|
| 469 |
get_from (tmpfile, address);
|
| 470 |
if (strlen (address) <= 1)
|
| 471 |
return;
|
| 472 |
|
| 473 |
switch (type)
|
| 474 |
{
|
| 475 |
case 100:
|
| 476 |
outfile = HELPFILE;
|
| 477 |
break;
|
| 478 |
case 101:
|
| 479 |
stats (FL_STATS, address);
|
| 480 |
return; /* send useage stats */
|
| 481 |
case 200:
|
| 482 |
outfile = KEYFILE;
|
| 483 |
break;
|
| 484 |
case 201:
|
| 485 |
abilities (address);
|
| 486 |
return;
|
| 487 |
}
|
| 488 |
if (strlen (outfile) > 1)
|
| 489 |
{
|
| 490 |
if ((fp = open_mix_file (outfile, "r")) == NULL)
|
| 491 |
return;
|
| 492 |
if ((pp = open_sendmail (MIDDLEMAN, &tmp)) == NULL)
|
| 493 |
return;
|
| 494 |
to (pp, address);
|
| 495 |
while (getline (line, sizeof (line), fp) != NULL)
|
| 496 |
fprintf (pp, "%s\n", line);
|
| 497 |
fclose (fp);
|
| 498 |
close_sendmail (pp, tmp);
|
| 499 |
}
|
| 500 |
}
|
| 501 |
|
| 502 |
int
|
| 503 |
kind_of_message (char *filename)
|
| 504 |
/*
|
| 505 |
Returns -1 if error
|
| 506 |
Returns 0 if not a remailer message
|
| 507 |
Returns 1 if normal remailer message
|
| 508 |
Returns 2 if a type 2 remailer
|
| 509 |
Returns 100 this is a request for the help file
|
| 510 |
Returns 101 this is a request for the remailer usage statistics
|
| 511 |
Returns 200 request for the remailer's public key
|
| 512 |
Returns 201 request for remailer configuration line (flags indicating
|
| 513 |
abilities)
|
| 514 |
*/
|
| 515 |
{
|
| 516 |
FILE *fptr, *block;
|
| 517 |
char line[256], *t, buff[256];
|
| 518 |
int type = 0;
|
| 519 |
|
| 520 |
if ((fptr = open_mix_file (filename, "r")) == NULL)
|
| 521 |
return (-1);
|
| 522 |
getline (line, sizeof (line), fptr);
|
| 523 |
while (line[0] != '\0' && line[0] != ':')
|
| 524 |
{
|
| 525 |
if (strileft (line, "Subject:"))
|
| 526 |
{
|
| 527 |
t = line + sizeof ("Subject:") - 1;
|
| 528 |
while (*t == ' ' || *t == '\t')
|
| 529 |
t++;
|
| 530 |
if (strieq (t, "help"))
|
| 531 |
type = 100;
|
| 532 |
if (strieq (t, "remailer-help"))
|
| 533 |
type = 100;
|
| 534 |
if (strieq (t, "remailer-stats"))
|
| 535 |
type = 101;
|
| 536 |
if (strieq (t, "remailer-key"))
|
| 537 |
type = 200;
|
| 538 |
if (strieq (t, "remailer-conf"))
|
| 539 |
type = 201;
|
| 540 |
if (strieq (t, "freedom-help") ||
|
| 541 |
strieq (t, "freedom-stats") ||
|
| 542 |
strieq (t, "freedom-key") ||
|
| 543 |
strieq (t, "freedom-conf"))
|
| 544 |
type = 1;
|
| 545 |
}
|
| 546 |
if (strileft (line, "encrypted:"))
|
| 547 |
type = 1;
|
| 548 |
if (!T1PGPONLY && (strileft (line, "anon-to:") ||
|
| 549 |
strileft (line, "request-remailing-to:") ||
|
| 550 |
strileft (line, "remail-to:") ||
|
| 551 |
strileft (line, "anon-post-to:") ||
|
| 552 |
strileft (line, "post-to:") ||
|
| 553 |
strileft (line, "anon-send-to:") ||
|
| 554 |
strileft (line, "send-to:")))
|
| 555 |
type = 1;
|
| 556 |
if (type != 0)
|
| 557 |
{
|
| 558 |
fclose (fptr);
|
| 559 |
return (type);
|
| 560 |
}
|
| 561 |
if (strileft (line, "From") || strileft (line, "Reply-To") ||
|
| 562 |
strileft (line, "Sender"))
|
| 563 |
{
|
| 564 |
if ((block = try_open_mix_file (SOURCEBLOCK, "r")) != NULL)
|
| 565 |
{
|
| 566 |
while (getline (buff, sizeof (buff), block) != NULL)
|
| 567 |
{
|
| 568 |
if (buff[0] == '#' || strlen (buff) < 1)
|
| 569 |
continue; /* skip blank lines */
|
| 570 |
if (rxmatch (line, buff))
|
| 571 |
{ /* if buff is in From line */
|
| 572 |
fclose (block);
|
| 573 |
fclose (fptr);
|
| 574 |
return (-1); /* blocked address treated as an error */
|
| 575 |
}
|
| 576 |
}
|
| 577 |
fclose (block);
|
| 578 |
}
|
| 579 |
else
|
| 580 |
fprintf (errlog, "Could not open %s.\n", SOURCEBLOCK);
|
| 581 |
}
|
| 582 |
if (getline (line, sizeof (line), fptr) == NULL)
|
| 583 |
break; /* scan for first blank line */
|
| 584 |
}
|
| 585 |
while (line[0] == '\0' && getline (line, sizeof (line), fptr) != NULL);
|
| 586 |
/*read in next line till not blank again */
|
| 587 |
if (strncmp (line, "::", 2) != 0)
|
| 588 |
{ /* if first non blank is not :: then
|
| 589 |
not a remailer message */
|
| 590 |
type = 0;
|
| 591 |
}
|
| 592 |
else
|
| 593 |
{ /* It is a remailer */
|
| 594 |
getline (line, sizeof (line), fptr);
|
| 595 |
if (strileft (line, "Remailer-Type:"))
|
| 596 |
/* All Type 2 messages start with this ... */
|
| 597 |
type = 2;
|
| 598 |
else if (T1PGPONLY && !strileft (line, "Encrypted:"))
|
| 599 |
type = 0; /* don't remail plaintext messages */
|
| 600 |
else
|
| 601 |
type = 1;
|
| 602 |
}
|
| 603 |
fclose (fptr);
|
| 604 |
return (type);
|
| 605 |
}
|
| 606 |
|
| 607 |
int
|
| 608 |
main (int argc, char *argv[])
|
| 609 |
{
|
| 610 |
FILE *fptr, *lockptr;
|
| 611 |
char tmpfile[80], tmpfile2[80];
|
| 612 |
int i, error, type;
|
| 613 |
int rem = 0, snd = 0, lat = 0, chain = 0, gen = 0, keymgt = 0;
|
| 614 |
int path = 0, type_list = 0, demon = 0, randseed = 0, queue = 0;
|
| 615 |
errlog = stderr;
|
| 616 |
|
| 617 |
init_mix ();
|
| 618 |
|
| 619 |
for (i = 1; i < argc; i++)
|
| 620 |
{
|
| 621 |
if (strchr (argv[i], '-') != NULL)
|
| 622 |
{
|
| 623 |
if (streq (argv[i], "-R"))
|
| 624 |
rem = 1;
|
| 625 |
if (streq (argv[i], "-r"))
|
| 626 |
rem = 1; /* some aliases don't allow caps */
|
| 627 |
if (streq (argv[i], "-S"))
|
| 628 |
snd = 1;
|
| 629 |
if (streq (argv[i], "-L"))
|
| 630 |
lat = 1;
|
| 631 |
if (streq (argv[i], "-G"))
|
| 632 |
gen = 1;
|
| 633 |
if (streq (argv[i], "-GD"))
|
| 634 |
gen = 2;
|
| 635 |
if (streq (argv[i], "-K"))
|
| 636 |
keymgt = 1;
|
| 637 |
if (streq (argv[i], "-P"))
|
| 638 |
path = 1;
|
| 639 |
if (streq (argv[i], "-T"))
|
| 640 |
type_list = 1;
|
| 641 |
if (streq (argv[i], "-D"))
|
| 642 |
demon = 1;
|
| 643 |
if (streq (argv[i], "-D1"))
|
| 644 |
demon = 2;
|
| 645 |
if (streq (argv[i], "-c"))
|
| 646 |
chain = 1;
|
| 647 |
if (streq (argv[i], "-X"))
|
| 648 |
randseed = 1;
|
| 649 |
if (streq (argv[i], "-Q"))
|
| 650 |
{
|
| 651 |
queue = 1;
|
| 652 |
if ((i + 1 < argc) && (argv[i + 1][0] != '-'))
|
| 653 |
queue_msg (argv[++i]);
|
| 654 |
else
|
| 655 |
queue_msg (NULL);
|
| 656 |
}
|
| 657 |
}
|
| 658 |
}
|
| 659 |
|
| 660 |
if (!rem && !snd && !lat && !gen && !keymgt && !path && !type_list && !demon && !randseed && !queue)
|
| 661 |
chain = 1;
|
| 662 |
|
| 663 |
if (path)
|
| 664 |
{
|
| 665 |
printf ("%s\n", mix_dir); /* note no trailing slash here */
|
| 666 |
printf ("%s\n", REMAILERLIST);
|
| 667 |
printf ("%s\n", VERSION);
|
| 668 |
}
|
| 669 |
if (type_list)
|
| 670 |
{
|
| 671 |
file_to_out (REMAILERLIST);
|
| 672 |
}
|
| 673 |
if (randseed)
|
| 674 |
{
|
| 675 |
get_randomness ();
|
| 676 |
}
|
| 677 |
if (chain)
|
| 678 |
{
|
| 679 |
chain_2 (argc, argv);
|
| 680 |
rem = snd = lat = 0; /* chain kills all others */
|
| 681 |
}
|
| 682 |
if (rem)
|
| 683 |
{
|
| 684 |
error = dump_to_file (tmpfile);
|
| 685 |
if (error == 0)
|
| 686 |
exit (1);
|
| 687 |
type = kind_of_message (tmpfile);
|
| 688 |
if (type == -1)
|
| 689 |
unlink (tmpfile);
|
| 690 |
if (type == 0)
|
| 691 |
{
|
| 692 |
file_to_out (tmpfile);
|
| 693 |
unlink (tmpfile);
|
| 694 |
}
|
| 695 |
if (type == 1)
|
| 696 |
{
|
| 697 |
if (strlen (TYPE1) > 1)
|
| 698 |
{ /* is there a type 1 handler defined */
|
| 699 |
type_1 (tmpfile);
|
| 700 |
stats (FL_MESSAGE | FL_OLD, NULL);
|
| 701 |
}
|
| 702 |
unlink (tmpfile);
|
| 703 |
}
|
| 704 |
if (type == 2)
|
| 705 |
{
|
| 706 |
/*
|
| 707 |
* changing this section to allow multiple Mixmaster
|
| 708 |
* Messages in one file going to Mixmaster
|
| 709 |
*/
|
| 710 |
#if 0
|
| 711 |
if (type_2 (tmpfile) == 0)
|
| 712 |
{
|
| 713 |
stats (FL_MESSAGE | FL_NEW, NULL); /* count one type 2 message */
|
| 714 |
}
|
| 715 |
unlink (tmpfile);
|
| 716 |
#endif
|
| 717 |
if ((fptr = open_mix_file (tmpfile, "r")) != NULL)
|
| 718 |
while (extract_type2_message (fptr, tmpfile2))
|
| 719 |
{
|
| 720 |
if (type_2 (tmpfile2) == 0)
|
| 721 |
{
|
| 722 |
stats (FL_MESSAGE | FL_NEW, NULL); /* count one type 2 message */
|
| 723 |
}
|
| 724 |
unlink (tmpfile2);
|
| 725 |
}
|
| 726 |
unlink (tmpfile);
|
| 727 |
}
|
| 728 |
if (type > 2)
|
| 729 |
{
|
| 730 |
help_files (type, tmpfile);
|
| 731 |
unlink (tmpfile);
|
| 732 |
}
|
| 733 |
}
|
| 734 |
if (snd)
|
| 735 |
{
|
| 736 |
if (process_pool () <= 0)
|
| 737 |
fprintf (errlog, "Error in sending mail from the pool!\n");
|
| 738 |
mix_lock ("mail", &lockptr);
|
| 739 |
packetID_housekeeping ();
|
| 740 |
process_partial ();
|
| 741 |
mix_unlock ("mail", lockptr);
|
| 742 |
}
|
| 743 |
if (gen == 2)
|
| 744 |
generate_DH ();
|
| 745 |
else if (gen)
|
| 746 |
{
|
| 747 |
generate_permanent_key ();
|
| 748 |
update_keys (NULL);
|
| 749 |
}
|
| 750 |
if (keymgt)
|
| 751 |
{
|
| 752 |
if (!isatty (fileno (stdin)))
|
| 753 |
update_keys (stdin); /* new keys */
|
| 754 |
else
|
| 755 |
update_keys (NULL);
|
| 756 |
}
|
| 757 |
if (lat)
|
| 758 |
{
|
| 759 |
mix_lock ("latent", &lockptr);
|
| 760 |
process_latent ();
|
| 761 |
mix_unlock ("latent", lockptr);
|
| 762 |
}
|
| 763 |
if (demon)
|
| 764 |
{
|
| 765 |
mix_server (demon);
|
| 766 |
}
|
| 767 |
close_our_random ();
|
| 768 |
|
| 769 |
return (0);
|
| 770 |
}
|