summaryrefslogtreecommitdiffstats
path: root/source3/script/tests/test_homes.sh
blob: be8e9b20d58fbaf6eb1ecbf771d9c9672f181626 (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
#!/bin/sh

# Copyright (c) Andreas Schneider <asn@samba.org>
# License: GPLv3

if [ $# -lt 7 ]; then
	echo "Usage: test_homes.sh SERVER USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT CONFIGURATION"
	exit 1
fi

SERVER="${1}"
USERNAME="${2}"
PASSWORD="${3}"
LOCAL_PATH="${4}"
PREFIX="${5}"
SMBCLIENT="${6}"
CONFIGURATION="${7}"
shift 7

incdir=$(dirname $0)/../../../testprogs/blackbox
. $incdir/subunit.sh

failed=0

test_gooduser_home()
{
	tmpfile=$PREFIX/smbclient_homes_gooduser_commands
	cat >$tmpfile <<EOF
ls
quit
EOF

	USERNAME=gooduser

	cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/$USERNAME $CONFIGURATION < $tmpfile 2>&1'
	eval echo "$cmd"
	out=$(eval $cmd)
	ret=$?
	rm -f $tmpfile

	if [ $ret -ne 0 ]; then
		echo "$out"
		echo "failed to connect error $ret"
		return 1
	fi

	echo "$out" | grep 'Try "help" to get a list of possible commands.'
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "$out"
		echo 'failed - should get: Try "help" to get a list of possible commands.'
		return 1
	fi

	return 0
}

test_eviluser_home()
{
	tmpfile=$PREFIX/smbclient_homes_eviluser_commands
	cat >$tmpfile <<EOF
ls
quit
EOF

	USERNAME=eviluser

	cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/$USERNAME $CONFIGURATION < $tmpfile 2>&1'
	eval echo "$cmd"
	out=$(eval $cmd)
	ret=$?
	rm -f $tmpfile

	if [ $ret -ne 1 ]; then
		echo "$out"
		echo "The server should reject connecting ret=$ret"
		return 1
	fi

	echo "$out" | grep 'NT_STATUS_BAD_NETWORK_NAME'
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "$out"
		echo 'failed - should get: NT_STATUS_BAD_NETWORK_NAME.'
		return 1
	fi

	return 0
}

test_slashuser_home()
{
	tmpfile=$PREFIX/smbclient_homes_slashuser_commands
	cat >$tmpfile <<EOF
ls
quit
EOF

	USERNAME=slashuser

	cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/$USERNAME $CONFIGURATION < $tmpfile 2>&1'
	eval echo "$cmd"
	out=$(eval $cmd)
	ret=$?
	rm -f $tmpfile

	if [ $ret -ne 1 ]; then
		echo "$out"
		echo "The server should reject connecting ret=$ret"
		return 1
	fi

	echo "$out" | grep 'NT_STATUS_BAD_NETWORK_NAME'
	ret=$?
	if [ $ret -ne 0 ]; then
		echo "$out"
		echo 'failed - should get: NT_STATUS_BAD_NETWORK_NAME.'
		return 1
	fi

	return 0
}

testit "test gooduser home" \
	test_gooduser_home ||
	failed=$(expr $failed + 1)

testit "test eviluser home reject" \
	test_eviluser_home ||
	failed=$(expr $failed + 1)

testit "test slashuser home reject" \
	test_slashuser_home ||
	failed=$(expr $failed + 1)

testok $0 $failed