MCPcopy Index your code
hub / github.com/secdev/scapy / search

Method search

scapy/layers/ldap.py:2210–2340  ·  view source on GitHub ↗

Perform a LDAP search. :param baseObject: the dn of the base object to search in. :param filter: the filter to apply to the search (currently unsupported) :param scope: 0=baseObject, 1=singleLevel, 2=wholeSubtree

(
        self,
        baseObject: str = "",
        filter: str = "",
        scope=0,
        derefAliases=0,
        sizeLimit=300000,
        timeLimit=3000,
        attrsOnly=0,
        attributes: List[str] = [],
        controls: List[LDAP_Control] = [],
    )

Source from the content-addressed store, hash-verified

2208 _TEXT_REG = re.compile(b"^[%s]*$" % re.escape(string.printable.encode()))
2209
2210 def search(
2211 self,
2212 baseObject: str = "",
2213 filter: str = "",
2214 scope=0,
2215 derefAliases=0,
2216 sizeLimit=300000,
2217 timeLimit=3000,
2218 attrsOnly=0,
2219 attributes: List[str] = [],
2220 controls: List[LDAP_Control] = [],
2221 ) -> Dict[str, List[Any]]:
2222 """
2223 Perform a LDAP search.
2224
2225 :param baseObject: the dn of the base object to search in.
2226 :param filter: the filter to apply to the search (currently unsupported)
2227 :param scope: 0=baseObject, 1=singleLevel, 2=wholeSubtree
2228 """
2229 if baseObject == "rootDSE":
2230 baseObject = ""
2231 if filter:
2232 filter = LDAP_Filter.from_rfc2254_string(filter)
2233 else:
2234 # Default filter: (objectClass=*)
2235 filter = LDAP_Filter(
2236 filter=LDAP_FilterPresent(
2237 present=ASN1_STRING(b"objectClass"),
2238 )
2239 )
2240 # we loop as we might need more than one packet thanks to paging
2241 cookie = b""
2242 entries = {}
2243 while True:
2244 resp = self.sr1(
2245 LDAP_SearchRequest(
2246 filter=filter,
2247 attributes=[
2248 LDAP_SearchRequestAttribute(type=ASN1_STRING(attr))
2249 for attr in attributes
2250 ],
2251 baseObject=ASN1_STRING(baseObject),
2252 scope=ASN1_ENUMERATED(scope),
2253 derefAliases=ASN1_ENUMERATED(derefAliases),
2254 sizeLimit=ASN1_INTEGER(sizeLimit),
2255 timeLimit=ASN1_INTEGER(timeLimit),
2256 attrsOnly=ASN1_BOOLEAN(attrsOnly),
2257 ),
2258 controls=(
2259 controls
2260 + (
2261 [
2262 # This control is only usable when bound.
2263 LDAP_Control(
2264 controlType="1.2.840.113556.1.4.319",
2265 criticality=True,
2266 controlValue=LDAP_realSearchControlValue(
2267 size=200, # paging to 200 per 200

Callers 6

lsFunction · 0.45
__init__.pyFile · 0.45
name2addrMethod · 0.45
_parse_tcpreplay_resultFunction · 0.45
_matchFunction · 0.45
loadMethod · 0.45

Calls 15

sr1Method · 0.95
ASN1_STRINGClass · 0.90
ASN1_ENUMERATEDClass · 0.90
ASN1_INTEGERClass · 0.90
ASN1_BOOLEANClass · 0.90
LDAP_FilterClass · 0.85
LDAP_FilterPresentClass · 0.85
LDAP_SearchRequestClass · 0.85
LDAP_ControlClass · 0.85
LDAP_ExceptionClass · 0.85

Tested by

no test coverage detected