Skip to content

Commit

Permalink
Korjattu memberOf toiminta
Browse files Browse the repository at this point in the history
  • Loading branch information
ollitanska committed Dec 13, 2023
1 parent b28b793 commit 2b7ebba
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
21 changes: 17 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ FROM debian:bookworm

ENV OPENLDAP_VERSION 2.5.13

# RUN apt-get update && \
# DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
# slapd=${OPENLDAP_VERSION}* && \
# apt-get clean && \
# rm -rf /var/lib/apt/lists/*
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
slapd=${OPENLDAP_VERSION}* && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
slapd=${OPENLDAP_VERSION}* && apt-get install nano supervisor ldap-utils net-tools -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -13,11 +18,19 @@ RUN mv /etc/ldap /etc/ldap.dist
COPY modules/ /etc/ldap.dist/modules

COPY entrypoint.sh /entrypoint.sh
COPY populate.sh /populate.sh

RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

RUN chmod +x /entrypoint.sh
RUN chmod +x /populate.sh

EXPOSE 389

VOLUME ["/etc/ldap", "/var/lib/ldap"]

ENTRYPOINT ["/entrypoint.sh"]
# ENTRYPOINT ["/entrypoint.sh"]

CMD ["slapd", "-d", "32768", "-u", "openldap", "-g", "openldap"]
# CMD ["slapd", "-d", "32768", "-u", "openldap", "-g", "openldap"]
CMD ["/usr/bin/supervisord"]
23 changes: 15 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ EOF
sed -i "s/\(olcPPolicyDefault: \)PPOLICY_DN/\1${SLAPD_PPOLICY_DN_PREFIX}$dc_string/g" $file
fi

echo "Added module $file"

slapmodify -n0 -F /etc/ldap/slapd.d -l "$file"
done
done
Expand All @@ -107,14 +109,19 @@ if [[ "$first_run" == "true" ]]; then
fi
fi

if [[ "$first_run" == "true" ]]; then
if [[ -d "/etc/ldap/prepopulate/data" ]]; then
for file in `ls /etc/ldap/prepopulate/data/*.ldif`; do
slapadd -F /etc/ldap/slapd.d -l "$file"
done
fi
fi
# if [[ "$first_run" == "true" ]]; then
# if [[ -d "/etc/ldap/prepopulate/data" ]]; then
# for file in `ls /etc/ldap/prepopulate/data/*.ldif`; do
# slapadd -F /etc/ldap/slapd.d -l "$file"
# done
# fi
# fi

# chown -R openldap:openldap /etc/ldap/slapd.d/ /var/lib/ldap/ /var/run/slapd/

# exec "$@"

chown -R openldap:openldap /etc/ldap/slapd.d/ /var/lib/ldap/ /var/run/slapd/

exec "$@"
#exec "$@"
slapd -d 32768 -u openldap -g openldap
3 changes: 1 addition & 2 deletions modules/memberof.ldif
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ olcModuleLoad: memberof.la
dn: cn=module{0},cn=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: refint.la

olcModuleLoad: refint.la
33 changes: 33 additions & 0 deletions populate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
set -e
first_run=true

if [[ -f "/etc/ldap/ldap_populated" ]]; then
first_run=false
fi

# Wait until 'LDAP started and listens on port 389'.
while [ -z "`netstat -tln | grep 389`" ]; do
echo 'Waiting for LDAP to start ...'
sleep 1
done
echo 'LDAP started.'

dc_string=""
IFS="."; declare -a dc_parts=($SLAPD_DOMAIN); unset IFS

for dc_part in "${dc_parts[@]}"; do
dc_string="$dc_string,dc=$dc_part"
done

echo "DC string: $dc_string"

if [[ "$first_run" == "true" ]]; then
echo "Loading prepopulate data."
if [[ -d "/etc/ldap/prepopulate/data/" ]]; then
for file in `ls /etc/ldap/prepopulate/data/*.ldif`; do
ldapadd -x -D cn=admin$dc_string -w $SLAPD_PASSWORD -f "$file"
done
fi
touch /etc/ldap/ldap_populated
fi
14 changes: 14 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[supervisord]
nodaemon=true
logfile_backups=1

[program:ldap]
command=./entrypoint.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

[program:populate]
command=./populate.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

0 comments on commit 2b7ebba

Please sign in to comment.