/
ldap.sh
executable file
·178 lines (156 loc) · 3.96 KB
/
ldap.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh
#+
# Copyright 2011 iXsystems, Inc.
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted providing that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#####################################################################
ldap_opt() { echo l; }
ldap_help() { echo "Dump LDAP Configuration"; }
ldap_directory() { echo "LDAP"; }
ldap_func()
{
local onoff
onoff=$(${FREENAS_SQLITE_CMD} ${FREENAS_CONFIG} "
SELECT
ldap_enable
FROM
directoryservice_ldap
ORDER BY
-id
LIMIT 1
")
enabled="DISABLED"
if [ "${onoff}" = "1" ]
then
enabled="ENABLED"
fi
section_header "LDAP Status"
echo "LDAP is ${enabled}"
section_footer
#
# dump LDAP configuration
#
local IFS="|"
read hostname basedn binddn anonbind usersuffix \
groupsuffix passwordsuffix machinesuffix sudosuffix \
use_default_domain ssl has_samba_schema <<-__LDAP__
$(${FREENAS_SQLITE_CMD} ${FREENAS_CONFIG} "
SELECT
ldap_hostname,
ldap_basedn,
ldap_binddn,
ldap_anonbind,
ldap_usersuffix,
ldap_groupsuffix,
ldap_passwordsuffix,
ldap_machinesuffix,
ldap_sudosuffix,
ldap_ssl,
ldap_has_samba_schema
FROM
directoryservice_ldap
ORDER BY
-id
LIMIT 1
")
__LDAP__
IFS="
"
section_header "LDAP Settings"
cat<<-__EOF__
Hostname: ${hostname}
Base DN: ${basedn}
Bind DN: ${binddn}
Anonymous Bind: ${anonbind}
User Suffix: ${usersuffix}
Group Suffix: ${groupsuffix}
Password Suffix: ${passwordsuffix}
Machine Suffix: ${machinesuffix}
SUDO Suffix: ${sudosuffix}
Use Default Domain: ${use_default_domain}
SSL: ${ssl}
Samba Schema: ${has_samba_schema}
__EOF__
section_footer
#
# Dump nsswitch.conf
#
section_header "${PATH_NS_CONF}"
sc "${PATH_NS_CONF}"
section_footer
#
# Dump kerberos configuration
#
section_header "${PATH_KRB5_CONFIG}"
sc "${PATH_KRB5_CONFIG}" 2>/dev/null
section_footer
#
# Dump samba configuration
#
section_header "${SAMBA_CONF}"
sc "${SAMBA_CONF}"
section_footer
#
# List kerberos tickets
#
section_header "Kerberos Tickets - 'klist'"
klist
section_footer
#
# Dump LDAP configuration
#
section_header "${LDAP_CONF}"
sc "${LDAP_CONF}"
section_footer
#
# Dump NSLCD configuration
#
section_header "${NSLCD_CONF}"
sc "${NSLCD_CONF}" | grep -iv ldap_default_authtok
section_footer
#
# Dump generated LDAP config file
#
section_header "${LDAP_CONFIG_FILE}"
sc "${LDAP_CONFIG_FILE}"
section_footer
#
# Try to generate an LDAP config file
#
section_header "ldaptool get config_file"
${LDAP_TOOL} get config_file
section_footer
#
# Dump LDAP users and groups
#
section_header "LDAP Users - 'getent passwd'"
getent passwd | head -50
section_header "LDAP Groups - 'getent group'"
getent group | head -50
section_footer
#
# Dump cache info
#
cache_func "LDAP"
}