38 lines
1.0 KiB
Bash
38 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
LDAP_SERVER="ldaps://your-ldap-server.com:636"
|
|
LDAP_BIND_DN="your-ldap-username"
|
|
LDAP_BIND_PASSWORD="your-ldap-password"
|
|
LDAP_BASE_DN="ou=Users,dc=example,dc=com"
|
|
LDAP_SEARCH_USER="username"
|
|
|
|
# Test 1: Basic connectivity check
|
|
echo "Testing basic connectivity..."
|
|
ldapsearch -H "$LDAP_SERVER" -x -b "" -s base
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: Failed to connect to LDAP server."
|
|
exit 1
|
|
fi
|
|
|
|
# Test 2: Bind with user account
|
|
echo "Testing bind with user account..."
|
|
ldapsearch -H "$LDAP_SERVER" -D "$LDAP_BIND_DN" -w "$LDAP_BIND_PASSWORD" -b "$LDAP_BASE_DN" -s sub "(objectClass=*)"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: Failed to bind with LDAP user account."
|
|
exit 1
|
|
fi
|
|
|
|
# Test 3: Search for a user
|
|
echo "Searching for user: $LDAP_SEARCH_USER..."
|
|
ldapsearch -H "$LDAP_SERVER" -D "$LDAP_BIND_DN" -w "$LDAP_BIND_PASSWORD" -b "$LDAP_BASE_DN" -s sub "(sAMAccountName=$LDAP_SEARCH_USER)"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Error: Failed to search for user."
|
|
exit 1
|
|
fi
|
|
|
|
echo "All tests passed successfully."
|
|
exit 0
|