-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldap_search_with_and_operation.sh
45 lines (37 loc) · 1.25 KB
/
ldap_search_with_and_operation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# LDAP Search Example with AND Operator
# Demonstrates using the AND operator in an ldapsearch command.
# This script demonstrates an LDAP search with the AND operator using the provided connection details. It searches for entries with both the objectClass=inetOrgPerson and uid=pasteur conditions and retrieves the specified attributes (cn and uid). The provided sample output displays the result of the LDAP search.
# Connection Details
HOST="ldap.forumsys.com"
PORT=389
BIND_DN="cn=read-only-admin,dc=example,dc=com"
ADMIN_PASSWORD="password"
BASE_DN="dc=example,dc=com"
# Search with AND Operator
SEARCH_FILTER="(&(objectclass=inetOrgPerson)(uid=pasteur))"
ATTRIBUTES="cn uid"
# Running the ldapsearch command with AND Operator
ldapsearch -x -h $HOST -p $PORT -D "$BIND_DN" -w "$ADMIN_PASSWORD" -b "$BASE_DN" "$SEARCH_FILTER" $ATTRIBUTES
<<EOF
Sample Output:
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: (&(objectclass=inetOrgPerson)(uid=pasteur))
# requesting: cn uid
#
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
dn: uid=pasteur,dc=example,dc=com
cn: Louis Pasteur
uid: pasteur
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
EOF