8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:40:38 +01:00

Fixed support of maps with same hash value

This commit is contained in:
alexpeshkoff 2014-05-06 10:07:08 +00:00
parent da1e63df21
commit 148f60aa94
2 changed files with 34 additions and 19 deletions

View File

@ -145,6 +145,12 @@ namespace Firebird
return nextElement;
}
C* next(const K& key)
{
Entry* e = next();
return (e && e->isEqual(key)) ? e->get() : NULL;
}
virtual bool isEqual(const K&) const = 0;
virtual C* get() = 0;
}; // class Entry
@ -154,11 +160,13 @@ namespace Firebird
public:
explicit Hash(MemoryPool&)
: duplicates(false)
{
clean();
}
Hash()
: duplicates(false)
{
clean();
}
@ -184,8 +192,14 @@ namespace Firebird
}
}
void enableDuplicates(bool mode)
{
duplicates = mode;
}
private:
Entry* data[HASHSIZE];
bool duplicates;
Entry** locate(const K& key, size_t h)
{
@ -213,7 +227,7 @@ namespace Firebird
bool add(C* value)
{
Entry** e = locate(KeyOfValue::generate(*value));
if (*e)
if ((!duplicates) && (*e))
{
return false; // sorry, duplicate
}

View File

@ -54,7 +54,7 @@
#define getpid _getpid
#endif
#define MAP_DEBUG(A)
#define MAP_DEBUG(A) A
using namespace Firebird;
@ -231,7 +231,9 @@ class Cache : public MapHash, public GlobalStorage
public:
Cache(const NoCaseString& aliasDb, const NoCaseString& db)
: alias(getPool(), aliasDb), name(getPool(), db), dataFlag(false)
{ }
{
enableDuplicates(true);
}
void populate(IAttachment *att)
{
@ -359,24 +361,23 @@ public:
if (!dataFlag)
return;
Map* to = lookup(from);
if (! to)
return;
for (Map* to = lookup(from); to; to = to->next(from))
{
MAP_DEBUG(fprintf(stderr, "Match!!\n"));
unsigned flagRole = to->toRole ? FLAG_ROLE : FLAG_USER;
if (info.found & flagRole)
continue;
if (info.current & flagRole)
(Arg::Gds(isc_map_multi) << originalUserName).raise();
MAP_DEBUG(fprintf(stderr, "Match!!\n"));
unsigned flagRole = to->toRole ? FLAG_ROLE : FLAG_USER;
if (info.found & flagRole)
return;
if (info.current & flagRole)
(Arg::Gds(isc_map_multi) << originalUserName).raise();
info.current |= flagRole;
info.current |= flagRole;
AuthReader::Info newInfo;
newInfo.type = to->toRole ? NM_ROLE : NM_USER;
newInfo.name = to->to == "*" ? originalUserName : to->to;
newInfo.secDb = this->name;
newBlock.add(newInfo);
AuthReader::Info newInfo;
newInfo.type = to->toRole ? NM_ROLE : NM_USER;
newInfo.name = to->to == "*" ? originalUserName : to->to;
newInfo.secDb = this->name;
newBlock.add(newInfo);
}
}
void varPlugin(AuthReader::Info& info, Map from, AuthWriter& newBlock)