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
12desc="ldap configuration"
13
14open_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
20active_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
26commands=(
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
36file_name=$"ldap_bmcdump_$EPOCHTIME"
37output_file_dir="$TMP_DIR/ldap_bmcdump"
38output_file="$output_file_dir/$file_name"
39
40if [ -e "$output_file" ]; then
41    rm "$output_file"
42fi
43
44if [ ! -d "$output_file_dir" ]; then
45    mkdir -p "$output_file_dir"
46fi
47
48ldapEnabled="false"
49
50if 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
60fi
61
62if [ "$ldapEnabled" == "false" ]; then
63    log_warning "skipping LDAP dump: LDAP is not enabled"
64    exit 0;
65else
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"
82fi
83