libpath_add() { [ -z "$1" ] && return LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$1 } # pass in a string that ends in dirsrv-name or slapd-name, # and convert it to just "name" normalize_server_id() { servid=$1 servid=`echo "$servid" | sed 's/^.*\///'` servid=`echo "$servid" | sed 's/^dirsrv-//'` servid=`echo "$servid" | sed 's/^slapd-//'` echo $servid } # look for all initconfig files in the given directory # the initconfig files are the files used in the startup scripts # to start each instance # e.g. /etc/sysconfig/dirsrv-INST # these scripts contain the pointer CONFIG_DIR to where the instance # configuration files are to be found # if the given directory is empty, look in @initconfigdir@ # if not running as root, look for non-system instances in # $HOME/.dirsrv # ignore the dirsrv-admin admin server config file # get_initconfig_files() { dir=${1:-@initconfigdir@} # convert # uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),..... # to # 0 # this is the only portable, secure way to determine the id number userid=`id | awk -F'[=(]+' '{print $2}'` if [ "$userid" -ne 0 ] ; then # magic - see start-dirsrv, DSCreate.pm::get_initconfigdir, etc. extradir=$HOME/.@package_name@ if [ -d $extradir ] ; then extra="$extradir/@package_name@-*" fi fi # setting the env var forces the use of it and nothing else if [ -n "$INITCONFIGDIR" ] ; then dir=$INITCONFIGDIR extra= fi retfiles= found=1 for file in $dir/@package_name@-* $extra ; do if [ ! -r "$file" ] ; then continue ; fi case "$file" in */@package_name@-admin) continue ;; esac if [ -z "$retfiles" ] ; then retfiles=$file else retfiles="$retfiles $file" fi found=0 done echo $retfiles return $found # 0 return means success - at least one found } # # get_init_file() # # The init file is the instance specific file under # the @initconfig@ directory e.g. # /etc/sysconfig/dirsrv-instance # The presence and readability of this file means this is a # valid instance of directory server (except @package_name@-admin) # The CONFIG_DIR directive in this file tells us where to # look for the main server config # First grab all the @package_name@ init files # Then check if a server id was provided, if not, return the # one found if there is only one # If a servid was provided, make sure there is an init file # for that instance # Return the @initconfigdir@/@package_name@-$servid file name # get_init_file() { dir=$1 servid=$2 first="yes" inst_count=0 instances="" # normalize servid, if given if [ -n "$servid" ] then servid=`normalize_server_id $servid` fi for configfile in `get_initconfig_files $dir` do inst_count=`expr $inst_count + 1` id=`normalize_server_id $configfile` if [ -n "$servid" -a "$id" = "$servid" ] then # found it echo $configfile exit 0 fi if [ $first == "yes" ] then instances=$id first="no" else instances=$instances", $id" fi done # server id not provided, check if there is only one instance if [ -z "$servid" -a $inst_count -eq 1 ] then # return the file echo $configfile exit 0 else # Either we have an invalid name, or more than one instance is available # Return the available instances instead of the config file echo $instances exit 1; fi } # # # process_dse () { configdir=$1 pid=$2 file="$configdir/dse.ldif" shopt -s nocasematch OLD_IFC=$IFC IFS="" while read -r LINE do if [[ $LINE != \ * ]] && [ "$output" != "" ] then echo "$output" >> /tmp/DSSharedLib.$pid output="" fi if [ "$output" != "" ] && [[ $LINE == \ * ]] then # continuation line, strip the space and append it LINE=`echo "$LINE" | sed -e 's/^ //'` output=$output$LINE elif [[ $LINE == nsslapd-port* ]] then output=$LINE; elif [[ $LINE == nsslapd-localhost* ]] then output=$LINE; elif [[ $LINE == nsslapd-securePort* ]] then output=$LINE; elif [[ $LINE == nsslapd-security* ]] then output=$LINE; elif [[ $LINE == nsslapd-ldapilisten* ]] then output=$LINE; elif [[ $LINE == nsslapd-ldapifilepath* ]] then output=$LINE; elif [[ $LINE == nsslapd-rootdn* ]] then output=$LINE; elif [[ $LINE == nsslapd-ldapiautobind* ]] then output=$LINE; elif [[ $LINE == nsslapd-certdir* ]] then output=$LINE; fi done < $file IFS=$OLD_IFS } # # Check protocol # check_protocol () { protocol=$1 security=$2 ldapi=$3 openldap=$4 if [ "$protocol" == "LDAPI" ] && [ "$openldap" != "yes" ]; then echo "" exit elif [ "$protocol" == "LDAPI" ] && [ "$ldapi" == "off" ]; then echo "" exit elif [ "$protocol" == "STARTTLS" ]; then if [ "$security" == "" ] || [ "$security" == "off" ]; then echo "" exit fi elif [ "$protocol" == "LDAPS" ]; then if [ "$security" == "" ] || [ "$security" == "off" ]; then echo "" exit fi fi if [ "$protocol" != "" ]; then if [ "$protocol" != "STARTTLS" ] && [ "$protocol" != "LDAPS" ] && [ "$protocol" != "LDAPI" ] && [ "$protocol" != "LDAP" ] then echo "" exit fi fi echo "$protocol" }