r25034: Remove unused variables.
[kai/samba.git] / source4 / torture / raw / setfileinfo.c
index fa286ae4daf0a016e0d90e0de069d4eb2854eecd..1178af4e9fb09a98190f993f99401304e93141d3 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/>.
 */
 
 #include "includes.h"
+#include "torture/torture.h"
+#include "system/time.h"
+#include "libcli/raw/libcliraw.h"
+#include "libcli/libcli.h"
+#include "torture/util.h"
+#include "torture/raw/proto.h"
 
 #define BASEDIR "\\testsfileinfo"
 
    for each call we test that it succeeds, and where possible test 
    for consistency between the calls. 
 */
-BOOL torture_raw_sfileinfo(int dummy)
+bool torture_raw_sfileinfo(struct torture_context *torture, 
+                          struct smbcli_state *cli)
 {
-       struct cli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
-       int fnum_saved, d_fnum, fnum2, fnum = -1;
+       bool ret = true;
+       int fnum = -1;
        char *fnum_fname;
        char *fnum_fname_new;
        char *path_fname;
@@ -49,28 +53,23 @@ BOOL torture_raw_sfileinfo(int dummy)
        asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n);
        asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n);
 
-       if (!torture_open_connection(&cli)) {
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
-       mem_ctx = talloc_init("torture_sfileinfo");
-
-       cli_deltree(cli->tree, BASEDIR);
-       cli_mkdir(cli->tree, BASEDIR);
-
 #define RECREATE_FILE(fname) do { \
-       if (fnum != -1) cli_close(cli->tree, fnum); \
-       fnum = create_complex_file(cli, mem_ctx, fname); \
+       if (fnum != -1) smbcli_close(cli->tree, fnum); \
+       fnum = create_complex_file(cli, torture, fname); \
        if (fnum == -1) { \
-               printf("(%d) ERROR: open of %s failed (%s)\n", \
-                      __LINE__, fname, cli_errstr(cli->tree)); \
+               printf("(%s) ERROR: open of %s failed (%s)\n", \
+                      __location__, fname, smbcli_errstr(cli->tree)); \
                ret = False; \
                goto done; \
        }} while (0)
 
 #define RECREATE_BOTH do { \
                RECREATE_FILE(path_fname); \
-               cli_close(cli->tree, fnum); \
+               smbcli_close(cli->tree, fnum); \
                RECREATE_FILE(fnum_fname); \
        } while (0)
 
@@ -80,18 +79,18 @@ BOOL torture_raw_sfileinfo(int dummy)
        check_fnum = True; \
        call_name = #call; \
        sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
-       sfinfo.generic.file.fnum = fnum; \
+       sfinfo.generic.in.file.fnum = fnum; \
        status = smb_raw_setfileinfo(cli->tree, &sfinfo); \
        if (!NT_STATUS_EQUAL(status, rightstatus)) { \
-               printf("(%d) %s - %s (should be %s)\n", __LINE__, #call, \
+               printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
                        nt_errstr(status), nt_errstr(rightstatus)); \
                ret = False; \
        } \
        finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \
-       finfo1.generic.in.fnum = fnum; \
-       status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo1); \
+       finfo1.generic.in.file.fnum = fnum; \
+       status2 = smb_raw_fileinfo(cli->tree, torture, &finfo1); \
        if (!NT_STATUS_IS_OK(status2)) { \
-               printf("(%d) %s pathinfo - %s\n", __LINE__, #call, nt_errstr(status)); \
+               printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status)); \
                ret = False; \
        }} while (0)
 
@@ -99,26 +98,26 @@ BOOL torture_raw_sfileinfo(int dummy)
        check_fnum = False; \
        call_name = #call; \
        sfinfo.generic.level = RAW_SFILEINFO_ ## call; \
-       sfinfo.generic.file.fname = path_fname; \
+       sfinfo.generic.in.file.path = path_fname; \
        status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
        if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \
