Skip to content

Commit

Permalink
Inverted LDAP query fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Oct 8, 2022
1 parent 0a7b076 commit 0bb948b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions modules/query/ldapparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,36 @@ func parseLDAPRuneQuery(s []rune, ao *engine.Objects) ([]rune, NodeFilter, error
// Strip (
s = s[1:]
var subqueries []NodeFilter
var query NodeFilter
var err error

var invert bool

if s[0] == '!' {
invert = true
s = s[1:]
}

var result NodeFilter

switch s[0] {
case '(': // double wrapped query?
s, query, err = parseLDAPRuneQuery(s, ao)
s, result, err = parseLDAPRuneQuery(s, ao)
if err != nil {
return nil, nil, err
}
if len(s) == 0 {
return nil, nil, errors.New("Missing closing ) in query")
}
// Strip )
return s[1:], query, nil
s = s[1:]
case '&':
s, subqueries, err = parseMultipleLDAPRuneQueries(s[1:], ao)
if err != nil {
return nil, nil, err
}
// Strip )
return s[1:], andquery{subqueries}, nil
s = s[1:]
result = andquery{subqueries}
case '|':
s, subqueries, err = parseMultipleLDAPRuneQueries(s[1:], ao)
if err != nil {
Expand All @@ -72,7 +75,15 @@ func parseLDAPRuneQuery(s []rune, ao *engine.Objects) ([]rune, NodeFilter, error
return nil, nil, errors.New("Query should end with )")
}
// Strip )
return s[1:], orquery{subqueries}, nil
s = s[1:]
result = orquery{subqueries}
}

if result != nil {
if invert {
result = notquery{result}
}
return s, result, nil
}

// parse one Attribute = Value pair
Expand Down Expand Up @@ -281,8 +292,6 @@ valueloop:
}
}

var result NodeFilter

// Decide what to do
switch modifier {
case "":
Expand Down

0 comments on commit 0bb948b

Please sign in to comment.