~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source4/torture/basic/charset.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

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