Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert PR 3013 (Support unary '+' operators for strings) from BABEL_4_4_STABLE #3281

Closed
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
2 changes: 1 addition & 1 deletion .github/composite-actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ runs:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update --fix-missing -y
sudo apt-get install uuid-dev openjdk-8-jre libicu-dev libxml2-dev openssl libssl-dev python3-dev libossp-uuid-dev libpq-dev cmake pkg-config g++ build-essential bison mssql-tools unixodbc-dev libsybdb5 freetds-dev freetds-common gdal-bin libgdal-dev libgeos-dev gdb
sudo apt-get install uuid-dev openjdk-8-jre libicu-dev libxml2-dev openssl libssl-dev python3-dev libossp-uuid-dev libpq-dev cmake pkg-config g++ build-essential bison mssql-tools unixodbc-dev libsybdb5 freetds-dev freetds-common gdal-bin libgdal-dev libgeos-dev gdb libkrb5-dev
sudo apt install -y ccache
sudo apt-get install lcov
sudo /usr/sbin/update-ccache-symlinks
Expand Down
14 changes: 7 additions & 7 deletions .github/configuration/upgrade-test-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: '14.14',
version: '14.15',
upgrade-type: null
},
{
Expand All @@ -125,7 +125,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: 15.9,
version: '15.10',
upgrade-type: null
},
{
Expand Down Expand Up @@ -177,11 +177,11 @@ upgrade-version: [{
upgrade-type: null
},
{
version: '14.14',
version: '14.15',
upgrade-type: major
},
{
version: 15.9,
version: '15.10',
upgrade-type: major
},
{
Expand All @@ -207,7 +207,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: 15.9,
version: '15.10',
upgrade-type: null
},
{
Expand All @@ -220,7 +220,7 @@ upgrade-version: [{
{
upgrade-path: [
{
version: 15.9,
version: '15.10',
upgrade-type: null
},
{
Expand All @@ -237,7 +237,7 @@ upgrade-version: [{
upgrade-type: null
},
{
version: 15.9,
version: '15.10',
upgrade-type: minor
},
{
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/clone_engine_repo.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEFAULT_BRANCH=BABEL_4_X_DEV__PG_16_X
DEFAULT_BRANCH=BABEL_4_4_STABLE__PG_16_6
12 changes: 6 additions & 6 deletions .github/template/version-branch-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
'14.13':
engine_branch: BABEL_2_10_STABLE__PG_14_13
extension_branch: BABEL_2_10_STABLE
'14.14':
engine_branch: BABEL_2_X_DEV__PG_14_X
extension_branch: BABEL_2_X_DEV
'14.15':
engine_branch: BABEL_2_11_STABLE__PG_14_15
extension_branch: BABEL_2_11_STABLE
'15.2':
engine_branch: BABEL_3_1_STABLE__PG_15_2
extension_branch: BABEL_3_1_STABLE
Expand All @@ -70,9 +70,9 @@
'15.8':
engine_branch: BABEL_3_7_STABLE__PG_15_8
extension_branch: BABEL_3_7_STABLE
'15.9':
engine_branch: BABEL_3_X_DEV__PG_15_X
extension_branch: BABEL_3_X_DEV
'15.10':
engine_branch: BABEL_3_8_STABLE__PG_15_10
extension_branch: BABEL_3_8_STABLE
'16.1':
engine_branch: BABEL_4_0_STABLE__PG_16_1
extension_branch: BABEL_4_0_STABLE
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/major-version-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
env:
OLD_INSTALL_DIR: psql_source
NEW_INSTALL_DIR: psql_target
ENGINE_BRANCH_FROM: BABEL_2_X_DEV__PG_14_X
EXTENSION_BRANCH_FROM: BABEL_2_X_DEV
ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_15
EXTENSION_BRANCH_FROM: BABEL_2_11_STABLE

runs-on: ubuntu-20.04
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/singledb-version-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
env:
OLD_INSTALL_DIR: psql_source
NEW_INSTALL_DIR: psql_target
ENGINE_BRANCH_FROM: BABEL_2_X_DEV__PG_14_X
EXTENSION_BRANCH_FROM: BABEL_2_X_DEV
ENGINE_BRANCH_FROM: BABEL_2_11_STABLE__PG_14_15
EXTENSION_BRANCH_FROM: BABEL_2_11_STABLE

runs-on: ubuntu-20.04
steps:
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TSQL_SRC = ../babelfishpg_tsql

PG_CFLAGS += -Werror -Wfloat-conversion
PG_CFLAGS += -fstack-protector-strong
PG_CPPFLAGS += -I$(TSQL_SRC) -I$(PG_SRC) -I$(tds_top_dir) -DFAULT_INJECTOR
PG_CPPFLAGS += -I$(TSQL_SRC) -I$(PG_SRC) -I$(tds_top_dir)

# Exclude the following files from the build (sometimes these
# files are included in another c file)
Expand Down
3 changes: 3 additions & 0 deletions contrib/babelfishpg_tds/src/backend/tds/tdslogin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,9 @@ CheckGSSAuth(Port *port)
oldContext = MemoryContextSwitchTo(TopMemoryContext);
pfree(port->user_name);
port->user_name = convertUsernameToCanonicalform(gbuf.value);

/* Assign canonical form username to loginInfo->username. */
loginInfo->username = pstrdup(port->user_name);
if ((at_pos = strchr(gbuf.value, '@')) != NULL && loginInfo)
{
/* skip '@' */
Expand Down
1 change: 1 addition & 0 deletions contrib/babelfishpg_tsql/antlr/TSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -4831,6 +4831,7 @@ keyword
| PREDICATE
| PREDICT
| PRIMARY_ROLE
| PRIMARY_SQBRACKET
| PRIOR
| PRIORITY
| PRIORITY_LEVEL
Expand Down
6 changes: 3 additions & 3 deletions contrib/babelfishpg_tsql/sql/information_schema_tsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -850,16 +850,16 @@ GRANT SELECT ON information_schema_tsql.key_column_usage TO PUBLIC;
*/
CREATE OR REPLACE VIEW information_schema_tsql.schemata AS
SELECT CAST(sys.db_name() AS sys.sysname) AS "CATALOG_NAME",
CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1)
CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN PG_CATALOG.RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1)
ELSE np.nspname END AS sys.nvarchar(128)) AS "SCHEMA_NAME",
-- For system-defined schemas, schema-owner name will be same as schema_name
-- For user-defined schemas having default owner, schema-owner will be dbo
-- For user-defined schemas with explicit owners, rolname contains dbname followed
-- by owner name, so need to extract the owner name from rolname always.
CAST(CASE WHEN sys.bbf_is_shared_schema(np.nspname) = TRUE THEN np.nspname
WHEN r.rolname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN
CASE WHEN RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo'
ELSE RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END
CASE WHEN PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo'
ELSE PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END
AS sys.nvarchar(128)) AS "SCHEMA_OWNER",
CAST(null AS sys.varchar(6)) AS "DEFAULT_CHARACTER_SET_CATALOG",
CAST(null AS sys.varchar(3)) AS "DEFAULT_CHARACTER_SET_SCHEMA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ LANGUAGE plpgsql;
* So make sure that any SQL statement (DDL/DML) being added here can be executed multiple times without affecting
* final behaviour.
*/

-- This is a temporary procedure which is only meant to be called during upgrade
CREATE OR REPLACE PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins()
LANGUAGE C
AS 'babelfishpg_tsql', 'revoke_guest_from_mapped_logins';

CALL sys.babelfish_revoke_guest_from_mapped_logins();

-- Drop this procedure after it gets executed once.
DROP PROCEDURE sys.babelfish_revoke_guest_from_mapped_logins();

DO $$
DECLARE
exception_message text;
Expand Down Expand Up @@ -4406,16 +4417,16 @@ GRANT EXECUTE ON PROCEDURE sys.sp_procedure_params_100_managed TO PUBLIC;

CREATE OR REPLACE VIEW information_schema_tsql.schemata AS
SELECT CAST(sys.db_name() AS sys.sysname) AS "CATALOG_NAME",
CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1)
CAST(CASE WHEN np.nspname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN PG_CATALOG.RIGHT(np.nspname, LENGTH(np.nspname) - LENGTH(sys.db_name()) - 1)
ELSE np.nspname END AS sys.nvarchar(128)) AS "SCHEMA_NAME",
-- For system-defined schemas, schema-owner name will be same as schema_name
-- For user-defined schemas having default owner, schema-owner will be dbo
-- For user-defined schemas with explicit owners, rolname contains dbname followed
-- by owner name, so need to extract the owner name from rolname always.
CAST(CASE WHEN sys.bbf_is_shared_schema(np.nspname) = TRUE THEN np.nspname
WHEN r.rolname LIKE PG_CATALOG.CONCAT(sys.db_name(),'%') THEN
CASE WHEN RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo'
ELSE RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END
CASE WHEN PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) = 'db_owner' THEN 'dbo'
ELSE PG_CATALOG.RIGHT(r.rolname, LENGTH(r.rolname) - LENGTH(sys.db_name()) - 1) END ELSE 'dbo' END
AS sys.nvarchar(128)) AS "SCHEMA_OWNER",
CAST(null AS sys.varchar(6)) AS "DEFAULT_CHARACTER_SET_CATALOG",
CAST(null AS sys.varchar(3)) AS "DEFAULT_CHARACTER_SET_SCHEMA",
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/babelfish_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*/

#define BABELFISH_VERSION_STR "4.4.0"
#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 16.5.0.0"
#define BABELFISH_INTERNAL_VERSION_STR "Babelfish 16.6.0.0"
#define BABEL_COMPATIBILITY_VERSION "12.0.2000.8"
#define BABEL_COMPATIBILITY_MAJOR_VERSION "12"
53 changes: 37 additions & 16 deletions contrib/babelfishpg_tsql/src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,10 @@ get_authid_user_ext_physical_name(const char *db_name, const char *login)
{
Relation bbf_authid_user_ext_rel;
HeapTuple tuple_user_ext;
ScanKeyData key[3];
TableScanDesc scan;
char *user_name = NULL;
NameData *login_name;
ScanKeyData key[2];

if (!db_name || !login)
return NULL;
Expand All @@ -956,20 +956,16 @@ get_authid_user_ext_physical_name(const char *db_name, const char *login)

login_name = (NameData *) palloc0(NAMEDATALEN);
snprintf(login_name->data, NAMEDATALEN, "%s", login);

ScanKeyInit(&key[0],
Anum_bbf_authid_user_ext_login_name,
BTEqualStrategyNumber, F_NAMEEQ,
NameGetDatum(login_name));
Anum_bbf_authid_user_ext_login_name,
BTEqualStrategyNumber, F_NAMEEQ,
NameGetDatum(login_name));
ScanKeyInit(&key[1],
Anum_bbf_authid_user_ext_database_name,
BTEqualStrategyNumber, F_TEXTEQ,
CStringGetTextDatum(db_name));
ScanKeyInit(&key[2],
Anum_bbf_authid_user_ext_user_can_connect,
BTEqualStrategyNumber, F_INT4EQ,
Int32GetDatum(1));

scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 3, key);
Anum_bbf_authid_user_ext_database_name,
BTEqualStrategyNumber, F_TEXTEQ,
CStringGetTextDatum(db_name));
scan = table_beginscan_catalog(bbf_authid_user_ext_rel, 2, key);

tuple_user_ext = heap_getnext(scan, ForwardScanDirection);
if (HeapTupleIsValid(tuple_user_ext))
Expand Down Expand Up @@ -1074,6 +1070,28 @@ get_authid_user_ext_db_users(const char *db_name)
return db_users_list;
}

/* Checks if the user is enabled on a given database. */
static bool
user_has_dbaccess(const char *user)
{
HeapTuple tuple;
bool has_access = false;
tuple = SearchSysCache1(AUTHIDUSEREXTROLENAME, CStringGetDatum(user));

if (HeapTupleIsValid(tuple))
{
bool isnull = true;
int user_can_connect = 0;
Datum datum = SysCacheGetAttr(AUTHIDUSEREXTROLENAME, tuple, Anum_bbf_authid_user_ext_user_can_connect, &isnull);
Assert(!isnull);
user_can_connect = DatumGetInt32(datum);
if (user_can_connect == 1)
has_access = true;
ReleaseSysCache(tuple);
}
return has_access;
}

/*
* Checks if there exists any user for respective database and login,
* if there is not any then use dbo or guest user.
Expand All @@ -1091,6 +1109,9 @@ get_user_for_database(const char *db_name)
user = get_authid_user_ext_physical_name(db_name, login);
login_is_db_owner = 0 == strncmp(login, get_owner_of_db(db_name), NAMEDATALEN);

if (user && !user_has_dbaccess(user) && !guest_has_dbaccess((char *) db_name))
user = NULL;

if (!user)
{
Oid datdba;
Expand Down Expand Up @@ -1326,10 +1347,10 @@ void
clean_up_bbf_server_def()
{
/* Fetch the relation */
Relation bbf_servers_def_rel = table_open(get_bbf_servers_def_oid(), RowExclusiveLock);
Relation bbf_servers_def_rel = table_open(get_bbf_servers_def_oid(), AccessExclusiveLock);
/* Truncate the relation */
heap_truncate_one_rel(bbf_servers_def_rel);
table_close(bbf_servers_def_rel, RowExclusiveLock);
table_close(bbf_servers_def_rel, AccessExclusiveLock);
}

/*****************************************
Expand Down Expand Up @@ -3139,7 +3160,7 @@ create_guest_role_for_db(const char *dbname)
if (list_length(logins) > 0)
{
stmt = parsetree_nth_stmt(res, i++);
update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins);
update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins, NULL);
}

GetUserIdAndSecContext(&save_userid, &save_sec_context);
Expand Down
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/dbcmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner)
/* Grant dbo role to owner */
stmt = parsetree_nth_stmt(res, i++);
update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(dbo)),
list_make1(make_rolespec_node(owner)));
list_make1(make_rolespec_node(owner)), NULL);
}

