aboutsummaryrefslogtreecommitdiffstats
path: root/sos/plugins/ldap.py
blob: ef551f01d24832a553ef14d1d280a292de17cb90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin


class Ldap(Plugin):
    """LDAP configuration
    """

    plugin_name = "ldap"
    profiles = ('identity', 'sysmgmt', 'system')
    ldap_conf = "/etc/openldap/ldap.conf"

    def setup(self):
        super(Ldap, self).setup()
        self.add_copy_spec("/etc/ldap.conf")

    def postproc(self):
        self.do_file_sub("/etc/ldap.conf", r"(\s*bindpw\s*)\S+", r"\1******")


class RedHatLdap(Ldap, RedHatPlugin):

    packages = ('openldap', 'nss-pam-ldapd')
    files = ('/etc/ldap.conf', '/etc/pam_ldap.conf')

    def setup(self):
        super(RedHatLdap, self).setup()
        self.add_forbidden_path([
            "/etc/openldap/certs/password",
            "/etc/openldap/certs/pwfile.txt",
            "/etc/openldap/certs/pin.txt",
            "/etc/openldap/certs/*passw*",
            "/etc/openldap/certs/key3.db"
        ])

        self.add_copy_spec([
            self.ldap_conf,
            "/etc/openldap/certs/cert8.db",
            "/etc/openldap/certs/secmod.db",
            "/etc/nslcd.conf",
            "/etc/pam_ldap.conf"
        ])
        self.add_cmd_output("certutil -L -d /etc/openldap")

    def postproc(self):
        super(RedHatLdap, self).postproc()
        self.do_file_sub(
            "/etc/nslcd.conf",
            r"(\s*bindpw\s*)\S+",
            r"\1********"
        )
        self.do_file_sub(
            "/etc/pam_ldap.conf",
            r"(\s*bindpw\s*)\S+",
            r"\1********"
        )


class DebianLdap(Ldap, DebianPlugin, UbuntuPlugin):

    ldap_conf = "/etc/ldap/ldap.conf"
    packages = ('slapd', 'ldap-utils')

    def setup(self):
        super(DebianLdap, self).setup()

        ldap_search = "ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// "

        self.add_copy_spec([
            self.ldap_conf,
            "/etc/slapd.conf",
            "/etc/ldap/slapd.d"
            "/etc/nslcd.conf",
        ])

        self.add_cmd_output("ldapsearch -x -b '' -s base 'objectclass=*'")
        self.add_cmd_output(
            ldap_search + "-b cn=config '(!(objectClass=olcSchemaConfig))'",
            suggest_filename="configuration_minus_schemas")
        self.add_cmd_output(
            ldap_search + "-b cn=schema,cn=config dn",
            suggest_filename="loaded_schemas")
        self.add_cmd_output(
            ldap_search + "-b cn=config '(olcAccess=*)' olcAccess olcSuffix",
            suggest_filename="access_control_lists")

    def postproc(self):
        super(DebianLdap, self).postproc()
        self.do_file_sub(
            "/etc/nslcd.conf",
            r"(\s*bindpw\s*)\S+",
            r"\1********"
        )
        self.do_cmd_output_sub(
            "ldapsearch",
            r"(olcRootPW\: \s*)\S+",
            r"\1********"
        )


# vim: set et ts=4 sw=4 :