comparison cinst/mozilla.c @ 279:cb5f082e90c5

Factor out the iteration over profiles and certs.
author Sascha Wilde <wilde@intevation.de>
date Wed, 02 Apr 2014 13:46:19 +0200
parents 539c856cb5da
children 6c4b3ff4a356
comparison
equal deleted inserted replaced
278:539c856cb5da 279:cb5f082e90c5
466 else 466 else
467 { 467 {
468 DEBUGPRINTF("Could not open nss certificate store in %s!\n", pdir); 468 DEBUGPRINTF("Could not open nss certificate store in %s!\n", pdir);
469 } 469 }
470 free(cert_name); 470 free(cert_name);
471 return success;
472 }
473
474 /**
475 * @brief Apply a function to a list of certificates and profiles
476 *
477 * The function must have the signature:
478 *
479 * bool function(char *pdir, SECItem der_cert)
480 *
481 * where pdir is the path of an profile and der_cert is an raw DER
482 * formatted certificate. The function must return true on success
483 * and false on failure.
484 *
485 * This function is intended wor use with the import_cert and
486 * remove_cert functions.
487 *
488 * @param[in] fn the function to apply
489 * @param[inout] certs a secitem list holding the certificates
490 * the list will be change (emptied)!
491 * @param[in] pdirs the NULL terminated list of profile directories
492 * @returns true on success and false on failure
493 */
494 bool
495 apply_to_certs_and_profiles(bool fn(char *, SECItem *),
496 seciteml_t **certs, char **pdirs)
497 {
498 SECItem *cert;
499 bool success = true;
500
501 while ((cert = seciteml_pop(certs)) != NULL)
502 {
503 for (int i=0; pdirs[i] != NULL; i++)
504 {
505 if (! (*fn)(pdirs[i], cert))
506 success = false;
507 }
508 free(cert->data);
509 free(cert);
510 }
511
471 return success; 512 return success;
472 } 513 }
473 514
474 /** 515 /**
475 * @brief Parse IPC commands from standard input. 516 * @brief Parse IPC commands from standard input.
538 main () 579 main ()
539 { 580 {
540 char **pdirs; 581 char **pdirs;
541 seciteml_t *certs_to_remove = NULL; 582 seciteml_t *certs_to_remove = NULL;
542 seciteml_t *certs_to_add = NULL; 583 seciteml_t *certs_to_add = NULL;
543 SECItem *secitemp;
544 584
545 pdirs = 585 pdirs =
546 get_all_profile_dirs(); 586 get_all_profile_dirs();
547 587
548 if (pdirs != NULL) 588 if (pdirs != NULL)
549 { 589 {
550 parse_commands(&certs_to_add, &certs_to_remove); 590 parse_commands(&certs_to_add, &certs_to_remove);
551 591
552 while ((secitemp = seciteml_pop(&certs_to_remove)) != NULL) 592 puts("OLD List of installed certs:");
553 { 593 for (int i=0; pdirs[i] != NULL; i++)
554 for (int i=0; pdirs[i] != NULL; i++) 594 nss_list_certs(pdirs[i]);
555 { 595
556 puts(pdirs[i]); 596 if (! apply_to_certs_and_profiles(remove_cert, &certs_to_remove, pdirs))
557 if (! remove_cert(pdirs[i], secitemp)) 597 return_code |= WARN_MOZ_COULD_NOT_REMOVE_CERT;
558 return_code |= WARN_MOZ_COULD_NOT_REMOVE_CERT; 598
559 puts("List of installed certs:"); 599 if (! apply_to_certs_and_profiles(import_cert, &certs_to_add, pdirs))
560 nss_list_certs(pdirs[i]); 600 return_code |= WARN_MOZ_COULD_NOT_ADD_CERT;
561 } 601
562 free(secitemp->data); 602 puts("NEW List of installed certs:");
563 free(secitemp); 603 for (int i=0; pdirs[i] != NULL; i++)
564 } 604 nss_list_certs(pdirs[i]);
565 605
566 while ((secitemp = seciteml_pop(&certs_to_add)) != NULL)
567 {
568 for (int i=0; pdirs[i] != NULL; i++)
569 {
570 puts(pdirs[i]);
571 if (! import_cert(pdirs[i], secitemp))
572 return_code |= WARN_MOZ_COULD_NOT_ADD_CERT;
573 nss_list_certs(pdirs[i]);
574 }
575 free(secitemp->data);
576 free(secitemp);
577 }
578
579 strv_free(pdirs); 606 strv_free(pdirs);
580 } 607 }
581 exit(return_code); 608 exit(return_code);
582 } 609 }

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