From 1399a6f15ffee6c84167aa62968081fd776fb5ac Mon Sep 17 00:00:00 2001 From: Lars Karlslund Date: Tue, 4 Jan 2022 20:44:49 +0100 Subject: [PATCH] Optimized object label function performance --- modules/engine/object.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/engine/object.go b/modules/engine/object.go index ee09b82..b9b2343 100644 --- a/modules/engine/object.go +++ b/modules/engine/object.go @@ -272,18 +272,26 @@ func (o *Object) DN() string { return o.OneAttrString(DistinguishedName) } +var labelattrs = []Attribute{ + LDAPDisplayName, + DisplayName, + Name, + DownLevelLogonName, + SAMAccountName, + Description, + DistinguishedName, + ObjectGUID, + ObjectSid, +} + func (o *Object) Label() string { - return util.Default( - o.OneAttrString(LDAPDisplayName), - o.OneAttrString(DisplayName), - o.OneAttrString(Name), - o.OneAttrString(DownLevelLogonName), - o.OneAttrString(SAMAccountName), - o.OneAttrString(Description), - o.OneAttrString(DistinguishedName), - o.OneAttrString(ObjectGUID), - o.OneAttrString(ObjectSid), - ) + for _, attr := range labelattrs { + val := o.OneAttrString(attr) + if val != "" { + return val + } + } + return fmt.Sprintf("OBJ %v", o) } func (o *Object) Type() ObjectType { @@ -329,7 +337,7 @@ func (o *Object) Type() ObjectType { o.objecttype = ObjectTypeComputer case "Group-Policy-Container": o.objecttype = ObjectTypeGroupPolicyContainer - case "Domain Trust": + case "Trusted-Domain": o.objecttype = ObjectTypeTrust case "Attribute-Schema": o.objecttype = ObjectTypeAttributeSchema