****************************************************************************** * Result Packets * ******************************************************************************/
()
| 498 | ******************************************************************************/ |
| 499 | |
| 500 | func (mc *mysqlConn) readAuthResult() ([]byte, string, error) { |
| 501 | data, err := mc.readPacket() |
| 502 | if err != nil { |
| 503 | return nil, "", err |
| 504 | } |
| 505 | |
| 506 | // packet indicator |
| 507 | switch data[0] { |
| 508 | |
| 509 | case iOK: |
| 510 | // resultUnchanged, since auth happens before any queries or |
| 511 | // commands have been executed. |
| 512 | return nil, "", mc.resultUnchanged().handleOkPacket(data) |
| 513 | |
| 514 | case iAuthMoreData: |
| 515 | return data[1:], "", err |
| 516 | |
| 517 | case iEOF: |
| 518 | if len(data) == 1 { |
| 519 | // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_packets_protocol_old_auth_switch_request.html |
| 520 | return nil, "mysql_old_password", nil |
| 521 | } |
| 522 | pluginEndIndex := bytes.IndexByte(data, 0x00) |
| 523 | if pluginEndIndex < 0 { |
| 524 | return nil, "", ErrMalformPkt |
| 525 | } |
| 526 | plugin := string(data[1:pluginEndIndex]) |
| 527 | authData := data[pluginEndIndex+1:] |
| 528 | if len(authData) > 0 && authData[len(authData)-1] == 0 { |
| 529 | authData = authData[:len(authData)-1] |
| 530 | } |
| 531 | return authData, plugin, nil |
| 532 | |
| 533 | default: // Error otherwise |
| 534 | return nil, "", mc.handleErrorPacket(data) |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | // Returns error if Packet is not a 'Result OK'-Packet |
| 539 | func (mc *okHandler) readResultOK() error { |
no test coverage detected