forked from gcoop-libre/freeipa-sssd-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipa-hlt-chk
executable file
·226 lines (191 loc) · 4.97 KB
/
ipa-hlt-chk
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2023 Osiris Alejandro Gomez <[email protected]>
# Copyright (C) 2023 Osiris Alejandro Gomez <[email protected]>
#
# 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 3 of the License, or
# 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, see <http://www.gnu.org/licenses/>.
[[ -n "$BASH_DEBUG" ]] && PS4='+ ${EPOCHREALTIME} ${LINENO} ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' set -x
[[ -n "$BIN" ]] || BIN="$(basename "$0")"
function dmy2iso()
{
local DATE="${1% *}" TIME="${1#* }"
echo "${DATE}" | tr '/' ' ' | while read -r DD MM YY _
do
date -d "$YY-$MM-$DD $TIME" +'%F %T'
done
}
function get_iface()
{
ip r s default | awk '/default via/ {print $5}'
}
function get_ip()
{
ip r | awk "/dev $IFACE.*link src/ {print \$9}" | head -1
}
function get_gw()
{
ip r s default | awk '/^default via/ {print $3}'
}
function get_fqdn()
{
hostname -f
}
function get_serial()
{
sudo cat /sys/class/dmi/id/product_serial
}
function sssctl_config_check()
{
local RETURN='NO ERRORS FOUND'
if [[ -e "$SSSD_CONF" ]]
then
RETURN="$(sudo sssctl config-check 2>/dev/null | head -1)"
RC="$?"
[[ "$RC" -eq 0 ]] || RETURN="INVALID CONFIG"
else
RETURN="NOT FOUND $SSSD_CONF"
fi
echo "$RETURN"
}
function get_ad()
{
sudo grep ad_domain "$SSSD_CONF" 2>/dev/null \
| head -1 \
| cut -d= -f2 \
| tr -d ' '
}
function get_sss_cnf()
{
local RETURN="NOT FOUND $SSSD_CONF"
if [[ -e "$SSSD_CONF" ]]
then
RETURN="$(sudo grep "$1" "$SSSD_CONF" 2>/dev/null \
| head -1 \
| cut -d= -f2 \
| tr -d ' ')"
fi
echo "$RETURN"
}
function get_ipa_dom()
{
get_sss_cnf ipa_domain
}
function get_ipa_srv()
{
get_sss_cnf ipa_server
}
function get_srv()
{
[[ -z "$2" ]] && return
dig +short SRV "_$1._tcp.$2" \
| head -1 \
| awk '{print $4}'
}
function get_sssd()
{
sudo sssctl domain-status --online --start "$(hostname -d)" 2>&1 \
| cut -d: -f2- \
| sed 's/^ \+//g' \
| sed 's/ \+$//g'
}
function get_krb5()
{
sudo kinit -V -kt /etc/krb5.keytab 2>&1 \
| grep -o "Authenticated to Kerberos v5" \
| cut -d' ' -f1
}
function get_tgt()
{
local RETURN=''
if ! command -v klist >/dev/null
then
RETURN='NOT FOUND klist COMMAND'
else
KRBTGT_EXPIRES="$(sudo klist | awk '/krbtgt/ {print $3,$4}')"
KRBTGT_DATE="$(dmy2iso "$KRBTGT_EXPIRES")"
KRBTGT_EXPOC="$(date -d "$KRBTGT_DATE" +%s)"
RETURN="$KRBTGT_DATE"
NOW="$(date -d 'now' +'%s')"
[[ "$NOW" -gt "$KRBTGT_EXPOC" ]] && RETURN+=" EXPIRED"
fi
echo "$RETURN"
}
function msg()
{
local NOW
PERCENT="$(echo "$ITEM $TOTAL" | awk '{printf "%3d",($1/$2)*100}')"
NOW="$(date +'%F %T')"
printf "%s %4s [%02d] %s\\n" "$NOW" "${PERCENT}%" "$ITEM" "${1}"
[[ "$LOGGER" -eq 1 ]] && logger -t "$BIN" -p "$PRIORITY" "${1}"
ITEM=$((ITEM+1))
sleep "$SLEEP"
}
function get_a()
{
if [[ -z "$2" ]]
then
dig +short A "$1"
else
dig +short A "$1" "$2"
fi
}
function get_ptr()
{
if [[ -z "$2" ]]
then
dig +short -x "$1"
else
[[ "$2" =~ ^NOT\ FOUND ]] || dig +short -x "$1" "@$2"
fi
}
function get_total()
{
grep -cE '^msg ' "$0"
}
function main()
{
[[ -n "$LOGGER" ]] || LOGGER=1
[[ -n "$PRIORITY" ]] || PRIORITY='user.info'
[[ -n "$SLEEP" ]] || SLEEP=0.1
[[ -n "$SSSD_CONF" ]] || SSSD_CONF='/etc/sssd/sssd.conf'
declare -i ITEM=1 PERCENT=0 TOTAL=0
TOTAL="$(get_total)"
IFACE="$(get_iface)"
IP="$(get_ip)"
GW="$(get_gw)"
FQDN="$(get_fqdn)"
AD="$(get_ad)"
IPA_DOM="$(get_ipa_dom)"
IPA_SRV="$(get_ipa_srv)"
IPA_IP="$(get_a "$IPA_SRV")"
msg "Check Hostname: ${FQDN}"
msg "Check Serial: $(get_serial)"
msg "Check IP: ${IP}"
msg "Check Gateway: ${GW}"
msg "Check SSSD Config: $(sssctl_config_check)"
msg "Check AD Domain: $AD"
msg "Check IPA Domain: $IPA_DOM"
msg "Check IPA Server: $IPA_SRV"
msg "Check AD SRV LDAP: $(get_srv ldap "$AD")"
msg "Check AD SRV KRB5: $(get_srv kerberos "$AD")"
msg "Check IPA SRV LDAP: $(get_srv ldap "$IPA_DOM")"
msg "Check IPA SRV KRB5: $(get_srv kerberos "$IPA_DOM")"
msg "Check IPA DNS Query: $IPA_IP"
msg "Check PTR: $IP $(get_ptr "$IP" "$GW") @$GW"
msg "Check PTR: $IP $(get_ptr "$IP" "$IPA_SRV") @$IPA_IP"
msg "Check SSSD Status: $(get_sssd)"
msg "Check Kerberos Keytab: $(get_krb5)"
msg "Check Kerberos TGT: $(get_tgt)"
}
main "$@"