-
Notifications
You must be signed in to change notification settings - Fork 105
Added sp_helplogins - stored proc that provides information about logins and users associated with those logins. #3733
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
Open
ayushdsh
wants to merge
63
commits into
babelfish-for-postgresql:BABEL_5_X_DEV
Choose a base branch
from
ayushdsh:babel-5742
base: BABEL_5_X_DEV
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 52 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
0079da2
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 23684fe
Removed tests from singledb-schedule since these tests are expected to
ayushdsh 6b2ddbb
Addressed comments - improved join conditions, separated prepare script
ayushdsh 68f7149
Rectified upgrade scripts
ayushdsh f442c91
Removing upgrade script to test test-failures
ayushdsh 89a9344
Added prepare script to ignore in jdbc_schedule
ayushdsh 5d9038d
Added view all_database_users to expected of upgrade validation
ayushdsh 55db312
Added wrapper around original stored proc to reduce duplication and
ayushdsh 2f1dc51
Removed view from expected of upgrade validation
ayushdsh 8ccfbc0
Rectified testcases
ayushdsh f48e50c
Rectified jdbc_schedule
ayushdsh df98409
Added internal view to expected upgrade and sql validation
ayushdsh 9bc8e3b
Trying to rectify tests
ayushdsh 5d695e2
Rectified to fix database collation failures
ayushdsh fd42f89
Rectified testcases and added test for internal views
ayushdsh 85e306d
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 26f75bb
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 4cc439e
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 398125e
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 9b50dbd
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 2425564
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 663a316
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 0fc2d30
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh 5da07e6
Added statements for understanding dump-restore failure
ayushdsh 2c483cc
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh bca0d80
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 371d20f
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 2226e16
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh 80b72dc
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh ad1d519
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh e8954bf
Merge branch 'BABEL_5_X_DEV' into babel-5742
ayushdsh 119924b
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh aa9f842
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 511b6b9
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh b515544
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh 2764fc9
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 3befb69
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 19b2dae
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh e458cde
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 3c2d645
testing to find out failures in GA where tests are not able to get ms…
ayushdsh 40a83d2
testing to find out failures in GA where tests are not able to get ms…
ayushdsh 6c89c70
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 223e37e
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 13e8f22
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 976e4ec
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh 5d1fbf8
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh e878316
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh 5474f10
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 03f3072
testing dump-restore
ayushdsh c32f785
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 6d06f27
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 589aaa6
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 76e1b7b
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh 34def74
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh f5dae32
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh c39bb30
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh ec9288a
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh b9e5667
Handling overflow and incorrect outputs in case of certain money and …
ayushdsh 75f09f3
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh add79f9
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 93cf527
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh 3faa1b8
Merge branch 'babelfish-for-postgresql:BABEL_5_X_DEV' into babel-5742
ayushdsh f239e46
Added sp_helplogins which is a system stored procedure that provides …
ayushdsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3754,3 +3754,140 @@ BEGIN | |
END; | ||
$$ LANGUAGE pltsql; | ||
GRANT EXECUTE ON PROCEDURE sys.sp_procedure_params_100_managed TO PUBLIC; | ||
|
||
CREATE OR REPLACE PROCEDURE sys.sp_helplogins(IN "@loginname" sys.sysname DEFAULT NULL) | ||
LANGUAGE pltsql | ||
AS $$ | ||
DECLARE @input_loginname sys.sysname; | ||
DECLARE @current_username sys.nvarchar(128) | ||
DECLARE @is_sysadmin BIT | ||
BEGIN | ||
|
||
IF is_srvrolemember('securityadmin') = 0 | ||
BEGIN | ||
RAISERROR('User does not have permission to perform this action.', 16, 1); | ||
RETURN 0; | ||
END | ||
|
||
SET @current_username = LOWER(sys.suser_name()); | ||
SET @is_sysadmin = is_srvrolemember('sysadmin'); | ||
|
||
IF @loginname IS NULL | ||
BEGIN | ||
SELECT DISTINCT | ||
CAST(LExt.orig_loginname AS sys.SYSNAME) AS LoginName, | ||
CAST(CAST(Base.oid AS INT) AS sys.varbinary(85)) AS sid, | ||
ayushdsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CAST(LExt.default_database_name AS SYS.SYSNAME) AS DefDBName, | ||
CAST(LExt.default_language_name AS SYS.SYSNAME) AS DefLangName, | ||
CASE | ||
WHEN Ext.login_name IS NOT NULL AND Ext.login_name = LExt.rolname COLLATE database_default THEN CAST('YES' AS sys.varchar(5)) | ||
WHEN Db.owner COLLATE database_default = LExt.orig_loginname THEN CAST('YES' AS sys.varchar(5)) | ||
ELSE CAST('NO' AS sys.varchar(5)) | ||
END AS AUser, | ||
CAST('NO' AS sys.varchar(8)) AS ARemote -- Currently we do not support linking local logins to remote logins | ||
FROM pg_catalog.pg_roles AS Base | ||
INNER JOIN sys.babelfish_authid_login_ext AS LExt ON Base.rolname = LExt.rolname | ||
LEFT JOIN sys.babelfish_authid_user_ext AS Ext ON Ext.login_name = Base.rolname AND Ext.type != 'R' | ||
LEFT JOIN sys.babelfish_sysdatabases AS Db ON Db.name COLLATE database_default = LExt.default_database_name | ||
WHERE LExt.type NOT IN ('R', 'Z') | ||
|
||
SELECT | ||
CAST(COALESCE(NULLIF(UExt.login_name, ''), Db.owner) AS sys.SYSNAME) AS LoginName, | ||
CAST(UExt.database_name AS sys.SYSNAME) AS DBName, | ||
CAST(UExt.orig_username AS SYS.SYSNAME) AS UserName, | ||
CAST('User' AS sys.varchar(8)) AS UserOrAlias | ||
FROM sys.babelfish_authid_user_ext UExt | ||
LEFT JOIN sys.babelfish_sysdatabases Db ON Db.name COLLATE database_default = UExt.database_name | ||
WHERE UExt.type != 'R' AND | ||
UExt.orig_username != 'guest' AND | ||
has_dbaccess(UExt.database_name) = 1 AND | ||
( | ||
@is_sysadmin = 1 OR | ||
UExt.login_name = @current_username OR | ||
ISNULL(UExt.login_name, '') = '' OR | ||
EXISTS ( | ||
SELECT 1 | ||
FROM pg_catalog.pg_auth_members AS Authmbr | ||
INNER JOIN pg_catalog.pg_roles AS PGR1 ON PGR1.oid = Authmbr.roleid | ||
INNER JOIN pg_catalog.pg_roles AS PGR2 ON PGR2.oid = Authmbr.member | ||
INNER JOIN sys.babelfish_authid_user_ext AS UExt1 ON PGR1.rolname = UExt1.rolname | ||
INNER JOIN sys.babelfish_authid_user_ext AS UExt2 ON PGR2.rolname = UExt2.rolname | ||
WHERE UExt1.orig_username IN ('db_securityadmin', 'db_accessadmin') | ||
AND UExt2.database_name = UExt.database_name | ||
AND UExt2.login_name = @current_username | ||
) | ||
) | ||
UNION | ||
SELECT | ||
CAST(COALESCE(NULLIF(UExt2.login_name, ''), Db.owner) AS sys.SYSNAME) AS LoginName, | ||
CAST(UExt2.database_name AS sys.SYSNAME) AS DBName, | ||
CAST(UExt1.orig_username AS sys.SYSNAME) AS UserName, | ||
CAST('Member of' AS sys.varchar(10)) AS UserOrAlias | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The column type should be char(8), please fix it at other places as well. |
||
FROM pg_catalog.pg_auth_members AS Authmbr | ||
INNER JOIN pg_catalog.pg_roles AS PGR1 ON PGR1.oid = Authmbr.roleid | ||
INNER JOIN pg_catalog.pg_roles AS PGR2 ON PGR2.oid = Authmbr.member | ||
INNER JOIN sys.babelfish_authid_user_ext AS UExt1 ON PGR1.rolname = UExt1.rolname AND UExt1.type = 'R' | ||
INNER JOIN sys.babelfish_authid_user_ext AS UExt2 ON PGR2.rolname = UExt2.rolname AND UExt2.orig_username != 'db_owner' | ||
LEFT JOIN sys.babelfish_sysdatabases Db ON Db.name COLLATE database_default = UExt1.database_name | ||
WHERE | ||
has_dbaccess(UExt2.database_name) = 1 AND | ||
( | ||
@is_sysadmin = 1 OR | ||
UExt2.login_name = @current_username OR | ||
ISNULL(UExt2.login_name, '') = '' | ||
) | ||
END | ||
ELSE | ||
BEGIN | ||
|
||
SET @input_loginname = sys.RTRIM(@loginname); | ||
|
||
SELECT DISTINCT | ||
CAST(LExt.orig_loginname AS sys.SYSNAME) AS LoginName, | ||
CAST(CAST(Base.oid AS INT) AS sys.varbinary(85)) AS sid, | ||
CAST(LExt.default_database_name AS SYS.SYSNAME) AS DefDBName, | ||
CAST(LExt.default_language_name AS SYS.SYSNAME) AS DefLangName, | ||
CASE | ||
WHEN Ext.login_name IS NOT NULL AND Ext.login_name = LExt.rolname COLLATE database_default THEN CAST('YES' AS sys.varchar(5)) | ||
WHEN Db.owner COLLATE database_default = LExt.orig_loginname THEN CAST('YES' AS sys.varchar(5)) | ||
ELSE CAST('NO' AS sys.varchar(5)) | ||
END AS AUser, | ||
CAST('NO' AS sys.varchar(8)) AS ARemote -- Currently we do not support linking local logins to remote logins | ||
FROM pg_catalog.pg_roles AS Base | ||
INNER JOIN sys.babelfish_authid_login_ext AS LExt ON Base.rolname = LExt.rolname | ||
LEFT JOIN sys.babelfish_authid_user_ext AS Ext ON Ext.login_name = Base.rolname AND Ext.type != 'R' | ||
LEFT JOIN sys.babelfish_sysdatabases AS Db ON Db.name COLLATE database_default = LExt.default_database_name | ||
WHERE LExt.type NOT IN ('R', 'Z') AND LExt.orig_loginname = @input_loginname | ||
|
||
SELECT | ||
CAST(COALESCE(NULLIF(UExt.login_name, ''), Db.owner) AS sys.SYSNAME) AS LoginName, | ||
CAST(UExt.database_name AS sys.SYSNAME) AS DBName, | ||
CAST(UExt.orig_username AS SYS.SYSNAME) AS UserName, | ||
CAST('User' AS sys.varchar(8)) AS UserOrAlias | ||
FROM sys.babelfish_authid_user_ext UExt | ||
LEFT JOIN sys.babelfish_sysdatabases Db ON Db.name COLLATE database_default = UExt.database_name | ||
WHERE UExt.type != 'R' AND | ||
UExt.orig_username != 'guest' AND | ||
has_dbaccess(UExt.database_name) = 1 AND | ||
COALESCE(NULLIF(UExt.login_name, ''), Db.owner) = @input_loginname | ||
UNION | ||
SELECT | ||
CAST(COALESCE(NULLIF(UExt2.login_name, ''), Db.owner) AS sys.SYSNAME) AS LoginName, | ||
CAST(UExt2.database_name AS sys.SYSNAME) AS DBName, | ||
CAST(UExt1.orig_username AS SYS.SYSNAME) AS UserName, | ||
CAST('Member of' AS sys.varchar(10)) AS UserOrAlias | ||
FROM pg_catalog.pg_auth_members AS Authmbr | ||
INNER JOIN pg_catalog.pg_roles AS PGR1 ON PGR1.oid = Authmbr.roleid | ||
INNER JOIN pg_catalog.pg_roles AS PGR2 ON PGR2.oid = Authmbr.member | ||
INNER JOIN sys.babelfish_authid_user_ext AS UExt1 ON PGR1.rolname = UExt1.rolname AND UExt1.type = 'R' | ||
INNER JOIN sys.babelfish_authid_user_ext AS UExt2 ON PGR2.rolname = UExt2.rolname AND UExt2.orig_username != 'db_owner' | ||
LEFT JOIN sys.babelfish_sysdatabases Db ON Db.name COLLATE database_default = UExt1.database_name | ||
WHERE | ||
has_dbaccess(UExt2.database_name) = 1 AND | ||
COALESCE(NULLIF(UExt2.login_name, ''), Db.owner) = @input_loginname | ||
END; | ||
|
||
RETURN 0; | ||
END; | ||
$$; | ||
GRANT EXECUTE ON PROCEDURE sys.sp_helplogins TO PUBLIC; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,6 @@ GO | |
|
||
DROP LOGIN babel_5146_user_l1; | ||
GO | ||
|
||
GRANT CONNECT TO guest; | ||
GO |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.