/[pkg-mixmaster]/trunk/Mix/Src/main.c
ViewVC logotype

Contents of /trunk/Mix/Src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 988 - (hide annotations) (download)
Fri Mar 7 16:52:23 2008 UTC (5 years, 3 months ago) by colin
File MIME type: text/plain
File size: 22641 byte(s)
Move --config option up the help output so it's obvious that it's for both client and remailer use.
1 rabbi 934 /* Mixmaster version 3.0 -- (C) 1999 - 2006 Anonymizer Inc. and others.
2 rabbi 1
3     Mixmaster may be redistributed and modified under certain conditions.
4     This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5     ANY KIND, either express or implied. See the file COPYRIGHT for
6     details.
7    
8     Command-line based frontend
9 weasel 647 $Id$ */
10 rabbi 1
11    
12     #include "mix3.h"
13 rabbi 186 #include "pgp.h"
14 rabbi 1 #include <stdio.h>
15     #include <string.h>
16     #include <ctype.h>
17 weaselp 120 #include <stdlib.h>
18 rabbi 1 #ifdef POSIX
19     #include <unistd.h>
20 rabbi 262 #else /* end of POSIX */
21 rabbi 1 #include <io.h>
22 rabbi 262 #endif /* else if not POSIX */
23 weaselp 506 #include <assert.h>
24 rabbi 1
25     static char *largopt(char *p, char *opt, char *name, int *error);
26     static void noarg(char *name, char p);
27 weasel 924 static int check_get_pass(int force, int never_ask_for_passphrase);
28 rabbi 1
29     /** main *****************************************************************/
30    
31     /* Returns:
32     0 successful operation
33     1 command line error
34     2 client error condition */
35    
36 rabbi 30 #ifdef WIN32SERVICE
37     int mix_main(int argc, char *argv[])
38     #else
39 rabbi 1 int main(int argc, char *argv[])
40 rabbi 262 #endif /* WIN32SERVICE */
41 rabbi 1 {
42     int error = 0, deflt = 1, help = 0, readmail = 0, send = -1, sendpool = 0,
43 weasel 852 header = 1, maint = 0, keygen = 0, verbose = 0, sign = 0, encrypt = 0,
44 rabbi 771 redirect_mail = 0, about=0, version=0;
45 weaselp 177 int daemon = 0, type_list = 0, nodetach = 0;
46 weasel 852 int update_stats = 0, update_pingerlist = 0;
47 weasel 924 int never_ask_for_passphrase = 0;
48 rabbi 1
49     #ifdef USE_SOCK
50     int pop3 = 0;
51    
52 rabbi 262 #endif /* USE_SOCK */
53 rabbi 1 char *filename = NULL;
54     int i;
55     int ret = 0;
56     char *p, *q;
57     char chain[1024] = "";
58     char nym[LINELEN] = "";
59 weasel 852 BUFFER *nymopt, *pseudonym, *attachments, *statssrc;
60 rabbi 1 int numcopies = 0; /* default value set in mix.cfg */
61     BUFFER *msg, *chainlist, *field, *content;
62     FILE *f;
63 weasel 852 char pingpath[PATHMAX];
64 rabbi 1
65 weaselp 506 /* Check if parse_yearmonthday works */
66     assert(parse_yearmonthday("2003-04-01") == 1049155200);
67    
68 rabbi 1 mix_init(NULL);
69    
70     msg = buf_new();
71     chainlist = buf_new();
72     nymopt = buf_new();
73     pseudonym = buf_new();
74     attachments = buf_new();
75     field = buf_new();
76     content = buf_new();
77 weasel 852 statssrc = buf_new();
78 rabbi 1
79     #ifdef USE_NCURSES
80     if (argc == 1) {
81     if (isatty(fileno(stdin)))
82     menu_main();
83     else
84     menu_folder(0, NULL);
85 weaselp 498 goto clientpool;
86 rabbi 1 }
87 rabbi 262 #endif /* USE_NCURSES */
88 rabbi 1 if (argc > 1 && strleft(argv[1], "-f")) {
89 weasel 852 menu_folder(strlen(argv[1]) > 2 ? argv[1][2] : 0, argc < 3 ? NULL : argv[2]);
90 weaselp 498 goto clientpool;
91 rabbi 1 }
92     for (i = 1; i < argc; i++) {
93     p = argv[i];
94     if (p[0] == '-' && p[1] != '\0') {
95     if (p[1] == '-') {
96     p += 2;
97     if (strieq(p, "help"))
98     help = 1, deflt = 0;
99 weasel 852 else if (streq(p, "version"))
100     version = 1, deflt = 0;
101     else if (streq(p, "about"))
102     about = 1, deflt = 0;
103 rabbi 1 else if (streq(p, "verbose"))
104     verbose = 1;
105 weaselp 332 else if (streq(p, "type-list"))
106     type_list = 1;
107 rabbi 1 else if (streq(p, "dummy"))
108     send = MSG_NULL, deflt = 0;
109     else if (streq(p, "remailer"))
110     maint = 1, deflt = 0;
111     else if (streq(p, "generate-key"))
112     keygen = 2, deflt = 0;
113     else if (streq(p, "update-keys"))
114     keygen = 1, deflt = 0;
115     else if (streq(p, "send"))
116     sendpool = 1, deflt = 0;
117     else if (streq(p, "read-mail"))
118     readmail = 1, deflt = 0;
119 weaselp 512 else if (streq(p, "redirect"))
120     redirect_mail = 1, deflt = 0;
121 rabbi 147 else if (streq(p, "store-mail"))
122     readmail = 2, deflt = 0;
123 rabbi 1 #ifdef USE_SOCK
124     else if (streq(p, "pop-mail"))
125     pop3 = 1, deflt = 0;
126 rabbi 262 #endif /* USE_SOCK */
127 rabbi 1 else if (streq(p, "daemon"))
128     daemon = 1, deflt = 0;
129 weaselp 177 else if (streq(p, "no-detach"))
130     nodetach = 1;
131 rabbi 1 else if (streq(p, "post"))
132     send = MSG_POST;
133     else if (streq(p, "mail"))
134     send = MSG_MAIL;
135     else if (streq(p, "sign"))
136     sign = 1;
137     else if (streq(p, "encrypt"))
138     encrypt = 1;
139 weasel 924 else if (streq(p, "no-ask-passphrase"))
140     never_ask_for_passphrase = 1;
141 weasel 852 else if (streq(p, "update-pinger-list"))
142     update_pingerlist = 1;
143     else if (streq(p, "update-stats")) {
144     buf_clear(statssrc);
145     f = mix_openfile(STATSSRC, "r");
146     if (f != NULL) {
147     buf_read(statssrc, f);
148     fclose(f);
149     }
150     if (statssrc->length > 0) {
151     update_stats = 1;
152     } else {
153     deflt = 0;
154     fprintf(stderr, "%s: No current stats source --%s\n", argv[0], p);
155     }
156     } else if (strleft(p, "update-stats") && p[strlen("update-stats")] == '=') {
157     buf_clear(statssrc);
158     buf_appendf(statssrc, "%s", (p + strlen("update-stats") + 1));
159     if (statssrc->length > 0) {
160     update_stats = 1;
161     } else {
162     fprintf(stderr, "%s: No stats source specified --%s\n", argv[0], p);
163     }
164     } else if ((q = largopt(p, "to", argv[0], &error)) != NULL) {
165 rabbi 1 header = 0;
166     buf_appendf(msg, "To: %s\n", q);
167     } else if ((q = largopt(p, "post-to", argv[0], &error)) != NULL) {
168     send = MSG_POST, header = 0;
169     buf_appendf(msg, "Newsgroups: %s\n", q);
170     } else if ((q = largopt(p, "subject", argv[0], &error)) != NULL) {
171     buf_appendf(msg, "Subject: %s\n", q);
172     } else if ((q = largopt(p, "header", argv[0], &error)) != NULL) {
173     buf_appendf(msg, "%s\n", q);
174     } else if ((q = largopt(p, "chain", argv[0], &error)) != NULL) {
175     buf_appendf(msg, "Chain: %s\n", q);
176     }
177 weaselp 332 #ifdef USE_PGP
178 rabbi 1 else if ((q = largopt(p, "reply-chain", argv[0], &error)) != NULL) {
179     buf_appendf(msg, "Reply-Chain: %s\n", q);
180     } else if ((q = largopt(p, "latency", argv[0], &error)) != NULL) {
181     buf_appendf(msg, "Latency: %s\n", q);
182     } else if ((q = largopt(p, "attachment", argv[0], &error)) != NULL) {
183     buf_appendf(attachments, "%s\n", q);
184 weaselp 576 #ifdef NYMSUPPORT
185 rabbi 1 } else if ((q = largopt(p, "nym-config", argv[0], &error)) != NULL) {
186     deflt = 0;
187     strncpy(nym, q, sizeof(nym));
188     if (i > argc && strileft(argv[i + 1], "name="))
189     buf_sets(pseudonym, argv[++i] + 5);
190     else if (i > argc && strileft(argv[i + 1], "opt="))
191     buf_appends(nymopt, argv[++i] + 5);
192     } else if ((q = largopt(p, "nym", argv[0], &error)) != NULL) {
193     buf_appendf(msg, "Nym: %s\n", q);
194 weaselp 576 #endif /* NYMSUPPORT */
195 rabbi 1 }
196 rabbi 262 #endif /* USE_PGP */
197 rabbi 1 else if ((q = largopt(p, "copies", argv[0], &error)) != NULL) {
198     sscanf(q, "%d", &numcopies);
199 disastry 265 } else if ((q = largopt(p, "config", argv[0], &error)) != NULL) {
200     strncpy(MIXCONF, q, PATHMAX);
201     MIXCONF[PATHMAX-1] = 0;
202     mix_config(); /* configuration file changed - reread it */
203 rabbi 1 } else if (error == 0 && mix_configline(p) == 0) {
204     fprintf(stderr, "%s: Invalid option %s\n", argv[0], argv[i]);
205     error = 1;
206     }
207     } else {
208     while (*++p) {
209     switch (*p) {
210     case 'd':
211     send = MSG_NULL, deflt = 0;
212     break;
213     case 'R':
214     readmail = 1, deflt = 0;
215     break;
216 rabbi 147 case 'I':
217     readmail = 2, deflt = 0;
218     break;
219 rabbi 1 case 'S':
220     sendpool = 1, deflt = 0;
221     break;
222     case 'M':
223     maint = 1, deflt = 0;
224     break;
225     #ifdef USE_SOCK
226     case 'P':
227     pop3 = 1, deflt = 0;
228     break;
229 rabbi 262 #endif /* USE_SOCK */
230 rabbi 1 case 'D':
231     daemon = 1, deflt = 0;
232     break;
233     case 'G':
234     keygen = 2, deflt = 0;
235     break;
236     case 'K':
237     keygen = 1, deflt = 0;
238     break;
239     case 'L': /* backwards compatibility */
240     break;
241     case 'v':
242     verbose = 1;
243     break;
244     case 'h':
245     help = 1, deflt = 0;
246     break;
247     case 'T':
248     type_list = 1;
249     break;
250 weasel 852 case 'V':
251     version = 1, deflt = 0;
252     break;
253 rabbi 1 case 't':
254     if (*(p + 1) == 'o')
255     p++;
256     header = 0;
257     if (i < argc - 1)
258     buf_appendf(msg, "To: %s\n", argv[++i]);
259     else {
260 weasel 852 fprintf(stderr, "%s: Missing argument for option -to\n", argv[0]);
261 rabbi 1 error = 1;
262     }
263     break;
264     case 's':
265     if (i < argc - 1)
266     buf_appendf(msg, "Subject: %s\n", argv[++i]);
267     else {
268     noarg(argv[0], *p);
269     error = 1;
270     }
271     break;
272     case 'l':
273     if (i < argc - 1)
274     buf_appendf(msg, "Chain: %s\n", argv[++i]);
275     else {
276     noarg(argv[0], *p);
277     error = 1;
278     }
279     break;
280     case 'r':
281     if (i < argc - 1)
282 weaselp 120 buf_appendf(msg, "Reply-Chain: %s\n", argv[++i]);
283 rabbi 1 else {
284     noarg(argv[0], *p);
285     error = 1;
286     }
287     break;
288     #ifdef USE_PGP
289     case 'n':
290     if (i < argc - 1)
291     buf_appendf(msg, "Nym: %s\n", argv[++i]);
292     else {
293     noarg(argv[0], *p);
294     error = 1;
295     }
296     break;
297 rabbi 262 #endif /* USE_PGP */
298 rabbi 1 case 'c':
299     if (i < argc - 1)
300     sscanf(argv[++i], "%d", &numcopies);
301     else {
302     noarg(argv[0], *p);
303     error = 1;
304     }
305     break;
306     case 'p':
307     send = MSG_POST;
308     break;
309     case 'g':
310     if (i < argc - 1) {
311     send = MSG_POST, header = 0;
312     buf_appendf(msg, "Newsgroups: %s\n", argv[++i]);
313     } else {
314     noarg(argv[0], *p);
315     error = 1;
316     }
317 weaselp 69 break;
318 rabbi 1 case 'a':
319     if (i < argc - 1)
320     buf_appendf(attachments, "%s\n", argv[++i]);
321     else {
322     noarg(argv[0], *p);
323     error = 1;
324     }
325 weaselp 69 break;
326 rabbi 1 case 'm':
327     send = MSG_MAIL;
328     break;
329     default:
330     fprintf(stderr, "%s: Invalid option -%c\n", argv[0], *p);
331     error = 1;
332     break;
333     }
334     }
335     }
336     } else {
337     if (strchr(argv[i], '@')) {
338     header = 0;
339     buf_appendf(msg, "To: %s\n", argv[i]);
340     } else {
341     if (filename == NULL)
342     filename = argv[i];
343     else {
344     fprintf(stderr, "%s: Error in command line: %s\n", argv[0], argv[i]);
345     error = 1;
346     }
347     }
348     }
349     }
350    
351     if (error) {
352     ret = 1;
353     goto end;
354     }
355 colin 937
356 rabbi 1 if (type_list) {
357 weaselp 168 BUFFER *type2list;
358     type2list = buf_new();
359     if (prepare_type2list(type2list) < 0) {
360 rabbi 101 fprintf(stderr, "Cannot print type2.list.\n");
361     ret = 2;
362 weaselp 168 } else {
363     printf("%s", type2list->data);
364     };
365     buf_free(type2list);
366 rabbi 1 goto end;
367     }
368 colin 937
369 rabbi 771 if (version) {
370     printf("Mixmaster %s\n", VERSION);
371 weasel 852 ret = 0;
372 rabbi 771 goto end;
373     }
374 colin 937
375 weasel 852 if (update_pingerlist) {
376     mixfile(pingpath, ALLPINGERSFILE);
377     if (verbose) printf ("downloading %s...\n", ALLPINGERSURL);
378     if (url_download(ALLPINGERSURL, pingpath) < 0) {
379     printf(" Download failed... Try again later.\n");
380     errlog(ERRORMSG, "All Pingers File Download failed.\n");
381     } else {
382     if (verbose) printf(" Done.\n");
383     errlog(LOG, "All Pingers File Downloaded OK.\n");
384     }
385     ret = 0;
386     goto end;
387     }
388 colin 937
389 weasel 852 if (update_stats) {
390 colin 899 ret = download_stats(statssrc->data);
391     if (ret == -3) {
392 weasel 852 fprintf(stderr, "Stats source does not include all required files.\n");
393 colin 899 } else if (ret == -2) {
394     fprintf(stderr, "Could not open stats source file for writing\n");
395     } else if (ret == -1) {
396     fprintf(stderr, "Stats source download failed.\n");
397 weasel 852 }
398     ret = 0;
399     goto end;
400     }
401 colin 937
402     #ifdef USE_NCURSES
403     /* If we get here then it's possible we still want to use the NCURSES interface */
404     if (deflt && (send == -1) && isatty(fileno(stdin))) {
405     menu_main();
406     goto clientpool;
407     }
408     #endif /* USE_NCURSES */
409    
410 rabbi 771 if (help ||about ||(isatty(fileno(stdin)) && isatty(fileno(stdout))))
411 rabbi 770 fprintf(stderr, "Mixmaster %s\n", VERSION);
412 rabbi 771 if (help ||about)
413 rabbi 770 printf("\n\n");
414 rabbi 771 if (about) {
415 rabbi 770 printf("Many people have contributed to the source code for Mixmaster.\n");
416     printf("These contributors include:\n\n");
417 rabbi 921 printf("Lance Cottrell\n");
418 rabbi 770 printf("Janis Jagars\n");
419     printf("Ulf Moeller\n");
420     printf("Peter Palfrader\n");
421     printf("Len Sassaman\n");
422     printf("\nand others. For full information on copyright and license issues,\n");
423     printf("read the bundled file COPYRIGHT.\n\n");
424     ret = 0;
425 weasel 852 goto end;
426 rabbi 770 }
427 colin 937
428 rabbi 1 if (help) {
429     printf("Usage: %s [options] [user@host] [filename]\n\n", argv[0]);
430     printf("Options:\n\
431     \n\
432     -h, --help summary of command line options\n\
433 rabbi 770 -V, --version print version information\n\
434 rabbi 771 --about print authorship information\n\
435 colin 988 --config=file use alternate configuration file\n\
436 rabbi 1 -T, --type-list list available remailers\n\
437     -t, --to=user@host the recipient's address(es)\n\
438     -g, --post-to=newsgroup newsgroup(s) to post to\n\
439     -p, --post input is a Usenet article\n\
440     -m, --mail input is a mail message\n\
441     -s, --subject=subject message subject\n\
442     --header='header line' arbitrary message headers\n\
443     -a, --attachment=file attach a file\n"
444     #ifdef USE_PGP
445 weaselp 574 #ifdef NYMSUPPORT
446     "-n, --nym=yournym use pseudonym to send the message\n"
447     #endif /* NYMSUPPORT */
448 colin 925 " --encrypt encrypt the message using the PGP format\n\
449 rabbi 1 --sign sign the message using the PGP format\n"
450 rabbi 262 #endif /* USE_PGP */
451 rabbi 1 "-l, --chain=mix1,mix2,mix3,... specify a remailer chain\n\
452     -c, --copies=num send num copies to increase reliability\n\
453     -d, --dummy generate a dummy message\n\
454     -S, --send send the message(s) in the pool\n"
455     #ifdef USE_PGP
456 weaselp 575 #ifdef NYMSUPPORT
457 rabbi 1 " --nym-config=yournym generate a new pseudonym\n\
458     --latency=hours reply chain latency\n\
459     --reply-chain=rem1,rem2,... reply chain for the pseudonym\n"
460 weaselp 575 #endif /* NYMSUPPORT */
461 rabbi 262 #endif /* USE_PGP */
462 rabbi 1 "-v, --verbose output informational messages\n\
463 weasel 852 -f [file] read a mail folder\n\
464     --update-pinger-list Download an updated all pingers list file\n\
465     --update-stats[=source] Download updated stats\n"
466    
467 rabbi 1 #ifndef USE_NCURSES
468     "\n-fr, -ff, -fg [file] send reply/followup/group reply to a message\n"
469 rabbi 262 #endif /* USE_NCURSES */
470 rabbi 1 "\nThe input file is expected to contain mail headers if no address is\n\
471     specified in the command line.\n\
472     \n\
473     Remailer:\n\
474     \n\
475     -R, --read-mail read remailer message from stdin\n\
476 rabbi 147 -I, --store-mail read remailer msg from stdin, do not decrypt\n\
477 rabbi 1 -M, --remailer process the remailer pool\n\
478 weaselp 199 -D, --daemon remailer as background process\n\
479 weaselp 177 --no-detach do not detach from terminal as daemon\n"
480 rabbi 1 #ifdef USE_SOCK
481     "-S, --send force sending messages from the pool\n"
482 rabbi 262 #endif /* USE_SOCK */
483 rabbi 1 "-P, --pop-mail force getting messages from POP3 servers\n\
484     -G, --generate-key generate a new remailer key\n\
485 colin 988 -K, --update-keys generate remailer keys if necessary\n"
486 rabbi 30 #ifdef WIN32SERVICE
487     "\n\
488     WinNT service:\n\
489     \n\
490 rabbi 37 --install-svc install the service\n\
491     --remove-svc remove the service\n\
492     --run-svc run as a service\n"
493 rabbi 262 #endif /* WIN32SERVICE */
494 rabbi 30 );
495 rabbi 1
496     ret = 0;
497     goto end;
498     }
499 colin 937
500 rabbi 1 if (deflt && send == -1)
501     send = MSG_MAIL;
502     if (nym[0] != 0)
503     send = -1;
504     if ((send == MSG_MAIL || send == MSG_POST) && filename == NULL &&
505     header == 1 && isatty(fileno(stdin))) {
506     /* we don't get here if USE_NCURSES is set */
507     printf("Run `%s -h' to view a summary of the command line options.\n\nEnter the message, complete with headers.\n",
508     argv[0]);
509     #ifdef UNIX
510     printf("When done, press ^D.\n\n");
511     #else
512     printf("When done, press ^Z.\n\n");
513 rabbi 262 #endif /* else not UNIX */
514 rabbi 1 }
515     if (header == 0)
516     buf_nl(msg);
517    
518 weasel 700 /* timeskew check */
519     if (REMAIL == 1)
520     mix_check_timeskew();
521    
522 weaselp 512 if (readmail || redirect_mail || send == MSG_MAIL || send == MSG_POST) {
523 rabbi 1 if (filename == NULL || streq(filename, "-"))
524     f = stdin;
525     else {
526     f = fopen(filename, "r");
527     if (f == NULL)
528     fprintf(stderr, "Can't open %s.\n", filename);
529     }
530    
531     if (f && buf_read(msg, f) != -1) {
532 weaselp 194 if (readmail == 1) {
533 weasel 924 check_get_pass(1, never_ask_for_passphrase);
534 rabbi 1 mix_decrypt(msg);
535 weaselp 194 } else if (readmail == 2)
536 rabbi 147 pool_add(msg, "inf");
537 weaselp 512 if (send == MSG_MAIL || send == MSG_POST || redirect_mail) {
538 rabbi 1 BUFFER *sendmsg;
539     int numdest = 0;
540    
541     sendmsg = buf_new();
542    
543     while (buf_getheader(msg, field, content) == 0) {
544     if (bufieq(field, "nym")) {
545     strncpy(nym, content->data, sizeof(nym));
546     } else if (bufieq(field, "chain"))
547     if (strchr(content->data, ';')) {
548     i = strchr(content->data, ';') - (char *)content->data;
549     strncpy(chain, content->data, i);
550     if (strstr(content->data + i, "copies=") != NULL) {
551     sscanf(strstr(content->data + i, "copies=") +
552     sizeof("copies=") - 1, "%d", &numcopies);
553     }
554     } else
555     strncpy(chain, content->data, sizeof(chain));
556     else { /* line goes into message */
557 weaselp 512 if (((redirect_mail || send == MSG_MAIL) && bufieq(field, "to"))
558 rabbi 1 || (send == MSG_POST && bufieq(field, "newsgroups")))
559     numdest++;
560 weaselp 512 if (bufieq(field, "from") && !redirect_mail)
561 rabbi 1 fprintf(stderr, "Warning: The message has a From: line.\n");
562     buf_appendheader(sendmsg, field, content);
563     }
564     }
565     buf_nl(sendmsg);
566     buf_rest(sendmsg, msg);
567    
568     while (buf_getline(attachments, field) != -1)
569     if (attachfile(sendmsg, field) == -1) {
570     errlog(ERRORMSG, "Can't attach %b!\n", field);
571     ret = 2;
572     goto end;
573     }
574    
575     #ifdef USE_PGP
576     if (nym[0] != 0 && strchr(nym, '@') == NULL)
577     strcatn(nym, "@", sizeof(nym));
578     if (sign || encrypt) {
579     BUFFER *pass;
580    
581     pass = buf_new();
582     user_pass(pass);
583     if (pgp_mailenc((encrypt ? PGP_ENCRYPT : 0) |
584     (nym[0] != 0 && sign ? PGP_SIGN : 0) |
585     PGP_TEXT | PGP_REMAIL, sendmsg, nym,
586     pass, NULL, NYMSECRING) != 0) {
587     fprintf(stderr, "Encryption failed: missing key!");
588     ret = 2;
589     goto end;
590     }
591     buf_free(pass);
592     }
593     if (nym[0] != 0) {
594 weaselp 574 #ifdef NYMSUPPORT
595 rabbi 1 if (nym_encrypt(sendmsg, nym, send) == 0)
596     send = MSG_MAIL;
597     else
598 weaselp 574 #endif /* NYMSUPPORT */
599 rabbi 1 fprintf(stderr, "Nym error, sending message anonymously.\n");
600     }
601 rabbi 262 #endif /* USE_PGP */
602 rabbi 1 if (numdest == 0) {
603     fprintf(stderr, "No destination address given!\n");
604     ret = 2;
605     } else if (numcopies < 0 || numcopies > 10) {
606     fprintf(stderr, "Invalid number of copies!\n");
607     ret = 2;
608     } else {
609 weaselp 512 if ( ( redirect_mail ?
610     redirect_message(sendmsg, chain, numcopies, chainlist) :
611     mix_encrypt(send, sendmsg, chain, numcopies, chainlist)
612     ) == -1) {
613 rabbi 1 ret = 2;
614     if (chainlist->length)
615     fprintf(stderr, "%s\n", chainlist->data);
616     else
617     fprintf(stderr, "Failed!\n");
618     } else if (verbose) {
619     fprintf(stderr, "Chain: ");
620     buf_write(chainlist, stderr);
621     }
622     }
623    
624     buf_free(sendmsg);
625     }
626     if (filename != NULL)
627     fclose(f);
628     } else
629     ret = 2;
630     }
631     if (send == MSG_NULL) {
632     if (msg->length) {
633     while (buf_getheader(msg, field, content) == 0) {
634     if (bufieq(field, "chain"))
635     strncpy(chain, content->data, sizeof(chain));
636     }
637     }
638     if (mix_encrypt(MSG_NULL, NULL, chain, numcopies, chainlist) == -1) {
639     ret = 2;
640     if (chainlist->length)
641 weasel 852 printf("%s\n", chainlist->data);
642 rabbi 1 else
643     fprintf(stderr, "Failed!\n");
644     } else if (verbose) {
645 weasel 852 printf("Chain: ");
646     buf_write(chainlist, stdout);
647 rabbi 1 }
648     }
649     #ifdef USE_PGP
650 weaselp 574 #ifdef NYMSUPPORT
651 rabbi 1 if (nym[0] != 0) {
652     char nymserver[LINELEN] = "*";
653     BUFFER *chains;
654    
655     chains = buf_new();
656     if (numcopies < 1 || numcopies > 10)
657     numcopies = 1;
658     while (buf_getheader(msg, field, content) != -1) {
659     if (bufieq(field, "chain"))
660     strncpy(chain, content->data, sizeof(chain));
661     else if (bufieq(field, "reply-chain"))
662     buf_appendf(chains, "Chain: %b\n", content);
663     else if (field->length)
664     buf_appendheader(chains, field, content);
665     else
666     buf_nl(chains);
667     }
668 weaselp 120 if (strrchr(nym, '@')) {
669     strncpy(nymserver, strrchr(nym, '@'), sizeof(nymserver));
670     *strrchr(nym, '@') = '\0';
671 rabbi 1 }
672     if (nym_config(NYM_CREATE, nym, nymserver, pseudonym,
673     chain, numcopies, chains, nymopt) < 0) {
674     ret = 2;
675     fprintf(stderr, "Failed!\n");
676     }
677     user_delpass();
678     buf_free(chains);
679     }
680 weaselp 574 #endif /* NYMSUPPORT */
681 rabbi 262 #endif /* USE_PGP */
682 rabbi 1
683 weaselp 194 if (keygen) {
684 weasel 924 check_get_pass(0, never_ask_for_passphrase);
685 rabbi 1 keymgt(keygen);
686 weaselp 194 }
687 rabbi 1 if (sendpool)
688     mix_send();
689     #ifdef USE_SOCK
690     if (pop3)
691     pop3get();
692 rabbi 262 #endif /* USE_SOCK */
693 weaselp 194 if (maint) {
694 weasel 924 check_get_pass(1, never_ask_for_passphrase);
695 rabbi 1 mix_regular(0);
696 weaselp 194 }
697 rabbi 1
698 weaselp 498 clientpool:
699     if ((REMAIL == 0) && (CLIENTAUTOFLUSH == 1)) {
700     SENDPOOLTIME = 0;
701     RATE = 100;
702     mix_send();
703     };
704    
705 rabbi 1 end:
706     buf_free(field);
707     buf_free(content);
708     buf_free(chainlist);
709     buf_free(msg);
710     buf_free(nymopt);
711     buf_free(pseudonym);
712     buf_free(attachments);
713 weasel 852 buf_free(statssrc);
714 rabbi 1
715     if (daemon) {
716 weasel 924 check_get_pass(1, never_ask_for_passphrase);
717 rabbi 1 #ifdef UNIX
718 rabbi 186 if (! nodetach) {
719     int pid;
720 rabbi 1
721 weaselp 177 fprintf(stderr, "Detaching.\n");
722     /* Detach as suggested by the Unix Programming FAQ */
723     pid = fork();
724     if (pid > 0)
725     exit(0);
726     if (setsid() < 0) {
727     /* This should never happen. */
728     fprintf(stderr, "setsid() failed.\n");
729     exit(1);
730 weaselp 124 };
731 weaselp 177 pid = fork();
732     if (pid > 0)
733     exit(0);
734 weaselp 358 };
735     if (chdir(MIXDIR) < 0) {
736     if (chdir("/") < 0) {
737     fprintf(stderr, "Cannot chdir to mixdir or /.\n");
738     exit(1);
739 weaselp 177 };
740 weaselp 352 };
741     if (write_pidfile(PIDFILE)) {
742     fprintf(stderr, "Aborting.\n");
743     exit(1);
744     }
745     if (! nodetach) {
746 weaselp 177 freopen ("/dev/null", "r", stdin);
747     freopen ("/dev/null", "w", stdout);
748     freopen ("/dev/null", "w", stderr);
749     }
750 rabbi 262 #endif /* UNIX */
751 rabbi 1 mix_daemon();
752 weaselp 332 #ifdef UNIX
753 weasel 852 /* ifdef this one too, so that we do not need to export it from windows dll */
754 weaselp 197 clear_pidfile(PIDFILE);
755 rabbi 262 #endif /* UNIX */
756 rabbi 1 }
757     mix_exit();
758     return (ret);
759     }
760    
761     static char *largopt(char *p, char *opt, char *name, int *error)
762     {
763     if (streq(p, opt)) {
764     fprintf(stderr, "%s: Missing argument for option --%s\n", name, p);
765     *error = 1;
766     } else if (strleft(p, opt) && p[strlen(opt)] == '=') {
767     return (p + strlen(opt) + 1);
768     }
769     return (NULL);
770     }
771    
772     static void noarg(char *name, char p)
773     {
774     fprintf(stderr, "%s: Missing argument for option -%c\n", name, p);
775     }
776 weaselp 194
777 weasel 924 static int check_get_pass(int force, int never_ask_for_passphrase)
778 weaselp 194 /* get a passphrase and check against keys
779 rabbi 262 * if force != 0 passphrase must match with some key */
780 weaselp 194 {
781     BUFFER *pass, *pass2, *key;
782     int n = 0;
783    
784 weasel 924 if (PASSPHRASE[0] == '\0' && isatty(fileno(stdin)) && ! never_ask_for_passphrase) {
785 weaselp 196 pass = buf_new();
786     pass2 = buf_new();
787     key = buf_new();
788     buf_sets(pass, PASSPHRASE);
789 weaselp 579 while (
790     #ifdef USE_PGP
791     pgpdb_getkey(PK_DECRYPT, PGP_ES_RSA, NULL, NULL, NULL, NULL, NULL,
792 weaselp 196 NULL, NULL, NULL, pass) < 0 &&
793 disastry 254 pgpdb_getkey(PK_DECRYPT, PGP_E_ELG, NULL, NULL, NULL, NULL, NULL,
794 weaselp 196 NULL, NULL, NULL, pass) < 0 &&
795 weaselp 579 #endif /* USE_PGP */
796 weaselp 196 getv2seckey(NULL, key) < 0)
797     {
798     user_delpass();
799     if (n)
800     fprintf(stderr, "re-");
801     user_pass(pass);
802     strncpy(PASSPHRASE, pass->data, LINELEN);
803     PASSPHRASE[LINELEN-1] = 0;
804     if (!force) {
805     if (n && buf_eq(pass, pass2))
806     break;
807     buf_set(pass2, pass);
808     }
809     n=1;
810     }
811     user_delpass();
812     buf_free(pass);
813     buf_free(pass2);
814     buf_free(key);
815 weaselp 194
816 weaselp 196 strncpy(ENTEREDPASSPHRASE, PASSPHRASE, LINELEN);
817     ENTEREDPASSPHRASE[LINELEN-1] = 0;
818 weaselp 194 }
819     return 1;
820     }

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.5