2727 */
2828
2929#include " firebird.h"
30+ #include < utility>
3031#include " firebird/Interface.h"
3132#include " ../auth/SecureRemotePassword/Message.h"
3233#include " iberror.h"
@@ -61,20 +62,20 @@ using namespace Jrd;
6162namespace {
6263
6364// internalFlags bits
64- const ULONG FLAG_DB = 1 ;
65- const ULONG FLAG_SEC = 2 ;
66- const ULONG FLAG_DOWN_DB = 4 ;
67- const ULONG FLAG_DOWN_SEC = 8 ;
65+ constexpr ULONG FLAG_DB = 1 ;
66+ constexpr ULONG FLAG_SEC = 2 ;
67+ constexpr ULONG FLAG_DOWN_DB = 4 ;
68+ constexpr ULONG FLAG_DOWN_SEC = 8 ;
6869
6970// flagRolUsr values
70- const ULONG FLAG_USER = 1 ;
71- const ULONG FLAG_ROLE = 2 ;
71+ constexpr ULONG FLAG_USER = 1 ;
72+ constexpr ULONG FLAG_ROLE = 2 ;
7273
73- const char * NM_ROLE = " Role" ;
74- const char * NM_USER = " User" ;
75- const char * TYPE_SEEN = " Seen" ;
74+ constexpr const char * NM_ROLE = " Role" ;
75+ constexpr const char * NM_USER = " User" ;
76+ constexpr const char * TYPE_SEEN = " Seen" ;
7677
77- void check (const char * s, IStatus* st)
78+ void check (const char * s, const IStatus* st)
7879{
7980 if (!(st->getState () & IStatus::STATE_ERRORS))
8081 return ;
@@ -154,7 +155,7 @@ class AuthWriter : public ClumpletWriter
154155} // namespace Jrd
155156
156157
157- Mapping::DbHandle::DbHandle ()
158+ Mapping::DbHandle::DbHandle () noexcept
158159{ }
159160
160161void Mapping::DbHandle::setAttachment (IAttachment* att)
@@ -204,7 +205,7 @@ bool Mapping::DbHandle::attach(const char* aliasDb, ICryptKeyCallback* cryptCb)
204205 {
205206 const ISC_STATUS* s = st->getErrors ();
206207 MAP_DEBUG (isc_print_status (s));
207- bool missing = fb_utils::containsErrorCode (s, isc_io_error);
208+ const bool missing = fb_utils::containsErrorCode (s, isc_io_error);
208209 down = fb_utils::containsErrorCode (s, isc_shutdown);
209210 if (!(missing || down))
210211 check (" IProvider::attachDatabase" , &st);
@@ -440,7 +441,7 @@ void Mapping::Cache::search(ExtInfo& info, const Map& from, AuthWriter& newBlock
440441 for (Map* to = lookup (from); to; to = to->next (from))
441442 {
442443 MAP_DEBUG (fprintf (stderr, " Match!!\n " ));
443- unsigned flagRolUsr = to->toRole ? FLAG_ROLE : FLAG_USER;
444+ const unsigned flagRolUsr = to->toRole ? FLAG_ROLE : FLAG_USER;
444445 if (info.found & flagRolUsr)
445446 continue ;
446447
@@ -536,11 +537,11 @@ bool Mapping::Cache::map4(bool flagWild, unsigned flagSet, AuthReader& rdr, ExtI
536537 newBlock.append (workBlock);
537538 }
538539
539- unsigned mapMask = FLAG_USER | FLAG_ROLE;
540+ constexpr unsigned mapMask = FLAG_USER | FLAG_ROLE;
540541 return (info.found & mapMask) == mapMask;
541542}
542543
543- void Mapping::Cache::eraseEntry (Map* m)
544+ void Mapping::Cache::eraseEntry (Map* m) noexcept
544545{
545546 delete m;
546547}
@@ -575,7 +576,7 @@ class Found
575576public:
576577 enum What {FND_NOTHING, FND_PLUG, FND_SEC, FND_DB};
577578
578- Found ()
579+ Found () noexcept
579580 : found(FND_NOTHING)
580581 { }
581582
@@ -615,7 +616,7 @@ void resetMap(const char* securityDb, ULONG index);
615616
616617// ----------------------------------------------------
617618
618- class MappingHeader : public Firebird ::MemoryHeader
619+ class MappingHeader final : public Firebird::MemoryHeader
619620{
620621public:
621622 SLONG currentProcess;
@@ -632,14 +633,14 @@ class MappingHeader : public Firebird::MemoryHeader
632633 };
633634 Process process[1 ];
634635
635- static const ULONG FLAG_ACTIVE = 0x1 ;
636- static const ULONG FLAG_DELIVER = 0x2 ;
636+ static constexpr ULONG FLAG_ACTIVE = 0x1 ;
637+ static constexpr ULONG FLAG_DELIVER = 0x2 ;
637638};
638639
639640class MappingIpc final : public Firebird::IpcObject
640641{
641- static const USHORT MAPPING_VERSION = 1 ;
642- static const size_t DEFAULT_SIZE = 1024 * 1024 ;
642+ static constexpr USHORT MAPPING_VERSION = 1 ;
643+ static constexpr size_t DEFAULT_SIZE = 1024 * 1024 ;
643644
644645public:
645646 explicit MappingIpc (MemoryPool&)
@@ -652,6 +653,10 @@ class MappingIpc final : public Firebird::IpcObject
652653 shutdown ();
653654 }
654655
656+ // copying is prohibited
657+ MappingIpc (const MappingIpc&) = delete;
658+ MappingIpc& operator =(const MappingIpc&) = delete;
659+
655660 void shutdown ()
656661 {
657662 if (!sharedMemory)
@@ -667,8 +672,7 @@ class MappingIpc final : public Firebird::IpcObject
667672 fb_assert (sMem ->process [process].id );
668673 sMem ->process [process].flags &= ~MappingHeader::FLAG_ACTIVE;
669674
670- (void ) // Ignore errors in cleanup
671- sharedMemory->eventPost (&sMem ->process [process].notifyEvent );
675+ std::ignore = sharedMemory->eventPost (&sMem ->process [process].notifyEvent );
672676
673677 cleanupSync.waitForCompletion ();
674678
@@ -707,7 +711,7 @@ class MappingIpc final : public Firebird::IpcObject
707711 sMem ->currentProcess = -1 ;
708712 for (unsigned n = 0 ; n < sMem ->processes ; ++n)
709713 {
710- MappingHeader::Process* p = &sMem ->process [n];
714+ const MappingHeader::Process* p = &sMem ->process [n];
711715 if (!(p->flags & MappingHeader::FLAG_ACTIVE))
712716 continue ;
713717
@@ -741,7 +745,7 @@ class MappingIpc final : public Firebird::IpcObject
741745 continue ;
742746 }
743747
744- SLONG value = sharedMemory->eventClear (¤t->callbackEvent );
748+ const SLONG value = sharedMemory->eventClear (¤t->callbackEvent );
745749 p->flags |= MappingHeader::FLAG_DELIVER;
746750
747751 if (sharedMemory->eventPost (&p->notifyEvent ) != FB_SUCCESS)
@@ -876,7 +880,7 @@ class MappingIpc final : public Firebird::IpcObject
876880 MappingHeader::Process* p = &sharedMemory->getHeader ()->process [process];
877881 while (p->flags & MappingHeader::FLAG_ACTIVE)
878882 {
879- SLONG value = sharedMemory->eventClear (&p->notifyEvent );
883+ const SLONG value = sharedMemory->eventClear (&p->notifyEvent );
880884
881885 if (p->flags & MappingHeader::FLAG_DELIVER)
882886 {
@@ -938,10 +942,6 @@ class MappingIpc final : public Firebird::IpcObject
938942 USHORT getVersion () const override { return MAPPING_VERSION; }
939943 const char * getName () const override { return " MappingIpc" ; }
940944
941- // copying is prohibited
942- MappingIpc (const MappingIpc&);
943- MappingIpc& operator =(const MappingIpc&);
944-
945945 class Guard ;
946946 friend class Guard ;
947947 typedef SharedMemory<MappingHeader> MappingSharedMemory;
@@ -969,10 +969,10 @@ class MappingIpc final : public Firebird::IpcObject
969969 data->mutexUnlock ();
970970 }
971971
972- private:
973- Guard (const Guard&);
974- Guard& operator =(const Guard&);
972+ Guard (const Guard&) = delete ;
973+ Guard& operator =(const Guard&) = delete ;
975974
975+ private:
976976 MappingSharedMemory* const data;
977977 };
978978
@@ -984,7 +984,7 @@ class MappingIpc final : public Firebird::IpcObject
984984 AutoSharedMemory sharedMemory;
985985 Mutex initMutex;
986986 const SLONG processId;
987- unsigned process;
987+ unsigned process = 0 ;
988988 Semaphore startupSemaphore;
989989 ThreadFinishSync<MappingIpc*> cleanupSync;
990990};
@@ -996,7 +996,7 @@ void setupIpc()
996996 mappingIpc->setup ();
997997}
998998
999- const char * roleSql =
999+ constexpr const char * roleSql =
10001000" with recursive role_tree as ( "
10011001" select rdb$role_name as nm from system.rdb$roles "
10021002" where rdb$role_name = ? "
@@ -1008,7 +1008,7 @@ const char* roleSql =
10081008" join system.rdb$roles r on t.nm = r.rdb$role_name "
10091009 ;
10101010
1011- const char * userSql =
1011+ constexpr const char * userSql =
10121012" with recursive role_tree as ( "
10131013" select rdb$relation_name as nm from system.rdb$user_privileges "
10141014" where rdb$privilege = 'M' and rdb$field_name = 'D' and rdb$user = ? and rdb$user_type = 8 "
@@ -1028,7 +1028,7 @@ class SysPrivCache : public PermanentStorage
10281028 databases (getPool())
10291029 { }
10301030
1031- SyncObject* getSync ()
1031+ SyncObject* getSync () noexcept
10321032 {
10331033 return &sync;
10341034 }
@@ -1112,7 +1112,7 @@ class SysPrivCache : public PermanentStorage
11121112 }
11131113
11141114 private:
1115- class NameCache : private GenericMap <Pair<Left<string, UserId::Privileges> > >
1115+ class NameCache final : private GenericMap<Pair<Left<string, UserId::Privileges> > >
11161116 {
11171117 public:
11181118 NameCache (MemoryPool& p, const char * s)
@@ -1153,7 +1153,7 @@ class SysPrivCache : public PermanentStorage
11531153
11541154 RefPtr<IMessageMetadata> meta (curs->getMetadata (&st));
11551155 AutoPtr<UCHAR, ArrayDelete> buffer (FB_NEW UCHAR[meta->getMessageLength (&st)]);
1156- UCHAR* bits = buffer + meta->getOffset (&st, 0 );
1156+ const UCHAR* bits = buffer + meta->getOffset (&st, 0 );
11571157 UserId::Privileges g, l;
11581158
11591159 while (curs->fetchNext (&st, buffer) == IStatus::RESULT_OK)
@@ -1180,9 +1180,9 @@ class SysPrivCache : public PermanentStorage
11801180 const char * sql;
11811181 };
11821182
1183- class RoleCache : private GenericMap <Pair<Full<string, string> > >
1183+ class RoleCache final : private GenericMap<Pair<Full<string, string> > >
11841184 {
1185- static const char ROLESEP = ' \1 ' ;
1185+ static constexpr char ROLESEP = ' \1 ' ;
11861186
11871187 public:
11881188 RoleCache (MemoryPool& p)
@@ -1197,7 +1197,7 @@ class SysPrivCache : public PermanentStorage
11971197 return true ;
11981198 }
11991199
1200- string* r = get (name);
1200+ const string* r = get (name);
12011201 if (!r)
12021202 return false ;
12031203
@@ -1228,7 +1228,7 @@ class SysPrivCache : public PermanentStorage
12281228 Message cols;
12291229 Field<Varying> role (cols, MAX_SQL_IDENTIFIER_SIZE);
12301230
1231- const char * sql = " select RDB$RELATION_NAME from SYSTEM.RDB$USER_PRIVILEGES "
1231+ constexpr const char * sql = " select RDB$RELATION_NAME from SYSTEM.RDB$USER_PRIVILEGES "
12321232 " where RDB$USER = ? and RDB$PRIVILEGE = 'M' and RDB$USER_TYPE = 8 and RDB$OBJECT_TYPE = 13" ;
12331233
12341234 RefPtr<IResultSet> curs (REF_NO_INCR, iDb->openCursor (&st, tra, 0 , sql, 3 ,
@@ -1335,25 +1335,25 @@ bool Mapping::ensureCachePresence(RefPtr<Mapping::Cache>& cache, const char* ali
13351335}
13361336
13371337
1338- void Mapping::needAuthMethod (Firebird::string& method)
1338+ void Mapping::needAuthMethod (Firebird::string& method) noexcept
13391339{
13401340 fb_assert (!authMethod);
13411341 authMethod = &method;
13421342}
13431343
1344- void Mapping::needAuthBlock (Firebird::AuthReader::AuthBlock& block)
1344+ void Mapping::needAuthBlock (Firebird::AuthReader::AuthBlock& block) noexcept
13451345{
13461346 fb_assert (!newAuthBlock);
13471347 newAuthBlock = █
13481348}
13491349
1350- void Mapping::needSystemPrivileges (UserId::Privileges& privileges)
1350+ void Mapping::needSystemPrivileges (UserId::Privileges& privileges) noexcept
13511351{
13521352 fb_assert (!systemPrivileges);
13531353 systemPrivileges = &privileges;
13541354}
13551355
1356- void Mapping::setAuthBlock (const Firebird::AuthReader::AuthBlock& block)
1356+ void Mapping::setAuthBlock (const Firebird::AuthReader::AuthBlock& block) noexcept
13571357{
13581358 fb_assert (!authBlock);
13591359 authBlock = █
@@ -1389,7 +1389,7 @@ void Mapping::setInternalFlags()
13891389 }
13901390}
13911391
1392- void Mapping::setSqlRole (const Firebird::string& role)
1392+ void Mapping::setSqlRole (const Firebird::string& role) noexcept
13931393{
13941394 fb_assert (!sqlRole);
13951395 sqlRole = &role;
@@ -1445,7 +1445,7 @@ void Mapping::setSecurityDbAlias(const char* a, const char* mainExpandedName)
14451445 }
14461446}
14471447
1448- void Mapping::setErrorMessagesContextName (const char * context)
1448+ void Mapping::setErrorMessagesContextName (const char * context) noexcept
14491449{
14501450 errorMessagesContext = context;
14511451}
@@ -1527,7 +1527,8 @@ ULONG Mapping::mapUser(string& name, string& trustedRole)
15271527 newBlock.add (info);
15281528 }
15291529
1530- newBlock.append (*authBlock);
1530+ if (authBlock)
1531+ newBlock.append (*authBlock);
15311532
15321533 Found fName , fRole ;
15331534 MAP_DEBUG (fprintf (stderr, " Starting newblock scan\n " ));
@@ -1536,7 +1537,7 @@ ULONG Mapping::mapUser(string& name, string& trustedRole)
15361537 MAP_DEBUG (fprintf (stderr, " Newblock info: secDb=%s plugin=%s type=%s name=%s origPlug=%s\n " ,
15371538 info.secDb .c_str (), info.plugin .c_str (), info.type .c_str (), info.name .c_str (), info.origPlug .c_str ()));
15381539
1539- Found::What recordWeight =
1540+ const Found::What recordWeight =
15401541 (mainDb && info.secDb == mainDb) ? Found::FND_DB :
15411542 (securityAlias && info.secDb == secExpanded.c_str ()) ? Found::FND_SEC :
15421543 Found::FND_NOTHING;
@@ -1683,7 +1684,7 @@ RecordBuffer* MappingList::makeBuffer(thread_db* tdbb)
16831684 return getData (rel_global_auth_mapping);
16841685}
16851686
1686- RecordBuffer* MappingList::getList (thread_db* tdbb, jrd_rel* relation)
1687+ RecordBuffer* MappingList::getList (thread_db* tdbb, const jrd_rel* relation)
16871688{
16881689 fb_assert (relation);
16891690 fb_assert (relation->rel_id == rel_global_auth_mapping);
@@ -1802,7 +1803,7 @@ RecordBuffer* MappingList::getList(thread_db* tdbb, jrd_rel* relation)
18021803
18031804 if (!role.null )
18041805 {
1805- SINT64 v = role;
1806+ const SINT64 v = role;
18061807 putField (tdbb, record,
18071808 DumpField (f_sec_map_to_type, VALUE_INTEGER, sizeof (v), &v));
18081809 }
@@ -1818,7 +1819,7 @@ RecordBuffer* MappingList::getList(thread_db* tdbb, jrd_rel* relation)
18181819 RefPtr<IBlob> blb (REF_NO_INCR, att->openBlob (&st, tra, &desc, 0 , nullptr ));
18191820 check (" IAttachment::openBlob" , &st);
18201821 string buf;
1821- const FB_SIZE_T FLD_LIMIT = MAX_COLUMN_SIZE;
1822+ constexpr FB_SIZE_T FLD_LIMIT = MAX_COLUMN_SIZE;
18221823 unsigned length = 0 ;
18231824 blb->getSegment (&st, FLD_LIMIT, buf.getBuffer (FLD_LIMIT), &length);
18241825 check (" IBlob::getSegment" , &st);
0 commit comments