s3:torture:delete: untangle function call from result check
[kai/samba.git] / source3 / torture / denytest.c
index bf491bc22ee93648e6b845c2db3537814367d6e3..5b0eeec2fa75d8f1acbab1783d32866f7f2a1eed 100644 (file)
@@ -18,7 +18,9 @@
 */
 
 #include "includes.h"
-#include "torture.h"
+#include "system/filesys.h"
+#include "torture/proto.h"
+#include "libsmb/libsmb.h"
 
 extern bool torture_showall;
 
@@ -1410,8 +1412,9 @@ bool torture_denytest1(int dummy)
        uint16_t fnum1, fnum2;
        int i;
        bool correct = True;
-       NTSTATUS ret1, ret2;
+       NTSTATUS ret1, ret2, status;
        const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
+       size_t nread;
 
        if (!torture_open_connection(&cli1, 0)) {
                return False;
@@ -1420,9 +1423,10 @@ bool torture_denytest1(int dummy)
        printf("starting denytest1\n");
 
        for (i=0;i<2;i++) {
-               cli_unlink(cli1, fnames[i], aSYSTEM | aHIDDEN);
-               cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
-               cli_write(cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
+               cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               cli_openx(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
+               cli_writeall(cli1, fnum1, 0, (const uint8_t *)fnames[i], 0,
+                            strlen(fnames[i]), NULL);
                cli_close(cli1, fnum1);
        }
 
@@ -1434,10 +1438,10 @@ bool torture_denytest1(int dummy)
 
                progress_bar(i, ARRAY_SIZE(denytable1));
 
-               ret1 = cli_open(cli1, fname, 
+               ret1 = cli_openx(cli1, fname, 
                                 denytable1[i].mode1,
                                 denytable1[i].deny1, &fnum1);
-               ret2 = cli_open(cli1, fname, 
+               ret2 = cli_openx(cli1, fname, 
                                 denytable1[i].mode2,
                                 denytable1[i].deny2, &fnum2);
 
@@ -1448,10 +1452,15 @@ bool torture_denytest1(int dummy)
                } else {
                        char x = 1;
                        res = A_0;
-                       if (cli_read(cli1, fnum2, (char *)&x, 0, 1) == 1) {
+
+                       status = cli_read(cli1, fnum2, (char *)&x, 0, 1,
+                                         &nread);
+                       if (NT_STATUS_IS_OK(status) && nread == 1) {
                                res += A_R;
                        }
-                       if (cli_write(cli1, fnum2, 0, (char *)&x, 0, 1) == 1) {
+                       if (NT_STATUS_IS_OK(cli_writeall(cli1, fnum2, 0,
+                                                        (uint8_t *)&x, 0, 1,
+                                                        NULL))) {
                                res += A_W;
                        }
                }
@@ -1480,7 +1489,7 @@ bool torture_denytest1(int dummy)
        }
 
        for (i=0;i<2;i++) {
-               cli_unlink(cli1, fnames[i], aSYSTEM | aHIDDEN);
+               cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
                
        if (!torture_close_connection(cli1)) {
@@ -1501,8 +1510,9 @@ bool torture_denytest2(int dummy)
        uint16_t fnum1, fnum2;
        int i;
        bool correct = True;
-       NTSTATUS ret1, ret2;
+       NTSTATUS ret1, ret2, status;
        const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"};
+       size_t nread;
 
        if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
                return False;
@@ -1511,9 +1521,10 @@ bool torture_denytest2(int dummy)
        printf("starting denytest2\n");
 
        for (i=0;i<2;i++) {
-               cli_unlink(cli1, fnames[i], aSYSTEM | aHIDDEN);
-               cli_open(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
-               cli_write(cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
+               cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               cli_openx(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);
+               cli_writeall(cli1, fnum1, 0, (const uint8_t *)fnames[i], 0,
+                            strlen(fnames[i]), NULL);
                cli_close(cli1, fnum1);
        }
 
@@ -1523,10 +1534,10 @@ bool torture_denytest2(int dummy)
 
                progress_bar(i, ARRAY_SIZE(denytable2));
 
-               ret1 = cli_open(cli1, fname, 
+               ret1 = cli_openx(cli1, fname, 
                                 denytable2[i].mode1,
                                 denytable2[i].deny1, &fnum1);
-               ret2 = cli_open(cli2, fname, 
+               ret2 = cli_openx(cli2, fname, 
                                 denytable2[i].mode2,
                                 denytable2[i].deny2, &fnum2);
 
@@ -1537,10 +1548,15 @@ bool torture_denytest2(int dummy)
                } else {
                        char x = 1;
                        res = A_0;
-                       if (cli_read(cli2, fnum2, (char *)&x, 0, 1) == 1) {
-                               res += A_R;
-                       }
-                       if (cli_write(cli2, fnum2, 0, (char *)&x, 0, 1) == 1) {
+
+                        status = cli_read(cli2, fnum2, (char *)&x, 0, 1,
+                                          &nread);
+                        if (NT_STATUS_IS_OK(status) && nread == 1) {
+                                res += A_R;
+                        }
+                       if (NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0,
+                                                        (uint8_t *)&x, 0, 1,
+                                                        NULL))) {
                                res += A_W;
                        }
                }
@@ -1569,7 +1585,7 @@ bool torture_denytest2(int dummy)
        }
                
        for (i=0;i<2;i++) {
-               cli_unlink(cli1, fnames[i], aSYSTEM | aHIDDEN);
+               cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
 
        if (!torture_close_connection(cli1)) {