| 542 | } |
| 543 | |
| 544 | void CryptoManager::prepareChangeCryptState(thread_db* tdbb, const MetaName& plugName, |
| 545 | const MetaName& key) |
| 546 | { |
| 547 | if (plugName.length() > MAX_PLUGIN_NAME_LEN) |
| 548 | { |
| 549 | (Arg::Gds(isc_cp_name_too_long) << Arg::Num(MAX_PLUGIN_NAME_LEN)).raise(); |
| 550 | } |
| 551 | |
| 552 | const bool newCryptState = plugName.hasData(); |
| 553 | |
| 554 | int bak_state = Ods::hdr_nbak_unknown; |
| 555 | { // scope |
| 556 | BackupManager::StateReadGuard stateGuard(tdbb); |
| 557 | bak_state = dbb.dbb_backup_manager->getState(); |
| 558 | } |
| 559 | |
| 560 | { // window scope |
| 561 | CchHdr hdr(tdbb, LCK_read); |
| 562 | |
| 563 | // Check header page for flags |
| 564 | if (hdr->hdr_flags & Ods::hdr_crypt_process) |
| 565 | { |
| 566 | (Arg::Gds(isc_cp_process_active)).raise(); |
| 567 | } |
| 568 | |
| 569 | bool headerCryptState = hdr->hdr_flags & Ods::hdr_encrypted; |
| 570 | if (headerCryptState == newCryptState) |
| 571 | { |
| 572 | (Arg::Gds(isc_cp_already_crypted)).raise(); |
| 573 | } |
| 574 | |
| 575 | if (bak_state != Ods::hdr_nbak_normal) |
| 576 | { |
| 577 | (Arg::Gds(isc_wish_list) << Arg::Gds(isc_random) << |
| 578 | "Cannot crypt: please wait for nbackup completion").raise(); |
| 579 | } |
| 580 | |
| 581 | // Load plugin |
| 582 | if (newCryptState) |
| 583 | { |
| 584 | if (cryptPlugin) |
| 585 | { |
| 586 | if (!headerCryptState) |
| 587 | { |
| 588 | // unload old plugin |
| 589 | PluginManagerInterfacePtr()->releasePlugin(cryptPlugin); |
| 590 | cryptPlugin = NULL; |
| 591 | } |
| 592 | else |
| 593 | Arg::Gds(isc_cp_already_crypted).raise(); |
| 594 | } |
| 595 | |
| 596 | keyName = key; |
| 597 | loadPlugin(tdbb, plugName.c_str()); |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 |
nothing calls this directly
no test coverage detected