r14173: change smb interface structures to always use
[ira/wip.git] / source / torture / torture_util.c
index 3df1f3be41cd4474aa0269b4c915f671a4e3ac7b..bf227f4e9fe185796f148fb991c98ef48a9226d0 100644 (file)
@@ -20,9 +20,9 @@
 
 #include "includes.h"
 #include "libcli/raw/libcliraw.h"
+#include "libcli/libcli.h"
 #include "system/shmem.h"
 #include "system/time.h"
-#include "librpc/gen_ndr/ndr_security.h"
 
 
 /*
@@ -42,7 +42,7 @@ BOOL torture_setup_dir(struct smbcli_state *cli, const char *dname)
 /*
   create a directory, returning a handle to it
 */
-int create_directory_handle(struct smbcli_tree *tree, const char *dname)
+NTSTATUS create_directory_handle(struct smbcli_tree *tree, const char *dname, int *fnum)
 {
        NTSTATUS status;
        union smb_open io;
@@ -53,26 +53,27 @@ int create_directory_handle(struct smbcli_tree *tree, const char *dname)
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.root_fid = 0;
        io.ntcreatex.in.flags = 0;
-       io.ntcreatex.in.access_mask = SEC_FILE_ALL;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
        io.ntcreatex.in.alloc_size = 0;
-       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
        io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
        io.ntcreatex.in.security_flags = 0;
        io.ntcreatex.in.fname = dname;
 
        status = smb_raw_open(tree, mem_ctx, &io);
-       if (!NT_STATUS_IS_OK(status)) {
-               talloc_destroy(mem_ctx);
-               return -1;
+       talloc_free(mem_ctx);
+
+       if (NT_STATUS_IS_OK(status)) {
+               *fnum = io.ntcreatex.file.fnum;
        }
 
-       talloc_destroy(mem_ctx);
-       return io.ntcreatex.out.fnum;
+       return status;
 }
 
+
 /*
   sometimes we need a fairly complex file to work with, so we can test
   all possible attributes. 
@@ -99,20 +100,99 @@ int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const cha
 
        smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
 
-       /* setup some EAs */
-       setfile.generic.level = RAW_SFILEINFO_EA_SET;
+       if (strchr(fname, ':') == NULL) {
+               /* setup some EAs */
+               setfile.generic.level = RAW_SFILEINFO_EA_SET;
+               setfile.generic.file.fnum = fnum;
+               setfile.ea_set.in.num_eas = 2;  
+               setfile.ea_set.in.eas = talloc_array(mem_ctx, struct ea_struct, 2);
+               setfile.ea_set.in.eas[0].flags = 0;
+               setfile.ea_set.in.eas[0].name.s = "EAONE";
+               setfile.ea_set.in.eas[0].value = data_blob_talloc(mem_ctx, "VALUE1", 6);
+               setfile.ea_set.in.eas[1].flags = 0;
+               setfile.ea_set.in.eas[1].name.s = "SECONDEA";
+               setfile.ea_set.in.eas[1].value = data_blob_talloc(mem_ctx, "ValueTwo", 8);
+               status = smb_raw_setfileinfo(cli->tree, &setfile);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("Failed to setup EAs\n");
+               }
+       }
+
+       /* make sure all the timestamps aren't the same, and are also 
+          in different DST zones*/
+       setfile.generic.level = RAW_SFILEINFO_SETATTRE;
        setfile.generic.file.fnum = fnum;
-       setfile.ea_set.in.num_eas = 2;  
-       setfile.ea_set.in.eas = talloc_array_p(mem_ctx, struct ea_struct, 2);
-       setfile.ea_set.in.eas[0].flags = 0;
-       setfile.ea_set.in.eas[0].name.s = "EAONE";
-       setfile.ea_set.in.eas[0].value = data_blob_talloc(mem_ctx, "VALUE1", 6);
-       setfile.ea_set.in.eas[1].flags = 0;
-       setfile.ea_set.in.eas[1].name.s = "SECONDEA";
-       setfile.ea_set.in.eas[1].value = data_blob_talloc(mem_ctx, "ValueTwo", 8);
+
+       setfile.setattre.in.create_time = t + 9*30*24*60*60;
+       setfile.setattre.in.access_time = t + 6*30*24*60*60;
+       setfile.setattre.in.write_time  = t + 3*30*24*60*60;
+
        status = smb_raw_setfileinfo(cli->tree, &setfile);
        if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to setup EAs\n");