-               sfinfo.generic.file.fname = path_fname_new; \
+               sfinfo.generic.in.file.path = path_fname_new; \
                status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
        } \
        if (!NT_STATUS_EQUAL(status, rightstatus)) { \
-               printf("(%d) %s - %s (should be %s)\n", __LINE__, #call, \
+               printf("(%s) %s - %s (should be %s)\n", __location__, #call, \
                        nt_errstr(status), nt_errstr(rightstatus)); \
                ret = False; \
        } \
        finfo1.generic.level = RAW_FILEINFO_ALL_INFO; \
-       finfo1.generic.in.fname = path_fname; \
-       status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \
+       finfo1.generic.in.file.path = path_fname; \
+       status2 = smb_raw_pathinfo(cli->tree, torture, &finfo1); \
        if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \
-               finfo1.generic.in.fname = path_fname_new; \
-               status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo1); \
+               finfo1.generic.in.file.path = path_fname_new; \
+               status2 = smb_raw_pathinfo(cli->tree, torture, &finfo1); \
        } \
        if (!NT_STATUS_IS_OK(status2)) { \
-               printf("(%d) %s pathinfo - %s\n", __LINE__, #call, nt_errstr(status2)); \
+               printf("(%s) %s pathinfo - %s\n", __location__, #call, nt_errstr(status2)); \
                ret = False; \
        }} while (0)
 
@@ -126,50 +125,62 @@ BOOL torture_raw_sfileinfo(int dummy)
        do { if (NT_STATUS_IS_OK(status)) { \
                finfo2.generic.level = RAW_FILEINFO_ ## call; \
                if (check_fnum) { \
-                       finfo2.generic.in.fnum = fnum; \
-                       status2 = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo2); \
+                       finfo2.generic.in.file.fnum = fnum; \
+                       status2 = smb_raw_fileinfo(cli->tree, torture, &finfo2); \
                } else { \
-                       finfo2.generic.in.fname = path_fname; \
-                       status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \
+                       finfo2.generic.in.file.path = path_fname; \
+                       status2 = smb_raw_pathinfo(cli->tree, torture, &finfo2); \
                        if (NT_STATUS_EQUAL(status2, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { \
-                               finfo2.generic.in.fname = path_fname_new; \
-                               status2 = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo2); \
+                               finfo2.generic.in.file.path = path_fname_new; \
+                               status2 = smb_raw_pathinfo(cli->tree, torture, &finfo2); \
                        } \
                } \
                if (!NT_STATUS_IS_OK(status2)) { \
                        printf("%s - %s\n", #call, nt_errstr(status2)); \
+                       ret = False; \
                } \
        }} while (0)
 
 #define CHECK_VALUE(call, stype, field, value) do { \
        CHECK1(call); \
        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && finfo2.stype.out.field != value) { \
-               printf("(%d) %s - %s/%s should be 0x%x - 0x%x\n", __LINE__, \
+               printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
                       call_name, #stype, #field, \
                       (uint_t)value, (uint_t)finfo2.stype.out.field); \
-               dump_all_info(mem_ctx, &finfo1); \
+               dump_all_info(torture, &finfo1); \
+               ret = False; \
        }} while (0)
 
 #define CHECK_TIME(call, stype, field, value) do { \
        CHECK1(call); \
