@@ -19,7 +19,7 @@ import (
19
19
"unsafe"
20
20
)
21
21
22
- // New creates a new SaslClient.
22
+ // New creates a new SaslClient. The target parameter should be a hostname with no port.
23
23
func New (target , username , password string , passwordSet bool , props map [string ]string ) (* SaslClient , error ) {
24
24
initOnce .Do (initSSPI )
25
25
if initError != nil {
@@ -30,6 +30,7 @@ func New(target, username, password string, passwordSet bool, props map[string]s
30
30
serviceName := "mongodb"
31
31
serviceRealm := ""
32
32
canonicalizeHostName := false
33
+ var serviceHostSet bool
33
34
34
35
for key , value := range props {
35
36
switch strings .ToUpper (key ) {
@@ -43,25 +44,29 @@ func New(target, username, password string, passwordSet bool, props map[string]s
43
44
serviceRealm = value
44
45
case "SERVICE_NAME" :
45
46
serviceName = value
47
+ case "SERVICE_HOST" :
48
+ serviceHostSet = true
49
+ target = value
46
50
}
47
51
}
48
52
49
- hostname , _ , err := net .SplitHostPort (target )
50
- if err != nil {
51
- return nil , fmt .Errorf ("invalid endpoint (%s) specified: %s" , target , err )
52
- }
53
53
if canonicalizeHostName {
54
- names , err := net .LookupAddr (hostname )
54
+ // Should not canonicalize the SERVICE_HOST
55
+ if serviceHostSet {
56
+ return nil , fmt .Errorf ("CANONICALIZE_HOST_NAME and SERVICE_HOST canonot both be specified" )
57
+ }
58
+
59
+ names , err := net .LookupAddr (target )
55
60
if err != nil || len (names ) == 0 {
56
61
return nil , fmt .Errorf ("unable to canonicalize hostname: %s" , err )
57
62
}
58
- hostname = names [0 ]
59
- if hostname [len (hostname )- 1 ] == '.' {
60
- hostname = hostname [:len (hostname )- 1 ]
63
+ target = names [0 ]
64
+ if target [len (target )- 1 ] == '.' {
65
+ target = target [:len (target )- 1 ]
61
66
}
62
67
}
63
68
64
- servicePrincipalName := fmt .Sprintf ("%s/%s" , serviceName , hostname )
69
+ servicePrincipalName := fmt .Sprintf ("%s/%s" , serviceName , target )
65
70
if serviceRealm != "" {
66
71
servicePrincipalName += "@" + serviceRealm
67
72
}
0 commit comments