Skip to content

Commit f343710

Browse files
committed
fix: Failed to initialize organization object #12
1 parent 1fe0ba0 commit f343710

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

example/docker-compose/ldifs/init_org_tree.ldif

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dn: ${LDAP_INIT_ORG_DN}
77
description: ${LDAP_INIT_ORG_NAME}
88
objectClass: top
99
objectClass: organization
10-
o: ${LDAP_INIT_ORG_ATTR_O}
10+
${LDAP_INIT_ORG_COMPUTED_ATTRS}
1111

1212
dn: ou=Groups,${LDAP_INIT_ORG_DN}
1313
ou: Groups

image/ldifs/init_org_tree.ldif

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dn: ${LDAP_INIT_ORG_DN}
77
description: ${LDAP_INIT_ORG_NAME}
88
objectClass: top
99
objectClass: organization
10-
${LDAP_INIT_ORG_DN_ATTR}
10+
${LDAP_INIT_ORG_COMPUTED_ATTRS}
1111

1212
dn: ou=Groups,${LDAP_INIT_ORG_DN}
1313
ou: Groups

image/run.sh

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ if [ ! -e /etc/ldap/slapd.d/initialized ]; then
141141
/etc/init.d/slapd start
142142
# await ldap server start
143143
for i in {1..8}; do
144-
ldapwhoami -H ldapi:/// && break
145-
sleep 1
144+
ldapwhoami -H ldapi:/// && break
145+
sleep 1
146146
done
147147

148148
ldif add -Y EXTERNAL /opt/ldifs/schema_sudo.ldif
@@ -157,22 +157,31 @@ if [ ! -e /etc/ldap/slapd.d/initialized ]; then
157157
ldif add -Y EXTERNAL /opt/ldifs/init_module_ppolicy.ldif
158158

159159
if [ "${LDAP_INIT_ALLOW_CONFIG_ACCESS:-false}" == "true" ]; then
160-
ldif modify -Y EXTERNAL /opt/ldifs/init_config_admin_access.ldif
160+
ldif modify -Y EXTERNAL /opt/ldifs/init_config_admin_access.ldif
161161
fi
162162

163-
if [[ -z ${LDAP_INIT_ORG_ATTR_O:-} ]]; then
164-
# derive LDAP_INIT_ORG_ATTR_O (referenced by init_org_tree.ldif) from LDAP_INIT_ORG_DN
165-
if [[ "$LDAP_INIT_ORG_DN" =~ [oO]=([^,]*) ]]; then # check if "o=..." attribute is present in DN
166-
# e.g. LDAP_INIT_ORG_DN="O=example.com" -> LDAP_INIT_ORG_ATTR_O="example.com"
167-
# e.g. LDAP_INIT_ORG_DN="O=Example,DC=example,DC=com" -> LDAP_INIT_ORG_ATTR_O="Example"
168-
LDAP_INIT_ORG_DN_ATTR=${BASH_REMATCH[1]}
169-
elif [[ "${LDAP_INIT_ORG_DN}" =~ [dD][cC]= ]]; then
170-
# e.g. LDAP_INIT_ORG_DN="DC=example,DC=com" -> LDAP_INIT_ORG_ATTR_O="example.com"
171-
LDAP_INIT_ORG_DN_ATTR=$(echo $LDAP_INIT_ORG_DN | grep -ioP 'DC=\K[^,]+' | paste -sd '.')
172-
else
173-
log ERROR "Unable to derive required 'o' attribute of objectClass 'organization' from LDAP_INIT_ORG_DN='$LDAP_INIT_ORG_DN'"
174-
exit 1
175-
fi
163+
# calculate LDAP_INIT_ORG_COMPUTED_ATTRS variable, referenced in init_org_tree.ldif
164+
if [[ -z ${LDAP_INIT_ORG_ATTR_O:-} ]] && [[ "$LDAP_INIT_ORG_DN" =~ [oO]=([^,]*) ]]; then
165+
# derive 'o:' from LDAP_INIT_ORG_DN if LDAP_INIT_ORG_ATTR_O is unset and "O=..." is present
166+
# e.g. LDAP_INIT_ORG_DN="O=example.com" -> "o: example.com"
167+
# e.g. LDAP_INIT_ORG_DN="O=Example,DC=example,DC=com" -> "o: Example"
168+
LDAP_INIT_ORG_ATTR_O=${BASH_REMATCH[1]}
169+
fi
170+
if [[ "$LDAP_INIT_ORG_DN" =~ [dD][cC]=([^,]*) ]]; then
171+
LDAP_INIT_ORG_ATTR_DC=${BASH_REMATCH[1]}
172+
# derive 'o:' from LDAP_INIT_ORG_DN if LDAP_INIT_ORG_ATTR_O is unset and "DC=..." is present
173+
if [[ -z ${LDAP_INIT_ORG_ATTR_O:-} ]]; then
174+
# e.g. LDAP_INIT_ORG_DN="DC=example,DC=com" -> "o: example.com"
175+
LDAP_INIT_ORG_ATTR_O=$(echo "$LDAP_INIT_ORG_DN" | grep -ioP 'DC=\K[^,]+' | paste -sd '.')
176+
fi
177+
LDAP_INIT_ORG_COMPUTED_ATTRS="objectClass: dcObject
178+
o: $LDAP_INIT_ORG_ATTR_O
179+
dc: $LDAP_INIT_ORG_ATTR_DC"
180+
elif [[ -n ${LDAP_INIT_ORG_ATTR_O:-} ]]; then
181+
LDAP_INIT_ORG_COMPUTED_ATTRS="o: $LDAP_INIT_ORG_ATTR_O"
182+
else
183+
log ERROR "Unable to derive required 'o' attribute of objectClass 'organization' from LDAP_INIT_ORG_DN='$LDAP_INIT_ORG_DN'"
184+
exit 1
176185
fi
177186

178187
ldif add -x -D "$LDAP_INIT_ROOT_USER_DN" -w "$LDAP_INIT_ROOT_USER_PW" /opt/ldifs/init_org_tree.ldif

0 commit comments

Comments
 (0)