MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / changeCryptState

Method changeCryptState

src/jrd/CryptoManager.cpp:624–791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

622 }
623
624 void CryptoManager::changeCryptState(thread_db* tdbb, const string& plugName)
625 {
626 if (plugName.length() > 31)
627 {
628 (Arg::Gds(isc_cp_name_too_long) << Arg::Num(31)).raise();
629 }
630
631 const bool newCryptState = plugName.hasData();
632
633 try
634 {
635 // Create local copy of existing attachments
636 Sync dSync(&dbb.dbb_sync, FB_FUNCTION);
637 dSync.lock(SYNC_EXCLUSIVE);
638
639 AttachmentsRefHolder existing;
640 {
641 MutexLockGuard g(holdersMutex, FB_FUNCTION);
642 for (Attachment* att = dbb.dbb_attachments; att; att = att->att_next)
643 existing.add(att->getStable());
644 }
645
646 dSync.unlock();
647
648 // Disable cache I/O
649 BarSync::LockGuard writeGuard(tdbb, sync);
650
651 // header scope
652 CchHdr hdr(tdbb, LCK_write);
653 writeGuard.lock();
654
655 // Nbak's lock was taken in prepareChangeCryptState()
656 // If it was invalidated it's enough reason not to continue now
657 int bak_state = dbb.dbb_backup_manager->getState();
658 if (bak_state != Ods::hdr_nbak_normal)
659 {
660 (Arg::Gds(isc_wish_list) << Arg::Gds(isc_random) <<
661 "Cannot crypt: please wait for nbackup completion").raise();
662 }
663
664 // Check header page for flags
665 if (hdr->hdr_flags & Ods::hdr_crypt_process)
666 {
667 (Arg::Gds(isc_cp_process_active)).raise();
668 }
669
670 bool headerCryptState = hdr->hdr_flags & Ods::hdr_encrypted;
671 if (headerCryptState == newCryptState)
672 {
673 (Arg::Gds(isc_cp_already_crypted)).raise();
674 }
675
676 fb_assert(stateLock);
677 // Trigger lock on ChangeCryptState
678 if (!LCK_convert(tdbb, stateLock, CRYPT_CHANGE, LCK_WAIT))
679 {
680 fb_assert(tdbb->tdbb_status_vector->getState() & IStatus::STATE_ERRORS);
681 ERR_punt();

Callers

nothing calls this directly

Calls 15

GdsClass · 0.85
NumClass · 0.85
LCK_convertFunction · 0.85
ERR_puntFunction · 0.85
init_statusFunction · 0.85
LCK_read_dataFunction · 0.85
LCK_write_dataFunction · 0.85
getClumpletsMethod · 0.80
deleteWithTagMethod · 0.80
pluginMethod · 0.80
makeInstanceMethod · 0.80
setClumpletsMethod · 0.80

Tested by

no test coverage detected