if (guest)
Expand All @@ -178,7 +178,7 @@ gen_createdb_subcmds(const char *dbname, const char *owner)
if (list_length(logins) > 0)
{
stmt = parsetree_nth_stmt(res, i++);
update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins);
update_GrantRoleStmt(stmt, list_make1(make_accesspriv_node(guest)), logins, NULL);
}
}

Expand Down
4 changes: 2 additions & 2 deletions contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3908,10 +3908,10 @@ exec_stmt_change_dbowner(PLtsql_execstate *estate, PLtsql_stmt_change_dbowner *s
SetUserIdAndSecContext(get_bbf_role_admin_oid(), save_sec_context | SECURITY_LOCAL_USERID_CHANGE);

/* Revoke dbo role from the previous owner */
grant_revoke_dbo_to_login(get_owner_of_db(stmt->db_name), stmt->db_name, false);
grant_revoke_role_to_login(get_owner_of_db(stmt->db_name), get_dbo_role_name(stmt->db_name), NULL, false);

/* Grant dbo role to the new owner */
grant_revoke_dbo_to_login(stmt->new_owner_name, stmt->db_name, true);
grant_revoke_role_to_login(stmt->new_owner_name, get_dbo_role_name(stmt->db_name), NULL, true);
update_db_owner(stmt->new_owner_name, stmt->db_name);
}
PG_FINALLY();
Expand Down
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/pltsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,7 @@ extern void update_CreateSchemaStmt(Node *n, const char *schemaname, const char
extern void update_DropOwnedStmt(Node *n, List *role_list);
extern void update_DropRoleStmt(Node *n, const char *role);
extern void update_DropStmt(Node *n, const char *object);
extern void update_GrantRoleStmt(Node *n, List *privs, List *roles);
extern void update_GrantRoleStmt(Node *n, List *privs, List *roles, const char *grantor);
extern void update_GrantStmt(Node *n, const char *object, const char *obj_schema, const char *grantee, const char *priv);
extern void update_RenameStmt(Node *n, const char *old_name, const char *new_name);
extern void update_ViewStmt(Node *n, const char *view_schema);
Expand Down
7 changes: 6 additions & 1 deletion contrib/babelfishpg_tsql/src/pltsql_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ update_DropStmt(Node *n, const char *object)
}

void
update_GrantRoleStmt(Node *n, List *privs, List *roles)
update_GrantRoleStmt(Node *n, List *privs, List *roles, const char *grantor)
{
GrantRoleStmt *stmt = (GrantRoleStmt *) n;

Expand All @@ -1091,6 +1091,11 @@ update_GrantRoleStmt(Node *n, List *privs, List *roles)

stmt->granted_roles = privs;
stmt->grantee_roles = roles;

if (grantor && stmt->grantor)
{
stmt->grantor->rolename = pstrdup(grantor);
}
}

void
Expand Down
Loading
Loading