#!/bin/bash assert(){ [[ $? -eq 0 ]] || { [[ -n ${1} ]] && echo ${@} ; exit 1 ; } } # from https://github.com/dinkel/docker-openldap/blob/master/entrypoint.sh: # When not limiting the open file descritors limit, the memory consumption of # slapd is absurdly high. See https://github.com/docker/docker/issues/8231 ulimit -n 8192 slapd -u openldap -g openldap -h ldapi:/// assert "FATAL: sldapd died unexpectedly!" PIDFILE=$(ldapsearch -LLL -QY EXTERNAL -H ldapi:/// -b "cn=config" -s base \ olcPidFile | grep olcPidFile | awk '{print $2}') echo "slapd running. pidfile = ${PIDFILE}" [[ -n "${LDAP_DOMAIN}" ]] assert "FATAL: Please set LDAP_DOMAIN and retry." DN0="dc=${LDAP_DOMAIN//./,dc=}" LDAP_DOMAIN_DN=${LDAP_DOMAIN_DN:=${DN0}} echo "setting up domain = ${LDAP_DOMAIN}, dn = ${LDAP_DOMAIN_DN}" [[ -n "${LDAP_CONFIG_PASSWORD}" ]] assert "FATAL: Please set LDAP_CONFIG_PASSWORD and retry." LDAP_CONFIG_PWHASH=$(slappasswd -h "{SSHA}" -s "${LDAP_CONFIG_PASSWORD}") [[ -n "${LDAP_ADMIN_PASSWORD}" ]] assert "FATAL: Please set LDAP_ADMIN_PASSWORD and retry." LDAP_ADMIN_PWHASH=$(slappasswd -h "{SSHA}" -s "${LDAP_ADMIN_PASSWORD}") # TODO: verify password before updating ======================================= echo "Setting cn=admin,cn=config password" ldapmodify -QY EXTERNAL -H ldapi:/// <