summaryrefslogtreecommitdiffstats
path: root/testprogs/blackbox/test_client_kerberos.sh
blob: 54554ea32900c2b75ec8641a485ddf0d5faaa29d (plain)
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/sh
# Blackbox tests for kerberos client options
# Copyright (c) 2019      Andreas Schneider <asn@samba.org>

if [ $# -lt 6 ]; then
	cat <<EOF
Usage: test_client_kerberos.sh DOMAIN REALM USERNAME PASSWORD SERVER PREFIX CONFIGURATION
EOF
	exit 1
fi

DOMAIN=$1
REALM=$2
USERNAME=$3
PASSWORD=$4
SERVER=$5
PREFIX=$6
CONFIGURATION=$7
shift 7

failed=0

. $(dirname $0)/subunit.sh
. $(dirname $0)/common_test_fns.inc

samba_bindir="$BINDIR"
samba_rpcclient="$samba_bindir/rpcclient"
samba_smbclient="$samba_bindir/smbclient"
samba_smbtorture="$samba_bindir/smbtorture"

samba_kinit=$(system_or_builddir_binary kinit "${BINDIR}" samba4kinit)
samba_kdestroy=$(system_or_builddir_binary kdestroy "${BINDIR}" samba4kdestroy)

test_rpc_getusername()
{
	eval echo "$cmd"
	out=$(eval $cmd)
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "Failed to connect! Error: $ret"
		echo "$out"
		return 1
	fi

	echo "$out" | grep -q "Account Name: $USERNAME, Authority Name: $DOMAIN"
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "Incorrect account/authority name! Error: $ret"
		echo "$out"
		return 1
	fi

	return 0
}

test_smbclient()
{
	eval echo "$cmd"
	out=$(eval $cmd)
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "Failed to connect! Error: $ret"
		echo "$out"
	fi

	return $ret
}

test_smbclient_kerberos()
{
	eval echo "$cmd -d5"
	out=$(eval $cmd)
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "Failed to connect! Error: $ret"
		echo "$out"
		return 1
	fi

	echo "$out" | grep "Doing init for" >/dev/null 2>&1
	ret=$?
	if [ $ret -eq 0 ]; then
		echo "Kinit failed for smbclient"
		echo "$out"
		return 1
	fi

	return 0
}

KRB5CCNAME_PATH="$PREFIX/ccache_client_kerberos"
KRB5CCNAME="FILE:$KRB5CCNAME_PATH"
export KRB5CCNAME

### RPCCLIENT (legacy)
cmd='$samba_rpcclient ncacn_np:${SERVER} -U${USERNAME}%${PASSWORD} --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient legacy ntlm" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | USER=${USERNAME} $samba_rpcclient ncacn_np:${SERVER} --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient legacy ntlm interactive" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | $samba_rpcclient ncacn_np:${SERVER} -U${USERNAME} --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient legacy ntlm interactive with -U" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='$samba_rpcclient ncacn_np:${SERVER} -U${USERNAME}%${PASSWORD} -k --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient legacy kerberos" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | $samba_rpcclient ncacn_np:${SERVER} -U${USERNAME} -k --configfile=${CONFIGURATION} -c getusername 2>&1'
testit_expect_failure "test rpcclient legacy kerberos interactive (negative test)" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_rpcclient ncacn_np:${SERVER} -k --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient legacy kerberos ccache" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)
$samba_kdestroy

### RPCCLIENT
cmd='$samba_rpcclient ncacn_np:${SERVER} -U${USERNAME}%${PASSWORD} --use-kerberos=disabled --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient ntlm" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | USER=${USERNAME} $samba_rpcclient ncacn_np:${SERVER} --use-kerberos=disabled --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient ntlm interactive" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | $samba_rpcclient ncacn_np:${SERVER} -U${USERNAME} --use-kerberos=disabled --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient ntlm interactive with -U" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='$samba_rpcclient ncacn_np:${SERVER} -U${USERNAME}%${PASSWORD} --use-kerberos=required --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient kerberos" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | $samba_rpcclient ncacn_np:${SERVER} -U${USERNAME} --use-krb5-ccache=$KRB5CCNAME --configfile=${CONFIGURATION} -c getusername 2>&1'
testit_expect_failure "test rpcclient kerberos interactive (negative test)" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_rpcclient ncacn_np:${SERVER} --use-krb5-ccache=$KRB5CCNAME --configfile=${CONFIGURATION} -c getusername 2>&1'
testit "test rpcclient kerberos ccache" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)
$samba_kdestroy

