Просмотр исходного кода

Parameter renamed to allowCleartextPasswords

Joshua Prunier 10 лет назад
Родитель
Сommit
49823e2fe6
7 измененных файлов с 52 добавлено и 52 удалено
  1. 2 2
      README.md
  2. 16 16
      connection.go
  3. 1 1
      driver.go
  4. 11 11
      errors.go
  5. 7 7
      packets.go
  6. 2 2
      utils.go
  7. 13 13
      utils_test.go

+ 2 - 2
README.md

@@ -123,14 +123,14 @@ Default:        false
 `allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files.
 `allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files.
 [*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)
 [*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)
 
 
-##### `allowClearPasswords`
+##### `allowCleartextPasswords`
 
 
 ```
 ```
 Type:           bool
 Type:           bool
 Valid Values:   true, false
 Valid Values:   true, false
 Default:        false
 Default:        false
 ```
 ```
-`allowClearPasswords=true` allows the usage of the cleartext client side plugin. This can be insecure but is required by the [PAM authentication plugin](http://dev.mysql.com/doc/refman/5.5/en/pam-authentication-plugin.html).
+`allowCleartextPasswords=true` allows the usage of the cleartext client side plugin. This can be insecure but is required by the [PAM authentication plugin](http://dev.mysql.com/doc/refman/5.5/en/pam-authentication-plugin.html).
 
 
 ##### `allowOldPasswords`
 ##### `allowOldPasswords`
 
 

+ 16 - 16
connection.go

@@ -34,22 +34,22 @@ type mysqlConn struct {
 }
 }
 
 
 type config struct {
 type config struct {
-	user                string
-	passwd              string
-	net                 string
-	addr                string
-	dbname              string
-	params              map[string]string
-	loc                 *time.Location
-	tls                 *tls.Config
-	timeout             time.Duration
-	collation           uint8
-	allowAllFiles       bool
-	allowOldPasswords   bool
-	allowClearPasswords bool
-	clientFoundRows     bool
-	columnsWithAlias    bool
-	interpolateParams   bool
+	user                    string
+	passwd                  string
+	net                     string
+	addr                    string
+	dbname                  string
+	params                  map[string]string
+	loc                     *time.Location
+	tls                     *tls.Config
+	timeout                 time.Duration
+	collation               uint8
+	allowAllFiles           bool
+	allowOldPasswords       bool
+	allowCleartextPasswords bool
+	clientFoundRows         bool
+	columnsWithAlias        bool
+	interpolateParams       bool
 }
 }
 
 
 // Handles parameters set in DSN after the connection is established
 // Handles parameters set in DSN after the connection is established

+ 1 - 1
driver.go

@@ -107,7 +107,7 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
 				mc.Close()
 				mc.Close()
 				return nil, err
 				return nil, err
 			}
 			}