-       if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(&finfo2.stype.out.field) != value) { \
-               printf("(%d) %s - %s/%s should be 0x%x - 0x%x\n", __LINE__, \
+       if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && nt_time_to_unix(finfo2.stype.out.field) != value) { \
+               printf("(%s) %s - %s/%s should be 0x%x - 0x%x\n", __location__, \
                        call_name, #stype, #field, \
                        (uint_t)value, \
-                       (uint_t)nt_time_to_unix(&finfo2.stype.out.field)); \
-               printf("\t%s", http_timestring(mem_ctx, value)); \
-               printf("\t%s\n", nt_time_string(mem_ctx, &finfo2.stype.out.field)); \
-               dump_all_info(mem_ctx, &finfo1); \
+                       (uint_t)nt_time_to_unix(finfo2.stype.out.field)); \
+               printf("\t%s", timestring(torture, value)); \
+               printf("\t%s\n", nt_time_string(torture, finfo2.stype.out.field)); \
+               dump_all_info(torture, &finfo1); \
+               ret = False; \
        }} while (0)
 
 #define CHECK_STR(call, stype, field, value) do { \
        CHECK1(call); \
        if (NT_STATUS_IS_OK(status) && NT_STATUS_IS_OK(status2) && strcmp(finfo2.stype.out.field, value) != 0) { \
-               printf("(%d) %s - %s/%s should be '%s' - '%s'\n", __LINE__, \
+               printf("(%s) %s - %s/%s should be '%s' - '%s'\n", __location__, \
                        call_name, #stype, #field, \
                        value, \
                        finfo2.stype.out.field); \
-               dump_all_info(mem_ctx, &finfo1); \
+               dump_all_info(torture, &finfo1); \
+               ret = False; \
+       }} while (0)
+
+#define CHECK_STATUS(status, correct) do { \
+       if (!NT_STATUS_EQUAL(status, correct)) { \
+               printf("(%s) Incorrect status %s - should be %s\n", \
+                      __location__, nt_errstr(status), nt_errstr(correct)); \
+               ret = False; \
+               goto done; \
        }} while (0)
 
        
@@ -239,13 +250,13 @@ BOOL torture_raw_sfileinfo(int dummy)
        unix_to_nt_time(&sfinfo.basic_info.in.access_time, 0);
        unix_to_nt_time(&sfinfo.basic_info.in.write_time,  0);
        unix_to_nt_time(&sfinfo.basic_info.in.change_time, 0);
-       sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
+       sfinfo.basic_info.in.attrib = 0;
        CHECK_CALL_FNUM(BASIC_INFO, NT_STATUS_OK);
        CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
        CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
        CHECK_TIME(ALL_INFO, all_info, write_time,  basetime + 300);
        CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
-       CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_NORMAL);
+       CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_READONLY);
 
        printf("test basic_information level\n");
        basetime += 86400;
@@ -253,20 +264,20 @@ BOOL torture_raw_sfileinfo(int dummy)
        unix_to_nt_time(&sfinfo.basic_info.in.access_time, basetime + 200);
        unix_to_nt_time(&sfinfo.basic_info.in.write_time,  basetime + 300);
        unix_to_nt_time(&sfinfo.basic_info.in.change_time, basetime + 400);
-       sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
+       sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_NORMAL;
        CHECK_CALL_FNUM(BASIC_INFORMATION, NT_STATUS_OK);
        CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
        CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
        CHECK_TIME(ALL_INFO, all_info, write_time,  basetime + 300);
        CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
-       CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_READONLY);
+       CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_NORMAL);
 
        CHECK_CALL_PATH(BASIC_INFORMATION, NT_STATUS_OK);
        CHECK_TIME(ALL_INFO, all_info, create_time, basetime + 100);
        CHECK_TIME(ALL_INFO, all_info, access_time, basetime + 200);
        CHECK_TIME(ALL_INFO, all_info, write_time,  basetime + 300);
        CHECK_TIME(ALL_INFO, all_info, change_time, basetime + 400);
-       CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_READONLY);
+       CHECK_VALUE(ALL_INFO, all_info, attrib,     FILE_ATTRIBUTE_NORMAL);
 
        printf("a zero time means don't change\n");
        unix_to_nt_time(&sfinfo.basic_info.in.create_time, 0);
@@ -406,10 +417,64 @@ BOOL torture_raw_sfileinfo(int dummy)
 
        CHECK_CALL_PATH(MODE_INFORMATION, NT_STATUS_OK);
        CHECK_VALUE(MODE_INFORMATION, mode_information, mode, 0);
