LCOV - code coverage report
Current view: top level - source3/torture - test_posix_append.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 21 38 55.3 %
Date: 2024-02-28 12:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    reproducer for bug 6898
       4             :    Copyright (C) Volker Lendecke 2009
       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 "../libcli/security/security.h"
      23             : #include "libsmb/libsmb.h"
      24             : #include "libsmb/clirap.h"
      25             : 
      26             : /*
      27             :  * Make sure that GENERIC_WRITE does not trigger append. See
      28             :  * https://bugzilla.samba.org/show_bug.cgi?id=6898
      29             :  */
      30             : 
      31           4 : bool run_posix_append(int dummy)
      32             : {
      33           0 :         struct cli_state *cli;
      34           4 :         const char *fname = "append";
      35           0 :         NTSTATUS status;
      36           0 :         uint16_t fnum;
      37           0 :         off_t size;
      38           4 :         uint8_t c = '\0';
      39           4 :         bool ret = false;
      40             : 
      41           4 :         printf("Starting POSIX_APPEND\n");
      42             : 
      43           4 :         if (!torture_open_connection(&cli, 0)) {
      44           0 :                 return false;
      45             :         }
      46             : 
      47           4 :         status = torture_setup_unix_extensions(cli);
      48           4 :         if (!NT_STATUS_IS_OK(status)) {
      49           0 :                 printf("torture_setup_unix_extensions failed: %s\n",
      50             :                        nt_errstr(status));
      51           0 :                 goto fail;
      52             :         }
      53             : 
      54           4 :         status = cli_ntcreate(
      55             :                 cli, fname, 0,
      56             :                 GENERIC_WRITE_ACCESS|GENERIC_READ_ACCESS|DELETE_ACCESS,
      57             :                 FILE_ATTRIBUTE_NORMAL|FILE_FLAG_POSIX_SEMANTICS,
      58             :                 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
      59             :                 FILE_OVERWRITE_IF,
      60             :                 FILE_NON_DIRECTORY_FILE|FILE_DELETE_ON_CLOSE,
      61             :                 0, &fnum, NULL);
      62             : 
      63           4 :         if (!NT_STATUS_IS_OK(status)) {
      64           0 :                 printf("cli_ntcreate failed: %s\n", nt_errstr(status));
      65           0 :                 goto fail;
      66             :         }
      67             : 
      68             :         /*
      69             :          * Write two bytes at offset 0. With bug 6898 we would end up
      70             :          * with a file of 2 byte length.
      71             :          */
      72             : 
      73           4 :         status = cli_writeall(cli, fnum, 0, &c, 0, sizeof(c), NULL);
      74           4 :         if (!NT_STATUS_IS_OK(status)) {
      75           0 :                 printf("cli_write failed: %s\n", nt_errstr(status));
      76           0 :                 goto fail;
      77             :         }
      78           4 :         status = cli_writeall(cli, fnum, 0, &c, 0, sizeof(c), NULL);
      79           4 :         if (!NT_STATUS_IS_OK(status)) {
      80           0 :                 printf("cli_write failed: %s\n", nt_errstr(status));
      81           0 :                 goto fail;
      82             :         }
      83             : 
      84           4 :         status = cli_qfileinfo_basic(
      85             :                 cli, fnum, NULL, &size, NULL, NULL, NULL, NULL, NULL);
      86           4 :         if (!NT_STATUS_IS_OK(status)) {
      87           0 :                 printf("cli_qfileinfo_basic failed: %s\n", nt_errstr(status));
      88           0 :                 goto fail;
      89             :         }
      90             : 
      91           4 :         if (size != sizeof(c)) {
      92           0 :                 printf("BUG: Writing with O_APPEND!!\n");
      93           0 :                 goto fail;
      94             :         }
      95             : 
      96           4 :         ret = true;
      97           4 : fail:
      98           4 :         torture_close_connection(cli);
      99           4 :         return ret;
     100             : }

Generated by: LCOV version 1.14