+               printf("Failed to setup file times - %s\n", nt_errstr(status));
+       }
+
+       /* make sure all the timestamps aren't the same */
+       fileinfo.generic.level = RAW_FILEINFO_GETATTRE;
+       fileinfo.generic.file.fnum = fnum;
+
+       status = smb_raw_fileinfo(cli->tree, mem_ctx, &fileinfo);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to query file times - %s\n", nt_errstr(status));
+       }
+
+       if (setfile.setattre.in.create_time != fileinfo.getattre.out.create_time) {
+               printf("create_time not setup correctly\n");
+       }
+       if (setfile.setattre.in.access_time != fileinfo.getattre.out.access_time) {
+               printf("access_time not setup correctly\n");
+       }
+       if (setfile.setattre.in.write_time != fileinfo.getattre.out.write_time) {
+               printf("write_time not setup correctly\n");
+       }
+
+       return fnum;
+}
+
+
+/*
+  sometimes we need a fairly complex directory to work with, so we can test
+  all possible attributes. 
+*/
+int create_complex_dir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const char *dname)
+{
+       int fnum;
+       union smb_setfileinfo setfile;
+       union smb_fileinfo fileinfo;
+       time_t t = (time(NULL) & ~1);
+       NTSTATUS status;
+
+       smbcli_deltree(cli->tree, dname);
+       fnum = smbcli_nt_create_full(cli->tree, dname, 0, 
+                                    SEC_RIGHTS_DIR_ALL,
+                                    FILE_ATTRIBUTE_DIRECTORY,
+                                    NTCREATEX_SHARE_ACCESS_READ|
+                                    NTCREATEX_SHARE_ACCESS_WRITE, 
+                                    NTCREATEX_DISP_OPEN_IF,
+                                    NTCREATEX_OPTIONS_DIRECTORY, 0);
+       if (fnum == -1) return -1;
+
+       if (strchr(dname, ':') == NULL) {
+               /* setup some EAs */
+               setfile.generic.level = RAW_SFILEINFO_EA_SET;
+               setfile.generic.file.fnum = fnum;
+               setfile.ea_set.in.num_eas = 2;  
+               setfile.ea_set.in.eas = talloc_array(mem_ctx, struct ea_struct, 2);
+               setfile.ea_set.in.eas[0].flags = 0;
+               setfile.ea_set.in.eas[0].name.s = "EAONE";
+               setfile.ea_set.in.eas[0].value = data_blob_talloc(mem_ctx, "VALUE1", 6);
+               setfile.ea_set.in.eas[1].flags = 0;
+               setfile.ea_set.in.eas[1].name.s = "SECONDEA";
+               setfile.ea_set.in.eas[1].value = data_blob_talloc(mem_ctx, "ValueTwo", 8);
+               status = smb_raw_setfileinfo(cli->tree, &setfile);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("Failed to setup EAs\n");
+               }
        }
 
        /* make sure all the timestamps aren't the same, and are also 
@@ -131,7 +211,7 @@ int create_complex_file(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, const cha
 
        /* make sure all the timestamps aren't the same */
        fileinfo.generic.level = RAW_FILEINFO_GETATTRE;
