-
Notifications
You must be signed in to change notification settings - Fork 0
/
ldap_search_advanced.sh
48 lines (37 loc) · 1.33 KB
/
ldap_search_advanced.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
47
48
#!/bin/bash
# LDAP Search with Advanced Options
# Demonstrates using advanced options for custom LDAP searches.
#This script includes comments explaining the purpose of the script and demonstrates how to perform an LDAP search with advanced options.
#The provided example showcases the usage of the cn:caseExactMatch:=john filter to search for entries with a case-sensitive exact match of "john" in the cn attribute.
# Connection Details
HOSTNAME="ldap.forumsys.com"
HOSTPORT=389
BIND_DN="cn=read-only-admin"
BIND_PASSWORD="password"
# Search with AND Operator
SEARCH_BASE_DN="dc=example,dc=com"
SEARCH_FILTER="(objectclass=*)"
ATTRIBUTES="dn cn sAMAccountName"
# Search with AND Operator
ADVANCED_FILTER="sAMAccountName:caseExactMatch:=john"
# Running the ldapsearch command with admin credentials
echo ldapsearch -x -h $HOSTNAME -p $HOSTPORT -D "$BIND_DN" -w "$BIND_PASSWORD" -b "$SEARCH_BASE_DN" $ADVANCED_FILTER $ATTRIBUTES
ldapsearch -x -h $HOSTNAME -p $HOSTPORT -D "$BIND_DN" -w "$BIND_PASSWORD" -b "$SEARCH_BASE_DN" $ADVANCED_FILTER $ATTRIBUTES
<<OUTPUT
Sample Output:
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: cn:caseExactMatch:=john
# requesting: ALL
#
# search result
search: 2
result: 0 Success
# numResponses: 2
# numEntries: 1
dn: uid=john,dc=example,dc=com
cn: John Doe
sAMAccountName: john
OUTPUT