Skip to content

Improve LDAP user info retrieval#240

Open
AditiChikkali wants to merge 1 commit intoNSLS2:mainfrom
AditiChikkali:feature/whoami-test-page
Open

Improve LDAP user info retrieval#240
AditiChikkali wants to merge 1 commit intoNSLS2:mainfrom
AditiChikkali:feature/whoami-test-page

Conversation

@AditiChikkali
Copy link
Contributor

This PR refactors the LDAP user info retrieval logic to improve reliability and completeness of returned attributes.

Key changes:

  • Implements a two-step search strategy for posix accounts: first fetches all regular attributes (*), then explicitly fetches operational attributes (e.g., objectGUID, objectSid, memberOf, whenCreated, whenChanged, manager), and merges results.
  • Adds a reusable _extract_attributes helper to standardize extraction of LDAP entry attributes into Python dictionaries, handling bytes, lists, and strings.
  • Updates clean_object_class to robustly handle both string and list formats for the objectClass attribute, ensuring consistent output.
  • Improves generalized_time_to_str to reliably convert LDAP generalized time strings and datetime objects to readable UTC timestamps.

These changes address erratic behavior with missing attributes, ensure all required data is returned, and make downstream processing more robust and maintainable.

This PR addresses issue #8 by refactoring LDAP search logic to reliably fetch operational attributes.

…tribute searches, add robust attribute extraction and cleaning utilities
if isinstance(obj_class_val, list):
return [str(s).strip() for s in obj_class_val]
elif isinstance(obj_class_val, str):
return [s.strip() for s in obj_class_val.replace(",", " ").split() if s.strip()]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might not work as intended if the value includes spaces or escaped commas \,.

It would be fine to merge this and then update later iso needed though.

Comment on lines 46 to 47
if not conn.entries:
logger.warning("no posix entries found for the given username.")
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably still get logged as f"No LDAP posix entries found for {username}" or something similar.

Is it intentional to exit here in that case, or is it supposed to try the "recovery step" with OPERATIONAL_ATTRIBUTES before exiting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants