8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:03:02 +01:00

Make sample of key holder plugin partially usable when chaining plugins

This commit is contained in:
AlexPeshkoff 2020-10-26 19:43:20 +03:00
parent ff37d445ce
commit c851e3d421
2 changed files with 31 additions and 6 deletions

View File

@ -29,6 +29,8 @@
namespace namespace
{ {
IMaster* master = NULL;
class PluginModule : public IPluginModuleImpl<PluginModule, CheckStatusWrapper> class PluginModule : public IPluginModuleImpl<PluginModule, CheckStatusWrapper>
{ {
public: public:
@ -66,7 +68,8 @@ class CryptKeyHolder : public IKeyHolderPluginImpl<CryptKeyHolder, CheckStatusWr
{ {
public: public:
explicit CryptKeyHolder(IPluginConfig* cnf) throw() explicit CryptKeyHolder(IPluginConfig* cnf) throw()
: callbackInterface(this), named(NULL), config(cnf), key(0), owner(NULL) : callbackInterface(this), named(NULL), tempStatus(master->getStatus()),
config(cnf), key(0), owner(NULL)
{ {
config->addRef(); config->addRef();
} }
@ -74,6 +77,7 @@ public:
~CryptKeyHolder() ~CryptKeyHolder()
{ {
config->release(); config->release();
tempStatus.dispose();
} }
// IKeyHolderPlugin implementation // IKeyHolderPlugin implementation
@ -108,6 +112,9 @@ public:
ISC_UCHAR getKey() ISC_UCHAR getKey()
{ {
if (!key)
keyCallback(&tempStatus, NULL);
return key; return key;
} }
@ -177,6 +184,7 @@ private:
CallbackInterface callbackInterface; CallbackInterface callbackInterface;
NamedCallback *named; NamedCallback *named;
CheckStatusWrapper tempStatus;
IPluginConfig* config; IPluginConfig* config;
ISC_UCHAR key; ISC_UCHAR key;
@ -212,9 +220,18 @@ int CryptKeyHolder::keyCallback(CheckStatusWrapper* status, ICryptKeyCallback* c
{ {
FB_BOOLEAN b = confEntry->getBoolValue(); FB_BOOLEAN b = confEntry->getBoolValue();
confEntry->release(); confEntry->release();
if (b) if (b)
{ {
key = 0x5a; confEntry = getEntry(status, "Key");
if (confEntry)
{
key = confEntry->getIntValue();
confEntry->release();
}
else
key = 0x5a;
return 1; return 1;
} }
} }
@ -281,8 +298,9 @@ Factory factory;
} // anonymous namespace } // anonymous namespace
extern "C" void FB_DLL_EXPORT FB_PLUGIN_ENTRY_POINT(IMaster* master) extern "C" void FB_DLL_EXPORT FB_PLUGIN_ENTRY_POINT(IMaster* m)
{ {
master = m;
IPluginManager* pluginManager = master->getPluginManager(); IPluginManager* pluginManager = master->getPluginManager();
module.registerMe(pluginManager); module.registerMe(pluginManager);

View File

@ -5,10 +5,18 @@
# Key{Name} - integer value, a key with name "Name" (i.e. when one issues "ALTER DATABASE ENCRYPT ... # Key - integer value, a key used to "encrypt" database (i.e. when one issues "ALTER DATABASE ENCRYPT ..."
# KEY Doggy" configuration parameter KeyDoggy should be present). # without KEY clause configuration parameter Key is used). This key can be passed from client to server
by the chain of sample key holders.
#Key = 90 #Key = 90
# Key{Name} - integer value, a key with name "Name" (i.e. when one issues "ALTER DATABASE ENCRYPT ...
# KEY Doggy" configuration parameter KeyDoggy should be present). Such keys can not be passed from client
# to server.
#KeyDoggy = [0 - 255] #KeyDoggy = [0 - 255]
@ -19,4 +27,3 @@
#OnlyOwnKey = true #OnlyOwnKey = true