From a70e01be8cbf05a43e341dea5cd021b104b8afe4 Mon Sep 17 00:00:00 2001 From: P Aswini Kumar Date: Wed, 18 Sep 2024 12:09:10 +0530 Subject: [PATCH] [Fix] Database owner login is unable to view db objects in SSMS (#2925) Currently in babelfish when we create a login (e.g. postjend_svc) and a database (e.g. test) and make postjend_svc owner of test and then connect to SSMS object explorer as login "postjend_svc" to database "test" and try to expand the "Database" field to view the objects. It does not show anything. With this change the login with be able to expand the "Database" field. The issue arised because when the databases are expanded in SSMS, a query is being executed which contains a cross-db query. Currently, we handle cross-db queries by switching the database and current user. This cross-db query is resulting into permission denied error due to lack of permission of the current user (which is switched internally to master_guest) to insert into a table created in "test" db. Task: BABEL-5119, BABEL-5218 Signed-off-by: P Aswini Kumar --- contrib/babelfishpg_tsql/runtime/functions.c | 9 +- .../babelfishpg_tsql--3.7.0--3.8.0.sql | 30 + contrib/babelfishpg_tsql/src/dbcmds.c | 28 +- contrib/babelfishpg_tsql/src/pl_exec-2.c | 12 +- contrib/babelfishpg_tsql/src/pl_exec.c | 3 + contrib/babelfishpg_tsql/src/rolecmds.c | 77 ++ contrib/babelfishpg_tsql/src/rolecmds.h | 2 +- test/JDBC/expected/BABEL-5119-vu-cleanup.out | 27 + test/JDBC/expected/BABEL-5119-vu-prepare.out | 25 + test/JDBC/expected/BABEL-5119-vu-verify.out | 745 ++++++++++++++++++ test/JDBC/input/BABEL-5119-vu-cleanup.mix | 27 + test/JDBC/input/BABEL-5119-vu-prepare.mix | 25 + test/JDBC/input/BABEL-5119-vu-verify.mix | 366 +++++++++ test/JDBC/upgrade/15_8/schedule | 1 + test/JDBC/upgrade/latest/schedule | 1 + 15 files changed, 1368 insertions(+), 10 deletions(-) create mode 100644 test/JDBC/expected/BABEL-5119-vu-cleanup.out create mode 100644 test/JDBC/expected/BABEL-5119-vu-prepare.out create mode 100644 test/JDBC/expected/BABEL-5119-vu-verify.out create mode 100644 test/JDBC/input/BABEL-5119-vu-cleanup.mix create mode 100644 test/JDBC/input/BABEL-5119-vu-prepare.mix create mode 100644 test/JDBC/input/BABEL-5119-vu-verify.mix diff --git a/contrib/babelfishpg_tsql/runtime/functions.c b/contrib/babelfishpg_tsql/runtime/functions.c index 7205507e84..7c2885923e 100644 --- a/contrib/babelfishpg_tsql/runtime/functions.c +++ b/contrib/babelfishpg_tsql/runtime/functions.c @@ -58,6 +58,7 @@ #include "../src/catalog.h" #include "../src/timezone.h" #include "../src/collation.h" +#include "../src/dbcmds.h" #include "../src/rolecmds.h" #include "utils/fmgroids.h" #include "utils/acl.h" @@ -2620,6 +2621,7 @@ has_dbaccess(PG_FUNCTION_ARGS) const char *user = NULL; const char *login; int16 db_id; + bool login_is_db_owner; i = strlen(lowercase_db_name); while (i > 0 && isspace((unsigned char) lowercase_db_name[i - 1])) @@ -2632,6 +2634,7 @@ has_dbaccess(PG_FUNCTION_ARGS) login = GetUserNameFromId(GetSessionUserId(), false); user = get_authid_user_ext_physical_name(lowercase_db_name, login); + login_is_db_owner = 0 == strncmp(login, get_owner_of_db(lowercase_db_name), NAMEDATALEN); /* * Special cases: Database Owner should always have access If this DB has @@ -2642,7 +2645,11 @@ has_dbaccess(PG_FUNCTION_ARGS) Oid datdba; datdba = get_role_oid("sysadmin", false); - if (is_member_of_role(GetSessionUserId(), datdba)) + if (is_member_of_role(GetSessionUserId(), datdba) || login_is_db_owner) + /* + * The login will have access to the database if it is a member + * of sysadmin or it is the owner of the database. + */ user = get_dbo_role_name(lowercase_db_name); else { diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql index e6ce3eee7f..dfb53d85fc 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--3.7.0--3.8.0.sql @@ -11,6 +11,36 @@ SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false) * final behaviour. */ +-- Assigning dbo role to the db_owner login +DO $$ +DECLARE + owner_name NAME; + db_name TEXT; + role_name NAME; + owner_cursor CURSOR FOR SELECT DISTINCT owner, name FROM sys.babelfish_sysdatabases; +BEGIN + OPEN owner_cursor; + FETCH NEXT FROM owner_cursor INTO owner_name, db_name; + + WHILE FOUND + LOOP + SELECT rolname FROM sys.babelfish_authid_user_ext WHERE database_name = db_name INTO role_name; + + IF db_name = 'master' OR db_name = 'tempdb' OR db_name = 'msdb' + THEN + FETCH NEXT FROM owner_cursor INTO owner_name, db_name; + CONTINUE; + END IF; + + EXECUTE FORMAT('GRANT %I TO %I', role_name, owner_name); + + FETCH NEXT FROM owner_cursor INTO owner_name, db_name; + END LOOP; + + CLOSE owner_cursor; +END; +$$ LANGUAGE plpgsql; + CREATE OR REPLACE FUNCTION bbf_string_agg_finalfn_varchar(INTERNAL) RETURNS sys.VARCHAR AS 'string_agg_finalfn' LANGUAGE INTERNAL; diff --git a/contrib/babelfishpg_tsql/src/dbcmds.c b/contrib/babelfishpg_tsql/src/dbcmds.c index ffe32624e9..0f605c9b7e 100644 --- a/contrib/babelfishpg_tsql/src/dbcmds.c +++ b/contrib/babelfishpg_tsql/src/dbcmds.c @@ -50,7 +50,8 @@ static List *gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, const char *guest, - const char *guest_schema); + const char *guest_schema, + const char *owner); static List *gen_dropdb_subcmds(const char *schema, const char *db_owner, const char *dbo, @@ -98,7 +99,7 @@ have_createdb_privilege(void) * Generate subcmds for CREATE DATABASE. Note 'guest' can be NULL. */ static List * -gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, const char *guest, const char *guest_schema) +gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, const char *guest, const char *guest_schema, const char *owner) { StringInfoData query; List *res; @@ -106,6 +107,9 @@ gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, Node *stmt; int i = 0; int expected_stmt_num; + AccessPriv *acc; + List *privs = NIL; + RoleSpec *role_spec; /* * To avoid SQL injection, we generate statement parsetree with dummy @@ -116,6 +120,7 @@ gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, appendStringInfo(&query, "CREATE ROLE dummy INHERIT; "); appendStringInfo(&query, "CREATE ROLE dummy INHERIT CREATEROLE ROLE sysadmin IN ROLE dummy; "); appendStringInfo(&query, "GRANT CREATE, CONNECT, TEMPORARY ON DATABASE dummy TO dummy; "); + appendStringInfo(&query, "GRANT dummy TO dummy; "); if (guest) { @@ -136,9 +141,9 @@ gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, res = raw_parser(query.data, RAW_PARSE_DEFAULT); if (guest) - expected_stmt_num = list_length(logins) > 0 ? 9 : 8; + expected_stmt_num = list_length(logins) > 0 ? 10 : 9; else - expected_stmt_num = 6; + expected_stmt_num = 7; if (list_length(res) != expected_stmt_num) ereport(ERROR, @@ -156,6 +161,19 @@ gen_createdb_subcmds(const char *schema, const char *dbo, const char *db_owner, stmt = parsetree_nth_stmt(res, i++); update_GrantStmt(stmt, get_database_name(MyDatabaseId), NULL, dbo, NULL); + /* Grant dbo role to owner */ + stmt = parsetree_nth_stmt(res, i++); + acc = makeNode(AccessPriv); + acc->priv_name = pstrdup(dbo); + acc->cols = NIL; + privs = lappend(privs, acc); + + role_spec = makeNode(RoleSpec); + role_spec->roletype = ROLESPEC_CSTRING; + role_spec->location = -1; + role_spec->rolename = pstrdup(owner); + update_GrantRoleStmt(stmt, privs, list_make1(role_spec)); + if (guest) { stmt = parsetree_nth_stmt(res, i++); @@ -524,7 +542,7 @@ create_bbf_db_internal(const char *dbname, List *options, const char *owner, int /* Advance cmd counter to make the database visible */ CommandCounterIncrement(); - parsetree_list = gen_createdb_subcmds(dbo_scm, dbo_role, db_owner_role, guest, guest_scm); + parsetree_list = gen_createdb_subcmds(dbo_scm, dbo_role, db_owner_role, guest, guest_scm, owner); /* Set current user to session user for create permissions */ prev_current_user = GetUserNameFromId(GetUserId(), false); diff --git a/contrib/babelfishpg_tsql/src/pl_exec-2.c b/contrib/babelfishpg_tsql/src/pl_exec-2.c index 1421b6dadc..fcdf22282a 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec-2.c +++ b/contrib/babelfishpg_tsql/src/pl_exec-2.c @@ -20,6 +20,7 @@ #include "catalog.h" #include "dbcmds.h" #include "pl_explain.h" +#include "rolecmds.h" #include "session.h" /* helper function to get current T-SQL estate */ @@ -3869,9 +3870,14 @@ exec_stmt_change_dbowner(PLtsql_execstate *estate, PLtsql_stmt_change_dbowner *s ereport(ERROR, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), errmsg("The proposed new database owner is already a user or aliased in the database."))); } - - /* All validations done, perform the actual update */ - update_db_owner(stmt->new_owner_name, stmt->db_name); + + /* Revoke dbo role from the previous owner */ + grant_revoke_dbo_to_login(get_owner_of_db(stmt->db_name), stmt->db_name, false); + + /* Grant dbo role to the new owner */ + grant_revoke_dbo_to_login(stmt->new_owner_name, stmt->db_name, true); + update_db_owner(stmt->new_owner_name, stmt->db_name); + return PLTSQL_RC_OK; } diff --git a/contrib/babelfishpg_tsql/src/pl_exec.c b/contrib/babelfishpg_tsql/src/pl_exec.c index f934967fc8..f20a8815b6 100644 --- a/contrib/babelfishpg_tsql/src/pl_exec.c +++ b/contrib/babelfishpg_tsql/src/pl_exec.c @@ -4661,7 +4661,10 @@ exec_stmt_execsql(PLtsql_execstate *estate, * schemas, Change the session property. */ if (stmt->schema_name != NULL && (strcmp(stmt->schema_name, "sys") == 0 || strcmp(stmt->schema_name, "information_schema") == 0)) + { set_session_properties(stmt->db_name); + SetCurrentRoleId(GetSessionUserId(), false); + } } if (stmt->is_dml || stmt->is_ddl || stmt->is_create_view) { diff --git a/contrib/babelfishpg_tsql/src/rolecmds.c b/contrib/babelfishpg_tsql/src/rolecmds.c index 6f2c28fb1f..fbbf9f49e0 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.c +++ b/contrib/babelfishpg_tsql/src/rolecmds.c @@ -581,6 +581,83 @@ grant_guests_to_login(const char *login) pfree(query.data); } +/* + * Grant/revoke dbo role from the login. + * The 'is_grant' flag determines if the action is grant/revoke. + */ +void +grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant) +{ + StringInfoData query; + List *parsetree_list; + List *dbo = NIL; + Node *stmt; + RoleSpec *tmp; + PlannedStmt *wrapper; + AccessPriv *acc; + + const char *dbo_role_name = get_dbo_role_name(db_name); + + initStringInfo(&query); + + acc = makeNode(AccessPriv); + acc->priv_name = pstrdup(dbo_role_name); + acc->cols = NIL; + dbo = lappend(dbo, acc); + + if (is_grant) + { + /* Build dummy GRANT statement to grant membership to login */ + appendStringInfo(&query, "GRANT dummy TO dummy; "); + } + else + { + /* Build dummy REVOKE statement to revoke membership from login */ + appendStringInfo(&query, "REVOKE dummy FROM dummy; "); + } + + parsetree_list = raw_parser(query.data, RAW_PARSE_DEFAULT); + + if (list_length(parsetree_list) != 1) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("Expected 1 statement but get %d statements after parsing", + list_length(parsetree_list)))); + + /* Update the dummy statement with real values */ + stmt = parsetree_nth_stmt(parsetree_list, 0); + tmp = makeNode(RoleSpec); + tmp->roletype = ROLESPEC_CSTRING; + tmp->location = -1; + tmp->rolename = pstrdup(login); + + update_GrantRoleStmt(stmt, dbo, list_make1(tmp)); + + /* Run the built query */ + /* need to make a wrapper PlannedStmt */ + wrapper = makeNode(PlannedStmt); + wrapper->commandType = CMD_UTILITY; + wrapper->canSetTag = false; + wrapper->utilityStmt = stmt; + wrapper->stmt_location = 0; + wrapper->stmt_len = 23; + + /* do this step */ + ProcessUtility(wrapper, + "(ALTER DATABASE OWNER )", + false, + PROCESS_UTILITY_SUBCOMMAND, + NULL, + NULL, + None_Receiver, + NULL); + + /* make sure later steps can see the object created here */ + CommandCounterIncrement(); + + pfree(query.data); +} + static List * gen_droplogin_subcmds(const char *login) { diff --git a/contrib/babelfishpg_tsql/src/rolecmds.h b/contrib/babelfishpg_tsql/src/rolecmds.h index b74b96e7e8..4f1577e2c3 100644 --- a/contrib/babelfishpg_tsql/src/rolecmds.h +++ b/contrib/babelfishpg_tsql/src/rolecmds.h @@ -82,6 +82,6 @@ extern bool windows_domain_contains_invalid_chars(char *input); extern bool check_windows_logon_length(char *input); extern char* get_windows_domain_name(char* input); extern bool windows_domain_is_not_supported(char* domain_name); - +extern void grant_revoke_dbo_to_login(const char* login, const char* db_name, bool is_grant); #endif diff --git a/test/JDBC/expected/BABEL-5119-vu-cleanup.out b/test/JDBC/expected/BABEL-5119-vu-cleanup.out new file mode 100644 index 0000000000..dafab3b568 --- /dev/null +++ b/test/JDBC/expected/BABEL-5119-vu-cleanup.out @@ -0,0 +1,27 @@ +-- tsql +USE master +GO +DROP TABLE guest.BABEL5119_t4 +GO +DROP TABLE guest.BABEL5119_t5 +GO +DROP TABLE guest.BABEL5119_t6 +GO +DROP VIEW guest.BABEL5119_v4 +GO +DROP VIEW guest.BABEL5119_v5 +GO +DROP VIEW guest.BABEL5119_v6 +GO +DROP PROCEDURE guest.BABEL5119_p4 +GO +DROP PROCEDURE guest.BABEL5119_p5 +GO +DROP PROCEDURE guest.BABEL5119_p6 +GO +DROP LOGIN login_babel5119_1 +GO +DROP LOGIN login_babel5119_2 +GO +DROP DATABASE BABEL5119_db +GO diff --git a/test/JDBC/expected/BABEL-5119-vu-prepare.out b/test/JDBC/expected/BABEL-5119-vu-prepare.out new file mode 100644 index 0000000000..463665bed4 --- /dev/null +++ b/test/JDBC/expected/BABEL-5119-vu-prepare.out @@ -0,0 +1,25 @@ +-- tsql +CREATE DATABASE BABEL5119_db +GO + +USE BABEL5119_db +GO +CREATE TABLE BABEL5119_t1(a int) +GO +CREATE TABLE BABEL5119_t2(a int) +GO +CREATE TABLE BABEL5119_t3(a int) +GO +CREATE VIEW BABEL5119_v1 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v2 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v3 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p1 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p2 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p3 AS SELECT 1 +GO +-- terminate-tsql-conn diff --git a/test/JDBC/expected/BABEL-5119-vu-verify.out b/test/JDBC/expected/BABEL-5119-vu-verify.out new file mode 100644 index 0000000000..f32cfd3669 --- /dev/null +++ b/test/JDBC/expected/BABEL-5119-vu-verify.out @@ -0,0 +1,745 @@ +-- tsql +CREATE LOGIN login_babel5119_1 WITH PASSWORD = '12345678' +CREATE LOGIN login_babel5119_2 WITH PASSWORD = '12345678' +ALTER authorization on database::BABEL5119_db TO login_babel5119_1 +GO +-- terminate-tsql-conn + +-- tsql user=login_babel5119_1 password=12345678 +-- Creating objects in the guest schema +USE master +GO +CREATE TABLE BABEL5119_t4(a int) +GO +CREATE TABLE BABEL5119_t5(a int) +GO +CREATE TABLE BABEL5119_t6(a int) +GO +CREATE VIEW BABEL5119_v4 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v5 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v6 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p4 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p5 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p6 AS SELECT 1 +GO +-- terminate-tsql-conn user=login_babel5119_1 password=12345678 + +-- tsql +-- Testing crossdb queries for sysadmin +-- From 'master' database +USE master +GO + +-- Checking crossdb for sys views +SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_db +~~END~~ + + +SELECT name FROM BABEL5119_db.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_v1 +babel5119_v2 +babel5119_v3 +~~END~~ + + +SELECT name FROM BABEL5119_db.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_p1 +babel5119_p2 +babel5119_p3 +~~END~~ + + +-- Checking crossdb for information_schema_tsql +SELECT * FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar#!#varchar#!#varchar +master#!#guest#!#BABEL5119_t4#!#BASE TABLE +master#!#guest#!#BABEL5119_t5#!#BASE TABLE +master#!#guest#!#BABEL5119_t6#!#BASE TABLE +master#!#guest#!#babel5119_v4#!#VIEW +master#!#guest#!#babel5119_v5#!#VIEW +master#!#guest#!#babel5119_v6#!#VIEW +~~END~~ + + +SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_db.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +BABEL5119_t4#!#a +BABEL5119_t5#!#a +BABEL5119_t6#!#a +babel5119_v4#!#?column? +babel5119_v5#!#?column? +babel5119_v6#!#?column? +~~END~~ + + +SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_db.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +babel5119_v4#!#CREATE VIEW BABEL5119_v4 AS SELECT 1 +babel5119_v5#!#CREATE VIEW BABEL5119_v5 AS SELECT 1 +babel5119_v6#!#CREATE VIEW BABEL5119_v6 AS SELECT 1 +~~END~~ + + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO +~~START~~ +int#!#int +~~END~~ + + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_1(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_1 select name, object_id, schema_id from BABEL5119_db.sys.tables WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE #babel5119_tmp_table_2(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_2 SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 1~~ + + +CREATE TABLE #babel5119_tmp_table_3(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_3 SELECT TABLE_NAME FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO +~~ROW COUNT: 6~~ + + +SELECT has_dbaccess(BABEL5119_db.sys.databases.name) FROM BABEL5119_db.sys.databases WHERE BABEL5119_db.sys.databases.name='BABEL5119_db' +GO +~~START~~ +int +1 +~~END~~ + + +-- From 'BABEL5119_db' database +USE BABEL5119_db +GO + +SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_db +~~END~~ + + +SELECT name FROM master.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_v4 +babel5119_v5 +babel5119_v6 +~~END~~ + + +SELECT name FROM master.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_p4 +babel5119_p5 +babel5119_p6 +~~END~~ + + +-- Checking crossdb for information_schema_tsql +SELECT * FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar#!#varchar#!#varchar +babel5119_db#!#dbo#!#BABEL5119_t1#!#BASE TABLE +babel5119_db#!#dbo#!#BABEL5119_t2#!#BASE TABLE +babel5119_db#!#dbo#!#BABEL5119_t3#!#BASE TABLE +babel5119_db#!#dbo#!#babel5119_v1#!#VIEW +babel5119_db#!#dbo#!#babel5119_v2#!#VIEW +babel5119_db#!#dbo#!#babel5119_v3#!#VIEW +~~END~~ + + +SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +BABEL5119_t1#!#a +BABEL5119_t2#!#a +BABEL5119_t3#!#a +babel5119_v1#!#?column? +babel5119_v2#!#?column? +babel5119_v3#!#?column? +~~END~~ + + +SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +babel5119_v1#!#CREATE VIEW BABEL5119_v1 AS SELECT 1 +babel5119_v2#!#CREATE VIEW BABEL5119_v2 AS SELECT 1 +babel5119_v3#!#CREATE VIEW BABEL5119_v3 AS SELECT 1 +~~END~~ + + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO +~~START~~ +int#!#int +~~END~~ + + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_4(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_4 select name, object_id, schema_id from master.sys.tables WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE #babel5119_tmp_table_5(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_5 SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 1~~ + + +CREATE TABLE #babel5119_tmp_table_6(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_6 SELECT TABLE_NAME FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO +~~ROW COUNT: 6~~ + + +SELECT has_dbaccess(master.sys.databases.name) FROM master.sys.databases WHERE master.sys.databases.name='BABEL5119_db' +GO +~~START~~ +int +1 +~~END~~ + +-- terminate-tsql-conn + +-- tsql user=login_babel5119_1 password=12345678 +-- Testing crossdb queries for non-sysadmin db_owner +-- Checking crossdb for sys views +-- From 'master' database +USE master +GO + +SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_db +~~END~~ + + +SELECT name FROM BABEL5119_db.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_v1 +babel5119_v2 +babel5119_v3 +~~END~~ + + +SELECT name FROM BABEL5119_db.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_p1 +babel5119_p2 +babel5119_p3 +~~END~~ + + +-- Checking crossdb for information_schema_tsql +SELECT * FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar#!#varchar#!#varchar +master#!#guest#!#BABEL5119_t4#!#BASE TABLE +master#!#guest#!#BABEL5119_t5#!#BASE TABLE +master#!#guest#!#BABEL5119_t6#!#BASE TABLE +master#!#guest#!#babel5119_v4#!#VIEW +master#!#guest#!#babel5119_v5#!#VIEW +master#!#guest#!#babel5119_v6#!#VIEW +~~END~~ + + +SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_db.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +BABEL5119_t4#!#a +BABEL5119_t5#!#a +BABEL5119_t6#!#a +babel5119_v4#!#?column? +babel5119_v5#!#?column? +babel5119_v6#!#?column? +~~END~~ + + +SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_db.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +babel5119_v4#!#CREATE VIEW BABEL5119_v4 AS SELECT 1 +babel5119_v5#!#CREATE VIEW BABEL5119_v5 AS SELECT 1 +babel5119_v6#!#CREATE VIEW BABEL5119_v6 AS SELECT 1 +~~END~~ + + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO +~~START~~ +int#!#int +~~END~~ + + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_7(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_7 select name, object_id, schema_id from BABEL5119_db.sys.tables WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE #babel5119_tmp_table_8(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_8 SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 1~~ + + +CREATE TABLE #babel5119_tmp_table_9(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_9 SELECT TABLE_NAME FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO +~~ROW COUNT: 6~~ + + +SELECT has_dbaccess(BABEL5119_db.sys.databases.name) FROM BABEL5119_db.sys.databases WHERE BABEL5119_db.sys.databases.name='BABEL5119_db' +GO +~~START~~ +int +1 +~~END~~ + + +-- From 'BABEL5119_db' database +USE BABEL5119_db +GO + +SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_db +~~END~~ + + +SELECT name FROM master.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_v4 +babel5119_v5 +babel5119_v6 +~~END~~ + + +SELECT name FROM master.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_p4 +babel5119_p5 +babel5119_p6 +~~END~~ + + +-- Checking crossdb for information_schema_tsql +SELECT * FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar#!#varchar#!#varchar +babel5119_db#!#dbo#!#BABEL5119_t1#!#BASE TABLE +babel5119_db#!#dbo#!#BABEL5119_t2#!#BASE TABLE +babel5119_db#!#dbo#!#BABEL5119_t3#!#BASE TABLE +babel5119_db#!#dbo#!#babel5119_v1#!#VIEW +babel5119_db#!#dbo#!#babel5119_v2#!#VIEW +babel5119_db#!#dbo#!#babel5119_v3#!#VIEW +~~END~~ + + +SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +BABEL5119_t1#!#a +BABEL5119_t2#!#a +BABEL5119_t3#!#a +babel5119_v1#!#?column? +babel5119_v2#!#?column? +babel5119_v3#!#?column? +~~END~~ + + +SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +babel5119_v1#!#CREATE VIEW BABEL5119_v1 AS SELECT 1 +babel5119_v2#!#CREATE VIEW BABEL5119_v2 AS SELECT 1 +babel5119_v3#!#CREATE VIEW BABEL5119_v3 AS SELECT 1 +~~END~~ + + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO +~~START~~ +int#!#int +~~END~~ + + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO +~~START~~ +int#!#int +1#!#1 +~~END~~ + + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_10(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_10 select name, object_id, schema_id from master.sys.tables WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE #babel5119_tmp_table_11(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_11 SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 1~~ + + +CREATE TABLE #babel5119_tmp_table_12(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_12 SELECT TABLE_NAME FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO +~~ROW COUNT: 6~~ + + +SELECT has_dbaccess(master.sys.databases.name) FROM master.sys.databases WHERE master.sys.databases.name='BABEL5119_db' +GO +~~START~~ +int +1 +~~END~~ + +-- terminate-tsql-conn user=login_babel5119_1 password=12345678 + +-- tsql user=login_babel5119_2 password=12345678 +-- Testing crossdb queries for non-sysadmin non-db_owner +-- Checking crossdb for sys views +-- From 'master' database +USE master +GO + +SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +SELECT name FROM BABEL5119_db.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +SELECT name FROM BABEL5119_db.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +-- Checking crossdb for information_schema_tsql +SELECT * FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_db.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_db.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for table babel5119_t1)~~ + + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: permission denied for view babel5119_v1)~~ + + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_13(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_13 select name, object_id, schema_id from BABEL5119_db.sys.tables WHERE name LIKE 'BABEL5119%' +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +CREATE TABLE #babel5119_tmp_table_14(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_14 SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +CREATE TABLE #babel5119_tmp_table_15(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_15 SELECT TABLE_NAME FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +SELECT has_dbaccess(BABEL5119_db.sys.databases.name) FROM BABEL5119_db.sys.databases WHERE BABEL5119_db.sys.databases.name='BABEL5119_db' +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + + +SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_db +~~END~~ + + +SELECT name FROM master.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_v4 +babel5119_v5 +babel5119_v6 +~~END~~ + + +SELECT name FROM master.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO +~~START~~ +varchar +babel5119_p4 +babel5119_p5 +babel5119_p6 +~~END~~ + + +-- Checking crossdb for information_schema_tsql +SELECT * FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar#!#varchar#!#varchar +master#!#guest#!#BABEL5119_t4#!#BASE TABLE +master#!#guest#!#BABEL5119_t5#!#BASE TABLE +master#!#guest#!#BABEL5119_t6#!#BASE TABLE +master#!#guest#!#babel5119_v4#!#VIEW +master#!#guest#!#babel5119_v5#!#VIEW +master#!#guest#!#babel5119_v6#!#VIEW +~~END~~ + + +SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +BABEL5119_t4#!#a +BABEL5119_t5#!#a +BABEL5119_t6#!#a +babel5119_v4#!#?column? +babel5119_v5#!#?column? +babel5119_v6#!#?column? +~~END~~ + + +SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO +~~START~~ +nvarchar#!#nvarchar +babel5119_v4#!#CREATE VIEW BABEL5119_v4 AS SELECT 1 +babel5119_v5#!#CREATE VIEW BABEL5119_v5 AS SELECT 1 +babel5119_v6#!#CREATE VIEW BABEL5119_v6 AS SELECT 1 +~~END~~ + + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_16(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_16 select name, object_id, schema_id from master.sys.tables WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 3~~ + + +CREATE TABLE #babel5119_tmp_table_17(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_17 SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +GO +~~ROW COUNT: 1~~ + + +CREATE TABLE #babel5119_tmp_table_18(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_18 SELECT TABLE_NAME FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO +~~ROW COUNT: 6~~ + + +SELECT has_dbaccess(master.sys.databases.name) FROM master.sys.databases WHERE master.sys.databases.name='BABEL5119_db' +GO +~~START~~ +int +0 +~~END~~ + +-- terminate-tsql-conn user=login_babel5119_2 password=12345678 + +-- tsql user=login_babel5119_2 password=12345678 +-- Checking the permissions after alter +USE BABEL5119_db +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_2" is not able to access the database "babel5119_db" under the current security context)~~ + +-- terminate-tsql-conn user=login_babel5119_2 password=12345678 + +-- tsql +ALTER authorization on database::BABEL5119_db TO login_babel5119_2 +GO +-- terminate-tsql-conn + +-- tsql user=login_babel5119_1 password=12345678 +USE BABEL5119_db +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The server principal "login_babel5119_1" is not able to access the database "babel5119_db" under the current security context)~~ + +-- terminate-tsql-conn user=login_babel5119_1 password=12345678 + +-- tsql user=login_babel5119_2 password=12345678 +USE BABEL5119_db +GO +INSERT INTO BABEL5119_t1 VALUES(1) +GO +~~ROW COUNT: 1~~ + +-- terminate-tsql-conn user=login_babel5119_2 password=12345678 diff --git a/test/JDBC/input/BABEL-5119-vu-cleanup.mix b/test/JDBC/input/BABEL-5119-vu-cleanup.mix new file mode 100644 index 0000000000..81a65d47ad --- /dev/null +++ b/test/JDBC/input/BABEL-5119-vu-cleanup.mix @@ -0,0 +1,27 @@ +-- tsql +USE master +GO +DROP TABLE guest.BABEL5119_t4 +GO +DROP TABLE guest.BABEL5119_t5 +GO +DROP TABLE guest.BABEL5119_t6 +GO +DROP VIEW guest.BABEL5119_v4 +GO +DROP VIEW guest.BABEL5119_v5 +GO +DROP VIEW guest.BABEL5119_v6 +GO +DROP PROCEDURE guest.BABEL5119_p4 +GO +DROP PROCEDURE guest.BABEL5119_p5 +GO +DROP PROCEDURE guest.BABEL5119_p6 +GO +DROP LOGIN login_babel5119_1 +GO +DROP LOGIN login_babel5119_2 +GO +DROP DATABASE BABEL5119_db +GO \ No newline at end of file diff --git a/test/JDBC/input/BABEL-5119-vu-prepare.mix b/test/JDBC/input/BABEL-5119-vu-prepare.mix new file mode 100644 index 0000000000..f986075b5e --- /dev/null +++ b/test/JDBC/input/BABEL-5119-vu-prepare.mix @@ -0,0 +1,25 @@ +-- tsql +CREATE DATABASE BABEL5119_db +GO + +USE BABEL5119_db +GO +CREATE TABLE BABEL5119_t1(a int) +GO +CREATE TABLE BABEL5119_t2(a int) +GO +CREATE TABLE BABEL5119_t3(a int) +GO +CREATE VIEW BABEL5119_v1 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v2 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v3 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p1 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p2 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p3 AS SELECT 1 +GO +-- terminate-tsql-conn \ No newline at end of file diff --git a/test/JDBC/input/BABEL-5119-vu-verify.mix b/test/JDBC/input/BABEL-5119-vu-verify.mix new file mode 100644 index 0000000000..81c31ee52d --- /dev/null +++ b/test/JDBC/input/BABEL-5119-vu-verify.mix @@ -0,0 +1,366 @@ +-- tsql +CREATE LOGIN login_babel5119_1 WITH PASSWORD = '12345678' +CREATE LOGIN login_babel5119_2 WITH PASSWORD = '12345678' +ALTER authorization on database::BABEL5119_db TO login_babel5119_1 +GO +-- terminate-tsql-conn + +-- tsql user=login_babel5119_1 password=12345678 +-- Creating objects in the guest schema +USE master +GO +CREATE TABLE BABEL5119_t4(a int) +GO +CREATE TABLE BABEL5119_t5(a int) +GO +CREATE TABLE BABEL5119_t6(a int) +GO +CREATE VIEW BABEL5119_v4 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v5 AS SELECT 1 +GO +CREATE VIEW BABEL5119_v6 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p4 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p5 AS SELECT 1 +GO +CREATE PROCEDURE BABEL5119_p6 AS SELECT 1 +GO +-- terminate-tsql-conn user=login_babel5119_1 password=12345678 + +-- Testing crossdb queries for sysadmin +-- tsql +-- From 'master' database +USE master +GO + +-- Checking crossdb for sys views +SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM BABEL5119_db.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM BABEL5119_db.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +-- Checking crossdb for information_schema_tsql +SELECT * FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_db.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_db.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_1(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_1 select name, object_id, schema_id from BABEL5119_db.sys.tables WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_2(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_2 SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_3(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_3 SELECT TABLE_NAME FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO + +SELECT has_dbaccess(BABEL5119_db.sys.databases.name) FROM BABEL5119_db.sys.databases WHERE BABEL5119_db.sys.databases.name='BABEL5119_db' +GO + +-- From 'BABEL5119_db' database +USE BABEL5119_db +GO + +SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM master.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM master.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +-- Checking crossdb for information_schema_tsql +SELECT * FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_4(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_4 select name, object_id, schema_id from master.sys.tables WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_5(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_5 SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_6(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_6 SELECT TABLE_NAME FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO + +SELECT has_dbaccess(master.sys.databases.name) FROM master.sys.databases WHERE master.sys.databases.name='BABEL5119_db' +GO +-- terminate-tsql-conn + +-- Testing crossdb queries for non-sysadmin db_owner +-- tsql user=login_babel5119_1 password=12345678 +-- Checking crossdb for sys views +-- From 'master' database +USE master +GO + +SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM BABEL5119_db.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM BABEL5119_db.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +-- Checking crossdb for information_schema_tsql +SELECT * FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_db.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_db.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_7(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_7 select name, object_id, schema_id from BABEL5119_db.sys.tables WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_8(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_8 SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_9(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_9 SELECT TABLE_NAME FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO + +SELECT has_dbaccess(BABEL5119_db.sys.databases.name) FROM BABEL5119_db.sys.databases WHERE BABEL5119_db.sys.databases.name='BABEL5119_db' +GO + +-- From 'BABEL5119_db' database +USE BABEL5119_db +GO + +SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM master.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM master.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +-- Checking crossdb for information_schema_tsql +SELECT * FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_10(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_10 select name, object_id, schema_id from master.sys.tables WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_11(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_11 SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_12(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_12 SELECT TABLE_NAME FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO + +SELECT has_dbaccess(master.sys.databases.name) FROM master.sys.databases WHERE master.sys.databases.name='BABEL5119_db' +GO +-- terminate-tsql-conn user=login_babel5119_1 password=12345678 + +-- Testing crossdb queries for non-sysadmin non-db_owner +-- tsql user=login_babel5119_2 password=12345678 +-- Checking crossdb for sys views +-- From 'master' database +USE master +GO + +SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM BABEL5119_db.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM BABEL5119_db.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +-- Checking crossdb for information_schema_tsql +SELECT * FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, COLUMN_NAME FROM BABEL5119_db.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, VIEW_DEFINITION FROM BABEL5119_db.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +-- General crossdb queries +SELECT tb_1.*, tb_2.* FROM BABEL5119_db.dbo.BABEL5119_t1 tb_1, master.guest.BABEL5119_t4 tb_2 +GO + +SELECT vw_1.*, vw_2.* FROM BABEL5119_db.dbo.BABEL5119_v1 vw_1, master.guest.BABEL5119_v4 vw_2 +GO + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_13(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_13 select name, object_id, schema_id from BABEL5119_db.sys.tables WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_14(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_14 SELECT name FROM BABEL5119_db.sys.databases WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_15(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_15 SELECT TABLE_NAME FROM BABEL5119_db.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO + +SELECT has_dbaccess(BABEL5119_db.sys.databases.name) FROM BABEL5119_db.sys.databases WHERE BABEL5119_db.sys.databases.name='BABEL5119_db' +GO + +SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM master.sys.views WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +SELECT name FROM master.sys.procedures WHERE name LIKE 'BABEL5119%' +ORDER BY name +GO + +-- Checking crossdb for information_schema_tsql +SELECT * FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, COLUMN_NAME FROM master.information_schema_tsql.columns WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +SELECT TABLE_NAME, VIEW_DEFINITION FROM master.information_schema_tsql.views WHERE TABLE_NAME LIKE 'BABEL5119%' +ORDER BY TABLE_NAME +GO + +-- Using crossdb query data +CREATE TABLE #babel5119_tmp_table_16(name VARCHAR(MAX), object_id int, schema_id int) +INSERT INTO #babel5119_tmp_table_16 select name, object_id, schema_id from master.sys.tables WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_17(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_17 SELECT name FROM master.sys.databases WHERE name LIKE 'BABEL5119%' +GO + +CREATE TABLE #babel5119_tmp_table_18(name VARCHAR(MAX)) +INSERT INTO #babel5119_tmp_table_18 SELECT TABLE_NAME FROM master.information_schema_tsql.tables WHERE TABLE_NAME LIKE 'BABEL5119%' +GO + +SELECT has_dbaccess(master.sys.databases.name) FROM master.sys.databases WHERE master.sys.databases.name='BABEL5119_db' +GO +-- terminate-tsql-conn user=login_babel5119_2 password=12345678 + +-- Checking the permissions after alter +-- tsql user=login_babel5119_2 password=12345678 +USE BABEL5119_db +GO +-- terminate-tsql-conn user=login_babel5119_2 password=12345678 + +-- tsql +ALTER authorization on database::BABEL5119_db TO login_babel5119_2 +GO +-- terminate-tsql-conn + +-- tsql user=login_babel5119_1 password=12345678 +USE BABEL5119_db +GO +-- terminate-tsql-conn user=login_babel5119_1 password=12345678 + +-- tsql user=login_babel5119_2 password=12345678 +USE BABEL5119_db +GO +INSERT INTO BABEL5119_t1 VALUES(1) +GO +-- terminate-tsql-conn user=login_babel5119_2 password=12345678 \ No newline at end of file diff --git a/test/JDBC/upgrade/15_8/schedule b/test/JDBC/upgrade/15_8/schedule index 7006c42e09..de3457e62c 100644 --- a/test/JDBC/upgrade/15_8/schedule +++ b/test/JDBC/upgrade/15_8/schedule @@ -558,3 +558,4 @@ space alter-procedure-15_8-or-16_4 binary-datatype-operators cast-varchar-to-time +BABEL-5119 diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 18146ea67a..7c36b986bd 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -560,4 +560,5 @@ space binary-datatype-operators cast-varchar-to-time SELECT_INTO_TEST +BABEL-5119