| Ticket UUID: | 1852718 | |||
| Title: | ldap filters with binary values not handled correctly | |||
| Type: | Bug | Version: | None | |
| Submitter: | mic42 | Created on: | 2007-12-17 23:01:25 | |
| Subsystem: | ldap | Assigned To: | mic42 | |
| Priority: | 5 Medium | Severity: | ||
| Status: | Closed | Last Modified: | 2008-07-21 02:54:06 | |
| Resolution: | Fixed | Closed By: | mic42 | |
| Closed on: | 2008-07-20 19:54:06 | |||
| Description: |
The filter buildup proc doesn't handle escaped binary in the filter value correct. It should follow RFC 2254. | |||
| User Comments: |
mic42 added on 2008-07-21 02:54:06:
Logged In: YES user_id=302287 Originator: YES Fixed in ldap 1.7. mpc_janssen added on 2007-12-20 02:16:27: Logged In: YES
user_id=1463011
Originator: NO
Note that an even easier (complemetary) solution would be to use Tcl variables for binary data so one could write:
set data (())))
set query {(GUID=$data)}
mpc_janssen added on 2007-12-20 02:00:08: Logged In: YES
user_id=1463011
Originator: NO
The following version works correctly on strings I have tested
# include procs
proc ldap::parseFilter {filterString} {
if {![regexp -- {^\((.*)\)$} $filterString -> filterComp]} {
error "invalid filter string: syntax is \"( ..... )\""
}
set result [parseFilterComp $filterComp]
}
proc ldap::parseFilterComp {filterComp} {
set first [string index $filterComp 0]
set rest [string range $filterComp 1 end]
switch -- $first {
& -
| -
! {
return [linsert [parseFilterList $rest] 0 $first]
}
default {
return [subst -nocommands -novariables [regsub -all {\\(..)} $filterComp {\\u00\1}]]
}
}
}
proc ldap::parseFilterList {filterList} {
puts "pfl: $filterList"
set filters {}
if {[string length $filterList] == 0} {
return {}
}
if {[string index $filterList 0]!="("} {
error "invalid filter component, syntax \"( ....\""
} else {
set filter [ldap::getFilterListElement filterList]
puts "filter: $filter"
return [list [parseFilter ($filter)] {*}[parseFilterList $filterList]]
}
}
proc ldap::getFilterListElement {filterListVar} {
upvar 1 $filterListVar filterList
set depth 0
set item {}
while 1 {
set char [string index $filterList 0]
puts $char
switch -- $char {
( {incr depth}
) {incr depth -1}
}
append item $char
puts $item
set filterList [string range $filterList 1 end]
if {$depth == 0} {return [string range $item 1 end-1]}
if {[string length $filterList] == 0} { error "missing ')' brace" }
}
}
mpc_janssen added on 2007-12-20 01:06:49: Logged In: YES user_id=1463011 Originator: NO Hm the correct format according to the RFC is \hh where hh are hex digits, so my examples are incorrect. mpc_janssen added on 2007-12-20 01:01:18: Logged In: YES
user_id=1463011
Originator: NO
What I posted before will fail on {(GUID=\\)} for example.
mpc_janssen added on 2007-12-20 00:06:08: Logged In: YES
user_id=1463011
Originator: NO
The ldap library is naive in listufy the filterString in line 1352-1353 in ldap.tcl. This can be fixed by parsing the string. The code below should do the trick. Escaping of () in data in the search string remains the responsibility of the library user.
Example:
ldap::parseFilter "(&(objectGUID=3fas93*\\(#}\\))(&(cn=*)(on=*)))"
& objectGUID=3fas93*(#\}) {& cn=* on=*}
Code:
# include procs
proc ldap::parseFilter {filterString} {
if {![regexp -- {^\((.*)\)$} $filterString -> filterComp]} {
error "invalid filter string: syntax is \"( ..... )\""
}
return [parseFilterComp $filterComp]
}
proc ldap::parseFilterComp {filterComp} {
set first [string index $filterComp 0]
set rest [string range $filterComp 1 end]
switch -- $first {
& -
| -
! {
return [linsert [parseFilterList $rest] 0 $first]
}
default {
# we have an item return as a single element list
return [string map {"\\(" "(" "\\)" ")"} $filterComp]
}
}
}
proc ldap::parseFilterList {filterList} {
puts "pfl: $filterList"
set filters {}
if {[string length $filterList] == 0} {
return {}
}
if {[string index $filterList 0]!="("} {
error "invalid filter component, syntax \"( ....\""
} else {
set filter [ldap::getFilterListElement filterList]
puts $filter
return [list [parseFilter ($filter)] {*}[parseFilterList $filterList]]
}
}
proc ldap::getFilterListElement {filterListVar} {
upvar 1 $filterListVar filterList
set prev {}
set depth 0
set idx 0
foreach cur [split $filterList ""] {
switch -- $cur {
( { if {$prev ne "\\"} {incr depth} }
) { if {$prev ne "\\"} {incr depth -1} }
}
incr idx
set prev $cur
if {$depth == 0} {
set item [string range $filterList 1 $idx-2]
set filterList [string range $filterList $idx end]
return $item
}
}
}
# and replace regexps by: set filterString [parseFilter $filterString]
| |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki