r14464: Don't include ndr_BASENAME.h files unless strictly required, instead
[kai/samba-autobuild/.git] / source4 / torture / basic / charset.c
index 330dcf1707b839408f2e92482f2f16b15ed640f9..186b265e19336720c44c2632ea4404bdf334bcc5 100644 (file)
@@ -21,6 +21,9 @@
 */
 
 #include "includes.h"
+#include "torture/torture.h"
+#include "libcli/raw/libcliraw.h"
+#include "libcli/libcli.h"
 
 #define BASEDIR "\\chartest\\"
 
@@ -40,8 +43,9 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
        int i;
        NTSTATUS status;
 
-       ucs_name = malloc((1+u_name_len)*2);
+       ucs_name = talloc_size(mem_ctx, (1+u_name_len)*2);
        if (!ucs_name) {
+               printf("Failed to create UCS2 Name - talloc() failure\n");
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -50,23 +54,23 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
        }
        SSVAL(ucs_name, i*2, 0);
 
-       i = convert_string_allocate(CH_UCS2, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname);
+       i = convert_string_talloc(ucs_name, CH_UTF16, CH_UNIX, ucs_name, (1+u_name_len)*2, (void **)&fname);
        if (i == -1) {
-               free(ucs_name);
+               printf("Failed to convert UCS2 Name into unix - convert_string_talloc() failure\n");
+               talloc_free(ucs_name);
                return NT_STATUS_NO_MEMORY;
        }
 
-       asprintf(&fname2, "%s%s", BASEDIR, fname);
+       fname2 = talloc_asprintf(ucs_name, "%s%s", BASEDIR, fname);
        if (!fname2) {
-               free(fname);
-               free(ucs_name);
+               talloc_free(ucs_name);
                return NT_STATUS_NO_MEMORY;
        }
 
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
        io.ntcreatex.in.root_fid = 0;
-       io.ntcreatex.in.access_mask = GENERIC_RIGHTS_FILE_ALL_ACCESS;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.alloc_size = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
@@ -79,9 +83,7 @@ static NTSTATUS unicode_open(struct smbcli_tree *tree,
 
        status = smb_raw_open(tree, mem_ctx, &io);
 
-       free(fname);
-       free(fname2);
-       free(ucs_name);
+       talloc_free(ucs_name);
 
        return status;
 }
@@ -226,7 +228,7 @@ static BOOL test_widea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        return True;
 }
 
-BOOL torture_charset(int dummy)
+BOOL torture_charset(void)
 {
        static struct smbcli_state *cli;
        BOOL ret = True;
@@ -240,12 +242,7 @@ BOOL torture_charset(int dummy)
 
        printf("Starting charset tests\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
-               printf("Failed to clean " BASEDIR "\n");
-               return False;
-       }
-       if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }