Skip to content

Commit 22aad63

Browse files
committed
Multi-attribute index, another progressbar, fixup with UniqueSource set to DomainPart when loading, RootDSE is synthesized and imported, performance optimizations
1 parent 02ddc47 commit 22aad63

File tree

9 files changed

+290
-129
lines changed

9 files changed

+290
-129
lines changed

collector/main.go

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

33
import (
4+
"fmt"
5+
"os"
6+
47
"github.com/lkarlslund/adalanche/modules/integrations/localmachine/collect"
58
"github.com/lkarlslund/adalanche/modules/version"
69
"github.com/mattn/go-colorable"
@@ -31,6 +34,14 @@ func Execute(cmd *cobra.Command, args []string) error {
3134
log.Info().Msg("Debug logging enabled")
3235
}
3336

37+
// Ensure the data folder is available
38+
if _, err := os.Stat(*datapath); os.IsNotExist(err) {
39+
err = os.MkdirAll(*datapath, 0711)
40+
if err != nil {
41+
return fmt.Errorf("Could not create data folder %v: %v", datapath, err)
42+
}
43+
}
44+
3445
return collect.Collect(*datapath)
3546
}
3647

go.mod

+7-3
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ require (
119119
go.uber.org/multierr v1.6.0 // indirect
120120
go.uber.org/zap v1.17.0 // indirect
121121
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
122-
golang.org/x/mod v0.5.0 // indirect
122+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
123123
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
124124
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
125-
golang.org/x/tools v0.1.7 // indirect
125+
golang.org/x/tools v0.1.10 // indirect
126126
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
127127
google.golang.org/protobuf v1.27.1 // indirect
128128
gopkg.in/fsnotify.v1 v1.4.7 // indirect
@@ -134,4 +134,8 @@ require (
134134
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
135135
)
136136

137-
require github.com/lkarlslund/stringsplus v0.0.0-20211104080454-45e60fe6edc0 // indirect
137+
require (
138+
github.com/dmarkham/enumer v1.5.5 // indirect
139+
github.com/lkarlslund/stringsplus v0.0.0-20211104080454-45e60fe6edc0 // indirect
140+
github.com/pascaldekloe/name v1.0.0 // indirect
141+
)

go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185/go.mod h1:cFRxtTwT
156156
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
157157
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91 h1:Izz0+t1Z5nI16/II7vuEo/nHjodOg0p7+OiDpjX5t1E=
158158
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
159+
github.com/dmarkham/enumer v1.5.5 h1:LpOGL3PQTPOM87rgowZEf7Z5EmkgnKqUtS92Vo+vqzs=
160+
github.com/dmarkham/enumer v1.5.5/go.mod h1:qHwULwuCxYFAFM5KCkpF1U/U0BF5sNQKLccvUzKNY2w=
159161
github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
160162
github.com/dop251/goja v0.0.0-20220214123719-b09a6bfa842f h1:ztRywKO1rqqS8li0TDcnwi9AGsqAH0ky9NaND69/Ccc=
161163
github.com/dop251/goja v0.0.0-20220214123719-b09a6bfa842f/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk=
@@ -559,6 +561,8 @@ github.com/open2b/scriggo v0.52.2 h1:gGwfp+E/1dwZj/9wVDljyTXHBG6v/7GlqS1H0fHvGUU
559561
github.com/open2b/scriggo v0.52.2/go.mod h1:BT/Y/AXiydiLxhbfupynMyF0n2L9/qB57jTbu5+fgh4=
560562
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
561563
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
564+
github.com/pascaldekloe/name v1.0.0 h1:n7LKFgHixETzxpRv2R77YgPUFo85QHGZKrdaYm7eY5U=
565+
github.com/pascaldekloe/name v1.0.0/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
562566
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
563567
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
564568
github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ=
@@ -781,6 +785,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
781785
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
782786
golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q=
783787
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
788+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
789+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
784790
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
785791
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
786792
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -1034,6 +1040,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
10341040
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
10351041
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
10361042
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
1043+
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
1044+
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
10371045
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10381046
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
10391047
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

modules/engine/attributevalue.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ func (avs AttributeValueSlice) Len() int {
121121
}
122122

123123
type AttributeValueOne struct {
124-
AttributeValue
124+
Value AttributeValue
125125
}
126126

127127
func (avo AttributeValueOne) Len() int {
128128
return 1
129129
}
130130

131131
func (avo AttributeValueOne) Slice() []AttributeValue {
132-
return AttributeValueSlice{avo.AttributeValue}
132+
return AttributeValueSlice{avo.Value}
133133
}
134134

135135
func (avo AttributeValueOne) StringSlice() []string {
136-
return []string{avo.AttributeValue.String()}
136+
return []string{avo.Value.String()}
137137
}
138138

139139
type AttributeValue interface {

modules/engine/object.go

+65-44
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ func (o *Object) runlock() {
125125
}
126126
}
127127

128+
func (o *Object) Absorb(source *Object) {
129+
o.AbsorbEx(source, false)
130+
}
131+
128132
// Absorbs data and Pwn relationships from another object, sucking the soul out of it
129133
// The sources empty shell should be discarded afterwards (i.e. not appear in an Objects collection)
130-
func (o *Object) Absorb(source *Object) {
134+
func (o *Object) AbsorbEx(source *Object, fast bool) {
131135
if o == source {
132136
log.Fatal().Msg("Can't absorb myself")
133137
}
@@ -140,49 +144,53 @@ func (o *Object) Absorb(source *Object) {
140144
defer o.unlock()
141145

142146
target := o
143-
for attr, values := range source.values {
144-
var val AttributeValues
145-
tval := target.attr(attr)
146-
sval := values
147-
148-
if tval.Len() == 0 {
149-
val = sval
150-
} else if sval.Len() == 0 {
151-
panic(fmt.Sprintf("Attribute %v with ZERO LENGTH data failure", attr.String()))
152-
} else if tval.Len() == 1 && sval.Len() == 1 {
153-
tvalue := tval.Slice()[0]
154-
svalue := sval.Slice()[0]
155-
156-
if CompareAttributeValues(tvalue, svalue) {
157-
val = tval // They're the same, so pick any
147+
148+
// Fast mode does not merge values, it just relinks the source to the target
149+
if !fast {
150+
for attr, values := range source.values {
151+
var val AttributeValues
152+
tval := target.attr(attr)
153+
sval := values
154+
155+
if tval.Len() == 0 {
156+
val = sval
157+
} else if sval.Len() == 0 {
158+
panic(fmt.Sprintf("Attribute %v with ZERO LENGTH data failure", attr.String()))
159+
} else if tval.Len() == 1 && sval.Len() == 1 {
160+
tvalue := tval.Slice()[0]
161+
svalue := sval.Slice()[0]
162+
163+
if CompareAttributeValues(tvalue, svalue) {
164+
val = tval // They're the same, so pick any
165+
} else {
166+
// They're not the same, join them
167+
val = AttributeValueSlice{tvalue, svalue}
168+
}
158169
} else {
159-
// They're not the same, join them
160-
val = AttributeValueSlice{tvalue, svalue}
161-
}
162-
} else {
163-
// One or more of them have more than one value, do it the hard way
164-
tvalslice := tval.Slice()
165-
svalslice := sval.Slice()
166-
167-
resultingvalues := make([]AttributeValue, tval.Len())
168-
copy(resultingvalues, tvalslice)
169-
170-
for _, svalue := range svalslice {
171-
var alreadythere bool
172-
compareloop:
173-
for _, tvalue := range tvalslice {
174-
if CompareAttributeValues(svalue, tvalue) { // Crap!!
175-
alreadythere = true
176-
break compareloop
170+
// One or more of them have more than one value, do it the hard way
171+
tvalslice := tval.Slice()
172+
svalslice := sval.Slice()
173+
174+
resultingvalues := make([]AttributeValue, tval.Len())
175+
copy(resultingvalues, tvalslice)
176+
177+
for _, svalue := range svalslice {
178+
var alreadythere bool
179+
compareloop:
180+
for _, tvalue := range tvalslice {
181+
if CompareAttributeValues(svalue, tvalue) { // Crap!!
182+
alreadythere = true
183+
break compareloop
184+
}
185+
}
186+
if !alreadythere {
187+
resultingvalues = append(resultingvalues, svalue)
177188
}
178189
}
179-
if !alreadythere {
180-
resultingvalues = append(resultingvalues, svalue)
181-
}
190+
val = AttributeValueSlice(resultingvalues)
182191
}
183-
val = AttributeValueSlice(resultingvalues)
192+
target.set(attr, val)
184193
}
185-
target.set(attr, val)
186194
}
187195

188196
for pwntarget, methods := range source.CanPwn {
@@ -234,15 +242,15 @@ func (o *Object) Absorb(source *Object) {
234242
source.memberofrecursive = nil
235243

236244
for _, child := range source.children {
237-
target.Adopt(child)
245+
target.adopt(child)
238246
}
239247

240248
// If the source has a parent, but the target doesn't we assimilate that role (muhahaha)
241249
if source.parent != nil {
242250
if target.parent == nil {
243251
target.ChildOf(source.parent)
244252
}
245-
source.parent.RemoveChild(source)
253+
source.parent.removeChild(source)
246254
source.parent = nil
247255
}
248256

@@ -472,7 +480,7 @@ func (o *Object) OneAttrString(attr Attribute) string {
472480
return ""
473481
}
474482
if ao, ok := a.(AttributeValueOne); ok {
475-
return ao.String()
483+
return ao.Value.String()
476484
}
477485
if a.Len() == 1 {
478486
log.Warn().Msg("Inefficient attribute storage - multival used for one value ...")
@@ -772,6 +780,8 @@ func (o *Object) setFlex(flexinit ...interface{}) {
772780
continue
773781
}
774782
data = append(data, v)
783+
case AttributeValueOne:
784+
data = append(data, v.Value)
775785
case AttributeValueSlice:
776786
for _, value := range v {
777787
if ignoreblanks && value.IsZero() {
@@ -1082,13 +1092,24 @@ func (o *Object) Adopt(child *Object) {
10821092

10831093
child.lock()
10841094
if child.parent != nil {
1085-
child.parent.RemoveChild(child)
1095+
child.parent.lock()
1096+
child.parent.removeChild(child)
1097+
child.parent.unlock()
10861098
}
10871099
child.parent = o
10881100
child.unlock()
10891101
}
10901102

1091-
func (o *Object) RemoveChild(child *Object) {
1103+
func (o *Object) adopt(child *Object) {
1104+
o.children = append(o.children, child)
1105+
1106+
if child.parent != nil {
1107+
child.parent.removeChild(child)
1108+
}
1109+
child.parent = o
1110+
}
1111+
1112+
func (o *Object) removeChild(child *Object) {
10921113
for i, curchild := range o.children {
10931114
if curchild == child {
10941115
if len(o.children) == 1 {

0 commit comments

Comments
 (0)