Skip to content

Commit 49823e2

Browse files
committed
Parameter renamed to allowCleartextPasswords
1 parent 4f478ef commit 49823e2

File tree

7 files changed

+52
-52
lines changed

7 files changed

+52
-52
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ Default: false
123123
`allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files.
124124
[*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)
125125

126-
##### `allowClearPasswords`
126+
##### `allowCleartextPasswords`
127127

128128
```
129129
Type: bool
130130
Valid Values: true, false
131131
Default: false
132132
```
133-
`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).
133+
`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).
134134

135135
##### `allowOldPasswords`
136136

connection.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ type mysqlConn struct {
3434
}
3535

3636
type config struct {
37-
user string
38-
passwd string
39-
net string
40-
addr string
41-
dbname string
42-
params map[string]string
43-
loc *time.Location
44-
tls *tls.Config
45-
timeout time.Duration
46-
collation uint8
47-
allowAllFiles bool
48-
allowOldPasswords bool
49-
allowClearPasswords bool
50-
clientFoundRows bool
51-
columnsWithAlias bool
52-
interpolateParams bool
37+
user string
38+
passwd string
39+
net string
40+
addr string
41+
dbname string
42+
params map[string]string
43+
loc *time.Location
44+
tls *tls.Config
45+
timeout time.Duration
46+
collation uint8
47+
allowAllFiles bool
48+
allowOldPasswords bool
49+
allowCleartextPasswords bool
50+
clientFoundRows bool
51+
columnsWithAlias bool
52+
interpolateParams bool
5353
}
5454

5555
// Handles parameters set in DSN after the connection is established

driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
107107
mc.Close()
108108
return nil, err
109109
}
110-
} else if mc.cfg != nil && mc.cfg.allowClearPasswords && err == ErrClearPassword {
110+
} else if mc.cfg != nil && mc.cfg.allowCleartextPasswords && err == ErrCleartextPassword {
111111
if err = mc.writeClearAuthPacket(); err != nil {
112112
mc.Close()
113113
return nil, err

errors.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ import (
1919

2020
// Various errors the driver might return. Can change between driver versions.
2121
var (
22-
ErrInvalidConn = errors.New("Invalid Connection")
23-
ErrMalformPkt = errors.New("Malformed Packet")
24-
ErrNoTLS = errors.New("TLS encryption requested but server does not support TLS")
25-
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")
26-
ErrClearPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowClearPasswords=1' to your DSN.")
27-
ErrUnknownPlugin = errors.New("The authentication plugin is not supported.")
28-
ErrOldProtocol = errors.New("MySQL-Server does not support required Protocol 41+")
29-
ErrPktSync = errors.New("Commands out of sync. You can't run this command now")
30-
ErrPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?")
31-
ErrPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
32-
ErrBusyBuffer = errors.New("Busy buffer")
22+
ErrInvalidConn = errors.New("Invalid Connection")
23+
ErrMalformPkt = errors.New("Malformed Packet")
24+
ErrNoTLS = errors.New("TLS encryption requested but server does not support TLS")
25+
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")
26+
ErrCleartextPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN.")
27+
ErrUnknownPlugin = errors.New("The authentication plugin is not supported.")
28+
ErrOldProtocol = errors.New("MySQL-Server does not support required Protocol 41+")
29+
ErrPktSync = errors.New("Commands out of sync. You can't run this command now")
30+
ErrPktSyncMul = errors.New("Commands out of sync. Did you run multiple statements at once?")
31+
ErrPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
32+
ErrBusyBuffer = errors.New("Busy buffer")
3333
)
3434

3535
var errLog Logger = log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile)

packets.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ func (mc *mysqlConn) writeOldAuthPacket(cipher []byte) error {
337337
func (mc *mysqlConn) writeClearAuthPacket() error {
338338
// Calculate the packet length and add a tailing 0
339339
pktLen := len(mc.cfg.passwd) + 1
340-
data := mc.buf.takeSmallBuffer(4 + pktLen)
341-
if data == nil {
342-
// can not take the buffer. Something must be wrong with the connection
343-
errLog.Print(ErrBusyBuffer)
344-
return driver.ErrBadConn
345-
}
340+
data := mc.buf.takeSmallBuffer(4 + pktLen)
341+
if data == nil {
342+
// can not take the buffer. Something must be wrong with the connection
343+
errLog.Print(ErrBusyBuffer)
344+
return driver.ErrBadConn
345+
}
346346

347347
// Add the clear password [null terminated string]
348348
copy(data[4:], mc.cfg.passwd)
@@ -441,7 +441,7 @@ func (mc *mysqlConn) readResultOK() error {
441441
return ErrOldPassword
442442
} else if plugin == "mysql_clear_password" {
443443
// using clear text password
444-
return ErrClearPassword
444+
return ErrCleartextPassword
445445
} else {
446446
return ErrUnknownPlugin
447447
}

utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ func parseDSNParams(cfg *config, params string) (err error) {
202202
}
203203

204204
// Use cleartext authentication mode (MySQL 5.5.10+)
205-
case "allowClearPasswords":
205+
case "allowCleartextPasswords":
206206
var isBool bool
207-
cfg.allowClearPasswords, isBool = readBool(value)
207+
cfg.allowCleartextPasswords, isBool = readBool(value)
208208
if !isBool {
209209
return fmt.Errorf("Invalid Bool value: %s", value)
210210
}

utils_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ var testDSNs = []struct {
2222
out string
2323
loc *time.Location
2424
}{
25-
{"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},
26-
{"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},
27-
{"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},
28-
{"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},
29-
{"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},
30-
{"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},
31-
{"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},
32-
{"/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},
33-
{"@/", "&{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},
34-
{"/", "&{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},
35-
{"", "&{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},
36-
{"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},
37-
{"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},
25+
{"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},
26+
{"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},
27+
{"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},
28+
{"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},
29+
{"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},
30+
{"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},
31+
{"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},
32+
{"/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},
33+
{"@/", "&{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},
34+
{"/", "&{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},
35+
{"", "&{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},
36+
{"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},
37+
{"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},
3838
}
3939

4040
func TestDSNParser(t *testing.T) {

0 commit comments

Comments
 (0)