-		} else if mc.cfg != nil && mc.cfg.allowClearPasswords && err == ErrClearPassword {
+		} else if mc.cfg != nil && mc.cfg.allowCleartextPasswords && err == ErrCleartextPassword {
 			if err = mc.writeClearAuthPacket(); err != nil {
 			if err = mc.writeClearAuthPacket(); err != nil {
 				mc.Close()
 				mc.Close()
 				return nil, err
 				return nil, err

+ 11 - 11
errors.go

@@ -19,17 +19,17 @@ import (
 
 
 // Various errors the driver might return. Can change between driver versions.
 // Various errors the driver might return. Can change between driver versions.
 var (
 var (
-	ErrInvalidConn   = errors.New("Invalid Connection")
-	ErrMalformPkt    = errors.New("Malformed Packet")
-	ErrNoTLS         = errors.New("TLS encryption requested but server does not support TLS")
-	ErrOldPassword   = errors.New("This user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
-	ErrClearPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowClearPasswords=1' to your DSN.")
-	ErrUnknownPlugin = errors.New("The authentication plugin is not supported.")
-	ErrOldProtocol   = errors.New("MySQL-Server does not support required Protocol 41+")
-	ErrPktSync       = errors.New("Commands out of sync. You can't run this command now")
-	ErrPktSyncMul    = errors.New("Commands out of sync. Did you run multiple statements at once?")
-	ErrPktTooLarge   = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
-	ErrBusyBuffer    = errors.New("Busy buffer")
+	ErrInvalidConn       = errors.New("Invalid Connection")
+	ErrMalformPkt        = errors.New("Malformed Packet")
+	ErrNoTLS             = errors.New("TLS encryption requested but server does not support TLS")
+	ErrOldPassword       = errors.New("This user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
+	ErrCleartextPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN.")
+	ErrUnknownPlugin     = errors.New("The authentication plugin is not supported.")
+	ErrOldProtocol       = errors.New("MySQL-Server does not support required Protocol 41+")
+	ErrPktSync           = errors.New("Commands out of sync. You can't run this command now")
+	ErrPktSyncMul        = errors.New("Commands out of sync. Did you run multiple statements at once?")
+	ErrPktTooLarge       = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
+	ErrBusyBuffer        = errors.New("Busy buffer")
 )
 )
 
 
 var errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)
 var errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)

+ 7 - 7
packets.go

@@ -337,12 +337,12 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error {
 func (mc *mysqlConn) writeClearAuthPacket() error {
 func (mc *mysqlConn) writeClearAuthPacket() error {
 	// Calculate the packet length and add a tailing 0
 	// Calculate the packet length and add a tailing 0
 	pktLen := len(mc.cfg.passwd) + 1
 	pktLen := len(mc.cfg.passwd) + 1
-        data := mc.buf.takeSmallBuffer(4 + pktLen)
-        if data == nil {
-                // can not take the buffer. Something must be wrong with the connection
-                errLog.Print(ErrBusyBuffer)
-                return driver.ErrBadConn
-        }
+	data := mc.buf.takeSmallBuffer(4 + pktLen)
+	if data == nil {
+		// can not take the buffer. Something must be wrong with the connection
+		errLog.Print(ErrBusyBuffer)
+		return driver.ErrBadConn
+	}
 
 
 	// Add the clear password [null terminated string]
 	// Add the clear password [null terminated string]
 	copy(data[4:], mc.cfg.passwd)
 	copy(data[4:], mc.cfg.passwd)
@@ -441,7 +441,7 @@ func (mc *mysqlConn) readResultOK() error {
 					return ErrOldPassword
 					return ErrOldPassword
 				} else if plugin == "mysql_clear_password" {
 				} else if plugin == "mysql_clear_password" {
 					// using clear text password
 					// using clear text password
-					return ErrClearPassword
+					return ErrCleartextPassword
 				} else {
 				} else {
 					return ErrUnknownPlugin
 					return ErrUnknownPlugin
 				}
 				}

+ 2 - 2
utils.go

@@ -202,9 +202,9 @@ func parseDSNParams(cfg *config, params string) (err error) {
 			}
 			}
 
 
 		// Use cleartext authentication mode (MySQL 5.5.10+)
 		// Use cleartext authentication mode (MySQL 5.5.10+)
-		case "allowClearPasswords":
+		case "allowCleartextPasswords":
 			var isBool bool
 			var isBool bool
-			cfg.allowClearPasswords, isBool = readBool(value)
+			cfg.allowCleartextPasswords, isBool = readBool(value)
 			if !isBool {
 			if !isBool {
 				return fmt.Errorf("Invalid Bool value: %s", value)
 				return fmt.Errorf("Invalid Bool value: %s", value)
 			}
 			}

+ 13 - 13
utils_test.go

@@ -22,19 +22,19 @@ var testDSNs = []struct {
 	out string
 	out string
 	loc *time.Location
 	loc *time.Location
 }{
 }{
-	{"username:password@protocol(address)/dbname?param=value", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"username:password@protocol(address)/dbname?param=value&columnsWithAlias=true", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:true interpolateParams:false}", time.UTC},
-	{"user@unix(/path/to/socket)/dbname?charset=utf8", "&{user:user passwd: net:unix addr:/path/to/socket dbname:dbname params:map[charset:utf8] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8mb4,utf8] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"user:password@/dbname?loc=UTC&timeout=30s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci", "&{user:user passwd:password net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls:<nil> timeout:30000000000 collation:224 allowAllFiles:true allowOldPasswords:true allowClearPasswords:false clientFoundRows:true columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local", "&{user:user passwd:p@ss(word) net:tcp addr:[de:ad:be:ef::ca:fe]:80 dbname:dbname params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.Local},
-	{"/dbname", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"@/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"user:p@/ssword@/", "&{user:user passwd:p@/ssword net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
-	{"unix/?arg=%2Fsome%2Fpath.ext", "&{user: passwd: net:unix addr:/tmp/mysql.sock dbname: params:map[arg:/some/path.ext] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowClearPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"username:password@protocol(address)/dbname?param=value", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"username:password@protocol(address)/dbname?param=value&columnsWithAlias=true", "&{user:username passwd:password net:protocol addr:address dbname:dbname params:map[param:value] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:true interpolateParams:false}", time.UTC},
+	{"user@unix(/path/to/socket)/dbname?charset=utf8", "&{user:user passwd: net:unix addr:/path/to/socket dbname:dbname params:map[charset:utf8] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify", "&{user:user passwd:password net:tcp addr:localhost:5555 dbname:dbname params:map[charset:utf8mb4,utf8] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"user:password@/dbname?loc=UTC&timeout=30s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci", "&{user:user passwd:password net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls:<nil> timeout:30000000000 collation:224 allowAllFiles:true allowOldPasswords:true allowCleartextPasswords:false clientFoundRows:true columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local", "&{user:user passwd:p@ss(word) net:tcp addr:[de:ad:be:ef::ca:fe]:80 dbname:dbname params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.Local},
+	{"/dbname", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname:dbname params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"@/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"/", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"", "&{user: passwd: net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"user:p@/ssword@/", "&{user:user passwd:p@/ssword net:tcp addr:127.0.0.1:3306 dbname: params:map[] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
+	{"unix/?arg=%2Fsome%2Fpath.ext", "&{user: passwd: net:unix addr:/tmp/mysql.sock dbname: params:map[arg:/some/path.ext] loc:%p tls:<nil> timeout:0 collation:33 allowAllFiles:false allowOldPasswords:false allowCleartextPasswords:false clientFoundRows:false columnsWithAlias:false interpolateParams:false}", time.UTC},
 }
 }
 
 
 func TestDSNParser(t *testing.T) {
 func TestDSNParser(t *testing.T) {