summaryrefslogtreecommitdiffstats
path: root/source3/torture/utable.c
blob: ea36487f64eaefc5a0e04d1b80ce6ebc2fac9997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 
   Unix SMB/Netbios implementation.
   Version 3.0
   SMB torture tester - unicode table dumper
   Copyright (C) Andrew Tridgell 2001
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#define NO_SYSLOG

#include "includes.h"

BOOL torture_utable(int dummy)
{
	static struct cli_state cli;
	fstring fname, alt_name;
	int fnum;
	smb_ucs2_t c2;
	int c, len;
	int chars_allowed=0, alt_allowed=0;

	printf("starting utable\n");

	if (!torture_open_connection(&cli)) {
		return False;
	}

	cli_mkdir(&cli, "\\utable");

	for (c=1; c < 0x10000; c++) {
		char *p;

		SSVAL(&c2, 0, c);
		fstrcpy(fname, "\\utable\\x");
		p = fname+strlen(fname);
		len = convert_string(CH_UCS2, CH_UNIX, 
				     &c2, 2, 
				     p, sizeof(fname)-strlen(fname));
		p[len] = 0;
		fstrcat(fname,"_a_long_extension");

		fnum = cli_open(&cli, fname, O_RDWR | O_CREAT | O_TRUNC, 
				DENY_NONE);
		if (fnum == -1) continue;

		chars_allowed++;

		cli_qpathinfo_alt_name(&cli, fname, alt_name);

		if (strncmp(alt_name, "X_A_L", 5) != 0) {
			alt_allowed++;
			/* d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); */
		}

		cli_close(&cli, fnum);
		cli_unlink(&cli, fname);

		if (c % 100 == 0) {
			printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed);
		}
	}
	printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed);

	cli_rmdir(&cli, "\\utable");

	d_printf("%d chars allowed   %d alt chars allowed\n", chars_allowed, alt_allowed);

	return True;
}


static char *form_name(int c)
{
	static fstring fname;
	smb_ucs2_t c2;
	char *p;
	int len;

	fstrcpy(fname, "\\utable\\x");
	p = fname+strlen(fname);
	SSVAL(&c2, 0, c);

	len = convert_string(CH_UCS2, CH_UNIX, 
			     &c2, 2, 
			     p, sizeof(fname)-strlen(fname));
	p[len] = 0;
	fstrcat(fname,"_a_long_extension");
	return fname;
}

BOOL torture_casetable(int dummy)
{
	static struct cli_state cli;
	char *fname;
	int fnum;
	int c;

	printf("starting utable\n");

	if (!torture_open_connection(&cli)) {
		return False;
	}

	cli_mkdir(&cli, "\\utable");
	cli_unlink(&cli, "\\utable\\*");

	for (c=1; c < 0x10000; c++) {
		fname = form_name(c);
		fnum = cli_nt_create_full(&cli, fname, 
					  GENERIC_ALL_ACCESS, 
					  FILE_ATTRIBUTE_NORMAL,
					  FILE_SHARE_NONE,
					  FILE_CREATE, 0);

		if (fnum == -1 && 
		    NT_STATUS_EQUAL(cli_nt_error(&cli),NT_STATUS_OBJECT_NAME_COLLISION)) {
			/* found a character equivalence! */
			int c2;
			
			fnum = cli_nt_create_full(&cli, fname, 
						  GENERIC_ALL_ACCESS, 
						  FILE_ATTRIBUTE_NORMAL,
						  FILE_SHARE_NONE,
						  FILE_OPEN, 0);
			if (fnum == -1 || 
			    cli_read(&cli, fnum, (char *)&c2, 0, sizeof(c2)) != sizeof(c2)) {
				continue;
			}

			printf("%04x == %04x\n", c, c2);
			cli_close(&cli, fnum);
			continue;
		}

		cli_write(&cli, fnum, 0, (char *)&c, 0, sizeof(c));
		cli_close(&cli, fnum);
	}

	cli_unlink(&cli, "\\utable\\*");
	cli_rmdir(&cli, "\\utable");

	return True;
}