Skip to content

Commit

Permalink
Proper locking on MemberOfSID and added AttrTime and AttrBool methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Jun 15, 2022
1 parent 8fc7446 commit f7476d9
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions modules/engine/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ func setThreadsafe(enable bool) {
var UnknownGUID = uuid.UUID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}

type Object struct {
values AttributeValueMap
PwnableBy PwnConnections
CanPwn PwnConnections
parent *Object
sdcache *SecurityDescriptor
sid windowssecurity.SID
children []*Object
values AttributeValueMap
PwnableBy PwnConnections
CanPwn PwnConnections
parent *Object
sdcache *SecurityDescriptor
sid windowssecurity.SID
children []*Object

members map[*Object]struct{}
membersrecursive map[*Object]struct{}

Expand All @@ -73,11 +74,6 @@ type Object struct {
objecttype ObjectType
}

type Connection struct {
Target *Object
Means string
}

var IgnoreBlanks = "_IGNOREBLANKS_"

func NewObject(flexinit ...interface{}) *Object {
Expand Down Expand Up @@ -532,6 +528,16 @@ func (o *Object) AttrInt(attr Attribute) (int64, bool) {
return v, ok
}

func (o *Object) AttrTime(attr Attribute) (time.Time, bool) {
v, ok := o.OneAttrRaw(attr).(time.Time)
return v, ok
}

func (o *Object) AttrBool(attr Attribute) (bool, bool) {
v, ok := o.OneAttrRaw(attr).(bool)
return v, ok
}

func (o *Object) AttrTimestamp(attr Attribute) (time.Time, bool) { // FIXME, switch to auto-time formatting
v, ok := o.AttrInt(attr)
if !ok {
Expand Down Expand Up @@ -638,34 +644,48 @@ func (o *Object) recursememberof(memberof *map[*Object]struct{}) bool {
}

func (o *Object) MemberOfSID(recursive bool) []windowssecurity.SID {
o.lock()
defer o.unlock()

o.rlock()
if !recursive {
if o.memberofsid == nil {
o.memberofsid = make([]windowssecurity.SID, len(o.memberof))
mos := o.memberofsid
if mos == nil {
o.runlock()
memberofsid := make([]windowssecurity.SID, len(o.memberof))
i := 0
for memberof := range o.memberof {
o.memberofsid[i] = memberof.SID()
memberofsid[i] = memberof.SID()
i++
}
o.lock()
o.memberofsid = memberofsid
o.unlock()

return memberofsid
}

return o.memberofsid
o.runlock()
return mos
}

if o.memberofsidrecursive != nil {
return o.memberofsidrecursive
mosr := o.memberofsidrecursive
if mosr != nil {
o.runlock()
return mosr
}

memberofrecursive := o.memberofr(true)
o.memberofsidrecursive = make([]windowssecurity.SID, len(memberofrecursive))
o.runlock()

mosr = make([]windowssecurity.SID, len(memberofrecursive))

for i, memberof := range memberofrecursive {
o.memberofsidrecursive[i] = memberof.SID()
mosr[i] = memberof.SID()
}

return o.memberofsidrecursive
o.lock()
o.memberofsidrecursive = mosr
o.unlock()

return mosr
}

// Wrapper for Set - easier to call
Expand Down

0 comments on commit f7476d9

Please sign in to comment.