8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 21:23:04 +01:00

Fixed CORE-5134: Samples of dbcrypt-related plugins contain references to internal files

This commit is contained in:
alexpeshkoff 2016-03-11 15:11:04 +00:00
parent 13bb1d3bd8
commit 0e32c78489
5 changed files with 55 additions and 55 deletions

View File

@ -24,13 +24,7 @@
* Contributor(s): ______________________________________. * Contributor(s): ______________________________________.
*/ */
#include <stdio.h> #include "../interfaces/ifaceExamples.h"
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <ibase.h>
#include <firebird/Interface.h>
using namespace Firebird; using namespace Firebird;

View File

@ -24,18 +24,7 @@
* Contributor(s): ______________________________________. * Contributor(s): ______________________________________.
*/ */
#include <stdio.h> #include "../interfaces/ifaceExamples.h"
#include <string.h>
#include <stdint.h>
#include "ibase.h"
#include "firebird/Interface.h"
#include "firebird.h" // Needed for atomic support
#include "../common/classes/fb_atomic.h"
using namespace Firebird;
namespace namespace
{ {
@ -129,7 +118,7 @@ public:
return owner; return owner;
} }
UCHAR getKey() ISC_UCHAR getKey()
{ {
return key; return key;
} }
@ -144,7 +133,7 @@ private:
unsigned int callback(unsigned int, const void*, unsigned int length, void* buffer) unsigned int callback(unsigned int, const void*, unsigned int length, void* buffer)
{ {
UCHAR k = holder->getKey(); ISC_UCHAR k = holder->getKey();
if (!k) if (!k)
{ {
return 0; return 0;
@ -164,7 +153,7 @@ private:
class NamedCallback : public ICryptKeyCallbackImpl<NamedCallback, CheckStatusWrapper> class NamedCallback : public ICryptKeyCallbackImpl<NamedCallback, CheckStatusWrapper>
{ {
public: public:
NamedCallback(NamedCallback* n, const char* nm, UCHAR k) NamedCallback(NamedCallback* n, const char* nm, ISC_UCHAR k)
: next(n), key(k) : next(n), key(k)
{ {
strncpy(name, nm, sizeof(name)); strncpy(name, nm, sizeof(name));
@ -184,16 +173,16 @@ private:
char name[32]; char name[32];
NamedCallback* next; NamedCallback* next;
UCHAR key; ISC_UCHAR key;
}; };
CallbackInterface callbackInterface; CallbackInterface callbackInterface;
NamedCallback *named; NamedCallback *named;
IPluginConfig* config; IPluginConfig* config;
UCHAR key; ISC_UCHAR key;
AtomicCounter refCounter; FbSampleAtomic refCounter;
IReferenceCounted* owner; IReferenceCounted* owner;
IConfigEntry* getEntry(CheckStatusWrapper* status, const char* entryName); IConfigEntry* getEntry(CheckStatusWrapper* status, const char* entryName);
@ -265,7 +254,7 @@ ICryptKeyCallback* CryptKeyHolder::keyHandle(CheckStatusWrapper* status, const c
confEntry->release(); confEntry->release();
if (k > 0 && k < 256) if (k > 0 && k < 256)
{ {
named = new NamedCallback(named, keyName, static_cast<UCHAR>(k)); named = new NamedCallback(named, keyName, static_cast<ISC_UCHAR>(k));
return named; return named;
} }
} }

View File

@ -24,13 +24,7 @@
* Contributor(s): ______________________________________. * Contributor(s): ______________________________________.
*/ */
#include <stdint.h> #include "../interfaces/ifaceExamples.h"
#include "ibase.h"
#include "firebird/Interface.h"
#include "firebird.h" // Needed for atomic support
#include "../common/classes/fb_atomic.h"
using namespace Firebird; using namespace Firebird;
@ -131,9 +125,9 @@ public:
private: private:
IPluginConfig* config; IPluginConfig* config;
char savedKeyName[32]; char savedKeyName[32];
UCHAR key; ISC_UCHAR key;
AtomicCounter refCounter; FbSampleAtomic refCounter;
IReferenceCounted* owner; IReferenceCounted* owner;
void noKeyError(CheckStatusWrapper* status); void noKeyError(CheckStatusWrapper* status);
@ -169,8 +163,8 @@ void DbCrypt::encrypt(CheckStatusWrapper* status, unsigned int length, const voi
return; return;
} }
const UCHAR* f = static_cast<const UCHAR*>(from); const ISC_UCHAR* f = static_cast<const ISC_UCHAR*>(from);
UCHAR* t = static_cast<UCHAR*>(to); ISC_UCHAR* t = static_cast<ISC_UCHAR*>(to);
while (length--) while (length--)
{ {
@ -188,8 +182,8 @@ void DbCrypt::decrypt(CheckStatusWrapper* status, unsigned int length, const voi
return; return;
} }
const UCHAR* f = static_cast<const UCHAR*>(from); const ISC_UCHAR* f = static_cast<const ISC_UCHAR*>(from);
UCHAR* t = static_cast<UCHAR*>(to); ISC_UCHAR* t = static_cast<ISC_UCHAR*>(to);
while (length--) while (length--)
{ {

View File

@ -66,10 +66,13 @@ private:
} }
}; };
FbSampleAtomic referenceCounter;
public: public:
unsigned offset, nullOffset, length; unsigned offset, nullOffset, length;
MyMetadata() MyMetadata()
: referenceCounter(0)
{ {
IUtil* utl = master->getUtilInterface(); IUtil* utl = master->getUtilInterface();
ThrowStatusWrapper s(master->getStatus()); ThrowStatusWrapper s(master->getStatus());
@ -86,16 +89,17 @@ public:
s.dispose(); s.dispose();
} }
// Dummy IReferenceCounted implementation
// JUST a SAMPLE - interface will be placed on stack, ignore reference counts !!!
// In real life please use your favorite atomic incr/decr here
// and create reference counted interfaces on heap.
void addRef() void addRef()
{ } {
++referenceCounter;
}
int release() int release()
{ {
return 1; int rc = --referenceCounter;
if (!rc)
delete this;
return rc;
} }
// IMessageMetadata implementation // IMessageMetadata implementation
@ -200,15 +204,17 @@ int main()
IAttachment* att = NULL; IAttachment* att = NULL;
ITransaction* tra = NULL; ITransaction* tra = NULL;
IResultSet* curs = NULL; IResultSet* curs = NULL;
MyMetadata* meta = NULL;
// Instance of our metadata
MyMetadata meta;
// allocate output buffer
buffer = new unsigned char[meta.length];
try try
{ {
// Instance of our metadata
meta = new MyMetadata;
meta->addRef();
// allocate output buffer
buffer = new unsigned char[meta->length];
// attach employee db // attach employee db
att = prov->attachDatabase(&status, "employee", 0, NULL); att = prov->attachDatabase(&status, "employee", 0, NULL);
@ -216,12 +222,12 @@ int main()
tra = att->startTransaction(&status, 0, NULL); tra = att->startTransaction(&status, 0, NULL);
// open cursor // open cursor
curs = att->openCursor(&status, tra, 0, "select current_user from rdb$database", 3, NULL, NULL, &meta, NULL, 0); curs = att->openCursor(&status, tra, 0, "select current_user from rdb$database", 3, NULL, NULL, meta, NULL, 0);
// fetch record from cursor and print it // fetch record from cursor and print it
curs->fetchNext(&status, buffer); curs->fetchNext(&status, buffer);
ISC_SHORT l = to<ISC_SHORT>(buffer, meta.offset); ISC_SHORT l = to<ISC_SHORT>(buffer, meta->offset);
printf("<%*.*s>\n", l, l, buffer + meta.offset + sizeof(ISC_SHORT)); printf("<%*.*s>\n", l, l, buffer + meta->offset + sizeof(ISC_SHORT));
// close interfaces // close interfaces
curs->close(&status); curs->close(&status);
@ -251,9 +257,11 @@ int main()
if (att) if (att)
att->release(); att->release();
// generic cleanup
if (meta)
meta->release();
prov->release(); prov->release();
status.dispose(); status.dispose();
delete[] buffer; delete[] buffer;
return rc; return rc;

View File

@ -28,7 +28,22 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#include <atomic>
typedef std::atomic_int FbSampleAtomic;
#else
typedef int FbSampleAtomic;
#endif
#include <ibase.h> #include <ibase.h>
#include <firebird/Interface.h> #include <firebird/Interface.h>
#if defined(_WIN32)
#define FB_DLL_EXPORT __declspec(dllexport)
#elif defined(__APPLE__)
#define FB_DLL_EXPORT __attribute__((visibility("default")))
#else
#define FB_DLL_EXPORT
#endif
using namespace Firebird; using namespace Firebird;