blob: f96c8ec7e47d8c51b10716bbf596c9483a508cf3 (
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
|
#!/bin/sh
if [ $# -lt 7 ]; then
cat <<EOF
Usage: test_worm.sh SERVER SERVER_IP USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT ADDARGS
EOF
exit 1
fi
SERVER="${1}"
SERVER_IP="${2}"
USERNAME="${3}"
PASSWORD="${4}"
LOCAL_PATH="${5}"
PREFIX="${6}"
SMBCLIENT="${7}"
SMBCLIENT="$VALGRIND ${SMBCLIENT}"
shift 7
ADDARGS="$*"
incdir=$(dirname "$0")/../../../testprogs/blackbox
. "$incdir"/subunit.sh
failed=0
# Do not let deprecated option warnings muck this up
SAMBA_DEPRECATED_SUPPRESS=1
export SAMBA_DEPRECATED_SUPPRESS
# Define the test environment/filenames.
#
share_test_dir="$LOCAL_PATH"
#
# Cleanup function.
#
do_cleanup()
{
(
#subshell.
cd "$share_test_dir" || return
rm -f must-be-deleted must-not-be-deleted must-be-deleted-after-ctime-refresh
)
rm -f $tmpfile
}
#
# Ensure we start from a clean slate.
#
do_cleanup
tmpfile=$PREFIX/smbclient_interactive_prompt_commands
test_worm()
{
# use echo because helo scripts don't support variables
echo "
put $tmpfile must-be-deleted
put $tmpfile must-be-deleted-after-ctime-refresh
put $tmpfile must-not-be-deleted
del must-be-deleted
quit" > $tmpfile
# make sure the directory is not too old for worm:
touch $share_test_dir
cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/worm -I$SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo "$cmd"
out=$(eval "$cmd")
ret=$?
rm -f "$tmpfile"
if [ $ret != 0 ]; then
printf "%s\n" "$out"
printf "failed worm smbclient run with error %s\n" "$ret"
return 1
fi
test -e $share_test_dir/must-be-deleted && {
printf "$0: ERROR: must-be-deleted was NOT deleted\n"
return 1
}
# now sleep grace_period (1s) and check if worm works properly:
sleep 1
echo "
posix
chmod 700 must-not-be-deleted
del must-not-be-deleted
del must-be-deleted-after-ctime-refresh
quit" > $tmpfile
# make sure the directory itself is not too old for worm:
touch $share_test_dir
# set a fresh ctime by doing a chmod:
chmod 644 $share_test_dir/must-be-deleted-after-ctime-refresh
cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/worm -I$SERVER_IP $ADDARGS < $tmpfile 2>&1'
eval echo "$cmd"
out=$(eval "$cmd")
test -e $share_test_dir/must-not-be-deleted || {
printf "$0: ERROR: must-not-be-deleted WAS deleted\n"
return 1
}
# if we're not root, return here:
test "$UID" = "0" || {
return 0
}
test -e $share_test_dir/must-be-deleted-after-ctime-refresh && {
printf "$0: ERROR: must-be-deleted-after-ctime-refresh was NOT deleted\n"
return 1
}
return 0
}
testit "worm" \
test_worm ||
failed=$((failed + 1))
#
# Cleanup.
do_cleanup
testok "$0" "$failed"
|