-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldap_search_limit_scope.sh
46 lines (36 loc) · 1.28 KB
/
ldap_search_limit_scope.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
46
#!/bin/bash
# LDAP Search with Limiting Search Scope
# Demonstrates searching within a specific subtree of the directory.
#This script includes comments explaining the purpose of the script and demonstrates how to perform an LDAP search within a specific subtree of the directory using the -b option. The provided example showcases searching for entries with objectClass=person within the "ou=Users,dc=example,dc=com" search base and retrieving the specified attributes. I
# Connection Details
HOSTNAME="ldap.forumsys.com"
HOSTPORT=389
BIND_DN="cn=read-only-admin"
BIND_PASSWORD="password"
# Search with Limiting Search Scope
SEARCH_BASE="ou=Users,dc=example,dc=com"
FILTER="(objectClass=person)"
ATTRIBUTES="cn mail"
# Running the ldapsearch command with limiting search scope
ldapsearch -x -h $HOST -p $PORT -D "$BIND_DN" -w "$ADMIN_PASSWORD" -b "$SEARCH_BASE" "$FILTER" $ATTRIBUTES
<<OUTPUT
Sample Output:
# extended LDIF
#
# LDAPv3
# base <ou=Users,dc=example,dc=com> with scope subtree
# filter: (objectClass=person)
# requesting: cn mail
#
# search result
search: 2
result: 0 Success
# numResponses: 3
# numEntries: 2
dn: uid=john,ou=Users,dc=example,dc=com
cn: John Doe
mail: [email protected]
dn: uid=emma,ou=Users,dc=example,dc=com
cn: Emma Johnson
mail: [email protected]
OUTPUT