2 Unix SMB/CIFS implementation.
4 SMB torture tester - charset test routines
6 Copyright (C) Andrew Tridgell 2001
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/smb2/proto.h"
27 #include "libcli/libcli.h"
28 #include "torture/util.h"
29 #include "param/param.h"
31 #define BASEDIR "chartest"
34 open a file using a set of unicode code points for the name
36 the prefix BASEDIR is added before the name
38 static NTSTATUS
unicode_open(struct torture_context
*tctx
,
39 struct smb2_tree
*tree
,
41 uint32_t create_disposition
,
42 const uint32_t *u_name
,
45 struct smb2_create io
= {0};
48 char *ucs_name
= NULL
;
52 ucs_name
= talloc_size(mem_ctx
, (1+u_name_len
)*2);
54 torture_comment(tctx
, "Failed to create UCS2 Name - talloc() failure\n");
55 return NT_STATUS_NO_MEMORY
;
58 for (i
=0;i
<u_name_len
;i
++) {
59 SSVAL(ucs_name
, i
*2, u_name
[i
]);
61 SSVAL(ucs_name
, i
*2, 0);
63 if (!convert_string_talloc_handle(ucs_name
, lpcfg_iconv_handle(tctx
->lp_ctx
), CH_UTF16
, CH_UNIX
, ucs_name
, (1+u_name_len
)*2, (void **)&fname
, &i
)) {
64 torture_comment(tctx
, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
65 talloc_free(ucs_name
);
66 return NT_STATUS_NO_MEMORY
;
69 fname2
= talloc_asprintf(ucs_name
, "%s\\%s", BASEDIR
, fname
);
71 talloc_free(ucs_name
);
72 torture_comment(tctx
, "Failed to create fname - talloc() failure\n");
73 return NT_STATUS_NO_MEMORY
;
76 io
.in
.create_flags
= NTCREATEX_FLAGS_EXTENDED
;
77 io
.in
.desired_access
= SEC_RIGHTS_FILE_ALL
;
78 io
.in
.file_attributes
= FILE_ATTRIBUTE_NORMAL
;
79 io
.in
.share_access
= NTCREATEX_SHARE_ACCESS_NONE
;
80 io
.in
.create_options
= 0;
81 io
.in
.impersonation_level
= SMB2_IMPERSONATION_ANONYMOUS
;
82 io
.in
.security_flags
= 0;
84 io
.in
.create_disposition
= create_disposition
;
86 status
= smb2_create(tree
, tctx
, &io
);
87 if (!NT_STATUS_IS_OK(status
)) {
88 talloc_free(ucs_name
);
92 smb2_util_close(tree
, io
.out
.file
.handle
);
93 talloc_free(ucs_name
);
99 see if the server recognises composed characters
101 static bool test_composed(struct torture_context
*tctx
,
102 struct smb2_tree
*tree
)
104 const uint32_t name1
[] = {0x61, 0x308};
105 const uint32_t name2
[] = {0xe4};
109 ret
= smb2_util_setup_dir(tctx
, tree
, BASEDIR
);
110 torture_assert_goto(tctx
, ret
, ret
, done
, "setting up basedir");
112 status
= unicode_open(tctx
, tree
, tctx
,
113 NTCREATEX_DISP_CREATE
, name1
, 2);
114 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
115 "Failed to create composed name");
117 status
= unicode_open(tctx
, tree
, tctx
,
118 NTCREATEX_DISP_CREATE
, name2
, 1);
119 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
120 "Failed to create accented character");
123 smb2_deltree(tree
, BASEDIR
);
128 see if the server recognises a naked diacritical
130 static bool test_diacritical(struct torture_context
*tctx
,
131 struct smb2_tree
*tree
)
133 const uint32_t name1
[] = {0x308};
134 const uint32_t name2
[] = {0x308, 0x308};
138 ret
= smb2_util_setup_dir(tctx
, tree
, BASEDIR
);
139 torture_assert_goto(tctx
, ret
, ret
, done
, "setting up basedir");
141 status
= unicode_open(tctx
, tree
, tctx
,
142 NTCREATEX_DISP_CREATE
, name1
, 1);
143 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
144 "Failed to create naked diacritical");
146 /* try a double diacritical */
147 status
= unicode_open(tctx
, tree
, tctx
,
148 NTCREATEX_DISP_CREATE
, name2
, 2);
149 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
150 "Failed to create double "
151 "naked diacritical");
154 smb2_deltree(tree
, BASEDIR
);
159 see if the server recognises a partial surrogate pair
161 static bool test_surrogate(struct torture_context
*tctx
,
162 struct smb2_tree
*tree
)
164 const uint32_t name1
[] = {0xd800};
165 const uint32_t name2
[] = {0xdc00};
166 const uint32_t name3
[] = {0xd800, 0xdc00};
170 ret
= smb2_util_setup_dir(tctx
, tree
, BASEDIR
);
171 torture_assert_goto(tctx
, ret
, ret
, done
, "setting up basedir");
173 status
= unicode_open(tctx
, tree
, tctx
, NTCREATEX_DISP_CREATE
, name1
, 1);
174 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
175 "Failed to create partial surrogate 1");
177 status
= unicode_open(tctx
, tree
, tctx
, NTCREATEX_DISP_CREATE
, name2
, 1);
178 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
179 "Failed to create partial surrogate 2");
181 status
= unicode_open(tctx
, tree
, tctx
, NTCREATEX_DISP_CREATE
, name3
, 2);
182 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
183 "Failed to create full surrogate");
186 smb2_deltree(tree
, BASEDIR
);
191 see if the server recognises wide-a characters
193 static bool test_widea(struct torture_context
*tctx
,
194 struct smb2_tree
*tree
)
196 const uint32_t name1
[] = {'a'};
197 const uint32_t name2
[] = {0xff41};
198 const uint32_t name3
[] = {0xff21};
202 ret
= smb2_util_setup_dir(tctx
, tree
, BASEDIR
);
203 torture_assert_goto(tctx
, ret
, ret
, done
, "setting up basedir");
205 status
= unicode_open(tctx
, tree
, tctx
, NTCREATEX_DISP_CREATE
, name1
, 1);
206 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
207 "Failed to create 'a'");
209 status
= unicode_open(tctx
, tree
, tctx
, NTCREATEX_DISP_CREATE
, name2
, 1);
210 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
211 "Failed to create wide-a");
213 status
= unicode_open(tctx
, tree
, tctx
, NTCREATEX_DISP_CREATE
, name3
, 1);
214 torture_assert_ntstatus_equal_goto(tctx
,
216 NT_STATUS_OBJECT_NAME_COLLISION
,
218 "Failed to create wide-A");
221 smb2_deltree(tree
, BASEDIR
);
225 struct torture_suite
*torture_smb2_charset(TALLOC_CTX
*mem_ctx
)
227 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "charset");
229 torture_suite_add_1smb2_test(suite
, "Testing composite character (a umlaut)", test_composed
);
230 torture_suite_add_1smb2_test(suite
, "Testing naked diacritical (umlaut)", test_diacritical
);
231 torture_suite_add_1smb2_test(suite
, "Testing partial surrogate", test_surrogate
);
232 torture_suite_add_1smb2_test(suite
, "Testing wide-a", test_widea
);