Skip to content

Commit

Permalink
Merge pull request #2 from nakagami/master
Browse files Browse the repository at this point in the history
Actualizacion
  • Loading branch information
ajoses committed Sep 19, 2019
2 parents edec3c8 + c3a44fa commit f05a1e9
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
dist: precise
dist: xenial
language: go
go:
- "1.7"
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -10,11 +10,11 @@ Firebird RDBMS http://firebirdsql.org SQL driver for Go
Requirements
-------------

* Firebird 2.1 or higher
* Firebird 2.5 or higher
* Golang 1.7 or higher

Installation
-------------
Modules get (go version < 1.11)
------------------------------------

::

Expand Down
7 changes: 7 additions & 0 deletions driver_go18.go
Expand Up @@ -89,6 +89,13 @@ func (fc *firebirdsqlConn) Ping(ctx context.Context) error {
if fc == nil {
return errors.New("Connection was closed")
}

rows, err := fc.query(ctx, "SELECT 1 from rdb$database", nil)
if err != nil {
return driver.ErrBadConn
}
rows.Close()

return nil
}

Expand Down
42 changes: 42 additions & 0 deletions driver_test.go
Expand Up @@ -776,3 +776,45 @@ func TestGoIssue65(t *testing.T) {
t.Fatalf(field01)
}*/
}

func TestGoIssue80(t *testing.T) {
temppath := TempFileName("test_issue80_")
conn, err := sql.Open("firebirdsql_createdb", "sysdba:masterkey@localhost:3050"+temppath)
if err != nil {
t.Fatalf("Error occured at sql.Open()")
}
defer conn.Close()

query := `
CREATE TABLE foo (
a VARCHAR(10),
b VARCHAR(10),
c BIGINT,
d INT,
e INT,
f INT,
g INT,
h INT,
i INT,
j INT,
k INT,
l INT,
m INT,
n INT
)
`

_, err = conn.Exec(query)
if err != nil {
t.Error(err)
}

_, err = conn.Exec(
"insert into foo(a, b, c, d, e, f, g, h, i, j, k, l, m, n) values (?, ?, ? ,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
" ", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)

if err != nil {
t.Error(err)
}

}
11 changes: 11 additions & 0 deletions go.mod
@@ -0,0 +1,11 @@
module github.com/nakagami/firebirdsql

go 1.13

require (
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7 // indirect
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b
)
97 changes: 65 additions & 32 deletions wireprotocol.go
Expand Up @@ -310,7 +310,7 @@ func (p *wireProtocol) _parse_status_vector() (*list.List, int, string, error) {
switch {
case n == isc_arg_gds:
b, err = p.recvPackets(4)
gds_code := int(bytes_to_bint32(b))
gds_code = int(bytes_to_bint32(b))
if gds_code != 0 {
gds_codes.PushBack(gds_code)
message += errmsgs[gds_code]
Expand Down Expand Up @@ -412,10 +412,37 @@ func (p *wireProtocol) _parse_connect_response(user string, password string, opt
ln = int(bytes_to_bint32(b))
_, _ = p.recvPacketsAlignment(ln) // keys

var authData []byte
var sessionKey []byte
if isAuthenticated == 0 {
var authData []byte
var sessionKey []byte
if (p.pluginName == "Srp" || p.pluginName == "Srp256") && len(data) > 2 {
if p.pluginName == "Srp" || p.pluginName == "Srp256" {

// TODO: normalize user

if len(data) == 0 {
p.opContAuth(bigToBytes(clientPublic), p.pluginName, PLUGIN_LIST, "")
b, _ := p.recvPackets(4)
if DEBUG_SRP && bytes_to_bint32(b) == op_cont_auth {
panic("auth error")
}

b, _ = p.recvPackets(4)
ln = int(bytes_to_bint32(b))
data, _ = p.recvPacketsAlignment(ln)

b, _ = p.recvPackets(4)
ln = int(bytes_to_bint32(b))
_, _ = p.recvPacketsAlignment(ln) // pluginName

b, _ = p.recvPackets(4)
ln = int(bytes_to_bint32(b))
_, _ = p.recvPacketsAlignment(ln) // pluginList

b, _ = p.recvPackets(4)
ln = int(bytes_to_bint32(b))
_, _ = p.recvPacketsAlignment(ln) // keys
}

ln = int(bytes_to_int16(data[:2]))
serverSalt := data[2 : ln+2]
serverPublic := bigFromHexString(bytes_to_str(data[4+ln:]))
Expand All @@ -430,35 +457,30 @@ func (p *wireProtocol) _parse_connect_response(user string, password string, opt
err = errors.New("_parse_connect_response() Unauthorized")
return
}
if wire_crypt {
// Send op_cont_auth
p.packInt(op_cont_auth)
p.packString(hex.EncodeToString(authData))
p.packString(options["auth_plugin_name"])
p.packString(PLUGIN_LIST)
p.packString("")
p.sendPackets()
_, _, _, err = p.opResponse()
if err != nil {
return
}

// Send op_crypt
p.packInt(op_crypt)
p.packString("Arc4")
p.packString("Symmetric")
p.sendPackets()
p.conn.setAuthKey(sessionKey)

_, _, _, err = p.opResponse()
if err != nil {
return
}
} else {
p.authData = authData // use later opAttach and opCreate
}
if opcode == op_cond_accept {
p.opContAuth(authData, options["auth_plugin_name"], PLUGIN_LIST, "")
_, _, _, err = p.opResponse()
if err != nil {
return
}

}
if wire_crypt && sessionKey != nil {
// Send op_crypt
p.packInt(op_crypt)
p.packString("Arc4")
p.packString("Symmetric")
p.sendPackets()
p.conn.setAuthKey(sessionKey)

_, _, _, err = p.opResponse()
if err != nil {
return
}
} else {
p.authData = authData // use later opAttach and opCreate
}

} else {
if opcode != op_accept {
err = errors.New("_parse_connect_response() protocol error")
Expand Down Expand Up @@ -739,6 +761,16 @@ func (p *wireProtocol) opAttach(dbName string, user string, password string, rol
p.sendPackets()
}

func (p *wireProtocol) opContAuth(authData []byte, authPluginName string, authPluginList string, keys string) {
p.debugPrint("opContAuth")
p.packInt(op_cont_auth)
p.packString(hex.EncodeToString(authData))
p.packString(authPluginName)
p.packString(authPluginList)
p.packString(keys)
p.sendPackets()
}

func (p *wireProtocol) opDropDatabase() {
p.debugPrint("opDropDatabase")
p.packInt(op_drop_database)
Expand Down Expand Up @@ -1197,7 +1229,8 @@ func (p *wireProtocol) paramsToBlr(transHandle int32, params []driver.Value, pro
n += 4 - n%4
}
for i := 0; i < n; i++ {
valuesList.PushBack([]byte{byte(nullIndicator.Mod(nullIndicator, bi256).Int64())})
var modres *big.Int = new(big.Int)
valuesList.PushBack([]byte{byte(modres.Mod(nullIndicator, bi256).Int64())})
nullIndicator = nullIndicator.Div(nullIndicator, bi256)
}
}
Expand Down

0 comments on commit f05a1e9

Please sign in to comment.