Skip to content

Commit

Permalink
LDAP_DEBUG sends entrypoint script output to stdout
Browse files Browse the repository at this point in the history
If LDAP_DEBUG is set then the entrypoint script for the slapd images
will invoke 'set -x' and send all output to stdout.
  • Loading branch information
skoranda committed Jun 17, 2018
1 parent 130df64 commit 9a81632
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions comanage-registry-slapd-base/comanage_ldap_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if [[ -n "${LDAP_DEBUG}" ]]; then
OUTPUT=/dev/stdout
set -x
else
OUTPUT=/dev/null
fi

##########################################
# Add a hyphen to an LDIF file to indicate multiple ldapmodify entries.
# Globals:
Expand Down Expand Up @@ -72,7 +79,7 @@ function comanage_ldap_utils::add_schemas() {
# If schema is not already installed add it.
if ! comanage_ldap_utils::schema_installed ${schema_name}; then
ldapmodify -Y EXTERNAL -H ldapi:/// -a \
-f "${file_name}" > /dev/null 2>&1
-f "${file_name}" > "${OUTPUT}" 2>&1
fi

done
Expand Down Expand Up @@ -132,9 +139,9 @@ replace: olcDbDirectory
olcDbDirectory: /var/lib/ldap.dist
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Kill slapd and remove the directory created by the Debian installation
# that was copied over and used to allow slapd to start initially.
Expand All @@ -152,9 +159,9 @@ add: olcModuleLoad
olcModuleLoad: syncprov
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Configure the directory with the injected suffix but the temporary
# password.
Expand All @@ -181,9 +188,10 @@ olcDbIndex: entryUUID eq
olcDbMaxSize: 1073741824
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -a -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -a \
-f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Configure slapd to use a better password hash.
cat <<EOF > /tmp/modify.ldif
Expand All @@ -196,9 +204,9 @@ add: olcPasswordHash
olcPasswordHash: {CRYPT}
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Create the actual contents of the directory and the admin DN
# with the injected password hash.
Expand All @@ -218,9 +226,9 @@ userPassword: ${root_pw}
EOF

ldapmodify -x -D ${root_dn} -w ${olc_root_pw_tmp} -H ldapi:/// -a \
-f /tmp/modify.ldif > /dev/null 2>&1
-f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Remove the temporary root password from the directory configuration.
cat <<EOF > /tmp/modify.ldif
Expand All @@ -229,9 +237,9 @@ changetype: modify
delete: olcRootPW
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Add the syncprov overlay.
cat <<EOF > /tmp/modify.ldif
Expand All @@ -242,9 +250,9 @@ olcOverlay: syncprov
olcSpCheckpoint: 10 1
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Stop slapd.
comanage_ldap_utils::stop_slapd_socket
Expand Down Expand Up @@ -280,9 +288,9 @@ replace: olcAccess
olcAccess: {0}to * by * none
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Load the back_ldap module.
cat <<EOF > /tmp/modify.ldif
Expand All @@ -292,9 +300,9 @@ add: olcModuleLoad
olcModuleLoad: back_ldap
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Enable the ldap backend.
cat <<EOF > /tmp/modify.ldif
Expand All @@ -303,9 +311,9 @@ objectClass: olcBackendConfig
olcBackend: ldap
EOF

ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > /dev/null 2>&1
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1

# Stop slapd.
comanage_ldap_utils::stop_slapd_socket
Expand Down Expand Up @@ -377,9 +385,9 @@ changetype: modify
EOF
cat $ldif >> /tmp/modify.ldif
ldapmodify -Y EXTERNAL -H ldapi:/// -c \
-f /tmp/modify.ldif > /dev/null 2>&1
rm -f /tmp/modify.ldif > /dev/null 2>&1
rm -f $ldif > /dev/null 2>&1
-f /tmp/modify.ldif > "${OUTPUT}" 2>&1
rm -f /tmp/modify.ldif > "${OUTPUT}" 2>&1
rm -f $ldif > "${OUTPUT}" 2>&1

fi
fi
Expand Down Expand Up @@ -565,9 +573,9 @@ function comanage_ldap_utils::loop_ldapmodify() {
sed -i s@%%"${s}"%%@"${replacement}"@g "${newldif}"
done

ldapmodify -c ${auth} -H ldapi:/// -f "${newldif}" > /dev/null 2>&1
ldapmodify -c ${auth} -H ldapi:/// -f "${newldif}" > "${OUTPUT}" 2>&1

rm -f "${newldif}" > /dev/null 2>&1
rm -f "${newldif}" > "${OUTPUT}" 2>&1
done
}

Expand Down Expand Up @@ -613,8 +621,8 @@ function comanage_ldap_utils::process_ldif() {
function comanage_ldap_utils::tls_attribute_exists() {
local attribute="$1"
ldapsearch -LLL -Y EXTERNAL -H ldapi:/// \
-b cn=config -s base $attribute 2>/dev/null \
| grep $attribute > /dev/null 2>&1
-b cn=config -s base $attribute 2>"${OUTPUT}" \
| grep $attribute > "${OUTPUT}" 2>&1
}

##########################################
Expand All @@ -631,8 +639,8 @@ function comanage_ldap_utils::schema_installed() {
local filter="(&(cn={*}$schema_name)(objectClass=olcSchemaConfig))"

ldapsearch -LLL -Y EXTERNAL -H ldapi:/// \
-b cn=schema,cn=config $filter dn 2>/dev/null \
| grep $schema_name > /dev/null 2>&1
-b cn=schema,cn=config $filter dn 2>"${OUTPUT}" \
| grep $schema_name > "${OUTPUT}" 2>&1
}

##########################################
Expand All @@ -645,7 +653,7 @@ function comanage_ldap_utils::schema_installed() {
# None
##########################################
function comanage_ldap_utils::start_slapd_socket() {
slapd -h ldapi:/// -u openldap -g openldap > /dev/null 2>&1
slapd -h ldapi:/// -u openldap -g openldap > "${OUTPUT}" 2>&1
}

##########################################
Expand Down

0 comments on commit 9a81632

Please sign in to comment.