nitinkotania | a670091 | 2023-12-05 12:15:07 -0600 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # config: 2 20 |
| 4 | # @brief: Get the ldap configuration |
| 5 | # |
| 6 | |
| 7 | # shellcheck disable=SC1091 |
| 8 | # shellcheck disable=SC2086 |
| 9 | |
| 10 | . "$DREPORT_INCLUDE"/functions |
| 11 | |
| 12 | desc="ldap configuration" |
| 13 | |
| 14 | open_ldap_command="busctl get-property \ |
| 15 | xyz.openbmc_project.Ldap.Config \ |
| 16 | /xyz/openbmc_project/user/ldap/openldap \ |
| 17 | xyz.openbmc_project.Object.Enable \ |
| 18 | 'Enabled'" |
| 19 | |
| 20 | active_dir_command="busctl get-property \ |
| 21 | xyz.openbmc_project.Ldap.Config \ |
| 22 | /xyz/openbmc_project/user/ldap/active_directory \ |
| 23 | xyz.openbmc_project.Object.Enable \ |
| 24 | 'Enabled'" |
| 25 | |
| 26 | commands=( |
| 27 | "systemctl status nslcd" |
| 28 | "systemctl status xyz.openbmc_project.Ldap.Config" |
| 29 | "busctl tree xyz.openbmc_project.Ldap.Config" |
| 30 | "busctl call xyz.openbmc_project.Ldap.Config \ |
| 31 | /xyz/openbmc_project/user/ldap \ |
| 32 | org.freedesktop.DBus.ObjectManager \ |
| 33 | 'GetManagedObjects'" |
| 34 | ) |
| 35 | |
| 36 | file_name=$"ldap_bmcdump_$EPOCHTIME" |
| 37 | output_file_dir="$TMP_DIR/ldap_bmcdump" |
| 38 | output_file="$output_file_dir/$file_name" |
| 39 | |
| 40 | if [ -e "$output_file" ]; then |
| 41 | rm "$output_file" |
| 42 | fi |
| 43 | |
| 44 | if [ ! -d "$output_file_dir" ]; then |
| 45 | mkdir -p "$output_file_dir" |
| 46 | fi |
| 47 | |
| 48 | ldapEnabled="false" |
| 49 | |
| 50 | if result=$(eval "$open_ldap_command" | awk '{print $NF}'); then |
| 51 | if [ "$result" == "true" ]; then |
| 52 | ldapEnabled="true" |
| 53 | elif [ "$result" == "false" ]; then |
| 54 | if result=$(eval "$active_dir_command" | awk '{print $NF}'); then |
| 55 | if [ "$result" == "true" ]; then |
| 56 | ldapEnabled="true" |
| 57 | fi |
| 58 | fi |
| 59 | fi |
| 60 | fi |
| 61 | |
| 62 | if [ "$ldapEnabled" == "false" ]; then |
| 63 | log_warning "skipping LDAP dump: LDAP is not enabled" |
| 64 | exit 0; |
| 65 | else |
| 66 | for cmd in "${commands[@]}"; do |
| 67 | result=$(eval "$cmd" ) |
| 68 | echo "=============$cmd=============" >> "$output_file" |
| 69 | echo "$result" >> "$output_file" |
| 70 | done |
| 71 | |
| 72 | command="cat $output_file" |
| 73 | file_name="usrmgrldap.log" |
| 74 | add_cmd_output "$command" "$file_name" "$desc" |
| 75 | rm -rf $output_file |
| 76 | |
| 77 | desc="nslcd config" |
| 78 | result=$(sed '/^bindpw/d' /etc/nslcd.conf) |
| 79 | command="printf \"%s\n\" \"\$result\"" |
| 80 | file_name="nslcd.conf" |
| 81 | add_cmd_output "$command" "$file_name" "$desc" |
| 82 | fi |