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

Contents of /branches/Mix-stats/Src/main.c

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.5