From bfa943c771a4b99f11d61f84670a788cdad8b780 Mon Sep 17 00:00:00 2001 From: Chris Hoffman Date: Thu, 10 Mar 2016 21:06:50 -0500 Subject: [PATCH] Changing DROP USER query to a more compatible version --- builtin/logical/mssql/secret_creds.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/builtin/logical/mssql/secret_creds.go b/builtin/logical/mssql/secret_creds.go index 89b4bf6b73..a7ca716123 100644 --- a/builtin/logical/mssql/secret_creds.go +++ b/builtin/logical/mssql/secret_creds.go @@ -121,8 +121,7 @@ func (b *backend) secretCredsRevoke( if err != nil { return nil, err } - revokeStmts = append(revokeStmts, fmt.Sprintf( - "USE [%s]; DROP USER IF EXISTS [%s];", dbName, qUsername)) + revokeStmts = append(revokeStmts, fmt.Sprintf(dropUserSQL, dbName, username, username)) } // we do not stop on error, as we want to remove as @@ -163,12 +162,23 @@ func (b *backend) secretCredsRevoke( return nil, nil } +const dropUserSQL = ` +USE [%s] +IF EXISTS + (SELECT name + FROM sys.database_principals + WHERE name = N'%s') +BEGIN + DROP USER [%s] +END +` + const dropLoginSQL = ` IF EXISTS (SELECT name FROM master.sys.server_principals - WHERE name = '%s') + WHERE name = N'%s') BEGIN - DROP LOGIN [%s] + DROP LOGIN [%s] END `