Debian Codegraph @

source3/script/tests/test_symlink_rename_smb1_posix.sh

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2
3 if [scip-shell system . . `[`. $# -lt 7 ]; then
4 catscip-shell system . . cat. <<EOF
5 Usage: test_symlink_rename_smb1_posix.sh SERVER SERVER_IP USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT
6 EOF
7 exit 1
8 fi
9
10 SERVER="${1}"
11 SERVER_IP="${2}"
12 USERNAME="${3}"
13 PASSWORD="${4}"
14 LOCAL_PATH="${5}"
15 PREFIX="${6}"
16 SMBCLIENT="${7}"
17 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
18 shift 6
19
20 incdir=$(dirnamescip-shell system . . dirname. "$0")/../../../testprogs/blackbox
21 . "$incdir"/subunit.sh
22
23 failed=0
24
25 # Do not let deprecated option warnings muck this up
26 SAMBA_DEPRECATED_SUPPRESS=1
27 export SAMBA_DEPRECATED_SUPPRESS
28
29 # Define the test environment/filenames.
30 #
31 share_test_dir="$LOCAL_PATH"
32 #
33 # These files/directories will be created.
34 #
35 file_outside_share="/tmp/symlink_rename_test_file.$$"
36 dir_outside_share="/tmp/symlink_rename_test_dir.$$"
37 file_outside_share_noperms="/tmp/symlink_rename_test_file_noperm.$$"
38 dir_outside_share_noperms="/tmp/symlink_rename_test_dir_noperm.$$"
39 #
40 # These two objects do not exist.
41 #
42 file_outside_share_noexist="/tmp/symlink_rename_test_noexist.$$"
43 dir_outside_share_noexist="/tmp/symlink_rename_test_dir_noexist.$$"
44
45 #
46 # Cleanup function.
47 #
48 do_cleanupscip-shell shell samba 2:4.24.3+dfsg-1 do_cleanup().()
49 {
50 (
51 #subshell.
52 cd "$share_test_dir" || return
53 rmscip-shell system . . rm. -f "file_exists"
54 rmscip-shell system . . rm. -f "symlink_noexist"
55 rmscip-shell system . . rm. -f "symlink_file_outside_share"
56 rmscip-shell system . . rm. -f "symlink_file_outside_share_noexist"
57 rmscip-shell system . . rm. -f "symlink_dir_outside_share"
58 rmscip-shell system . . rm. -f "symlink_dir_outside_share_noexist"
59 rmscip-shell system . . rm. -f "symlink_file_outside_share_noperms"
60 rmscip-shell system . . rm. -f "symlink_dir_outside_share_noperms"
61 # Links inside share.
62 rmscip-shell system . . rm. -f "symlink_file_inside_share_noperms"
63 rmscip-shell system . . rm. -f "file_inside_share_noperms"
64 rmscip-shell system . . rm. -f "symlink_dir_inside_share_noperms"
65 chmodscip-shell system . . chmod. 755 "dir_inside_share_noperms"
66 rmscip-shell system . . rm. -rf "dir_inside_share_noperms"
67 )
68 rmscip-shell system . . rm. -f "$file_outside_share"
69 rmscip-shell system . . rm. -rf "$dir_outside_share"
70 rmscip-shell system . . rm. -f "$file_outside_share_noperms"
71 rmscip-shell system . . rm. -rf "$dir_outside_share_noperms"
72 }
73
74 #
75 # Ensure we start from a clean slate.
76 #
77 do_cleanupscip-shell shell samba 2:4.24.3+dfsg-1 do_cleanup().
78
79 #
80 # Create the test files/directories/symlinks.
81 #
82 # File/directory explicitly outside share.
83 touchscip-shell system . . touch. "$file_outside_share"
84 mkdirscip-shell system . . mkdir. "$dir_outside_share"
85 # File/directory explicitly outside share with permission denied.
86 touchscip-shell system . . touch. "$file_outside_share_noperms"
87 chmodscip-shell system . . chmod. 0 "$file_outside_share_noperms"
88 mkdirscip-shell system . . mkdir. "$dir_outside_share_noperms"
89 chmodscip-shell system . . chmod. 0 "$dir_outside_share_noperms"
90 #
91 # Create links to these objects inside the share definition.
92 (
93 #subshell.
94 cd "$share_test_dir" || return
95 # Source file for all renames. None of these should succeed.
96 touchscip-shell system . . touch. "file_exists"
97 lnscip-shell system . . ln. -s "noexist" "symlink_noexist"
98 lnscip-shell system . . ln. -s "$file_outside_share" "symlink_file_outside_share"
99 lnscip-shell system . . ln. -s "$file_outside_share_noexist" "symlink_file_outside_share_noexist"
100 lnscip-shell system . . ln. -s "$dir_outside_share" "symlink_dir_outside_share"
101 lnscip-shell system . . ln. -s "$dir_outside_share_noexist" "symlink_dir_outside_share_noexist"
102 lnscip-shell system . . ln. -s "$file_outside_share_noperms" "symlink_file_outside_share_noperms"
103 lnscip-shell system . . ln. -s "$dir_outside_share_noperms" "symlink_dir_outside_share_noperms"
104 #
105 # Create symlinks to access denied file and directory
106 # objects within the share
107 touchscip-shell system . . touch. "file_inside_share_noperms"
108 chmodscip-shell system . . chmod. 0 "file_inside_share_noperms"
109 lnscip-shell system . . ln. -s "file_inside_share_noperms" "symlink_file_inside_share_noperms"
110 mkdirscip-shell system . . mkdir. "dir_inside_share_noperms"
111 touchscip-shell system . . touch. "dir_inside_share_noperms/noperm_file_exists"
112 chmodscip-shell system . . chmod. 0 "dir_inside_share_noperms"
113 lnscip-shell system . . ln. -s "dir_inside_share_noperms" "symlink_dir_inside_share_noperms"
114 )
115
116 #
117 # smbclient function given command, path, expected error, and posix.
118 #
119 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error().()
120 {
121 filecmd="$1"
122 filename1="$2"
123 filename2="$3"
124 expected_error="$4"
125 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
126 catscip-shell system . . cat. >"$tmpfile" <<EOF
127 posix
128 $filecmd $filename1 $filename2
129 quit
130 EOF
131 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I$SERVER_IP -mNT1 < $tmpfile 2>&1'
132 eval echo "$cmd"
133 out=$(eval "$cmd")
134 ret=$?
135 rmscip-shell system . . rm. -f "$tmpfile"
136
137 if [scip-shell system . . `[`. $ret != 0 ]; then
138 printfscip-shell system . . printf. "%s\n" "$out"
139 printfscip-shell system . . printf. "failed accessing local_symlinks with error %s\n" "$ret"
140 return 1
141 fi
142
143 if [scip-shell system . . `[`. "$expected_error" = "NT_STATUS_OK" ]; then
144 printfscip-shell system . . printf. "%s" "$out" | grepscip-shell system . . grep. -v "NT_STATUS_"
145 else
146 printfscip-shell system . . printf. "%s" "$out" | grepscip-shell system . . grep. "$expected_error"
147 fi
148 ret=$?
149 if [scip-shell system . . `[`. $ret != 0 ]; then
150 printfscip-shell system . . printf. "%s\n" "$out"
151 printfscip-shell system . . printf. "failed - should get %s doing posix \"%s %s %s\"\n" "$expected_error" "$filecmd" "$filename1" "$filename2"
152 return 1
153 fi
154 }
155
156 #
157 # SMB1+posix tests.
158 #
159 test_symlink_rename_SMB1_posixscip-shell shell samba 2:4.24.3+dfsg-1 test_symlink_rename_SMB1_posix().()
160 {
161 #
162 # rename commands.
163 # As all the targets exist as symlinks, these should all fail.
164 #
165 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_noexist" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
166 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_file_outside_share" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
167 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_file_outside_share_noexist" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
168 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_dir_outside_share" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
169 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_dir_outside_share_noexist" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
170 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_file_outside_share_noperms" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
171 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_dir_outside_share_noperms" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
172 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_file_inside_share_noperms" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
173 smbclient_expect_errorscip-shell shell samba 2:4.24.3+dfsg-1 smbclient_expect_error(). "rename" "file_exists" "symlink_dir_inside_share_noperms" "NT_STATUS_OBJECT_NAME_COLLISION" || return 1
174 return 0
175 }
176
177 testit "symlink_rename_SMB1_posix" \
178 test_symlink_rename_SMB1_posix ||
179 failed=$((failed + 1))
180
181 #
182 # Cleanup.
183 do_cleanupscip-shell shell samba 2:4.24.3+dfsg-1 do_cleanup().
184
185 testok "$0" "$failed"