#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/cspoc/utilities/cl_ldap_client_show.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)49	1.1  src/43haes/usr/sbin/cluster/cspoc/utilities/cl_ldap_client_show.sh, hacmp, 61haes_r714 11/28/11 14:56:10
. /usr/es/sbin/cluster/cspoc/cl_federatedsec_source
fsec_init

odm_check

[[ -z `odmget -q "group=LDAPClient and name=ServerList" HACMPLDAP` ]] && {  dspmsg -s 129 cspoc.cat 134 "A LDAP client is not defined.\n"; exit 2; }
SERVER_LIST=$(clodmget -n -q "group=LDAPClient and name=ServerList" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $SERVER_LIST ]] && ret_fail "Server list not found." 1 
BIND_DN=$(clodmget -n -q "group=LDAPClient and name=BindDN" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $BIND_DN ]] && ret_fail "Bind DN not found." 1 
AUTH_TYPE=$(clodmget -n -q "group=LDAPClient and name=AuthType" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $AUTH_TYPE ]] && ret_fail "Authentication type not found." 1 
BASE_DN=$(clodmget -n -q "group=LDAPClient and name=Suffix" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $BASE_DN ]] && ret_fail "Base DN not found." 1 
SSL_PORT_NUM=$(clodmget -n -q "group=LDAPClient and name=SSLPortNumber" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $SSL_PORT_NUM ]] && ret_fail "SSL Port number not found." 1 
CLNT_KDB_PATH=$(clodmget -n -q "group=LDAPClient and name=ClientKdbPath" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $CLNT_KDB_PATH ]] && ret_fail "Client key path not found." 1 
###################
KEY_PW=$(clodmget -n -q "group=LDAPClient and name=ClientKdbPwd" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $KEY_PW ]] && ret_fail "Key password not found." 1 
BIND_PW=$(clodmget -n -q "group=LDAPClient and name=BindDNPwd" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $BIND_PW ]] && ret_fail "Bind password not found." 1 
BASE_PATH=$(clodmget -n -q "group=LDAPServer and name=BasePath" -f value HACMPLDAP|sort -u 2>/dev/null) 
[[ -z $BASE_PATH ]] && ret_fail "Base path not found." 1 
###################

echo "
LDAP Server(s) = $SERVER_LIST
Bind DN = $BIND_DN
Authentication Type = $AUTH_TYPE
Suffix / Base DN = $BASE_DN
Server Port Number = $SSL_PORT_NUM
SSL Key Path = $CLNT_KDB_PATH
"

#checking whether client is up and running and accessible with the parameters stored
SERVER_LIST_CC=`echo $SERVER_LIST|sed 's/,/ /g'` 
[[ -z $SERVER_LIST_CC ]] && ret_fail "Server list not found." 1 
NODES=`cllsnode -c|sed '1d'|awk -F: '{print $1}'` 
[[ -z $NODES ]] && ret_fail "Nodes not found" 1 
for X in $NODES
do
	TNODE=$X
	cl_rsh -n $TNODE "lsldap" >/dev/null 2>&1 \
	|| (  dspmsg -s 129 cspoc.cat 123 "WARNING: Either ldap client daemon is not running or server is not accessible in node %s. Check and correct it.\n" "$TNODE" && continue )
	for Y in $SERVER_LIST_CC
	do
		cl_rsh -n $TNODE "${BASE_PATH}/bin/ldapsearch -h $Y -b $BASE_DN -Z -K $CLNT_KDB_PATH -P $KEY_PW -p $SSL_PORT_NUM objectclass=*" >/dev/null 2>&1 \
	||  dspmsg -s 129 cspoc.cat 124 "WARNING: LDAP client is not able to contact server in node %s. Check and correct it.\n" "$TNODE"
	done
done
###################

run_on_allnode "rm -rf $FSEC_LOG_DIR" || ret_fail "Removing log directory failed." $?

exit 0
