Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/common/classes/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../common/gdsassert.h"
#include <string.h>
#include <functional>
#include <initializer_list>

namespace Firebird {

Expand All @@ -42,6 +43,10 @@ class Vector
{
public:
Vector() : count(0) {}
Vector(const std::initializer_list<T> items) : count(0)
{
push(items.begin(), items.size());
}

T& operator[](FB_SIZE_T index) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion src/dsql/DdlNodes.epp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ DdlNode* CommentOnNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
case obj_package_constant:
{
QualifiedName constantName(subName, name.schema, name.object); // name is a package
dsqlScratch->qualifyNewName(constantName); // Search for a schema
dsqlScratch->qualifyExistingName(constantName, obj_package_constant); // Search for a schema

if (!PackageReferenceNode::constantExists(tdbb, transaction, constantName))
{
Expand Down
2 changes: 1 addition & 1 deletion src/dsql/ExprNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6477,7 +6477,7 @@ ValueExprNode* FieldNode::internalDsqlPass(DsqlCompilerScratch* dsqlScratch, Rec

if (constantName.package.hasData())
{
dsqlScratch->qualifyNewName(constantName);
dsqlScratch->qualifyExistingName(constantName, obj_package_constant);

if (PackageReferenceNode::constantExists(tdbb, dsqlScratch->getTransaction(), constantName))
{
Expand Down
5 changes: 4 additions & 1 deletion src/dsql/PackageNodes.epp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ string CreatePackageConstantNode::internalPrint(NodePrinter& printer) const
DdlNode::internalPrint(printer);

NODE_PRINT(printer, name);
NODE_PRINT(printer, source);
NODE_PRINT(printer, m_type);
NODE_PRINT(printer, m_expr);
NODE_PRINT(printer, m_isPrivate);
Expand All @@ -587,6 +588,8 @@ DdlNode* CreatePackageConstantNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
{
dsqlScratch->qualifyNewName(name);

source.ltrim("\n\r\t ");

m_expr = m_expr->dsqlPass(dsqlScratch);

QualifiedName dummyCollationName;
Expand Down Expand Up @@ -676,7 +679,7 @@ void CreatePackageConstantNode::executeCreate(thread_db* tdbb, DsqlCompilerScrat

CONST.RDB$PRIVATE_FLAG = m_isPrivate;

CONST.RDB$CONSTANT_SOURCE.NULL = TRUE;
attachment->storeMetaDataBlob(tdbb, transaction, &CONST.RDB$CONSTANT_SOURCE, source);
}
END_STORE
}
Expand Down
3 changes: 3 additions & 0 deletions src/dsql/PackageNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class CreatePackageConstantNode final : public DdlNode
dsql_fld* type = nullptr, ValueExprNode* value = nullptr, bool isPrivate = false)
: DdlNode(pool),
name(pool, name),
source(pool),
m_type(type),
m_expr(value),
m_isPrivate(isPrivate)
Expand Down Expand Up @@ -209,6 +210,8 @@ class CreatePackageConstantNode final : public DdlNode

public:
QualifiedName name;
Firebird::string source;

bool create = false;
bool alter = false;

Expand Down
1 change: 1 addition & 0 deletions src/dsql/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,7 @@ package_const_item
: symbol_package_const_name data_type_descriptor '=' value
{
$$ = newNode<CreatePackageConstantNode>(*$1, $2, $4);
$$->source = makeParseStr(YYPOSNARG(3), YYPOSNARG(4));
}
;

Expand Down
1 change: 1 addition & 0 deletions src/jrd/dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ inline constexpr const char* EXEC_PRIVILEGES = "X"; // execute privilege
inline constexpr const char* PACKAGE_PRIVILEGES = "XSIUD"; // all applicable package privileges
inline constexpr const char* USAGE_PRIVILEGES = "G"; // usage privilege
inline constexpr const char* ALL_DDL_PRIVILEGES = "CLO";
inline constexpr const char* SYSTEM_PACKAGE_PRIVILEGES = "XU"; // execute and usage privileges

inline constexpr int DYN_MSG_FAC = FB_IMPL_MSG_FACILITY_DYN;

Expand Down
55 changes: 31 additions & 24 deletions src/jrd/ini.epp
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,20 @@ namespace
const size_t ownerNameLength = ownerName.length();
fb_assert(ownerNameLength <= MAX_UCHAR);

const UCHAR privilege = package ? priv_execute : priv_usage;
Vector<UCHAR, 8> NON_REL_OWNER_ACL
{ACL_priv_list, priv_control, priv_alter, priv_drop, priv_usage, ACL_end};

const UCHAR NON_REL_OWNER_ACL[] =
{ACL_priv_list, priv_control, priv_alter, priv_drop, privilege, ACL_end};
Vector<UCHAR, 4> NON_REL_PUBLIC_ACL
{ACL_priv_list, priv_usage, ACL_end};

const UCHAR NON_REL_PUBLIC_ACL[] =
{ACL_priv_list, privilege, ACL_end};
if (package)
{
NON_REL_OWNER_ACL.insert(NON_REL_OWNER_ACL.getCount() - 2, priv_execute);
NON_REL_PUBLIC_ACL.insert(NON_REL_PUBLIC_ACL.getCount() - 2, priv_execute);
}

fb_assert(sizeof(buffer) >= 8 + ownerNameLength +
sizeof(NON_REL_OWNER_ACL) + sizeof(NON_REL_PUBLIC_ACL));
NON_REL_OWNER_ACL.getCount() + NON_REL_PUBLIC_ACL.getCount());

UCHAR* acl = buffer;
*acl++ = ACL_version;
Expand All @@ -352,14 +356,14 @@ namespace

*acl++ = ACL_end;

memcpy(acl, NON_REL_OWNER_ACL, sizeof(NON_REL_OWNER_ACL));
acl += sizeof(NON_REL_OWNER_ACL);
memcpy(acl, NON_REL_OWNER_ACL.begin(), NON_REL_OWNER_ACL.getCount());
acl += NON_REL_OWNER_ACL.getCount();

*acl++ = ACL_id_list;
*acl++ = ACL_end;

memcpy(acl, NON_REL_PUBLIC_ACL, sizeof(NON_REL_PUBLIC_ACL));
acl += sizeof(NON_REL_PUBLIC_ACL);
memcpy(acl, NON_REL_PUBLIC_ACL.begin(), NON_REL_PUBLIC_ACL.getCount());
acl += NON_REL_PUBLIC_ACL.getCount();

*acl++ = ACL_end; // Extra terminator to avoid scl.epp:walk_acl() missing the end

Expand Down Expand Up @@ -397,14 +401,14 @@ namespace
break;

case obj_package_header:
privileges = EXEC_PRIVILEGES;
privileges = SYSTEM_PACKAGE_PRIVILEGES;
break;

default:
fb_assert(false);
}

fb_assert(privileges && privileges[0] && !privileges[1]);
fb_assert(privileges);

const auto userName = getOwnerName();
fb_assert(userName && *userName);
Expand All @@ -415,20 +419,23 @@ namespace

for (unsigned i = 0; i < FB_NELEM(users); i++)
{
STORE(REQUEST_HANDLE handle TRANSACTION_HANDLE transaction)
PRIV IN RDB$USER_PRIVILEGES
for (const char* privilege = privileges; *privilege != '\0'; ++privilege)
{
PAD(users[i], PRIV.RDB$USER);
PAD(SYSTEM_SCHEMA, PRIV.RDB$RELATION_SCHEMA_NAME);
PAD(objName, PRIV.RDB$RELATION_NAME);
PRIV.RDB$PRIVILEGE[0] = *privileges;
PRIV.RDB$PRIVILEGE[1] = 0;
PRIV.RDB$GRANT_OPTION = grantOptions[i];
PRIV.RDB$USER_TYPE = obj_user;
PRIV.RDB$OBJECT_TYPE = objType;
PRIV.RDB$GRANTOR.NULL = TRUE;
STORE(REQUEST_HANDLE handle TRANSACTION_HANDLE transaction)
PRIV IN RDB$USER_PRIVILEGES
{
PAD(users[i], PRIV.RDB$USER);
PAD(SYSTEM_SCHEMA, PRIV.RDB$RELATION_SCHEMA_NAME);
PAD(objName, PRIV.RDB$RELATION_NAME);
PRIV.RDB$PRIVILEGE[0] = *privilege;
PRIV.RDB$PRIVILEGE[1] = 0;
PRIV.RDB$GRANT_OPTION = grantOptions[i];
PRIV.RDB$USER_TYPE = obj_user;
PRIV.RDB$OBJECT_TYPE = objType;
PRIV.RDB$GRANTOR.NULL = TRUE;
}
END_STORE
}
END_STORE
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/jrd/met.epp
Original file line number Diff line number Diff line change
Expand Up @@ -5509,6 +5509,25 @@ std::optional<ObjectType> MET_qualify_existing_name(thread_db* tdbb, QualifiedNa
break;
}

case obj_package_constant:
{
static const CachedRequestId consatntHandleId;
handle.reset(tdbb, consatntHandleId);

FOR (REQUEST_HANDLE handle)
CONST IN RDB$CONSTANTS
WITH CONST.RDB$SCHEMA_NAME EQ searchSchema.c_str() AND
CONST.RDB$CONSTANT_NAME EQ name.object.c_str() AND
CONST.RDB$PACKAGE_NAME EQUIV NULLIF(name.package.c_str(), '')
{
found = true;
break;
}
END_FOR

break;
}

default:
fb_assert(false);
}
Expand Down
Loading