2 Unix SMB/CIFS implementation.
3 SMB torture tester - unicode table dumper
4 Copyright (C) Andrew Tridgell 2001
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "system/filesys.h"
22 #include "system/locale.h"
23 #include "libcli/libcli.h"
24 #include "torture/util.h"
25 #include "param/param.h"
26 #include "torture/basic/proto.h"
27 #include "lib/util/sys_rw.h"
29 bool torture_utable(struct torture_context
*tctx
,
30 struct smbcli_state
*cli
)
38 int chars_allowed
=0, alt_allowed
=0;
39 uint8_t valid
[0x10000];
41 torture_comment(tctx
, "Generating valid character table\n");
43 memset(valid
, 0, sizeof(valid
));
45 torture_assert(tctx
, torture_setup_dir(cli
, "\\utable"),
46 "Setting up dir \\utable failed");
48 for (c
=1; c
< 0x10000; c
++) {
52 strncpy(fname
, "\\utable\\x", sizeof(fname
)-1);
53 p
= fname
+strlen(fname
);
55 if (!convert_string(CH_UTF16
, CH_UNIX
,
57 p
, sizeof(fname
)-strlen(fname
), &len
)) {
58 torture_comment(tctx
, "convert_string failed [%s]\n",
64 strncat(fname
,"_a_long_extension",sizeof(fname
)-1);
66 fnum
= smbcli_open(cli
->tree
, fname
, O_RDWR
| O_CREAT
| O_TRUNC
,
68 if (fnum
== -1) continue;
72 smbcli_qpathinfo_alt_name(cli
->tree
, fname
, &alt_name
);
74 if (strncmp(alt_name
, "X_A_L", 5) != 0) {
77 torture_comment(tctx
, "fname=[%s] alt_name=[%s]\n", fname
, alt_name
);
80 smbcli_close(cli
->tree
, fnum
);
81 smbcli_unlink(cli
->tree
, fname
);
84 if (torture_setting_bool(tctx
, "progress", true)) {
85 torture_comment(tctx
, "%d (%d/%d)\r", c
, chars_allowed
, alt_allowed
);
90 torture_comment(tctx
, "%d (%d/%d)\n", c
, chars_allowed
, alt_allowed
);
92 smbcli_rmdir(cli
->tree
, "\\utable");
94 torture_comment(tctx
, "%d chars allowed %d alt chars allowed\n", chars_allowed
, alt_allowed
);
96 fd
= open("valid.dat", O_WRONLY
|O_CREAT
|O_TRUNC
, 0644);
97 torture_assert(tctx
, fd
!= -1,
99 "Failed to create valid.dat - %s", strerror(errno
)));
100 sys_write_v(fd
, valid
, 0x10000);
102 torture_comment(tctx
, "wrote valid.dat\n");
108 static char *form_name(int c
)
110 static char fname
[256];
115 strncpy(fname
, "\\utable\\", sizeof(fname
)-1);
116 p
= fname
+strlen(fname
);
119 if (!convert_string(CH_UTF16
, CH_UNIX
,
121 p
, sizeof(fname
)-strlen(fname
), &len
)) {
128 bool torture_casetable(struct torture_context
*tctx
,
129 struct smbcli_state
*cli
)
134 #define MAX_EQUIVALENCE 8
135 codepoint_t equiv
[0x10000][MAX_EQUIVALENCE
];
137 torture_comment(tctx
, "Determining upper/lower case table\n");
139 memset(equiv
, 0, sizeof(equiv
));
141 torture_assert(tctx
, torture_setup_dir(cli
, "\\utable"),
142 "Error setting up dir \\utable");
144 for (c
=1; c
< 0x10000; c
++) {
147 if (c
== '.' || c
== '\\') continue;
149 torture_comment(tctx
, "%04x (%c)\n", c
, isprint(c
)?c
:'.');
151 fname
= form_name(c
);
152 if (fname
== NULL
) continue;
153 fnum
= smbcli_nt_create_full(cli
->tree
, fname
, 0,
155 SEC_RIGHT_MAXIMUM_ALLOWED
,
159 FILE_ATTRIBUTE_NORMAL
,
160 NTCREATEX_SHARE_ACCESS_NONE
,
161 NTCREATEX_DISP_OPEN_IF
, 0, 0);
164 torture_comment(tctx
, "Failed to create file with char %04x\n", c
);
170 if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli
->tree
, fnum
, NULL
, &size
,
171 NULL
, NULL
, NULL
, NULL
, NULL
))) continue;
174 /* found a character equivalence! */
175 int c2
[MAX_EQUIVALENCE
];
177 if (size
/sizeof(int) >= MAX_EQUIVALENCE
) {
178 torture_comment(tctx
, "too many chars match?? size=%d c=0x%04x\n",
180 smbcli_close(cli
->tree
, fnum
);
184 smbcli_read(cli
->tree
, fnum
, c2
, 0, size
);
185 torture_comment(tctx
, "%04x: ", c
);
187 for (i
=0; i
<size
/sizeof(int); i
++) {
188 torture_comment(tctx
, "%04x ", c2
[i
]);
189 equiv
[c
][i
+1] = c2
[i
];
191 torture_comment(tctx
, "\n");
194 smbcli_write(cli
->tree
, fnum
, 0, &c
, size
, sizeof(c
));
195 smbcli_close(cli
->tree
, fnum
);
198 smbcli_unlink_wcard(cli
->tree
, "\\utable\\*");
199 smbcli_rmdir(cli
->tree
, "\\utable");