Skip to content

Commit

Permalink
parser,ast: Support for authentication plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Jun 2, 2021
1 parent 10b704a commit 5ba724d
Show file tree
Hide file tree
Showing 4 changed files with 4,629 additions and 4,583 deletions.
26 changes: 21 additions & 5 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,21 @@ type AuthOption struct {
ByAuthString bool
AuthString string
HashString string
// TODO: support auth_plugin
AuthPlugin string
}

// Restore implements Node interface.
func (n *AuthOption) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("IDENTIFIED BY ")
ctx.WriteKeyWord("IDENTIFIED")
if n.AuthPlugin != "" {
ctx.WriteKeyWord(" WITH ")
ctx.WriteString(n.AuthPlugin)
}
if n.ByAuthString {
ctx.WriteKeyWord(" BY ")
ctx.WriteString(n.AuthString)
} else {
ctx.WriteKeyWord("PASSWORD ")
} else if n.HashString != "" {
ctx.WriteKeyWord(" AS ")
ctx.WriteString(n.HashString)
}
return nil
Expand Down Expand Up @@ -1100,7 +1105,18 @@ func (n *UserSpec) EncodedPassword() (string, bool) {
}

// Not a legal password string.
if len(opt.HashString) != 41 || !strings.HasPrefix(opt.HashString, "*") {
switch opt.AuthPlugin {
case mysql.AuthCachingSha2Password:
if len(opt.HashString) != mysql.SHAPWDHashLen {
return "", false
}
case "":
fallthrough
case mysql.AuthNativePassword:
if len(opt.HashString) != (mysql.PWDHashLen+1) || !strings.HasPrefix(opt.HashString, "*") {
return "", false
}
default:
return "", false
}
return opt.HashString, true
Expand Down
Loading

0 comments on commit 5ba724d

Please sign in to comment.