-       fileinfo.generic.in.fnum = fnum;
+       fileinfo.generic.file.fnum = fnum;
 
        status = smb_raw_fileinfo(cli->tree, mem_ctx, &fileinfo);
        if (!NT_STATUS_IS_OK(status)) {
@@ -238,8 +318,8 @@ void dump_all_info(TALLOC_CTX *mem_ctx, union smb_fileinfo *finfo)
        d_printf("\twrite_time:     %s\n", nt_time_string(mem_ctx, finfo->all_info.out.write_time));
        d_printf("\tchange_time:    %s\n", nt_time_string(mem_ctx, finfo->all_info.out.change_time));
        d_printf("\tattrib:         0x%x\n", finfo->all_info.out.attrib);
-       d_printf("\talloc_size:     %llu\n", (uint64_t)finfo->all_info.out.alloc_size);
-       d_printf("\tsize:           %llu\n", (uint64_t)finfo->all_info.out.size);
+       d_printf("\talloc_size:     %llu\n", (long long)finfo->all_info.out.alloc_size);
+       d_printf("\tsize:           %llu\n", (long long)finfo->all_info.out.size);
        d_printf("\tnlink:          %u\n", finfo->all_info.out.nlink);
        d_printf("\tdelete_pending: %u\n", finfo->all_info.out.delete_pending);
        d_printf("\tdirectory:      %u\n", finfo->all_info.out.directory);
@@ -257,7 +337,7 @@ void torture_all_info(struct smbcli_tree *tree, const char *fname)
        NTSTATUS status;
 
        finfo.generic.level = RAW_FILEINFO_ALL_INFO;
-       finfo.generic.in.fname = fname;
+       finfo.generic.file.path = fname;
        status = smb_raw_pathinfo(tree, mem_ctx, &finfo);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("%s - %s\n", fname, nt_errstr(status));
@@ -266,7 +346,7 @@ void torture_all_info(struct smbcli_tree *tree, const char *fname)
 
        d_printf("%s:\n", fname);
        dump_all_info(mem_ctx, &finfo);
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
 }
 
 
@@ -290,25 +370,6 @@ BOOL split_unc_name(const char *unc, char **server, char **share)
        return True;
 }
 
-/*
-  split a USER%PASS pair into username and password
-*/
-BOOL split_username(const char *pair, char **user, char **pass)
-{
-       char *p = strdup(pair);
-       if (!p) return False;
-
-       (*user) = p;
-
-       p = strchr(*user, '%');
-       if (!p) return False;
-
-       *p = 0;
-       (*pass) = p+1;
-       
-       return True;
-}
-
 /*
   set a attribute on a file
 */
@@ -318,7 +379,7 @@ BOOL torture_set_file_attribute(struct smbcli_tree *tree, const char *fname, uin
        NTSTATUS status;
 
        sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
-       sfinfo.generic.file.fname = fname;
+       sfinfo.generic.file.path = fname;
 
        ZERO_STRUCT(sfinfo.basic_info.in);
        sfinfo.basic_info.in.attrib = attrib;
@@ -343,13 +404,13 @@ NTSTATUS torture_set_sparse(struct smbcli_tree *tree, int fnum)
 
        nt.ntioctl.level = RAW_IOCTL_NTIOCTL;
        nt.ntioctl.in.function = 0x900c4;
-       nt.ntioctl.in.fnum = fnum;
+       nt.ntioctl.file.fnum = fnum;
        nt.ntioctl.in.fsctl = True;
        nt.ntioctl.in.filter = 0;
 
        status = smb_raw_ioctl(tree, mem_ctx, &nt);
 
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
 
        return status;
 }
@@ -366,7 +427,7 @@ NTSTATUS torture_check_ea(struct smbcli_state *cli,
        TALLOC_CTX *mem_ctx = talloc_new(cli);
 
        info.ea_list.level = RAW_FILEINFO_EA_LIST;
-       info.ea_list.file.fname = fname;
+       info.ea_list.file.path = fname;
        info.ea_list.in.num_names = 1;
        info.ea_list.in.ea_names = &ea;
 
@@ -384,7 +445,7 @@ NTSTATUS torture_check_ea(struct smbcli_state *cli,
                return NT_STATUS_EA_CORRUPT_ERROR;
        }
 
-       if (StrCaseCmp(eaname, info.ea_list.out.eas[0].name.s) != 0) {
+       if (strcasecmp_m(eaname, info.ea_list.out.eas[0].name.s) != 0) {
                printf("Expected ea '%s' not '%s' in ea_list\n",
                       eaname, info.ea_list.out.eas[0].name.s);
                talloc_free(mem_ctx);
@@ -410,8 +471,8 @@ NTSTATUS torture_check_ea(struct smbcli_state *cli,
 
        printf("Expected value '%s' not '%*.*s' for ea %s\n",
               value, 
-              info.ea_list.out.eas[0].value.length,
-              info.ea_list.out.eas[0].value.length,
+              (int)info.ea_list.out.eas[0].value.length,
+              (int)info.ea_list.out.eas[0].value.length,
               info.ea_list.out.eas[0].value.data,
               eaname);