Skip to content

Commit

Permalink
Fixes #18475: add software index in ldap
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceMacBuche committed Nov 13, 2020
1 parent d39871c commit 29235d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions rudder-webapp/SOURCES/rudder-upgrade
Expand Up @@ -54,7 +54,8 @@ trap 'anomaly_handler ${LINENO}' ERR INT TERM
# - 6.0.4 : Ensure that rudder-slapd sockbuf_max_incoming_auth is not lost at upgrade
# - 6.1.0 : Migrate RudderUniqueID to the template format
# - 6.1.0 : Add indexes cn,softwareVersion,directiveId in slapd.conf
# 6.1.1 : Update apache conf if it does not contain technique editor conf (file not updated by packaging
# - 6.1.1 : Update apache conf if it does not contain technique editor conf (file not updated by packaging
# - 6.2.0~beta2 : Add sofware and modifyTimestamp indexes in slapd.conf
####################################################################################

# Some paths
Expand Down Expand Up @@ -593,6 +594,18 @@ upgrade_slapdconf() {
fi
done

# 6.2.0~beta2:
# Add software and modifyTimestamp indexes in slapd.conf
for i in "software" "modifyTimestamp"; do
line="index\s*${i}\s*eq"
INDEX_COUNT=$(grep -c "^${line}" ${SLAPD_CONF} 2>/dev/null || true)
if [ ${INDEX_COUNT} -eq 0 ]; then
echo "Adding LDAP index on attribute: ${i}"
sed -i "/index\s*objectClass\s*eq/a index\t${i}\teq" ${SLAPD_CONF}
NEED_REINDEX=true
fi
done

# If user choose to replace configuration file, then /opt/rudder/etc/openldap/slapd.conf
# already contains the index, but nothing reindexed slapd
# We need to check for existence of slapd.conf.dpkg-old, its age, and if it contains index
Expand All @@ -601,7 +614,8 @@ upgrade_slapdconf() {
# if file exist, and is less than 1 hour old, check for index in it
if [ $(($(date +%s) - $(stat -c '%Z' ${SLAPD_CONF_BKP}))) -lt 3600 ]; then
INDEX_BKP_COUNT=$(grep -c "^index\s*directiveId\s*eq" ${SLAPD_CONF_BKP} 2>/dev/null || true)
if [ ${INDEX_BKP_COUNT} -eq 0 ]; then
INDEX_BKP_COUNT_2=$(grep -c "^index\s*modifyTimestamp\s*eq" ${SLAPD_CONF_BKP} 2>/dev/null || true)
if [ ${INDEX_BKP_COUNT} -eq 0 || ${INDEX_BKP_COUNT_2} -eq 0 ]; then
NEED_REINDEX=true
fi
fi
Expand Down
3 changes: 3 additions & 0 deletions rudder-webapp/SOURCES/slapd.conf
Expand Up @@ -64,6 +64,9 @@ index objectClass eq
index cn eq
index softwareVersion eq
index directiveId eq
index software eq
index modifyTimestamp eq


# 2 - Monitor
# Query statistics here by running:
Expand Down

0 comments on commit 29235d3

Please sign in to comment.