source: trunk/server/source4/torture/basic/charset.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 6.5 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 SMB torture tester - charset test routines
5
6 Copyright (C) Andrew Tridgell 2001
7
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.
12
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.
17
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/>.
20*/
21
22#include "includes.h"
23#include "libcli/libcli.h"
24#include "torture/util.h"
25#include "param/param.h"
26
27#define BASEDIR "\\chartest\\"
28
29/*
30 open a file using a set of unicode code points for the name
31
32 the prefix BASEDIR is added before the name
33*/
34static NTSTATUS unicode_open(struct torture_context *tctx,
35 struct smbcli_tree *tree,
36 TALLOC_CTX *mem_ctx,
37 uint32_t open_disposition,
38 const uint32_t *u_name,
39 size_t u_name_len)
40{
41 union smb_open io;
42 char *fname, *fname2=NULL, *ucs_name;
43 size_t i;
44 NTSTATUS status;
45
46 ucs_name = talloc_size(mem_ctx, (1+u_name_len)*2);
47 if (!ucs_name) {
48 printf("Failed to create UCS2 Name - talloc() failure\n");
49 return NT_STATUS_NO_MEMORY;
50 }
51
52 for (i=0;i<u_name_len;i++) {
53 SSVAL(ucs_name, i*2, u_name[i]);
54 }
55 SSVAL(ucs_name, i*2, 0);
56
57 if (!convert_string_talloc_convenience(ucs_name, lpcfg_iconv_convenience(tctx->lp_ctx), CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname, &i, false)) {
58 torture_comment(tctx, "Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
59 talloc_free(ucs_name);
60 return NT_STATUS_NO_MEMORY;
61 }
62
63 fname2 = talloc_asprintf(ucs_name, "%s%s", BASEDIR, fname);
64 if (!fname2) {
65 talloc_free(ucs_name);
66 return NT_STATUS_NO_MEMORY;
67 }
68
69 io.generic.level = RAW_OPEN_NTCREATEX;
70 io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
71 io.ntcreatex.in.root_fid.fnum = 0;
72 io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
73 io.ntcreatex.in.alloc_size = 0;
74 io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
75 io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
76 io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
77 io.ntcreatex.in.create_options = 0;
78 io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
79 io.ntcreatex.in.security_flags = 0;
80 io.ntcreatex.in.fname = fname2;
81 io.ntcreatex.in.open_disposition = open_disposition;
82
83 status = smb_raw_open(tree, tctx, &io);
84
85 talloc_free(ucs_name);
86
87 return status;
88}
89
90
91/*
92 see if the server recognises composed characters
93*/
94static bool test_composed(struct torture_context *tctx,
95 struct smbcli_state *cli)
96{
97 const uint32_t name1[] = {0x61, 0x308};
98 const uint32_t name2[] = {0xe4};
99 NTSTATUS status1, status2;
100
101 torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
102 "setting up basedir");
103
104 status1 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 2);
105 torture_assert_ntstatus_ok(tctx, status1, "Failed to create composed name");
106
107 status2 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
108
109 torture_assert_ntstatus_ok(tctx, status2, "Failed to create accented character");
110
111 return true;
112}
113
114/*
115 see if the server recognises a naked diacritical
116*/
117static bool test_diacritical(struct torture_context *tctx,
118 struct smbcli_state *cli)
119{
120 const uint32_t name1[] = {0x308};
121 const uint32_t name2[] = {0x308, 0x308};
122 NTSTATUS status1, status2;
123
124 torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
125 "setting up basedir");
126
127 status1 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
128
129 torture_assert_ntstatus_ok(tctx, status1, "Failed to create naked diacritical");
130
131 /* try a double diacritical */
132 status2 = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 2);
133
134 torture_assert_ntstatus_ok(tctx, status2, "Failed to create double naked diacritical");
135
136 return true;
137}
138
139/*
140 see if the server recognises a partial surrogate pair
141*/
142static bool test_surrogate(struct torture_context *tctx,
143 struct smbcli_state *cli)
144{
145 const uint32_t name1[] = {0xd800};
146 const uint32_t name2[] = {0xdc00};
147 const uint32_t name3[] = {0xd800, 0xdc00};
148 NTSTATUS status;
149
150 torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
151 "setting up basedir");
152
153 status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
154
155 torture_assert_ntstatus_ok(tctx, status, "Failed to create partial surrogate 1");
156
157 status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
158
159 torture_assert_ntstatus_ok(tctx, status, "Failed to create partial surrogate 2");
160
161 status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name3, 2);
162
163 torture_assert_ntstatus_ok(tctx, status, "Failed to create full surrogate");
164
165 return true;
166}
167
168/*
169 see if the server recognises wide-a characters
170*/
171static bool test_widea(struct torture_context *tctx,
172 struct smbcli_state *cli)
173{
174 const uint32_t name1[] = {'a'};
175 const uint32_t name2[] = {0xff41};
176 const uint32_t name3[] = {0xff21};
177 NTSTATUS status;
178
179 torture_assert(tctx, torture_setup_dir(cli, BASEDIR),
180 "setting up basedir");
181
182 status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name1, 1);
183
184 torture_assert_ntstatus_ok(tctx, status, "Failed to create 'a'");
185
186 status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name2, 1);
187
188 torture_assert_ntstatus_ok(tctx, status, "Failed to create wide-a");
189
190 status = unicode_open(tctx, cli->tree, tctx, NTCREATEX_DISP_CREATE, name3, 1);
191
192 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_OBJECT_NAME_COLLISION,
193 "Failed to create wide-A");
194
195 return true;
196}
197
198struct torture_suite *torture_charset(TALLOC_CTX *mem_ctx)
199{
200 struct torture_suite *suite = torture_suite_create(mem_ctx, "charset");
201
202 torture_suite_add_1smb_test(suite, "Testing composite character (a umlaut)", test_composed);
203 torture_suite_add_1smb_test(suite, "Testing naked diacritical (umlaut)", test_diacritical);
204 torture_suite_add_1smb_test(suite, "Testing partial surrogate", test_surrogate);
205 torture_suite_add_1smb_test(suite, "Testing wide-a", test_widea);
206
207 return suite;
208}
Note: See TracBrowser for help on using the repository browser.