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 1, 2021
1 parent 2cb914e commit bfe2354
Show file tree
Hide file tree
Showing 4 changed files with 4,530 additions and 4,487 deletions.
24 changes: 18 additions & 6 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 @@ -1125,8 +1130,15 @@ func (n *UserSpec) EncodedPassword() (string, bool) {
}

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

0 comments on commit bfe2354

Please sign in to comment.