-#if 1
-       printf("finally the rename_information level\n");
-       cli_close(cli->tree, create_complex_file(cli, mem_ctx, fnum_fname_new));
-       cli_close(cli->tree, create_complex_file(cli, mem_ctx, path_fname_new));
+
+#if 0
+       printf("test unix_basic level\n");
+       CHECK_CALL_FNUM(UNIX_BASIC, NT_STATUS_OK);
+       CHECK_CALL_PATH(UNIX_BASIC, NT_STATUS_OK);
+
+       printf("test unix_link level\n");
+       CHECK_CALL_FNUM(UNIX_LINK, NT_STATUS_OK);
+       CHECK_CALL_PATH(UNIX_LINK, NT_STATUS_OK);
+#endif
+
+done:
+       smb_raw_exit(cli->session);
+       smbcli_close(cli->tree, fnum);
+       if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fnum_fname))) {
+               printf("Failed to delete %s - %s\n", fnum_fname, smbcli_errstr(cli->tree));
+       }
+       if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, path_fname))) {
+               printf("Failed to delete %s - %s\n", path_fname, smbcli_errstr(cli->tree));
+       }
+
+       return ret;
+}
+
+/*
+ * basic testing of all RAW_SFILEINFO_RENAME call
+ */
+bool torture_raw_sfileinfo_rename(struct torture_context *torture,
+                                                                 struct smbcli_state *cli)
+{
+       BOOL ret = True;
+       int fnum_saved, d_fnum, fnum2, fnum = -1;
+       char *fnum_fname;
+       char *fnum_fname_new;
+       char *path_fname;
+       char *path_fname_new;
+       union smb_fileinfo finfo1, finfo2;
+       union smb_setfileinfo sfinfo;
+       NTSTATUS status, status2;
+       const char *call_name;
+       BOOL check_fnum;
+       int n = time(NULL) % 100;
+       
+       asprintf(&path_fname, BASEDIR "\\fname_test_%d.txt", n);
+       asprintf(&path_fname_new, BASEDIR "\\fname_test_new_%d.txt", n);
+       asprintf(&fnum_fname, BASEDIR "\\fnum_test_%d.txt", n);
+       asprintf(&fnum_fname_new, BASEDIR "\\fnum_test_new_%d.txt", n);
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return False;
+       }
+
+       RECREATE_BOTH;
+
+       ZERO_STRUCT(sfinfo);
+
+       smbcli_close(cli->tree, create_complex_file(cli, torture, fnum_fname_new));
+       smbcli_close(cli->tree, create_complex_file(cli, torture, path_fname_new));
 
        sfinfo.rename_information.in.overwrite = 0;
        sfinfo.rename_information.in.root_fid  = 0;
@@ -429,7 +494,7 @@ BOOL torture_raw_sfileinfo(int dummy)
        CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);
 
        printf("Trying rename with dest file open\n");
-       fnum2 = create_complex_file(cli, mem_ctx, fnum_fname);
+       fnum2 = create_complex_file(cli, torture, fnum_fname);
        sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
        sfinfo.rename_information.in.overwrite = 1;
        CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_ACCESS_DENIED);
@@ -442,9 +507,11 @@ BOOL torture_raw_sfileinfo(int dummy)
        fnum = fnum_saved;
 
        printf("Trying rename with dest file open and delete_on_close\n");
+       sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
+       sfinfo.rename_information.in.overwrite = 1;
        CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_ACCESS_DENIED);
 
-       cli_close(cli->tree, fnum2);
+       smbcli_close(cli->tree, fnum2);
        CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
        CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
 
@@ -454,12 +521,12 @@ BOOL torture_raw_sfileinfo(int dummy)
        CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
        CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
 
-       fnum2 = create_complex_file(cli, mem_ctx, fnum_fname);
+       fnum2 = create_complex_file(cli, torture, fnum_fname);
        sfinfo.rename_information.in.new_name  = fnum_fname_new+strlen(BASEDIR)+1;
        sfinfo.rename_information.in.overwrite = 0;
        CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_OK);
        CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname_new);
