Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ldapquery): add support multiple search fields #1240

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analyzers/LdapQuery/LdapQuery.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"name": "uid_search_field",
"description": "Specify here the field to use when searching by username. Eg: uid or sAMAccountName",
"type": "string",
"multi": false,
"multi": true,
"required": true
},
{
Expand Down
14 changes: 7 additions & 7 deletions analyzers/LdapQuery/ldapQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ def __init__(self):
username = self.get_param("config.LDAP_username", None, "username is missing")
password = self.get_param("config.LDAP_password", None, "password is missing")
self.base_dn = self.get_param("config.base_DN", None, "base_dn is missing")
uid_search_field = self.get_param(
self.search_field = self.get_param(
"config.uid_search_field", None, "uid_search_field is missing"
)
if self.data_type == "mail":
self.search_field = "mail"
else:
self.search_field = uid_search_field

self.attributes = self.get_param(
"config.attributes", None, "Missing attributes list to report"
)
Expand Down Expand Up @@ -74,7 +69,12 @@ def run(self):
try:

data = self.get_param("data", None, "Data is missing")
q = "({}={})".format(self.search_field, data)

if len(self.search_field) == 1:
q = "({}={})".format(self.search_field, data)
else:
search_fields = [f"({field}={data})" for field in self.search_field]
q = f"(|{search_fields.join('')})"

self.connection.search(self.base_dn, q, SUBTREE, attributes=self.attributes)
responses = self.connection.response
Expand Down