entrypoint.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. # Log everything to this log file. Use LOG env var or default /var/log/ldap.log
  3. ENTRYLOG=${LOG:-/var/log/ldap.log}
  4. echo Logfile: $ENTRYLOG
  5. exec &> $ENTRYLOG
  6. # Inspired by https://github.com/acobaugh/openldap-alpine
  7. # When not limiting the open file descriptors, the memory consumption
  8. # of slapd is absurdly high. See https://github.com/docker/docker/issues/8231
  9. ulimit -n 8192
  10. # If there's no cn=config database, initialize one.
  11. # Take the original slapd.conf file as template.
  12. if [ ! -d '/etc/openldap/slapd.d/cn=config' ]; then
  13. # Limit the access to the database
  14. SLAPD_CONFIG_ROOTPW=`< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo`
  15. # Generate a password hash
  16. config_rootpw_hash=`slappasswd -s "${SLAPD_CONFIG_ROOTPW}"`
  17. echo $SLAPD_CONFIG_ROOTPW > /etc/openldap/slapd.d/slapd_config_rootpw
  18. chmod 400 /etc/openldap/slapd.d/slapd_config_rootpw
  19. # Use the original slapd.conf file
  20. cp /etc/openldap/slapd.conf /tmp/slapd.conf
  21. # Set the correct suffix
  22. sed -i -e "s/dc=my-domain,dc=com/${SUFFIX}/g" /tmp/slapd.conf
  23. # Add more schemas
  24. sed -i -e "/core.schema/a include\t\t/etc/openldap/schema/cosine.schema" /tmp/slapd.conf
  25. sed -i -e "/cosine.schema/a include\t\t/etc/openldap/schema/inetorgperson.schema" /tmp/slapd.conf
  26. cat <<-EOF >> /tmp/slapd.conf
  27. #######################################################################
  28. # Dynamic config
  29. #######################################################################
  30. database config
  31. rootDN "cn=admin,cn=config"
  32. rootPW $config_rootpw_hash
  33. EOF
  34. # Generate config database from slapd.conf file.
  35. echo Generating configuration
  36. slaptest -f /tmp/slapd.conf -F /etc/openldap/slapd.d
  37. fi
  38. # Set all ownerships straight.
  39. chown -R ldap:ldap /etc/openldap/slapd.d
  40. mkdir /var/lib/openldap/run || true
  41. echo Starting slapd with $@
  42. exec "$@"