dreport: Added support to collect LDAP config data
LDAP related detailed data will be collected as part of BMC user
initiated Dump.
This commit will add 2 new file:
1. usrmgrldap.log (size: 3.1K)
2. nslcd.conf (size: 526B)
Tested By:
Tested by collecting BMC dump.
Change-Id: I09e35379935838c6f06d8604303f16a1febc8d3a
Signed-off-by: nitinkotania <gitnkotania@gmail.com>
diff --git a/tools/dreport.d/plugins.d/ldapdump b/tools/dreport.d/plugins.d/ldapdump
new file mode 100644
index 0000000..50bb5ff
--- /dev/null
+++ b/tools/dreport.d/plugins.d/ldapdump
@@ -0,0 +1,82 @@
+#!/bin/bash
+#
+# config: 2 20
+# @brief: Get the ldap configuration
+#
+
+# shellcheck disable=SC1091
+# shellcheck disable=SC2086
+
+. "$DREPORT_INCLUDE"/functions
+
+desc="ldap configuration"
+
+open_ldap_command="busctl get-property \
+ xyz.openbmc_project.Ldap.Config \
+ /xyz/openbmc_project/user/ldap/openldap \
+ xyz.openbmc_project.Object.Enable \
+ 'Enabled'"
+
+active_dir_command="busctl get-property \
+ xyz.openbmc_project.Ldap.Config \
+ /xyz/openbmc_project/user/ldap/active_directory \
+ xyz.openbmc_project.Object.Enable \
+ 'Enabled'"
+
+commands=(
+ "systemctl status nslcd"
+ "systemctl status xyz.openbmc_project.Ldap.Config"
+ "busctl tree xyz.openbmc_project.Ldap.Config"
+ "busctl call xyz.openbmc_project.Ldap.Config \
+ /xyz/openbmc_project/user/ldap \
+ org.freedesktop.DBus.ObjectManager \
+ 'GetManagedObjects'"
+)
+
+file_name=$"ldap_bmcdump_$EPOCHTIME"
+output_file_dir="$TMP_DIR/ldap_bmcdump"
+output_file="$output_file_dir/$file_name"
+
+if [ -e "$output_file" ]; then
+ rm "$output_file"
+fi
+
+if [ ! -d "$output_file_dir" ]; then
+ mkdir -p "$output_file_dir"
+fi
+
+ldapEnabled="false"
+
+if result=$(eval "$open_ldap_command" | awk '{print $NF}'); then
+ if [ "$result" == "true" ]; then
+ ldapEnabled="true"
+ elif [ "$result" == "false" ]; then
+ if result=$(eval "$active_dir_command" | awk '{print $NF}'); then
+ if [ "$result" == "true" ]; then
+ ldapEnabled="true"
+ fi
+ fi
+ fi
+fi
+
+if [ "$ldapEnabled" == "false" ]; then
+ log_warning "skipping LDAP dump: LDAP is not enabled"
+ exit 0;
+else
+ for cmd in "${commands[@]}"; do
+ result=$(eval "$cmd" )
+ echo "=============$cmd=============" >> "$output_file"
+ echo "$result" >> "$output_file"
+ done
+
+ command="cat $output_file"
+ file_name="usrmgrldap.log"
+ add_cmd_output "$command" "$file_name" "$desc"
+ rm -rf $output_file
+
+ desc="nslcd config"
+ result=$(sed '/^bindpw/d' /etc/nslcd.conf)
+ command="printf \"%s\n\" \"\$result\""
+ file_name="nslcd.conf"
+ add_cmd_output "$command" "$file_name" "$desc"
+fi