### SMBTORTURE (legacy)

cmd='$samba_smbtorture -U${USERNAME}%${PASSWORD} --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture legacy default" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='$samba_smbtorture -U${USERNAME}%${PASSWORD} -k no --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture legacy ntlm (kerberos=no)" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='$samba_smbtorture -U${USERNAME}%${PASSWORD} -k yes --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture legacy kerberos=yes" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_smbtorture -k yes --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture legacy kerberos=yes ccache" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)
$samba_kdestroy

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_smbtorture -k no --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit_expect_failure "test smbtorture legacy kerberos=no ccache (negative test)" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)
$samba_kdestroy

### SMBTORTURE

cmd='$samba_smbtorture -U${USERNAME}%${PASSWORD} --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture default" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='$samba_smbtorture -U${USERNAME}%${PASSWORD} --use-kerberos=disabled --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture ntlm (kerberos=no)" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

cmd='$samba_smbtorture -U${USERNAME}%${PASSWORD} --use-kerberos=required --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture kerberos=yes" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_smbtorture --use-krb5-ccache=$KRB5CCNAME --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit "test smbtorture kerberos=yes ccache" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)
$samba_kdestroy

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_smbtorture --use-kerbers=required --configfile=${CONFIGURATION} --maximum-runtime=30 --basedir=$PREFIX --option=torture:progress=no --target=samba4 ncacn_np:${SERVER} rpc.lsa-getuser 2>&1'
testit_expect_failure "test smbtorture kerberos=no ccache (negative test)" \
	test_rpc_getusername ||
	failed=$(expr $failed + 1)
$samba_kdestroy

### SMBCLIENT (legacy)
cmd='$samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME}%${PASSWORD} --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient legacy ntlm" \
	test_smbclient ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | USER=$USERNAME $samba_smbclient //${SERVER}/tmp -W ${DOMAIN} --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient legacy ntlm interactive" \
	test_smbclient ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | $samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME} --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient legacy ntlm interactive with -U" \
	test_smbclient ||
	failed=$(expr $failed + 1)

cmd='$samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME}%${PASSWORD} -k --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient legacy kerberos" \
	test_smbclient ||
	failed=$(expr $failed + 1)

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -k --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient legacy kerberos ccache" \
	test_smbclient ||
	failed=$(expr $failed + 1)
$samba_kdestroy

### SMBCLIENT tests for --use-kerberos=desired|required|disabled
cmd='$samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME}%${PASSWORD} --use-kerberos=disabled --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient ntlm" \
	test_smbclient ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | USER=$USERNAME $samba_smbclient //${SERVER}/tmp -W ${DOMAIN} --use-kerberos=disabled --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient ntlm interactive" \
	test_smbclient ||
	failed=$(expr $failed + 1)

cmd='echo ${PASSWORD} | $samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME} --use-kerberos=disabled --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient ntlm interactive with -U" \
	test_smbclient ||
	failed=$(expr $failed + 1)

cmd='$samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME}%${PASSWORD} --use-kerberos=desired --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient kerberos=desired" \
	test_smbclient_kerberos ||
	failed=$(expr $failed + 1)

cmd='$samba_smbclient //${SERVER}/tmp -W ${DOMAIN} -U${USERNAME}%${PASSWORD} --use-kerberos=required --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient kerberos=required" \
	test_smbclient_kerberos ||
	failed=$(expr $failed + 1)

kerberos_kinit $samba_kinit ${USERNAME}@${REALM} ${PASSWORD}
cmd='$samba_smbclient //${SERVER}/tmp --use-krb5-ccache=$KRB5CCNAME --configfile=${CONFIGURATION} -c "ls; quit"'
testit "test smbclient kerberos=required ccache" \
	test_smbclient ||
	failed=$(expr $failed + 1)
$samba_kdestroy

rm -rf $KRB5CCNAME_PATH

exit $failed