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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define BASEDIR "\\chartest\\"
28 open a file using a set of unicode code points for the name
30 the prefix BASEDIR is added before the name
32 static NTSTATUS unicode_open(struct smbcli_tree *tree,
34 uint32_t open_disposition,
35 const uint32_t *u_name,
39 char *fname, *fname2=NULL, *ucs_name;
43 ucs_name = talloc(mem_ctx, (1+u_name_len)*2);
45 printf("Failed to create UCS2 Name - talloc() failure\n");
46 return NT_STATUS_NO_MEMORY;
49 for (i=0;i<u_name_len;i++) {
50 SSVAL(ucs_name, i*2, u_name[i]);
52 SSVAL(ucs_name, i*2, 0);
54 i = convert_string_talloc(ucs_name, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname);
56 printf("Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
57 talloc_free(ucs_name);
58 return NT_STATUS_NO_MEMORY;
61 fname2 = talloc_asprintf(ucs_name, "%s%s", BASEDIR, fname);
63 talloc_free(ucs_name);
64 return NT_STATUS_NO_MEMORY;
67 io.generic.level = RAW_OPEN_NTCREATEX;
68 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
69 io.ntcreatex.in.root_fid = 0;
70 io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
71 io.ntcreatex.in.alloc_size = 0;
72 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
73 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
74 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
75 io.ntcreatex.in.create_options = 0;
76 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
77 io.ntcreatex.in.security_flags = 0;
78 io.ntcreatex.in.fname = fname2;
79 io.ntcreatex.in.open_disposition = open_disposition;
81 status = smb_raw_open(tree, mem_ctx, &io);
83 talloc_free(ucs_name);
90 see if the server recognises composed characters
92 static BOOL test_composed(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
94 const uint32_t name1[] = {0x61, 0x308};
95 const uint32_t name2[] = {0xe4};
96 NTSTATUS status1, status2;
98 printf("Testing composite character (a umlaut)\n");
100 status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 2);
101 if (!NT_STATUS_IS_OK(status1)) {
102 printf("Failed to create composed name - %s\n",
107 status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
109 if (!NT_STATUS_IS_OK(status2)) {
110 printf("Failed to create accented character - %s\n",
119 see if the server recognises a naked diacritical
121 static BOOL test_diacritical(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
123 const uint32_t name1[] = {0x308};
124 const uint32_t name2[] = {0x308, 0x308};
125 NTSTATUS status1, status2;
127 printf("Testing naked diacritical (umlaut)\n");
129 status1 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
131 if (!NT_STATUS_IS_OK(status1)) {
132 printf("Failed to create naked diacritical - %s\n",
137 /* try a double diacritical */
138 status2 = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 2);
140 if (!NT_STATUS_IS_OK(status2)) {
141 printf("Failed to create double naked diacritical - %s\n",
150 see if the server recognises a partial surrogate pair
152 static BOOL test_surrogate(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
154 const uint32_t name1[] = {0xd800};
155 const uint32_t name2[] = {0xdc00};
156 const uint32_t name3[] = {0xd800, 0xdc00};
159 printf("Testing partial surrogate\n");
161 status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
163 if (!NT_STATUS_IS_OK(status)) {
164 printf("Failed to create partial surrogate 1 - %s\n",
169 status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
171 if (!NT_STATUS_IS_OK(status)) {
172 printf("Failed to create partial surrogate 2 - %s\n",
177 status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 2);
179 if (!NT_STATUS_IS_OK(status)) {
180 printf("Failed to create full surrogate - %s\n",
189 see if the server recognises wide-a characters
191 static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
193 const uint32_t name1[] = {'a'};
194 const uint32_t name2[] = {0xff41};
195 const uint32_t name3[] = {0xff21};
198 printf("Testing wide-a\n");
200 status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name1, 1);
202 if (!NT_STATUS_IS_OK(status)) {
203 printf("Failed to create 'a' - %s\n",
208 status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name2, 1);
210 if (!NT_STATUS_IS_OK(status)) {
211 printf("Failed to create wide-a - %s\n",
216 status = unicode_open(cli->tree, mem_ctx, NTCREATEX_DISP_CREATE, name3, 1);
218 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
219 printf("Expected %s creating wide-A - %s\n",
220 nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION),
228 BOOL torture_charset(void)
230 static struct smbcli_state *cli;
234 mem_ctx = talloc_init("torture_charset");
236 if (!torture_open_connection(&cli)) {
240 printf("Starting charset tests\n");
242 if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
243 printf("Failed to clean " BASEDIR "\n");
246 if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
247 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
251 if (!test_composed(cli, mem_ctx)) {
255 if (!test_diacritical(cli, mem_ctx)) {
259 if (!test_surrogate(cli, mem_ctx)) {
263 if (!test_widea(cli, mem_ctx)) {