Skip to content

Commit 384586c

Browse files
committed
Fix regression due to att_security_class being missing during database creation. Use lazy initialization and predefine the security class name.
1 parent eecfe01 commit 384586c

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/jrd/constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ inline constexpr const char* PLG_LEGACY_SEC_SCHEMA = "PLG$LEGACY_SEC";
139139

140140
// Automatically created security classes for SQL objects.
141141
// Keep in sync with trig.h
142+
inline constexpr const char* DATABASE_CLASS = "SQL$DATABASE";
142143
inline constexpr const char* DEFAULT_CLASS = "SQL$DEFAULT";
143144
inline constexpr const char* SQL_SECCLASS_GENERATOR = "RDB$SECURITY_CLASS";
144145
inline constexpr const char* SQL_SECCLASS_PREFIX = "SQL$";

src/jrd/ini.epp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,7 @@ namespace
596596
}
597597
}
598598

599-
MetaName securityClass;
600-
securityClass.printf("%s%" SQUADFORMAT, SQL_SECCLASS_PREFIX,
601-
DPM_gen_id(tdbb, lookupGenerator(SQL_SECCLASS_GENERATOR), false, 1));
602-
603-
addSecurityClass(tdbb, securityClass);
599+
addSecurityClass(tdbb, DATABASE_CLASS);
604600

605601
handle.reset();
606602

@@ -609,7 +605,7 @@ namespace
609605
{
610606
MODIFY DB USING
611607
DB.RDB$SECURITY_CLASS.NULL = FALSE;
612-
PAD(securityClass, DB.RDB$SECURITY_CLASS);
608+
PAD(DATABASE_CLASS, DB.RDB$SECURITY_CLASS);
613609
END_MODIFY
614610
}
615611
END_FOR

src/jrd/scl.epp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ void SCL_check_database(thread_db* tdbb, SecurityClass::flags_t mask)
313313
SET_TDBB(tdbb);
314314

315315
Jrd::Attachment* const attachment = tdbb->getAttachment();
316+
317+
if (!attachment->att_security_class)
318+
attachment->att_security_class = SCL_get_class(tdbb, DATABASE_CLASS);
319+
316320
const SecurityClass* const att_class = attachment->att_security_class;
317321
if (att_class && (att_class->scl_flags & mask))
318322
return;
@@ -1152,7 +1156,16 @@ void UserId::sclInit(thread_db* tdbb, bool create)
11521156
user->usr_init_role = role_name;
11531157
attachment->att_user = user;
11541158

1155-
if (!create)
1159+
if (create)
1160+
{
1161+
dbb->dbb_owner = user->getUserName();
1162+
user->usr_privileges.load(INI_owner_privileges().c_str());
1163+
user->usr_granted_roles.clear();
1164+
user->usr_granted_roles.add(ADMIN_ROLE);
1165+
1166+
user->usr_flags &= ~USR_newrole;
1167+
}
1168+
else
11561169
{
11571170
AutoCacheRequest request(tdbb, irq_get_att_class, IRQ_REQUESTS);
11581171

@@ -1170,23 +1183,14 @@ void UserId::sclInit(thread_db* tdbb, bool create)
11701183
FOR(REQUEST_HANDLE request2)
11711184
FIRST 1 REL IN RDB$RELATIONS
11721185
WITH REL.RDB$SCHEMA_NAME EQ SYSTEM_SCHEMA AND
1173-
REL.RDB$RELATION_NAME EQ "RDB$DATABASE"
1186+
REL.RDB$RELATION_NAME EQ "RDB$DATABASE"
11741187
{
1175-
if (!REL.RDB$OWNER_NAME.NULL)
1188+
if (!REL.RDB$OWNER_NAME.NULL)
11761189
dbb->dbb_owner = REL.RDB$OWNER_NAME;
11771190
}
11781191
END_FOR
11791192
}
11801193
}
1181-
else
1182-
{
1183-
dbb->dbb_owner = user->getUserName();
1184-
user->usr_privileges.load(INI_owner_privileges().c_str());
1185-
user->usr_granted_roles.clear();
1186-
user->usr_granted_roles.add("RDB$ADMIN");
1187-
1188-
user->usr_flags &= ~USR_newrole;
1189-
}
11901194
}
11911195

11921196

0 commit comments

Comments
 (0)