LCOV - code coverage report
Current view: top level - source4/torture/basic - attr.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 37 155 23.9 %
Date: 2024-04-21 15:09:00 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    openattr tester
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2003
       7             :    
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             :    
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             :    
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "libcli/libcli.h"
      24             : #include "torture/util.h"
      25             : #include "system/filesys.h"
      26             : #include "libcli/security/security_descriptor.h"
      27             : #include "torture/basic/proto.h"
      28             : 
      29             : extern int torture_failures;
      30             : 
      31             : #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
      32             : 
      33             : 
      34             : static const uint32_t open_attrs_table[] = {
      35             :                 FILE_ATTRIBUTE_NORMAL,
      36             :                 FILE_ATTRIBUTE_ARCHIVE,
      37             :                 FILE_ATTRIBUTE_READONLY,
      38             :                 FILE_ATTRIBUTE_HIDDEN,
      39             :                 FILE_ATTRIBUTE_SYSTEM,
      40             : 
      41             :                 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
      42             :                 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
      43             :                 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
      44             :                 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
      45             :                 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
      46             :                 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
      47             : 
      48             :                 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
      49             :                 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
      50             :                 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
      51             :                 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
      52             : };
      53             : 
      54             : struct trunc_open_results {
      55             :         unsigned int num;
      56             :         uint32_t init_attr;
      57             :         uint32_t trunc_attr;
      58             :         uint32_t result_attr;
      59             : };
      60             : 
      61             : static const struct trunc_open_results attr_results[] = {
      62             :         { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
      63             :         { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
      64             :         { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
      65             :         { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
      66             :         { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
      67             :         { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
      68             :         { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
      69             :         { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
      70             :         { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
      71             :         { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
      72             :         { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
      73             :         { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
      74             :         { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
      75             :         { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
      76             :         { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
      77             :         { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
      78             :         { 119,  FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,  FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
      79             :         { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
      80             :         { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
      81             :         { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
      82             :         { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
      83             :         { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
      84             :         { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
      85             :         { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
      86             :         { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
      87             :         { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
      88             : };
      89             : 
      90             : 
      91           7 : bool torture_openattrtest(struct torture_context *tctx, 
      92             :                           struct smbcli_state *cli1)
      93             : {
      94           7 :         const char *fname = "\\openattr.file";
      95           1 :         int fnum1;
      96           1 :         uint16_t attr;
      97           1 :         unsigned int i, j, k, l;
      98           7 :         int failures = 0;
      99             : 
     100         119 :         for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
     101         112 :                 smbcli_setatr(cli1->tree, fname, 0, 0);
     102         112 :                 smbcli_unlink(cli1->tree, fname);
     103         128 :                 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
     104             :                                               SEC_FILE_WRITE_DATA, 
     105         112 :                                               open_attrs_table[i],
     106             :                                               NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
     107             :                 
     108         112 :                 torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "open %d (1) of %s failed (%s)", i, 
     109             :                                            fname, smbcli_errstr(cli1->tree)));
     110             : 
     111         112 :                 torture_assert_ntstatus_ok(tctx, 
     112             :                                                         smbcli_close(cli1->tree, fnum1),
     113             :                                                         talloc_asprintf(tctx, "close %d (1) of %s failed (%s)", i, fname, 
     114             :                                                         smbcli_errstr(cli1->tree)));
     115             : 
     116        1904 :                 for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
     117        2048 :                         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
     118             :                                                       SEC_FILE_READ_DATA|
     119             :                                                       SEC_FILE_WRITE_DATA, 
     120        1792 :                                                       open_attrs_table[j],
     121             :                                                       NTCREATEX_SHARE_ACCESS_NONE, 
     122             :                                                       NTCREATEX_DISP_OVERWRITE, 0, 0);
     123             : 
     124        1792 :                         if (fnum1 == -1) {
     125       31050 :                                 for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
     126       29900 :                                         if (attr_results[l].num == k) {
     127           0 :                                                 torture_result(tctx, TORTURE_FAIL,
     128             :                                                                 "[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)",
     129           0 :                                                                 k, open_attrs_table[i],
     130           0 :                                                                 open_attrs_table[j],
     131             :                                                                 fname, smbcli_errstr(cli1->tree));
     132        5980 :                                                 CHECK_MAX_FAILURES(error_exit);
     133             :                                         }
     134             :                                 }
     135        1150 :                                 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli1->tree), NT_STATUS_ACCESS_DENIED)) {
     136           0 :                                         torture_result(tctx, TORTURE_FAIL,
     137             :                                                         "[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s",
     138           0 :                                                         k, open_attrs_table[i], open_attrs_table[j],
     139             :                                                         smbcli_errstr(cli1->tree));
     140           0 :                                         CHECK_MAX_FAILURES(error_exit);
     141             :                                 }
     142             : #if 0
     143             :                                 torture_comment(tctx, "[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
     144             : #endif
     145        1150 :                                 k++;
     146        1150 :                                 continue;
     147             :                         }
     148             : 
     149         642 :                         torture_assert_ntstatus_ok(tctx, 
     150             :                                                                            smbcli_close(cli1->tree, fnum1),
     151             :                                                                         talloc_asprintf(tctx, "close %d (2) of %s failed (%s)", j, 
     152             :                                                                         fname, smbcli_errstr(cli1->tree)));
     153             : 
     154         642 :                         torture_assert_ntstatus_ok(tctx, 
     155             :                                                 smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL),
     156             :                                                 talloc_asprintf(tctx, "getatr(2) failed (%s)", smbcli_errstr(cli1->tree)));
     157             : 
     158             : #if 0
     159             :                         torture_comment(tctx, "[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
     160             :                                         k,  open_attrs_table[i],  open_attrs_table[j], attr );
     161             : #endif
     162             : 
     163       14877 :                         for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
     164       14417 :                                 if (attr_results[l].num == k) {
     165         182 :                                         if (attr != attr_results[l].result_attr ||
     166         182 :                                             open_attrs_table[i] != attr_results[l].init_attr ||
     167         182 :                                             open_attrs_table[j] != attr_results[l].trunc_attr) {
     168           0 :                                                 torture_result(tctx, TORTURE_FAIL,
     169             :                                                         "[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x",
     170           0 :                                                        k, open_attrs_table[i],
     171           0 :                                                        open_attrs_table[j],
     172             :                                                        (unsigned int)attr,
     173           0 :                                                        attr_results[l].result_attr);
     174           0 :                                                 CHECK_MAX_FAILURES(error_exit);
     175             :                                         }
     176         156 :                                         break;
     177             :                                 }
     178             :                         }
     179         642 :                         k++;
     180             :                 }
     181             :         }
     182           7 : error_exit:
     183           7 :         smbcli_setatr(cli1->tree, fname, 0, 0);
     184           7 :         smbcli_unlink(cli1->tree, fname);
     185             : 
     186           7 :         if (failures) {
     187           0 :                 return false;
     188             :         }
     189           6 :         return true;
     190             : }
     191             : 
     192           0 : bool torture_winattrtest(struct torture_context *tctx,
     193             :                           struct smbcli_state *cli1)
     194             : {
     195           0 :         const char *fname = "\\winattr1.file";
     196           0 :         const char *dname = "\\winattr1.dir";
     197           0 :         int fnum1;
     198           0 :         uint16_t attr;
     199           0 :         uint16_t j;
     200           0 :         uint32_t aceno;
     201           0 :         int failures = 0;
     202           0 :         union smb_fileinfo query, query_org;
     203           0 :         NTSTATUS status;
     204           0 :         struct security_descriptor *sd1, *sd2;
     205           0 :         ZERO_STRUCT(query);
     206           0 :         ZERO_STRUCT(query_org);
     207             : 
     208             :         /* Test winattrs for file */
     209           0 :         smbcli_unlink(cli1->tree, fname);
     210             : 
     211             :         /* Open a file*/
     212           0 :         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR | O_CREAT | O_TRUNC,
     213             :                         DENY_NONE);
     214           0 :         torture_assert(tctx, fnum1 != -1,
     215             :                        talloc_asprintf(tctx, "open(1) of %s failed (%s)\n",
     216             :                        fname, smbcli_errstr(cli1->tree)));
     217             : 
     218             : 
     219             :         /* Get security descriptor and store it*/
     220           0 :         query_org.generic.level = RAW_FILEINFO_SEC_DESC;
     221           0 :         query_org.generic.in.file.fnum = fnum1;
     222           0 :         status = smb_raw_fileinfo(cli1->tree, tctx, &query_org);
     223           0 :         if(!NT_STATUS_IS_OK(status)){
     224           0 :                 torture_comment(tctx, "smb_raw_fileinfo(1) of %s failed (%s)\n",
     225             :                                 fname, nt_errstr(status));
     226           0 :                 torture_assert_ntstatus_ok(tctx,
     227             :                                 smbcli_close(cli1->tree, fnum1),
     228             :                                 talloc_asprintf(tctx,
     229             :                                         "close(1) of %s failed (%s)\n",
     230             :                                         fname, smbcli_errstr(cli1->tree)));
     231           0 :                 CHECK_MAX_FAILURES(error_exit_file);
     232             :         }
     233           0 :         sd1 = query_org.query_secdesc.out.sd;
     234             : 
     235           0 :         torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
     236             :                        talloc_asprintf(tctx, "close(1) of %s failed (%s)\n",
     237             :                                        fname, smbcli_errstr(cli1->tree)));
     238             : 
     239             :         /*Set and get attributes*/
     240           0 :         for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
     241           0 :                 torture_assert_ntstatus_ok(tctx,
     242             :                         smbcli_setatr(cli1->tree, fname, open_attrs_table[j],0),
     243             :                         talloc_asprintf(tctx, "setatr(2) failed (%s)",
     244             :                                 smbcli_errstr(cli1->tree)));
     245             : 
     246           0 :                 torture_assert_ntstatus_ok(tctx,
     247             :                         smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL),
     248             :                         talloc_asprintf(tctx, "getatr(2) failed (%s)",
     249             :                         smbcli_errstr(cli1->tree)));
     250             : 
     251             :                 /* Check the result */
     252           0 :                 if((j == 0)&&(attr != FILE_ATTRIBUTE_ARCHIVE)){
     253           0 :                         torture_comment(tctx, "getatr check failed. \
     254             :                                         Attr applied [0x%x], got attr [0x%x], \
     255             :                                         should be [0x%x]",
     256           0 :                                         open_attrs_table[j],
     257           0 :                                         (uint16_t)attr,open_attrs_table[j +1]);
     258           0 :                         CHECK_MAX_FAILURES(error_exit_file);
     259             :                 }else{
     260             : 
     261           0 :                         if((j != 0) &&(attr != open_attrs_table[j])){
     262           0 :                                 torture_comment(tctx, "getatr check failed. \
     263             :                                         Attr applied [0x%x],got attr 0x%x, \
     264             :                                         should be 0x%x ",
     265           0 :                                         open_attrs_table[j], (uint16_t)attr,
     266           0 :                                         open_attrs_table[j]);
     267           0 :                                 CHECK_MAX_FAILURES(error_exit_file);
     268             :                         }
     269             : 
     270             :                 }
     271             : 
     272           0 :                 fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY | O_CREAT,
     273             :                                 DENY_NONE);
     274           0 :                 torture_assert(tctx, fnum1 != -1,
     275             :                        talloc_asprintf(tctx, "open(2) of %s failed (%s)\n",
     276             :                        fname, smbcli_errstr(cli1->tree)));
     277             :                 /*Get security descriptor */
     278           0 :                 query.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
     279           0 :                 query.query_secdesc.in.file.fnum = fnum1;
     280           0 :                 status = smb_raw_fileinfo(cli1->tree, tctx, &query);
     281           0 :                 if(!NT_STATUS_IS_OK(status)){
     282           0 :                         torture_comment(tctx,
     283             :                                 "smb_raw_fileinfo(2) of %s failed (%s)\n",
     284             :                                 fname, nt_errstr(status));
     285           0 :                         torture_assert_ntstatus_ok(tctx,
     286             :                                 smbcli_close(cli1->tree, fnum1),
     287             :                                 talloc_asprintf(tctx,
     288             :                                         "close(2) of %s failed (%s)\n",
     289             :                                         fname, smbcli_errstr(cli1->tree)));
     290           0 :                         CHECK_MAX_FAILURES(error_exit_file);
     291             :                 }
     292           0 :                 sd2 = query.query_secdesc.out.sd;
     293             : 
     294           0 :                 torture_assert_ntstatus_ok(tctx,smbcli_close(cli1->tree,fnum1),
     295             :                        talloc_asprintf(tctx, "close(2) of %s failed (%s)\n",
     296             :                                        fname, smbcli_errstr(cli1->tree)));
     297             : 
     298             :                 /*Compare security descriptors -- Must be same*/
     299           0 :                 for (aceno=0;(sd1->dacl&&aceno < sd1->dacl->num_aces);aceno++){
     300           0 :                         struct security_ace *ace1 = &sd1->dacl->aces[aceno];
     301           0 :                         struct security_ace *ace2 = &sd2->dacl->aces[aceno];
     302             : 
     303           0 :                         if (!security_ace_equal(ace1, ace2)) {
     304           0 :                                 torture_comment(tctx,
     305             :                                         "ACLs changed! Not expected!\n");
     306           0 :                                 CHECK_MAX_FAILURES(error_exit_file);
     307             :                         }
     308             :                 }
     309             : 
     310           0 :                 torture_comment(tctx, "[%d] setattr = [0x%x] got attr 0x%x\n",
     311           0 :                         j,  open_attrs_table[j], attr );
     312             : 
     313             :         }
     314             : 
     315           0 : error_exit_file:
     316           0 :         smbcli_setatr(cli1->tree, fname, 0, 0);
     317           0 :         smbcli_unlink(cli1->tree, fname);
     318             : 
     319             : /* Check for Directory. */
     320             : 
     321           0 :         smbcli_deltree(cli1->tree, dname);
     322           0 :         smbcli_rmdir(cli1->tree,dname);
     323             : 
     324             :         /* Open a directory */
     325           0 :         fnum1 = smbcli_nt_create_full(cli1->tree, dname, 0,
     326             :                                       SEC_RIGHTS_DIR_ALL,
     327             :                                       FILE_ATTRIBUTE_DIRECTORY,
     328             :                                       NTCREATEX_SHARE_ACCESS_NONE,
     329             :                                       NTCREATEX_DISP_OPEN_IF,
     330             :                                       NTCREATEX_OPTIONS_DIRECTORY, 0);
     331             :         /*smbcli_mkdir(cli1->tree,dname);*/
     332             : 
     333           0 :         torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx,
     334             :                         "open (1) of %s failed (%s)",
     335             :                           dname, smbcli_errstr(cli1->tree)));
     336             : 
     337             : 
     338             :         /* Get Security Descriptor */
     339           0 :         query_org.generic.level = RAW_FILEINFO_SEC_DESC;
     340           0 :         query_org.generic.in.file.fnum = fnum1;
     341           0 :         status = smb_raw_fileinfo(cli1->tree, tctx, &query_org);
     342           0 :         if(!NT_STATUS_IS_OK(status)){
     343           0 :                 torture_comment(tctx, "smb_raw_fileinfo(1) of %s failed (%s)\n",
     344             :                                 dname, nt_errstr(status));
     345           0 :                 torture_assert_ntstatus_ok(tctx,
     346             :                                 smbcli_close(cli1->tree, fnum1),
     347             :                                 talloc_asprintf(tctx,
     348             :                                         "close(1) of %s failed (%s)\n",
     349             :                                         dname, smbcli_errstr(cli1->tree)));
     350           0 :                 CHECK_MAX_FAILURES(error_exit_dir);
     351             :         }
     352           0 :         sd1 = query_org.query_secdesc.out.sd;
     353             : 
     354           0 :         torture_assert_ntstatus_ok(tctx,
     355             :                                 smbcli_close(cli1->tree, fnum1),
     356             :                                 talloc_asprintf(tctx,
     357             :                                 "close (1) of %s failed (%s)", dname,
     358             :                                 smbcli_errstr(cli1->tree)));
     359             : 
     360             :         /* Set and get win attributes*/
     361           0 :         for (j = 1; j < ARRAY_SIZE(open_attrs_table); j++) {
     362             : 
     363           0 :                 torture_assert_ntstatus_ok(tctx,
     364             :                 smbcli_setatr(cli1->tree, dname, open_attrs_table[j], 0),
     365             :                 talloc_asprintf(tctx, "setatr(2) failed (%s)",
     366             :                 smbcli_errstr(cli1->tree)));
     367             : 
     368           0 :                 torture_assert_ntstatus_ok(tctx,
     369             :                 smbcli_getatr(cli1->tree, dname, &attr, NULL, NULL),
     370             :                 talloc_asprintf(tctx, "getatr(2) failed (%s)",
     371             :                 smbcli_errstr(cli1->tree)));
     372             : 
     373           0 :                 torture_comment(tctx, "[%d] setatt = [0x%x] got attr 0x%x\n",
     374           0 :                         j,  open_attrs_table[j], attr );
     375             : 
     376             :                 /* Check the result */
     377           0 :                 if(attr != (open_attrs_table[j]|FILE_ATTRIBUTE_DIRECTORY)){
     378           0 :                         torture_comment(tctx, "getatr check failed. set attr \
     379             :                                 [0x%x], got attr 0x%x, should be 0x%x\n",
     380           0 :                                 open_attrs_table[j],
     381             :                                 (uint16_t)attr,
     382           0 :                                 (unsigned int)(open_attrs_table[j]|FILE_ATTRIBUTE_DIRECTORY));
     383           0 :                         CHECK_MAX_FAILURES(error_exit_dir);
     384             :                 }
     385             : 
     386           0 :                 fnum1 = smbcli_nt_create_full(cli1->tree, dname, 0,
     387             :                                       SEC_RIGHTS_DIR_READ,
     388             :                                       FILE_ATTRIBUTE_DIRECTORY,
     389             :                                       NTCREATEX_SHARE_ACCESS_NONE,
     390             :                                       NTCREATEX_DISP_OPEN,
     391             :                                       0,0);
     392             : 
     393           0 :                 torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx,
     394             :                         "open (2) of %s failed (%s)",
     395             :                           dname, smbcli_errstr(cli1->tree)));
     396             :                 /* Get security descriptor */
     397           0 :                 query.generic.level = RAW_FILEINFO_SEC_DESC;
     398           0 :                 query.generic.in.file.fnum = fnum1;
     399           0 :                 status = smb_raw_fileinfo(cli1->tree, tctx, &query);
     400           0 :                 if(!NT_STATUS_IS_OK(status)){
     401           0 :                         torture_comment(tctx, "smb_raw_fileinfo(2) of %s failed\
     402             :                                         (%s)\n", dname, nt_errstr(status));
     403           0 :                         torture_assert_ntstatus_ok(tctx,
     404             :                                         smbcli_close(cli1->tree, fnum1),
     405             :                                         talloc_asprintf(tctx,
     406             :                                         "close (2) of %s failed (%s)", dname,
     407             :                                         smbcli_errstr(cli1->tree)));
     408           0 :                         CHECK_MAX_FAILURES(error_exit_dir);
     409             :                 }
     410           0 :                 sd2 = query.query_secdesc.out.sd;
     411           0 :                 torture_assert_ntstatus_ok(tctx,
     412             :                                 smbcli_close(cli1->tree, fnum1),
     413             :                                 talloc_asprintf(tctx,
     414             :                                 "close (2) of %s failed (%s)", dname,
     415             :                                 smbcli_errstr(cli1->tree)));
     416             : 
     417             :                 /* Security descriptor must be same*/
     418           0 :                 for (aceno=0;(sd1->dacl&&aceno < sd1->dacl->num_aces);aceno++){
     419           0 :                         struct security_ace *ace1 = &sd1->dacl->aces[aceno];
     420           0 :                         struct security_ace *ace2 = &sd2->dacl->aces[aceno];
     421             : 
     422           0 :                         if (!security_ace_equal(ace1, ace2)) {
     423           0 :                                 torture_comment(tctx,
     424             :                                         "ACLs changed! Not expected!\n");
     425           0 :                                 CHECK_MAX_FAILURES(error_exit_dir);
     426             :                         }
     427             :                 }
     428             : 
     429             :         }
     430           0 : error_exit_dir:
     431           0 :         smbcli_deltree(cli1->tree, dname);
     432           0 :         smbcli_rmdir(cli1->tree,dname);
     433             : 
     434           0 :         if(failures)
     435           0 :                 return false;
     436           0 :         return true;
     437             : }

Generated by: LCOV version 1.14