smbd: rename sconn->raw_thread_pool to sconn->pool
[samba.git] / source3 / torture / denytest.c
index 045246f1269b99d6a894b1a464efd3ac497ce1ac..87f06618cead3cddb3465557fa19769c47e05906 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#define NO_SYSLOG
-
 #include "includes.h"
+#include "system/filesys.h"
+#include "torture/proto.h"
+#include "libsmb/libsmb.h"
 
-extern BOOL torture_showall;
+extern bool torture_showall;
 
 enum deny_result {A_0=0, A_X=1, A_R=2, A_W=3, A_RW=5};
 
 
-static char *denystr(int denymode)
+static const char *denystr(int denymode)
 {
        struct {
                int v;
-               char *name; 
+               const char *name; 
        } deny_modes[] = {
                {DENY_DOS, "DENY_DOS"},
                {DENY_ALL, "DENY_ALL"},
@@ -47,11 +47,11 @@ static char *denystr(int denymode)
        return "DENY_XXX";
 }
 
-static char *openstr(int mode)
+static const char *openstr(int mode)
 {
        struct {
                int v;
-               char *name; 
+               const char *name; 
        } open_modes[] = {
                {O_RDWR, "O_RDWR"},
                {O_RDONLY, "O_RDONLY"},
@@ -64,11 +64,11 @@ static char *openstr(int mode)
        return "O_XXX";
 }
 
-static char *resultstr(enum deny_result res)
+static const char *resultstr(enum deny_result res)
 {
        struct {
                enum deny_result res;
-               char *name; 
+               const char *name; 
        } results[] = {
                {A_X, "X"},
                {A_0, "-"},
@@ -76,7 +76,7 @@ static char *resultstr(enum deny_result res)
                {A_W, "W"},
                {A_RW,"RW"}};
        int i;
-       for (i=0;ARRAY_SIZE(results);i++) {
+       for (i=0;i<ARRAY_SIZE(results);i++) {
                if (results[i].res == res) return results[i].name;
        }
        return "*";
@@ -1406,53 +1406,61 @@ static void progress_bar(unsigned i, unsigned total)
 /*
   this produces a matrix of deny mode behaviour for 1 connection
  */
-BOOL torture_denytest1(int dummy)
+bool torture_denytest1(int dummy)
 {
-       static struct cli_state cli1;
-       int fnum1, fnum2;
+       struct cli_state *cli1;
+       uint16_t fnum1, fnum2;
        int i;
-       BOOL correct = True;
-       char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
+       bool correct = True;
+       NTSTATUS ret1, ret2, status;
+       const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"};
+       size_t nread;
 
-       if (!torture_open_connection(&cli1)) {
+       if (!torture_open_connection(&cli1, 0)) {
                return False;
        }
 
        printf("starting denytest1\n");
 
        for (i=0;i<2;i++) {
-               cli_unlink(&cli1, fnames[i]);
-               fnum1 = cli_open(&cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
-               cli_write(&cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
-               cli_close(&cli1, fnum1);
+               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);
        }
 
-       printf("testing %d entries\n", ARRAY_SIZE(denytable1));
+       printf("testing %ld entries\n", (unsigned long)ARRAY_SIZE(denytable1));
 
        for (i=0; i<ARRAY_SIZE(denytable1); i++) {
                enum deny_result res;
-               char *fname = fnames[denytable1[i].isexe];
+               const char *fname = fnames[denytable1[i].isexe];
 
                progress_bar(i, ARRAY_SIZE(denytable1));
 
-               fnum1 = cli_open(&cli1, fname, 
+               ret1 = cli_openx(cli1, fname, 
                                 denytable1[i].mode1,
-                                denytable1[i].deny1);
-               fnum2 = cli_open(&cli1, fname, 
+                                denytable1[i].deny1, &fnum1);
+               ret2 = cli_openx(cli1, fname, 
                                 denytable1[i].mode2,
-                                denytable1[i].deny2);
+                                denytable1[i].deny2, &fnum2);
 
-               if (fnum1 == -1) {
+               if (!NT_STATUS_IS_OK(ret1)) {
                        res = A_X;
-               } else if (fnum2 == -1) {
+               } else if (!NT_STATUS_IS_OK(ret2)) {
                        res = A_0;
                } else {
                        char x = 1;
                        res = A_0;
-                       if (cli_read(&cli1, fnum2, (void *)&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, (void *)&x, 0, 1) == 1) {
+                       if (NT_STATUS_IS_OK(cli_writeall(cli1, fnum2, 0,
+                                                        (uint8_t *)&x, 0, 1,
+                                                        NULL))) {
                                res += A_W;
                        }
                }
@@ -1472,15 +1480,19 @@ BOOL torture_denytest1(int dummy)
                               resultstr(denytable1[i].result));
                }
 
-               cli_close(&cli1, fnum1);
-               cli_close(&cli1, fnum2);
+               if (NT_STATUS_IS_OK(ret1)) {
+                       cli_close(cli1, fnum1);
+               }
+               if (NT_STATUS_IS_OK(ret2)) {
+                       cli_close(cli1, fnum2);
+               }
        }
 
        for (i=0;i<2;i++) {
-               cli_unlink(&cli1, fnames[i]);
+               cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
                
-       if (!torture_close_connection(&cli1)) {
+       if (!torture_close_connection(cli1)) {
                correct = False;
        }
        
@@ -1492,51 +1504,59 @@ BOOL torture_denytest1(int dummy)
 /*
   this produces a matrix of deny mode behaviour with 2 connections
  */
-BOOL torture_denytest2(int dummy)
+bool torture_denytest2(int dummy)
 {
-       static struct cli_state cli1, cli2;
-       int fnum1, fnum2;
+       static struct cli_state *cli1, *cli2;
+       uint16_t fnum1, fnum2;
        int i;
-       BOOL correct = True;
-       char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"};
+       bool correct = True;
+       NTSTATUS ret1, ret2, status;
+       const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"};
+       size_t nread;
 
-       if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
+       if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
                return False;
        }
 
        printf("starting denytest2\n");
 
        for (i=0;i<2;i++) {
-               cli_unlink(&cli1, fnames[i]);
-               fnum1 = cli_open(&cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE);
-               cli_write(&cli1, fnum1, 0, fnames[i], 0, strlen(fnames[i]));
-               cli_close(&cli1, fnum1);
+               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);
        }
 
        for (i=0; i<ARRAY_SIZE(denytable2); i++) {
                enum deny_result res;
-               char *fname = fnames[denytable2[i].isexe];
+               const char *fname = fnames[denytable2[i].isexe];
 
-               progress_bar(i, ARRAY_SIZE(denytable1));
+               progress_bar(i, ARRAY_SIZE(denytable2));
 
-               fnum1 = cli_open(&cli1, fname, 
+               ret1 = cli_openx(cli1, fname, 
                                 denytable2[i].mode1,
-                                denytable2[i].deny1);
-               fnum2 = cli_open(&cli2, fname, 
+                                denytable2[i].deny1, &fnum1);
+               ret2 = cli_openx(cli2, fname, 
                                 denytable2[i].mode2,
-                                denytable2[i].deny2);
+                                denytable2[i].deny2, &fnum2);
 
-               if (fnum1 == -1) {
+               if (!NT_STATUS_IS_OK(ret1)) {
                        res = A_X;
-               } else if (fnum2 == -1) {
+               } else if (!NT_STATUS_IS_OK(ret2)) {
                        res = A_0;
                } else {
                        char x = 1;
                        res = A_0;
-                       if (cli_read(&cli2, fnum2, (void *)&x, 0, 1) == 1) {
-                               res += A_R;
-                       }
-                       if (cli_write(&cli2, fnum2, 0, (void *)&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;
                        }
                }
@@ -1556,18 +1576,22 @@ BOOL torture_denytest2(int dummy)
                               resultstr(denytable2[i].result));
                }
 
-               cli_close(&cli1, fnum1);
-               cli_close(&cli2, fnum2);
+               if (NT_STATUS_IS_OK(ret1)) {
+                       cli_close(cli1, fnum1);
+               }
+               if (NT_STATUS_IS_OK(ret2)) {
+                       cli_close(cli2, fnum2);
+               }
        }
                
        for (i=0;i<2;i++) {
-               cli_unlink(&cli1, fnames[i]);
+               cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        }
 
-       if (!torture_close_connection(&cli1)) {
+       if (!torture_close_connection(cli1)) {
                correct = False;
        }
-       if (!torture_close_connection(&cli2)) {
+       if (!torture_close_connection(cli2)) {
                correct = False;
        }