comparison cinst/mozilla.c @ 315:b832231640ab

Read from file instead of stdin, if given.
author Sascha Wilde <wilde@intevation.de>
date Fri, 04 Apr 2014 13:34:15 +0200
parents 4033c16beb04
children 46fd11699646
comparison
equal deleted inserted replaced
313:f17226aa2e09 315:b832231640ab
1 /** 1 /**
2 * @file 2 * @file
3 * @brief Mozilla installation process 3 * @brief Mozilla installation process
4 * 4 *
5 * Reads from stdin a list of instructions in the form: 5 * Reads from a file given on command line or stdin a list of
6 * instructions in the form:
6 * 7 *
7 * I:<base64 DER econded certificate> 8 * I:<base64 DER econded certificate>
8 * R:<base64 DER econded certificate> 9 * R:<base64 DER econded certificate>
9 * ... 10 * ...
10 * 11 *
553 * certificates in DER format. 554 * certificates in DER format.
554 * @param[inout] install_list list of SECItems with certifiactes to install 555 * @param[inout] install_list list of SECItems with certifiactes to install
555 * @param[inout] remove_list list of SECItems with certifiactes to remove 556 * @param[inout] remove_list list of SECItems with certifiactes to remove
556 */ 557 */
557 static void 558 static void
558 parse_commands (seciteml_t **install_list, seciteml_t **remove_list) 559 parse_commands (FILE *stream,
560 seciteml_t **install_list, seciteml_t **remove_list)
559 { 561 {
560 char inpl[LINEBUFLEN]; 562 char inpl[LINEBUFLEN];
561 size_t inpllen; 563 size_t inpllen;
562 bool parserr = true; 564 bool parserr = true;
563 SECItem secitem; 565 SECItem secitem;
564 566
565 while ( fgets(inpl, LINEBUFLEN, stdin) != NULL ) 567 while ( fgets(inpl, LINEBUFLEN, stream) != NULL )
566 { 568 {
567 inpllen = strnlen(inpl, LINEBUFLEN); 569 inpllen = strnlen(inpl, LINEBUFLEN);
568 /* Validate input line: 570 /* Validate input line:
569 * - must be (much) longer than 3 characters 571 * - must be (much) longer than 3 characters
570 * - must start with "*:" 572 * - must start with "*:"
607 } 609 }
608 } 610 }
609 611
610 612
611 int 613 int
612 main () 614 main (int argc, char **argv)
613 { 615 {
614 char **dbdirs; 616 char **dbdirs;
615 seciteml_t *certs_to_remove = NULL; 617 seciteml_t *certs_to_remove = NULL;
616 seciteml_t *certs_to_add = NULL; 618 seciteml_t *certs_to_add = NULL;
619 FILE *input_stream;
620
621 switch (argc)
622 {
623 case 1:
624 DEBUGPRINTF("Opening STDIN for input..\n.");
625 input_stream = stdin;
626 break;
627 case 2:
628 DEBUGPRINTF("Opening %s for input...\n", argv[1]);
629 if ((input_stream = fopen(argv[1], "r")) == NULL)
630 {
631 DEBUGPRINTF("FATAL: Could not open %s for reading!\n",
632 argv[1]);
633 return_code = ERR_MOZ_FAILED_TO_OPEN_INPUT;
634 goto exit;
635 }
636 break;
637 default:
638 DEBUGPRINTF("FATAL: Wrong number of arguments!\n");
639 return_code = ERR_MOZ_WRONG_ARGC;
640 goto exit;
641 }
617 642
618 dbdirs = 643 dbdirs =
619 get_all_nssdb_dirs(); 644 get_all_nssdb_dirs();
620 645
621 if (dbdirs != NULL) 646 if (dbdirs != NULL)
622 { 647 {
623 parse_commands(&certs_to_add, &certs_to_remove); 648 parse_commands(input_stream, &certs_to_add, &certs_to_remove);
624 649
625 #ifdef DEBUGOUTPUT 650 #ifdef DEBUGOUTPUT
626 DEBUGPRINTF("OLD List of installed certs:\n"); 651 DEBUGPRINTF("OLD List of installed certs:\n");
627 for (int i=0; dbdirs[i] != NULL; i++) 652 for (int i=0; dbdirs[i] != NULL; i++)
628 DEBUG_nss_list_certs(dbdirs[i]); 653 DEBUG_nss_list_certs(dbdirs[i]);
640 DEBUG_nss_list_certs(dbdirs[i]); 665 DEBUG_nss_list_certs(dbdirs[i]);
641 #endif 666 #endif
642 667
643 strv_free(dbdirs); 668 strv_free(dbdirs);
644 } 669 }
670
671 fclose(input_stream);
672
673 exit:
645 exit(return_code); 674 exit(return_code);
646 } 675 }

http://wald.intevation.org/projects/trustbridge/