build(waf): fix a tab indentation to spaces
[Samba/gebeck_regimport.git] / source3 / torture / test_posix_append.c
blobd4784e8e7c29f1779f272fc09f08309a53d8c47e
1 /*
2 Unix SMB/CIFS implementation.
3 reproducer for bug 6898
4 Copyright (C) Volker Lendecke 2009
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/>.
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "../libcli/security/security.h"
23 #include "libsmb/libsmb.h"
26 * Make sure that GENERIC_WRITE does not trigger append. See
27 * https://bugzilla.samba.org/show_bug.cgi?id=6898
30 bool run_posix_append(int dummy)
32 struct cli_state *cli;
33 const char *fname = "append";
34 NTSTATUS status;
35 uint16_t fnum;
36 off_t size;
37 uint8_t c = '\0';
38 bool ret = false;
40 printf("Starting POSIX_APPEND\n");
42 if (!torture_open_connection(&cli, 0)) {
43 return false;
46 status = torture_setup_unix_extensions(cli);
47 if (!NT_STATUS_IS_OK(status)) {
48 printf("torture_setup_unix_extensions failed: %s\n",
49 nt_errstr(status));
50 goto fail;
53 status = cli_ntcreate(
54 cli, fname, 0,
55 GENERIC_WRITE_ACCESS|GENERIC_READ_ACCESS|DELETE_ACCESS,
56 FILE_ATTRIBUTE_NORMAL|FILE_FLAG_POSIX_SEMANTICS,
57 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
58 FILE_OVERWRITE_IF,
59 FILE_NON_DIRECTORY_FILE|FILE_DELETE_ON_CLOSE,
60 0, &fnum);
62 if (!NT_STATUS_IS_OK(status)) {
63 printf("cli_ntcreate failed: %s\n", nt_errstr(status));
64 goto fail;
68 * Write two bytes at offset 0. With bug 6898 we would end up
69 * with a file of 2 byte length.
72 status = cli_writeall(cli, fnum, 0, &c, 0, sizeof(c), NULL);
73 if (!NT_STATUS_IS_OK(status)) {
74 printf("cli_write failed: %s\n", nt_errstr(status));
75 goto fail;
77 status = cli_writeall(cli, fnum, 0, &c, 0, sizeof(c), NULL);
78 if (!NT_STATUS_IS_OK(status)) {
79 printf("cli_write failed: %s\n", nt_errstr(status));
80 goto fail;
83 status = cli_getattrE(cli, fnum, NULL, &size, NULL, NULL, NULL);
84 if (!NT_STATUS_IS_OK(status)) {
85 printf("cli_getatrE failed: %s\n", nt_errstr(status));
86 goto fail;
89 if (size != sizeof(c)) {
90 printf("BUG: Writing with O_APPEND!!\n");
91 goto fail;
94 ret = true;
95 fail:
96 torture_close_connection(cli);
97 return ret;