Skip to content

Commit 83bb9f7

Browse files
author
Niklas Voss
committed
Treat unicodePwd field differently for AD/Samba compatibility
1 parent 1682dc9 commit 83bb9f7

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.15
55
require (
66
github.com/go-ldap/ldap/v3 v3.2.4
77
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.4
8+
golang.org/x/text v0.3.3
89
)
910

1011
replace google.golang.org/api v0.28.0 => github.com/googleapis/google-api-go-client v0.28.0

provider/resource_ldap_object.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/go-ldap/ldap/v3"
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
16+
"golang.org/x/text/encoding/unicode"
1617
)
1718

1819
func resourceLDAPObject() *schema.Resource {
@@ -133,7 +134,8 @@ func resourceLDAPObjectCreate(d *schema.ResourceData, meta interface{}) error {
133134
// each map should only have one entry (see resource declaration)
134135
for name, value := range attribute.(map[string]interface{}) {
135136
log.Printf("[DEBUG] ldap_object::create - %q has attribute[%v] => %v (%T)", dn, name, value, value)
136-
m[name] = append(m[name], value.(string))
137+
v := toAttributeValue(name, value.(string))
138+
m[name] = append(m[name], v)
137139
}
138140
}
139141
// now loop through the map and add attributes with theys value(s)
@@ -373,7 +375,8 @@ func computeAndAddDeltas(modify *ldap.ModifyRequest, os, ns *schema.Set) error {
373375
for _, m := range ns.List() {
374376
for mk, mv := range m.(map[string]interface{}) {
375377
if k == mk {
376-
values = append(values, mv.(string))
378+
v := toAttributeValue(k, mv.(string))
379+
values = append(values, v)
377380
}
378381
}
379382
}
@@ -394,7 +397,8 @@ func computeAndAddDeltas(modify *ldap.ModifyRequest, os, ns *schema.Set) error {
394397
for _, m := range ns.List() {
395398
for mk, mv := range m.(map[string]interface{}) {
396399
if k == mk {
397-
values = append(values, mv.(string))
400+
v := toAttributeValue(k, mv.(string))
401+
values = append(values, v)
398402
}
399403
}
400404
}
@@ -403,3 +407,12 @@ func computeAndAddDeltas(modify *ldap.ModifyRequest, os, ns *schema.Set) error {
403407
}
404408
return nil
405409
}
410+
411+
func toAttributeValue(name, value string) string {
412+
if name == "unicodePwd" {
413+
utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
414+
pwdEncoded, _ := utf16.NewEncoder().String("\"" + value + "\"")
415+
return pwdEncoded
416+
}
417+
return value
418+
}

0 commit comments

Comments
 (0)