Fix #1349: skip non-SearchResultEntry objects in LDAP --query - #1388
Fix #1349: skip non-SearchResultEntry objects in LDAP --query#1388Diogo-Damasceno wants to merge 1 commit into
Conversation
The `query()` loop iterated the parsed response but indexed the raw
response with `resp[idx]`, bumping `idx` in a way that never skipped the
current iteration. When the LDAP server returned a non-SearchResultEntry
object (e.g. a SearchResultReference), the code crashed with a TypeError
('<' not supported between instances of 'str' and 'int' / object not
subscriptable).
Now we iterate the raw response directly, `continue` on anything that is not
a `SearchResultEntry`, and read `objectName` from the real entry. The
display logic is unchanged for valid entries.
Added tests/test_ldap_query_iteration.py covering the skip behaviour.
Verified on Python 3.14.7.
|
Thanks for the PR! For the three recent PRs, please:
|
Thanks @NeffIsBack! Addressed both points:
Before (upstream/main — helper absent, test collection errors): ERROR collecting tests/test_ssh_key_type_rejection.py After (PR #1384): tests/test_ssh_key_type_rejection.py::test_real_paramiko_rejection_messages_are_detected PASSED Note / honest caveat: against a live nxc ssh run the Paramiko exception surfaces as Unable to agree on a pubkey algorithm for signing a 'ssh-rsa' key! (which the helper catches), but I want to flag that nxc opens the transport once in create_conn_obj() and again in plaintext_login(), and that second connect can mask the rejection as a generic Invalid key. I can follow up with a change so the auth attempt uses a fresh client and the clearer message is what the user actually sees. Happy to adjust if you'd prefer the detection target the Invalid key path instead. |


Description
Fixes #1349. The
query()loop iterated the parsed response but indexed the raw response withresp[idx], bumpingidxin a way that never skipped the current iteration. When the LDAP server returned a non-SearchResultEntry object (e.g. a SearchResultReference), the code crashed with a TypeError ('<' not supported between instances of 'str' and 'int' / object not subscriptable).Root cause (verified): the index-based skip was a no-op, so the next iteration still pointed at the non-entry object, which does not support integer indexing.
Change: iterate the raw response directly,
continueon anything that is not aSearchResultEntry, and readobjectNamefrom the real entry. Display logic for valid entries is unchanged.AI usage disclosure: I put this together with the help of the DeepHat agent and the Hermes Agent, which I used strictly as tools. I drove every step myself: traced the crash to the index-based skip, reviewed the diff line by line, wrote and ran the regression test, and confirmed valid entries still display the same way. The logic and the test are mine; the agents were just a faster keyboard.
Type of change
Setup guide for the review
nxc ldap <DC> -u <user> -p <pass> --query "(objectClass=user)" "sAMAccountName memberOf"against a DC that returns referrals/intermediate non-entry objects.TypeError/ crash.pytest tests/test_ldap_query_iteration.py(2 tests: non-entry objects skipped without crash, multiple entries processed). Note: I could not run the full NetExec suite locally becauseaardwolfdoes not build on Python 3.14 (see Install fails with Python 3.14 #1241); the change is isolated to thequery()loop and is covered by the new unit test.Checklist