Skip to content

Commit

Permalink
dblib: fix SID parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommi2Day committed May 16, 2023
1 parent 86ca678 commit 78e74f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Go Library

## [v1.7.2 - 2023-05-16]
### Fixed
- dblib: fix SID parsing

## [v1.7.1 - 2023-05-10]
### New
- pwlib: add vault method to get_password
Expand Down
4 changes: 2 additions & 2 deletions dblib/tns.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func CheckTNSadmin(tnsadmin string) (dn string, err error) {
// BuildTnsEntry build map for entry
func BuildTnsEntry(filename string, desc string, tnsAlias string) TNSEntry {
var service = ""
reService := regexp.MustCompile(`(?mi)SERVICE_NAME\s*=\s*([\w.]+)`)
reService := regexp.MustCompile(`(?mi)(?:SERVICE_NAME|SID)\s*=\s*([\w.]+)`)
s := reService.FindStringSubmatch(desc)
if len(s) > 1 {
service = s[1]
Expand Down Expand Up @@ -194,7 +194,7 @@ func tnsSanity(entries TNSEntries) (tnsEntries TNSEntries, deletes int) {
se++
}
if len(e.Service) == 0 {
log.Errorf("Entry %s has no Service set", k)
log.Errorf("Entry %s has no SERVICE_NAME or SID set", k)
se++
}
if len(e.Servers) == 0 {
Expand Down
12 changes: 11 additions & 1 deletion dblib/tns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ XE1 =(DESCRIPTION =
(ADDRESS_LIST = (ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = XE1))
)
XE.SID =(DESCRIPTION =
(ADDRESS_LIST = (ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))
(CONNECT_DATA=(SID = XESID))
)
XE.error = Error
`

const sqlnetora = `
NAMES.DEFAULT_DOMAIN=local
NAMES.DIRECTORY_PATH=(TNSNAMES,EZCONNECT,LDAP)
`
const entryCount = 5
const entryCount = 6

var tnsAdmin = "testdata"

Expand Down Expand Up @@ -142,6 +146,12 @@ func TestParseTns(t *testing.T) {
success: true,
service: "XE",
},
{
name: "XE-SID",
alias: "XE.SID",
success: true,
service: "XESID",
},
{
name: "XE1-short-invalid",
alias: "XE1",
Expand Down

0 comments on commit 78e74f2

Please sign in to comment.