#!/bin/sh
# ####################################################################
# Exceed Connection Server 13.7
# Copyright (c) 1997-2009 Open Text Corporation. All Rights Reserved.
# ####################################################################
# getsslinfo.sh
# $Revision: 13958 $
# ####################################################################

get_platform()
{
	sysDir=`pwd`/bin/sys

	platDir=$sysDir/platform
	thisPlatform=`cat ${platDir}/id`

	cryptoLibNames=`cat ${platDir}/cryptoLibNames`
	sslLibNames=`cat ${platDir}/sslLibNames`
	sslLibDirs=`cat ${platDir}/sslLibDirs`
}

find_real_libname_of_this_lib_path_name()
{
 if [ "${thisPlatform}" = "aix-ppc64" ]; then
   echo "`ar -t ${this_lib_path_name}`" | read this_so
   fullLength=`expr length ${this_so}`
   libExtensionStartPosition=`expr index ${this_so} "."`
   libBaseNameLength=`expr ${libExtensionStartPosition} - 1`
   libExtensionLength=`expr ${fullLength} - ${libBaseNameLength}`
   
   libBaseName=`expr substr ${this_so} 1 ${libBaseNameLength}`
   libExtension=`expr substr ${this_so} ${libExtensionStartPosition} ${libExtensionLength}`
   this_lib_path_name="${this_lib_path_name}(${libBaseName}64${libExtension})"
  fi
}

find_crypto_lib()
{
  for lCryptoName in ${cryptoLibNames} ; do
    if [ "${ssl_found}" = "0" ] ; then
      crypto_lib_path_name=${lDir}/${lCryptoName}

      if [ -r ${crypto_lib_path_name} ]  ; then        
				this_lib_path_name=${crypto_lib_path_name}
				find_real_libname_of_this_lib_path_name
				crypto_lib_path_name=${this_lib_path_name}
        ssl_found="1"
      fi
    fi
  done
}

find_ssl_crypto_libs()
{
  for lName in ${sslLibNames} ; do
    if [ "${ssl_found}" = "0" ] ; then
      ssl_lib_path_name=${lDir}/${lName}
      
      if [ -r ${ssl_lib_path_name} ]  ; then
				this_lib_path_name=${ssl_lib_path_name}
				find_real_libname_of_this_lib_path_name
				ssl_lib_path_name=${this_lib_path_name}

        find_crypto_lib
      fi
    fi
  done
}

detect_ssl()
{
	get_platform
	
	ssl_found="0"
	rm -f ${ssl_available}	> 	/dev/null 2>&1
	
	for lDir in ${sslLibDirs} ; do
		find_ssl_crypto_libs
	done
	
	if [ "${ssl_found}" = "1" ] ; then
		sslable="1"
		touch "${ssl_available}"
	else
		ssl_lib_path_name=""
		crypto_lib_path_name=""
	fi
}

detect_ssh()
{
	this_ssh="ssh"
	
	rm -f ${ssl_available}	> 	/dev/null 2>&1

	sshcommand=`which ${this_ssh} 2> /dev/null `
	
	ssh_found=`echo ${sshcommand} | grep -c "${this_ssh}"`

	if [ ${ssh_found} = "0" ] ; then
		sshcommand=""
  	${ECHO} "${WARN}${SSH_NOT_FOUND2}" >> ${logfile}		
	else
		ssh_found="1"
		${ECHO} "$INFO EoDSSHCommand=$sshcommand" >> ${logfile}
		
		touch "${ssh_available}"
	fi
}

addSSLInfoToLogFile()
{
	if [ "${ssl_found}" = "1" ] ; then
		${ECHO} "${INFO} ECSSSLLibPath=$ssl_lib_path_name"	>> ${logfile}
		${ECHO} "${INFO} ECSCryptoLibPath=$crypto_lib_path_name" >> ${logfile}		
	else
  	${ECHO} "${WARN}${SSL_LIB_NOT_FOUND0} ${SSL_LIB_NOT_FOUND01} ${platDir}." >> ${logfile}
	fi
}

getSSLInfo()
{
	detect_ssh
	detect_ssl
	
	addSSLInfoToLogFile	
		
	pwdout=`bin/sys/keymgr --pwdgen`

	if [ ! -z "$pwdout" ] ; then
		for i in $pwdout
		do
			if [ -z "$dspwd" ] ; then
				dspwd=$i
			else
				dshash=$i
			fi
		done
	fi
}

getSSLInfo
