s3: Use cli_writeall instead of cli_write
[vlendec/samba-autobuild/.git] / source3 / torture / test_case_insensitive.c
1 /*
2    Unix SMB/CIFS implementation.
3    reproducer for bug 8042
4    Copyright (C) Volker Lendecke 2011
5
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.
10
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.
15
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/>.
18 */
19
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "system/filesys.h"
23
24 /*
25  * Regression test file creates on case insensitive file systems (e.g. OS/X)
26  * https://bugzilla.samba.org/show_bug.cgi?id=8042
27  */
28
29 bool run_case_insensitive_create(int dummy)
30 {
31         struct cli_state *cli;
32         uint16_t fnum;
33         NTSTATUS status;
34
35         printf("Starting case_insensitive_create\n");
36
37         if (!torture_open_connection(&cli, 0)) {
38                 return false;
39         }
40
41         status = cli_mkdir(cli, "x");
42         if (!NT_STATUS_IS_OK(status)) {
43                 printf("cli_mkdir failed: %s\n", nt_errstr(status));
44                 goto done;
45         }
46         status = cli_chkpath(cli, "X");
47         if (!NT_STATUS_IS_OK(status)) {
48                 printf("cli_chkpath failed: %s\n", nt_errstr(status));
49                 goto rmdir;
50         }
51         status = cli_open(cli, "x\\y", O_RDWR|O_CREAT, 0, &fnum);
52         if (!NT_STATUS_IS_OK(status)) {
53                 printf("cli_open failed: %s\n", nt_errstr(status));
54
55                 if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
56                         printf("Bug 8042 reappeared!!\n");
57                 }
58                 goto unlink;
59         }
60         status = cli_close(cli, fnum);
61         if (!NT_STATUS_IS_OK(status)) {
62                 printf("cli_close failed: %s\n", nt_errstr(status));
63                 goto done;
64         }
65 unlink:
66         status = cli_unlink(cli, "x\\y", 0);
67         if (!NT_STATUS_IS_OK(status)) {
68                 printf("cli_unlink failed: %s\n", nt_errstr(status));
69                 goto done;
70         }
71 rmdir:
72         status = cli_rmdir(cli, "x");
73         if (!NT_STATUS_IS_OK(status)) {
74                 printf("cli_close failed: %s\n", nt_errstr(status));
75         }
76 done:
77         torture_close_connection(cli);
78         return NT_STATUS_IS_OK(status);
79 }