Skip to content

Commit

Permalink
* lazy initialization for regexp
Browse files Browse the repository at this point in the history
* fix unit tests
* fix ConvertIntervalYM_DTY with wrong unsigned integer usage
* code formatting
  • Loading branch information
stle04 committed Sep 9, 2024
1 parent 78d53fd commit 487451c
Show file tree
Hide file tree
Showing 215 changed files with 2,562 additions and 1,939 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,8 @@ db, err := sql.Open("oracle", "")

### version 2.8.19
* add support for long input:
> if input parameter (string or []byte) size is larger than 32Kb the driver will switch to oracle type
`LongVarchar` and `LongRaw` so now you can input data with size up to 1 GB that fit into LONG and LOB columns
* long input: [example](https://github.com/sijms/go-ora/blob/master/examples/long_input/main.go) and [test](https://github.com/sijms/go-ora/blob/master/v2/TestIssues/long_input_test.go)
* if input parameter (string or []byte) larger than 32Kb the driver will swith type to `LongVarchar` and `LongRaw`
* so now you can input data with size up to 1 GB that fit into LONG and LOB columns
* add function `RegisterDial` to the configuration object that accept func input
```golang
config, err := go_ora.ParseConfig(`yours DSN string`)
Expand Down
12 changes: 9 additions & 3 deletions advanced_nego/advanced_nego.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/binary"
"errors"
"fmt"

"github.com/sijms/go-ora/network"
)

Expand Down Expand Up @@ -38,6 +39,7 @@ func NewAdvNego(session *network.Session) (*AdvNego, error) {
}
return output, nil
}

func (nego *AdvNego) readHeader() ([]int, error) {
num, err := nego.comm.session.GetInt64(4, false, true)
if err != nil {
Expand All @@ -62,13 +64,15 @@ func (nego *AdvNego) readHeader() ([]int, error) {
output[3], err = nego.comm.session.GetInt(1, false, true)
return output, err
}

func (nego *AdvNego) writeHeader(length, servCount int, errFlags uint8) {
nego.comm.session.PutInt(uint64(0xDEADBEEF), 4, true, false)
nego.comm.session.PutInt(length, 2, true, false)
nego.comm.session.PutInt(version, 4, true, false)
nego.comm.session.PutInt(servCount, 2, true, false)
nego.comm.session.PutBytes(errFlags)
}

func (nego *AdvNego) readServiceHeader() ([]int, error) {
output := make([]int, 3)
var err error
Expand All @@ -83,6 +87,7 @@ func (nego *AdvNego) readServiceHeader() ([]int, error) {
output[2], err = nego.comm.session.GetInt(4, false, true)
return output, err
}

func (nego *AdvNego) Read() error {
header, err := nego.readHeader()
if err != nil {
Expand Down Expand Up @@ -187,19 +192,20 @@ func (nego *AdvNego) Read() error {
if err != nil {
return err
}
//fmt.Println(nego.comm.session.GetBytes(10))
//return errors.New("interrupt")
// fmt.Println(nego.comm.session.GetBytes(10))
// return errors.New("interrupt")
return nil
}
return nego.comm.session.Write()
}

func (nego *AdvNego) Write() error {
nego.comm.session.ResetBuffer()
size := 0
for i := 1; i < 5; i++ {
size = size + 8 + nego.serviceList[i].getServiceDataLength()
}
//size += 13
// size += 13
nego.writeHeader(13+size, 4, 0)
err := nego.serviceList[4].writeServiceData()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions advanced_nego/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewAuthService(comm *AdvancedNegoComm) (*authService, error) {
},
status: 0xFCFF,
}
//var avaAuth []string
// var avaAuth []string
output.availableServiceNames = []string{"", "NTS", "KERBEROS5", "TCPS"}
output.availableServiceIDs = []int{0, 1, 1, 2}
//if runtime.GOOS == "windows" {
Expand All @@ -45,7 +45,7 @@ func NewAuthService(comm *AdvancedNegoComm) (*authService, error) {
//}
//level := conops.Encryption != null ? conops.Encryption : snoConfig[];
err := output.buildServiceList(connOption.AuthService, false, false)
//output.selectedServ, err = output.validate(strings.Split(str,","), true)
// output.selectedServ, err = output.validate(strings.Split(str,","), true)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions advanced_nego/comm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package advanced_nego

import (
"errors"

"github.com/sijms/go-ora/network"
)

Expand Down Expand Up @@ -73,6 +74,7 @@ func (comm *AdvancedNegoComm) readUB1() (number uint8, err error) {
number, err = comm.session.GetByte()
return
}

func (comm *AdvancedNegoComm) writeUB1(number uint8) {
comm.writePacketHeader(1, 2)
comm.session.PutBytes(number)
Expand Down Expand Up @@ -130,6 +132,7 @@ func (comm *AdvancedNegoComm) readStatus() (status int, err error) {
status, err = comm.session.GetInt(2, false, true)
return
}

func (comm *AdvancedNegoComm) readVersion() (uint32, error) {
_, err := comm.readPacketHeader(5)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions advanced_nego/data_integrity_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"crypto/rand"
"errors"
"fmt"
"github.com/sijms/go-ora/network/security"
"math/big"

"github.com/sijms/go-ora/network/security"
)

type dataIntegrityService struct {
Expand All @@ -29,7 +30,7 @@ func NewDataIntegrityService(comm *AdvancedNegoComm) (*dataIntegrityService, err
},
}
err := output.buildServiceList([]string{}, true, true)
//output.selectedServ, err = output.validate(strings.Split(str,","), true)
// output.selectedServ, err = output.validate(strings.Split(str,","), true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -107,6 +108,7 @@ func (serv *dataIntegrityService) readServiceData(subPacketNum int) error {
tracer.LogPacket("Shared Key:", serv.sharedKey)
return nil
}

func (serv *dataIntegrityService) writeServiceData() error {
serv.writeHeader(2)
comm := serv.comm
Expand All @@ -115,7 +117,7 @@ func (serv *dataIntegrityService) writeServiceData() error {
for i := 0; i < len(serv.selectedIndices); i++ {
index := serv.selectedIndices[i]
selectedIndices[i] = uint8(serv.availableServiceIDs[index])
//comm.session.PutBytes(uint8(serv.availableServiceIDs[index]))
// comm.session.PutBytes(uint8(serv.availableServiceIDs[index]))
}
comm.writeBytes(selectedIndices)
return nil
Expand All @@ -128,7 +130,7 @@ func (serv *dataIntegrityService) getServiceDataLength() int {
func (serv *dataIntegrityService) activateAlgorithm() error {
serv.comm.session.Context.AdvancedService.SessionKey = serv.sharedKey
serv.comm.session.Context.AdvancedService.IV = serv.iV
//return errors.New(fmt.Sprintf("advanced negotiation error: data integrity service algorithm: %d still not supported", serv.algoID))
// return errors.New(fmt.Sprintf("advanced negotiation error: data integrity service algorithm: %d still not supported", serv.algoID))
var algo security.OracleNetworkDataIntegrity = nil
var err error
switch serv.algoID {
Expand Down
119 changes: 62 additions & 57 deletions advanced_nego/default_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,75 +23,79 @@ type defaultService struct {
availableServiceIDs []int
selectedIndices []int
version uint32
//selectedServ map[string]int
//avaServs map[string]int
// selectedServ map[string]int
// avaServs map[string]int
}

func (serv *defaultService) getVersion() uint32 {
return serv.version
}

func (serv *defaultService) activateAlgorithm() error {
return nil
}

//func (serv *defaultService) writePacketHeader(session *network.Session, length, _type int) {
// // the driver call Anocommunication.ValidateType(length, type);
// session.PutInt(length, 2, true, false)
// session.PutInt(_type, 2, true, false)
//}
//func (serv *defaultService) readPacketHeader(session *network.Session, _type int) (length int, err error) {
// length, err = session.GetInt(2, false, true)
// if err != nil {
// return
// }
// receivedType, err := session.GetInt(2, false, true)
// if err != nil {
// return 0, err
// }
// if receivedType != _type {
// err = errors.New("advanced negotiation error: received type is not as stored type")
// return
// func (serv *defaultService) writePacketHeader(session *network.Session, length, _type int) {
// // the driver call Anocommunication.ValidateType(length, type);
// session.PutInt(length, 2, true, false)
// session.PutInt(_type, 2, true, false)
// }
// err = serv.validatePacketHeader(length, receivedType)
// return
//}
//func (serv *defaultService) validatePacketHeader(length, _type int) error {
// if _type < 0 || _type > 7 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// switch _type {
// case 0, 1:
// break
// case 2:
// if length > 1 {
// return errors.New("advanced negotiation error: cannot validate packet header")
//
// func (serv *defaultService) readPacketHeader(session *network.Session, _type int) (length int, err error) {
// length, err = session.GetInt(2, false, true)
// if err != nil {
// return
// }
// case 3:
// fallthrough
// case 6:
// if length > 2 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// receivedType, err := session.GetInt(2, false, true)
// if err != nil {
// return 0, err
// }
// if receivedType != _type {
// err = errors.New("advanced negotiation error: received type is not as stored type")
// return
// }
// case 4:
// fallthrough
// case 5:
// if length > 4 {
// err = serv.validatePacketHeader(length, receivedType)
// return
// }
//
// func (serv *defaultService) validatePacketHeader(length, _type int) error {
// if _type < 0 || _type > 7 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// case 7:
// if length < 10 {
// switch _type {
// case 0, 1:
// break
// case 2:
// if length > 1 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// case 3:
// fallthrough
// case 6:
// if length > 2 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// case 4:
// fallthrough
// case 5:
// if length > 4 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// case 7:
// if length < 10 {
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// default:
// return errors.New("advanced negotiation error: cannot validate packet header")
// }
// default:
// return errors.New("advanced negotiation error: cannot validate packet header")
// return nil
// }
//
// func (serv *defaultService) readUB2(session *network.Session) (number int, err error) {
// _, err = serv.readPacketHeader(session, 3)
// number, err = session.GetInt(2, false, true)
// return
// }
// return nil
//}
//func (serv *defaultService) readUB2(session *network.Session) (number int, err error) {
// _, err = serv.readPacketHeader(session, 3)
// number, err = session.GetInt(2, false, true)
// return
//}
func (serv *defaultService) writeHeader(serviceSubPackets int) {
serv.comm.session.PutInt(serv.serviceType, 2, true, false)
serv.comm.session.PutInt(serviceSubPackets, 2, true, false)
Expand Down Expand Up @@ -136,11 +140,11 @@ func (serv *defaultService) readAdvNegoLevel(level string) {

func (serv *defaultService) buildServiceList(userList []string, useLevel, useDefault bool) error {
serv.selectedIndices = make([]int, 0, 10)
//serv.selectedServ = make(map[string]int)
// serv.selectedServ = make(map[string]int)
if useLevel {
if serv.level == 1 {
serv.selectedIndices = append(serv.selectedIndices, 0)
//serv.selectedServ[""] = 0
// serv.selectedServ[""] = 0
return nil
}
if serv.level != 0 && serv.level != 2 && serv.level != 3 {
Expand All @@ -166,7 +170,7 @@ func (serv *defaultService) buildServiceList(userList []string, useLevel, useDef
}
if useLevel && serv.level == 2 {
serv.selectedIndices = append(serv.selectedIndices, 0)
//serv.selectedServ[""] = 0
// serv.selectedServ[""] = 0
}
}
return nil
Expand All @@ -182,7 +186,7 @@ func (serv *defaultService) buildServiceList(userList []string, useLevel, useDef
}
if useLevel && serv.level == 2 {
serv.selectedIndices = append(serv.selectedIndices, 0)
//serv.selectedServ[""] = 0
// serv.selectedServ[""] = 0
}
return nil
} else if strings.ToUpper(userList[0]) == "NONE" {
Expand All @@ -191,7 +195,7 @@ func (serv *defaultService) buildServiceList(userList []string, useLevel, useDef
}
if useLevel && serv.level == 0 {
serv.selectedIndices = append(serv.selectedIndices, 0)
//serv.selectedServ[""] = 0
// serv.selectedServ[""] = 0
}
for _, userItem := range userList {
if userItem == "" {
Expand Down Expand Up @@ -222,6 +226,7 @@ func (serv *defaultService) buildServiceList(userList []string, useLevel, useDef
}
return nil
}

func (serv *defaultService) validateResponse() error {
return nil
}
12 changes: 8 additions & 4 deletions advanced_nego/encrypt_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package advanced_nego
import (
"errors"
"fmt"

"github.com/sijms/go-ora/network/security"
)

Expand All @@ -17,13 +18,15 @@ func NewEncryptService(comm *AdvancedNegoComm) (*encryptService, error) {
comm: comm,
serviceType: 2,
version: 0xB200200,
availableServiceNames: []string{"", "RC4_40", "RC4_56", "RC4_128", "RC4_256",
"DES40C", "DES56C", "3DES112", "3DES168", "AES128", "AES192", "AES256"},
availableServiceNames: []string{
"", "RC4_40", "RC4_56", "RC4_128", "RC4_256",
"DES40C", "DES56C", "3DES112", "3DES168", "AES128", "AES192", "AES256",
},
availableServiceIDs: []int{0, 1, 8, 10, 6, 3, 2, 11, 12, 15, 16, 17},
},
}
err := output.buildServiceList([]string{"DES56C", "AES128", "AES192", "AES256"}, true, true)
//output.selectedServ, err = output.validate(strings.Split(str,","), true)
// output.selectedServ, err = output.validate(strings.Split(str,","), true)
if err != nil {
return nil, err
}
Expand All @@ -45,6 +48,7 @@ func (serv *encryptService) readServiceData(subPacketnum int) error {

return nil
}

func (serv *encryptService) writeServiceData() error {
serv.writeHeader(3)
comm := serv.comm
Expand All @@ -66,7 +70,7 @@ func (serv *encryptService) getServiceDataLength() int {

func (serv *encryptService) activateAlgorithm() error {
key := serv.comm.session.Context.AdvancedService.SessionKey
//iv := make([]byte, 16)
// iv := make([]byte, 16)
var algo security.OracleNetworkEncryption = nil
var err error
switch serv.algoID {
Expand Down
4 changes: 2 additions & 2 deletions advanced_nego/ntlmssp/authenticate_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (m authenicateMessage) MarshalBinary() ([]byte, error) {
return b.Bytes(), nil
}

//ProcessChallenge crafts an AUTHENTICATE message in response to the CHALLENGE message
//that was received from the server
// ProcessChallenge crafts an AUTHENTICATE message in response to the CHALLENGE message
// that was received from the server
func ProcessChallenge(challengeMessageData []byte, user, password string) ([]byte, error) {
if user == "" && password == "" {
return nil, errors.New("Anonymous authentication not supported")
Expand Down
Loading

0 comments on commit 487451c

Please sign in to comment.