Skip to content

Commit 03b615b

Browse files
MochalovAlexeyAlexeyMochalov
authored andcommitted
remove redundant plugin reload on super server, update it only on classic after stateLock ast (#8393)
Co-authored-by: aleksey.mochalov <[email protected]>
1 parent a0aa292 commit 03b615b

File tree

2 files changed

+18
-49
lines changed

2 files changed

+18
-49
lines changed

src/jrd/CryptoManager.cpp

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ namespace Jrd {
367367
return;
368368

369369
fb_assert(tdbb);
370-
lockAndReadHeader(tdbb, CRYPT_HDR_NOWAIT);
370+
lockAndReadHeader(tdbb, CRYPT_HDR_NOWAIT | CRYPT_RELOAD_PLUGIN);
371371
}
372372

373373
void CryptoManager::lockAndReadHeader(thread_db* tdbb, unsigned flags)
@@ -407,9 +407,15 @@ namespace Jrd {
407407
crypt = hdr->hdr_flags & Ods::hdr_encrypted;
408408
process = hdr->hdr_flags & Ods::hdr_crypt_process;
409409

410+
if (flags & CRYPT_RELOAD_PLUGIN && cryptPlugin)
411+
{
412+
PluginManagerInterfacePtr()->releasePlugin(cryptPlugin);
413+
cryptPlugin = NULL;
414+
}
415+
410416
// tdbb w/o attachment comes when database is shutting down in the end of detachDatabase()
411417
// the only needed here page is header, i.e. we can live w/o cryptPlugin
412-
if ((crypt || process) && tdbb->getAttachment())
418+
if ((crypt || process) && !cryptPlugin && tdbb->getAttachment())
413419
{
414420
ClumpletWriter hc(ClumpletWriter::UnTagged, hdr->hdr_page_size);
415421
hdr.getClumplets(hc);
@@ -418,56 +424,18 @@ namespace Jrd {
418424
else
419425
keyName = "";
420426

421-
if (!cryptPlugin)
427+
loadPlugin(tdbb, hdr->hdr_crypt_plugin);
428+
pluginName = hdr->hdr_crypt_plugin;
429+
string valid;
430+
calcValidation(valid, cryptPlugin);
431+
if (hc.find(Ods::HDR_crypt_hash))
422432
{
423-
loadPlugin(tdbb, hdr->hdr_crypt_plugin);
424-
pluginName = hdr->hdr_crypt_plugin;
425-
string valid;
426-
calcValidation(valid, cryptPlugin);
427-
if (hc.find(Ods::HDR_crypt_hash))
428-
{
429-
hc.getString(hash);
430-
if (hash != valid)
431-
(Arg::Gds(isc_bad_crypt_key) << keyName).raise();
432-
}
433-
else
434-
hash = valid;
433+
hc.getString(hash);
434+
if (hash != valid)
435+
(Arg::Gds(isc_bad_crypt_key) << keyName).raise();
435436
}
436437
else
437-
{
438-
for (GetPlugins<IKeyHolderPlugin> keyControl(IPluginManager::TYPE_KEY_HOLDER, dbb.dbb_config);
439-
keyControl.hasData(); keyControl.next())
440-
{
441-
// check does keyHolder want to provide a key for us
442-
IKeyHolderPlugin* keyHolder = keyControl.plugin();
443-
444-
FbLocalStatus st;
445-
int keyCallbackRc = keyHolder->keyCallback(&st, tdbb->getAttachment()->att_crypt_callback);
446-
st.check();
447-
if (!keyCallbackRc)
448-
continue;
449-
450-
// validate a key
451-
AutoPlugin<IDbCryptPlugin> crypt(checkFactory->makeInstance());
452-
setDbInfo(crypt);
453-
crypt->setKey(&st, 1, &keyHolder, keyName.c_str());
454-
455-
456-
string valid;
457-
calcValidation(valid, crypt);
458-
if (hc.find(Ods::HDR_crypt_hash))
459-
{
460-
hc.getString(hash);
461-
if (hash == valid)
462-
{
463-
// unload old plugin and set new one
464-
PluginManagerInterfacePtr()->releasePlugin(cryptPlugin);
465-
cryptPlugin = NULL;
466-
cryptPlugin = crypt.release();
467-
}
468-
}
469-
}
470-
}
438+
hash = valid;
471439
}
472440

473441
if (cryptPlugin && (flags & CRYPT_HDR_INIT))

src/jrd/CryptoManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class CryptoManager final : public Firebird::PermanentStorage, public BarSync::I
364364
void lockAndReadHeader(thread_db* tdbb, unsigned flags = 0);
365365
static const unsigned CRYPT_HDR_INIT = 0x01;
366366
static const unsigned CRYPT_HDR_NOWAIT = 0x02;
367+
static const unsigned CRYPT_RELOAD_PLUGIN = 0x04;
367368

368369
void addClumplet(Firebird::string& value, Firebird::ClumpletReader& block, UCHAR tag);
369370
void calcDigitalSignature(thread_db* tdbb, Firebird::string& signature, const class Header& hdr);

0 commit comments

Comments
 (0)