From 60ded9fc3f7978e9c9863b6ee7ad3d1c2a999a56 Mon Sep 17 00:00:00 2001 From: Lars Karlslund Date: Thu, 21 Apr 2022 08:18:35 +0200 Subject: [PATCH] Changed Attribute type from uint16 to int16, NonExistingAttribute = -1 --- modules/engine/attributes.go | 4 ++-- modules/engine/object.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/engine/attributes.go b/modules/engine/attributes.go index df71cf1..9540e8b 100644 --- a/modules/engine/attributes.go +++ b/modules/engine/attributes.go @@ -48,7 +48,7 @@ var mergeapprovers []mergeapproverinfo var attributenums []attributeinfo var ( - NonExistingAttribute = NewAttribute("*NON EXISTING ATTRIBUTE*") + NonExistingAttribute = Attribute(-1) DistinguishedName = NewAttribute("distinguishedName").Single().Unique() ObjectClass = NewAttribute("objectClass") @@ -98,7 +98,7 @@ var ( MetaLAPSInstalled = NewAttribute("_haslaps") ) -type Attribute uint16 +type Attribute int16 var attributemutex sync.RWMutex diff --git a/modules/engine/object.go b/modules/engine/object.go index d0d3ad1..f7dec29 100644 --- a/modules/engine/object.go +++ b/modules/engine/object.go @@ -630,7 +630,8 @@ func init() { func (o *Object) setFlex(flexinit ...interface{}) { var ignoreblanks bool - var attribute Attribute + attribute := NonExistingAttribute + data := avsPool.Get().(AttributeValueSlice) for _, i := range flexinit { if i == IgnoreBlanks { @@ -724,8 +725,11 @@ func (o *Object) setFlex(flexinit ...interface{}) { case NoValues: // Ignore it case Attribute: - if attribute != 0 && (!ignoreblanks || len(data) > 0) { - o.set(attribute, data) + if attribute != NonExistingAttribute && (!ignoreblanks || len(data) > 0) { + newdata := make(AttributeValueSlice, len(data)) + copy(newdata, data) + o.set(attribute, newdata) + data = data[:0] } attribute = v @@ -733,8 +737,10 @@ func (o *Object) setFlex(flexinit ...interface{}) { panic("SetFlex called with invalid type in object declaration") } } - if attribute != 0 && (!ignoreblanks || len(data) > 0) { + if attribute != NonExistingAttribute && (!ignoreblanks || len(data) > 0) { o.set(attribute, data) + } + if len(data) > 0 { data = data[:0] } avsPool.Put(data)