From c11f2638b92e62a226598b7d40a1f35dd84c242e Mon Sep 17 00:00:00 2001 From: Brian Kassouf Date: Thu, 27 Apr 2017 22:56:06 -0700 Subject: [PATCH] If user provides a revocation statement for MSSQL plugin honor it --- plugins/database/mssql/mssql.go | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugins/database/mssql/mssql.go b/plugins/database/mssql/mssql.go index 48da8ff08..a0d863080 100644 --- a/plugins/database/mssql/mssql.go +++ b/plugins/database/mssql/mssql.go @@ -142,6 +142,51 @@ func (m *MSSQL) RenewUser(statements dbplugin.Statements, username string, expir // then kill pending connections from that user, and finally drop the user and login from the // database instance. func (m *MSSQL) RevokeUser(statements dbplugin.Statements, username string) error { + if statements.RevocationStatements == "" { + return m.revokeUserDefault(username) + } + + // Get connection + db, err := m.getConnection() + if err != nil { + return err + } + + // Start a transaction + tx, err := db.Begin() + if err != nil { + return err + } + defer tx.Rollback() + + // Execute each query + for _, query := range strutil.ParseArbitraryStringSlice(statements.RevocationStatements, ";") { + query = strings.TrimSpace(query) + if len(query) == 0 { + continue + } + + stmt, err := tx.Prepare(dbutil.QueryHelper(query, map[string]string{ + "name": username, + })) + if err != nil { + return err + } + defer stmt.Close() + if _, err := stmt.Exec(); err != nil { + return err + } + } + + // Commit the transaction + if err := tx.Commit(); err != nil { + return err + } + + return nil +} + +func (m *MSSQL) revokeUserDefault(username string) error { // Get connection db, err := m.getConnection() if err != nil {