-       cli_close(cli->tree, fnum2);
+       smbcli_close(cli->tree, fnum2);
 
        sfinfo.rename_information.in.new_name  = fnum_fname+strlen(BASEDIR)+1;
        sfinfo.rename_information.in.overwrite = 0;
@@ -480,62 +547,46 @@ BOOL torture_raw_sfileinfo(int dummy)
        CHECK_STR(NAME_INFO, name_info, fname.s, path_fname);
 
        printf("Trying rename with a root fid\n");
-       d_fnum = create_directory_handle(cli->tree, BASEDIR);
+       status = create_directory_handle(cli->tree, BASEDIR, &d_fnum);
+       CHECK_STATUS(status, NT_STATUS_OK);
        sfinfo.rename_information.in.new_name  = fnum_fname_new+strlen(BASEDIR)+1;
        sfinfo.rename_information.in.root_fid = d_fnum;
        CHECK_CALL_FNUM(RENAME_INFORMATION, NT_STATUS_INVALID_PARAMETER);
        CHECK_STR(NAME_INFO, name_info, fname.s, fnum_fname);
-#endif
-
-#if 0
-       printf("test unix_basic level\n");
-       CHECK_CALL_FNUM(UNIX_BASIC, NT_STATUS_OK);
-       CHECK_CALL_PATH(UNIX_BASIC, NT_STATUS_OK);
-
-       printf("test unix_link level\n");
-       CHECK_CALL_FNUM(UNIX_LINK, NT_STATUS_OK);
-       CHECK_CALL_PATH(UNIX_LINK, NT_STATUS_OK);
-#endif
 
 done:
        smb_raw_exit(cli->session);
-       cli_close(cli->tree, fnum);
-       if (NT_STATUS_IS_ERR(cli_unlink(cli->tree, fnum_fname))) {
-               printf("Failed to delete %s - %s\n", fnum_fname, cli_errstr(cli->tree));
+       smbcli_close(cli->tree, fnum);
+       if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fnum_fname))) {
+               printf("Failed to delete %s - %s\n", fnum_fname, smbcli_errstr(cli->tree));
        }
-       if (NT_STATUS_IS_ERR(cli_unlink(cli->tree, path_fname))) {
-               printf("Failed to delete %s - %s\n", path_fname, cli_errstr(cli->tree));
+       if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, path_fname))) {
+               printf("Failed to delete %s - %s\n", path_fname, smbcli_errstr(cli->tree));
        }
 
-       torture_close_connection(cli);
-       talloc_destroy(mem_ctx);
        return ret;
 }
 
-
 /* 
    look for the w2k3 setpathinfo STANDARD bug
 */
-BOOL torture_raw_sfileinfo_bug(int dummy)
+bool torture_raw_sfileinfo_bug(struct torture_context *torture,
+                                                          struct smbcli_state *cli)
 {
-       struct cli_state *cli;
-       TALLOC_CTX *mem_ctx;
        const char *fname = "\\bug3.txt";
        union smb_setfileinfo sfinfo;
        NTSTATUS status;
        int fnum;
 
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       mem_ctx = talloc_init("torture_sfileinfo");
+       if (!torture_setting_bool(torture, "dangerous", false))
+               torture_skip(torture, 
+                       "torture_raw_sfileinfo_bug disabled - enable dangerous tests to use\n");
 
-       fnum = create_complex_file(cli, mem_ctx, fname);
-       cli_close(cli->tree, fnum);
+       fnum = create_complex_file(cli, torture, fname);
+       smbcli_close(cli->tree, fnum);
 
        sfinfo.generic.level = RAW_SFILEINFO_STANDARD;
-       sfinfo.generic.file.fname = fname;
+       sfinfo.generic.in.file.path = fname;
 
        sfinfo.standard.in.create_time = 0;
        sfinfo.standard.in.access_time = 0;