r9718: Work a bit on the SWAT interface
[kai/samba.git] / source / libcli / clifile.c
index cd01d510179f384cf168533d24dcaeebd971255a..0b9cac4c07c7014fa69b40a346b7198136f47dc0 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "libcli/raw/libcliraw.h"
 
 /****************************************************************************
  Hard/Symlink a file (UNIX extensions).
 ****************************************************************************/
 
-static BOOL cli_link_internal(struct cli_state *cli
-                             const char *fname_src, 
-                             const char *fname_dst, BOOL hard_link)
+static NTSTATUS smbcli_link_internal(struct smbcli_tree *tree
+                                 const char *fname_src, 
+                                 const char *fname_dst, BOOL hard_link)
 {
        union smb_setfileinfo parms;
        NTSTATUS status;
 
        if (hard_link) {
-               parms.generic.level = SMB_SFILEINFO_UNIX_HLINK;
+               parms.generic.level = RAW_SFILEINFO_UNIX_HLINK;
                parms.unix_hlink.file.fname = fname_src;
                parms.unix_hlink.in.link_dest = fname_dst;
        } else {
-               parms.generic.level = SMB_SFILEINFO_UNIX_LINK;
+               parms.generic.level = RAW_SFILEINFO_UNIX_LINK;
                parms.unix_link.file.fname = fname_src;
                parms.unix_link.in.link_dest = fname_dst;
        }
        
-       status = smb_raw_setpathinfo(cli->tree, &parms);
+       status = smb_raw_setpathinfo(tree, &parms);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 /****************************************************************************
  Map standard UNIX permissions onto wire representations.
 ****************************************************************************/
-static uint32  unix_perms_to_wire(mode_t perms)
+uint32_t unix_perms_to_wire(mode_t perms)
 {
-        unsigned int ret = 0;
+        uint_t ret = 0;
 
         ret |= ((perms & S_IXOTH) ?  UNIX_X_OTH : 0);
         ret |= ((perms & S_IWOTH) ?  UNIX_W_OTH : 0);
@@ -79,25 +81,29 @@ static uint32  unix_perms_to_wire(mode_t perms)
 /****************************************************************************
  Symlink a file (UNIX extensions).
 ****************************************************************************/
-BOOL cli_unix_symlink(struct cli_state *cli, const char *fname_src, const char *fname_dst)
+NTSTATUS smbcli_unix_symlink(struct smbcli_tree *tree, const char *fname_src, 
+                         const char *fname_dst)
 {
-       return cli_link_internal(cli, fname_src, fname_dst, False);
+       return smbcli_link_internal(tree, fname_src, fname_dst, False);
 }
 
 /****************************************************************************
  Hard a file (UNIX extensions).
 ****************************************************************************/
-BOOL cli_unix_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst)
+NTSTATUS smbcli_unix_hardlink(struct smbcli_tree *tree, const char *fname_src, 
+                          const char *fname_dst)
 {
-       return cli_link_internal(cli, fname_src, fname_dst, True);
+       return smbcli_link_internal(tree, fname_src, fname_dst, True);
 }
 
 
 /****************************************************************************
  Chmod or chown a file internal (UNIX extensions).
 ****************************************************************************/
-static BOOL cli_unix_chmod_chown_internal(struct cli_state *cli, const char *fname, 
-                                         uint32 mode, uint32 uid, uint32 gid)
+static NTSTATUS smbcli_unix_chmod_chown_internal(struct smbcli_tree *tree, 
+                                             const char *fname, 
+                                             uint32_t mode, uint32_t uid, 
+                                             uint32_t gid)
 {
        union smb_setfileinfo parms;
        NTSTATUS status;
@@ -108,34 +114,39 @@ static BOOL cli_unix_chmod_chown_internal(struct cli_state *cli, const char *fna
        parms.unix_basic.in.gid = gid;
        parms.unix_basic.in.mode = mode;
        
-       status = smb_raw_setpathinfo(cli->tree, &parms);
+       status = smb_raw_setpathinfo(tree, &parms);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 /****************************************************************************
  chmod a file (UNIX extensions).
 ****************************************************************************/
 
-BOOL cli_unix_chmod(struct cli_state *cli, const char *fname, mode_t mode)
+NTSTATUS smbcli_unix_chmod(struct smbcli_tree *tree, const char *fname, mode_t mode)
 {
-       return cli_unix_chmod_chown_internal(cli, fname, 
-               unix_perms_to_wire(mode), SMB_UID_NO_CHANGE, SMB_GID_NO_CHANGE);
+       return smbcli_unix_chmod_chown_internal(tree, fname, 
+                                            unix_perms_to_wire(mode), 
+                                            SMB_UID_NO_CHANGE, 
+                                            SMB_GID_NO_CHANGE);
 }
 
 /****************************************************************************
  chown a file (UNIX extensions).
 ****************************************************************************/
-BOOL cli_unix_chown(struct cli_state *cli, const char *fname, uid_t uid, gid_t gid)
+NTSTATUS smbcli_unix_chown(struct smbcli_tree *tree, const char *fname, uid_t uid, 
+                       gid_t gid)
 {
-       return cli_unix_chmod_chown_internal(cli, fname, SMB_MODE_NO_CHANGE, (uint32)uid, (uint32)gid);
+       return smbcli_unix_chmod_chown_internal(tree, fname, SMB_MODE_NO_CHANGE, 
+                                            (uint32_t)uid, (uint32_t)gid);
 }
 
 
 /****************************************************************************
  Rename a file.
 ****************************************************************************/
-BOOL cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst)
+NTSTATUS smbcli_rename(struct smbcli_tree *tree, const char *fname_src, 
+                   const char *fname_dst)
 {
        union smb_rename parms;
 
@@ -143,14 +154,15 @@ BOOL cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_
        parms.rename.in.attrib = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
        parms.rename.in.pattern1 = fname_src;
        parms.rename.in.pattern2 = fname_dst;
-       return NT_STATUS_IS_OK(smb_raw_rename(cli->tree, &parms));
+
+       return smb_raw_rename(tree, &parms);
 }
 
 
 /****************************************************************************
  Delete a file.
 ****************************************************************************/
-BOOL cli_unlink(struct cli_state *cli, const char *fname)
+NTSTATUS smbcli_unlink(struct smbcli_tree *tree, const char *fname)
 {
        struct smb_unlink parms;
 
@@ -160,39 +172,41 @@ BOOL cli_unlink(struct cli_state *cli, const char *fname)
        } else {
                parms.in.attrib = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY;
        }
-       return NT_STATUS_IS_OK(smb_raw_unlink(cli->tree, &parms));
+
+       return smb_raw_unlink(tree, &parms);
 }
 
 /****************************************************************************
  Create a directory.
 ****************************************************************************/
-BOOL cli_mkdir(struct cli_state *cli, const char *dname)
+NTSTATUS smbcli_mkdir(struct smbcli_tree *tree, const char *dname)
 {
        union smb_mkdir parms;
 
        parms.mkdir.level = RAW_MKDIR_MKDIR;
        parms.mkdir.in.path = dname;
 
-       return NT_STATUS_IS_OK(smb_raw_mkdir(cli->tree, &parms));
+       return smb_raw_mkdir(tree, &parms);
 }
 
 
 /****************************************************************************
  Remove a directory.
 ****************************************************************************/
-BOOL cli_rmdir(struct cli_state *cli, const char *dname)
+NTSTATUS smbcli_rmdir(struct smbcli_tree *tree, const char *dname)
 {
        struct smb_rmdir parms;
 
        parms.in.path = dname;
-       return NT_STATUS_IS_OK(smb_raw_rmdir(cli->tree, &parms));
+
+       return smb_raw_rmdir(tree, &parms);
 }
 
 
 /****************************************************************************
  Set or clear the delete on close flag.
 ****************************************************************************/
-BOOL cli_nt_delete_on_close(struct cli_state *cli, int fnum, BOOL flag)
+NTSTATUS smbcli_nt_delete_on_close(struct smbcli_tree *tree, int fnum, BOOL flag)
 {
        union smb_setfileinfo parms;
        NTSTATUS status;
@@ -201,9 +215,9 @@ BOOL cli_nt_delete_on_close(struct cli_state *cli, int fnum, BOOL flag)
        parms.disposition_info.file.fnum = fnum;
        parms.disposition_info.in.delete_on_close = flag;
        
-       status = smb_raw_setfileinfo(cli->tree, &parms);
+       status = smb_raw_setfileinfo(tree, &parms);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
@@ -211,11 +225,11 @@ BOOL cli_nt_delete_on_close(struct cli_state *cli, int fnum, BOOL flag)
  Create/open a file - exposing the full horror of the NT API :-).
  Used in CIFS-on-CIFS NTVFS.
 ****************************************************************************/
-int cli_nt_create_full(struct cli_state *cli, const char *fname,
-                uint32 CreatFlags, uint32 DesiredAccess,
-                uint32 FileAttributes, uint32 ShareAccess,
-                uint32 CreateDisposition, uint32 CreateOptions,
-                uint8 SecurityFlags)
+int smbcli_nt_create_full(struct smbcli_tree *tree, const char *fname,
+                      uint32_t CreatFlags, uint32_t DesiredAccess,
+                      uint32_t FileAttributes, uint32_t ShareAccess,
+                      uint32_t CreateDisposition, uint32_t CreateOptions,
+                      uint8_t SecurityFlags)
 {
        union smb_open open_parms;
        TALLOC_CTX *mem_ctx;
@@ -237,8 +251,8 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname,
        open_parms.ntcreatex.in.security_flags = SecurityFlags;
        open_parms.ntcreatex.in.fname = fname;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &open_parms);
-       talloc_destroy(mem_ctx);
+       status = smb_raw_open(tree, mem_ctx, &open_parms);
+       talloc_free(mem_ctx);
 
        if (NT_STATUS_IS_OK(status)) {
                return open_parms.ntcreatex.out.fnum;
@@ -252,11 +266,12 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname,
  Open a file (using SMBopenx)
  WARNING: if you open with O_WRONLY then getattrE won't work!
 ****************************************************************************/
-int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode)
+int smbcli_open(struct smbcli_tree *tree, const char *fname, int flags, 
+            int share_mode)
 {
        union smb_open open_parms;
-       unsigned openfn=0;
-       unsigned accessmode=0;
+       uint_t openfn=0;
+       uint_t accessmode=0;
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
 
@@ -303,8 +318,8 @@ int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode
        open_parms.openx.in.timeout = 0;
        open_parms.openx.in.fname = fname;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &open_parms);
-       talloc_destroy(mem_ctx);
+       status = smb_raw_open(tree, mem_ctx, &open_parms);
+       talloc_free(mem_ctx);
 
        if (NT_STATUS_IS_OK(status)) {
                return open_parms.openx.out.fnum;
@@ -317,7 +332,7 @@ int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode
 /****************************************************************************
  Close a file.
 ****************************************************************************/
-BOOL cli_close(struct cli_state *cli, int fnum)
+NTSTATUS smbcli_close(struct smbcli_tree *tree, int fnum)
 {
        union smb_close close_parms;
        NTSTATUS status;
@@ -325,16 +340,17 @@ BOOL cli_close(struct cli_state *cli, int fnum)
        close_parms.close.level = RAW_CLOSE_CLOSE;
        close_parms.close.in.fnum = fnum;
        close_parms.close.in.write_time = 0;
-       status = smb_raw_close(cli->tree, &close_parms);
-       return NT_STATUS_IS_OK(status);
+       status = smb_raw_close(tree, &close_parms);
+       return status;
 }
 
 /****************************************************************************
  send a lock with a specified locktype 
  this is used for testing LOCKING_ANDX_CANCEL_LOCK
 ****************************************************************************/
-NTSTATUS cli_locktype(struct cli_state *cli, int fnum, 
-                     uint32 offset, uint32 len, int timeout, unsigned char locktype)
+NTSTATUS smbcli_locktype(struct smbcli_tree *tree, int fnum, 
+                     uint32_t offset, uint32_t len, int timeout, 
+                     uint8_t locktype)
 {
        union smb_lock parms;
        struct smb_lock_entry lock[1];
@@ -346,12 +362,12 @@ NTSTATUS cli_locktype(struct cli_state *cli, int fnum,
        parms.lockx.in.timeout = timeout;
        parms.lockx.in.ulock_cnt = 0;
        parms.lockx.in.lock_cnt = 1;
-       lock[0].pid = cli->session->pid;
+       lock[0].pid = tree->session->pid;
        lock[0].offset = offset;
        lock[0].count = len;
        parms.lockx.in.locks = &lock[0];
 
-       status = smb_raw_lock(cli->tree, &parms);
+       status = smb_raw_lock(tree, &parms);
        
        return status;
 }
@@ -360,8 +376,9 @@ NTSTATUS cli_locktype(struct cli_state *cli, int fnum,
 /****************************************************************************
  Lock a file.
 ****************************************************************************/
-BOOL cli_lock(struct cli_state *cli, int fnum, 
-             uint32 offset, uint32 len, int timeout, enum brl_type lock_type)
+NTSTATUS smbcli_lock(struct smbcli_tree *tree, int fnum, 
+                 uint32_t offset, uint32_t len, int timeout, 
+                 enum brl_type lock_type)
 {
        union smb_lock parms;
        struct smb_lock_entry lock[1];
@@ -373,21 +390,21 @@ BOOL cli_lock(struct cli_state *cli, int fnum,
        parms.lockx.in.timeout = timeout;
        parms.lockx.in.ulock_cnt = 0;
        parms.lockx.in.lock_cnt = 1;
-       lock[0].pid = cli->session->pid;
+       lock[0].pid = tree->session->pid;
        lock[0].offset = offset;
        lock[0].count = len;
        parms.lockx.in.locks = &lock[0];
 
-       status = smb_raw_lock(cli->tree, &parms);
+       status = smb_raw_lock(tree, &parms);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
 /****************************************************************************
  Unlock a file.
 ****************************************************************************/
-BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len)
+NTSTATUS smbcli_unlock(struct smbcli_tree *tree, int fnum, uint32_t offset, uint32_t len)
 {
        union smb_lock parms;
        struct smb_lock_entry lock[1];
@@ -399,29 +416,30 @@ BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len)
        parms.lockx.in.timeout = 0;
        parms.lockx.in.ulock_cnt = 1;
        parms.lockx.in.lock_cnt = 0;
-       lock[0].pid = cli->session->pid;
+       lock[0].pid = tree->session->pid;
        lock[0].offset = offset;
        lock[0].count = len;
        parms.lockx.in.locks = &lock[0];
        
-       status = smb_raw_lock(cli->tree, &parms);
-       return NT_STATUS_IS_OK(status);
+       status = smb_raw_lock(tree, &parms);
+       return status;
 }
        
 
 /****************************************************************************
  Lock a file with 64 bit offsets.
 ****************************************************************************/
-BOOL cli_lock64(struct cli_state *cli, int fnum, 
-               SMB_OFF_T offset, SMB_OFF_T len, int timeout, enum brl_type lock_type)
+NTSTATUS smbcli_lock64(struct smbcli_tree *tree, int fnum, 
+                   off_t offset, off_t len, int timeout, 
+                   enum brl_type lock_type)
 {
        union smb_lock parms;
        int ltype;
        struct smb_lock_entry lock[1];
        NTSTATUS status;
 
-       if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
-               return cli_lock(cli, fnum, offset, len, timeout, lock_type);
+       if (!(tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
+               return smbcli_lock(tree, fnum, offset, len, timeout, lock_type);
        }
 
        parms.lockx.level = RAW_LOCK_LOCKX;
@@ -433,28 +451,29 @@ BOOL cli_lock64(struct cli_state *cli, int fnum,
        parms.lockx.in.timeout = timeout;
        parms.lockx.in.ulock_cnt = 0;
        parms.lockx.in.lock_cnt = 1;
-       lock[0].pid = cli->session->pid;
+       lock[0].pid = tree->session->pid;
        lock[0].offset = offset;
        lock[0].count = len;
        parms.lockx.in.locks = &lock[0];
 
-       status = smb_raw_lock(cli->tree, &parms);
+       status = smb_raw_lock(tree, &parms);
        
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
 /****************************************************************************
  Unlock a file with 64 bit offsets.
 ****************************************************************************/
-BOOL cli_unlock64(struct cli_state *cli, int fnum, SMB_OFF_T offset, SMB_OFF_T len)
+NTSTATUS smbcli_unlock64(struct smbcli_tree *tree, int fnum, off_t offset, 
+                        off_t len)
 {
        union smb_lock parms;
        struct smb_lock_entry lock[1];
        NTSTATUS status;
 
-       if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
-               return cli_unlock(cli, fnum, offset, len);
+       if (!(tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
+               return smbcli_unlock(tree, fnum, offset, len);
        }
 
        parms.lockx.level = RAW_LOCK_LOCKX;
@@ -463,34 +482,34 @@ BOOL cli_unlock64(struct cli_state *cli, int fnum, SMB_OFF_T offset, SMB_OFF_T l
        parms.lockx.in.timeout = 0;
        parms.lockx.in.ulock_cnt = 1;
        parms.lockx.in.lock_cnt = 0;
-       lock[0].pid = cli->session->pid;
+       lock[0].pid = tree->session->pid;
        lock[0].offset = offset;
        lock[0].count = len;
        parms.lockx.in.locks = &lock[0];
 
-       status = smb_raw_lock(cli->tree, &parms);
+       status = smb_raw_lock(tree, &parms);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
 /****************************************************************************
  Do a SMBgetattrE call.
 ****************************************************************************/
-BOOL cli_getattrE(struct cli_state *cli, int fd,
-               uint16 *attr, size_t *size,
-               time_t *c_time, time_t *a_time, time_t *m_time)
+NTSTATUS smbcli_getattrE(struct smbcli_tree *tree, int fnum,
+                     uint16_t *attr, size_t *size,
+                     time_t *c_time, time_t *a_time, time_t *m_time)
 {              
        union smb_fileinfo parms;
        NTSTATUS status;
 
        parms.getattre.level = RAW_FILEINFO_GETATTRE;
-       parms.getattre.in.fnum = fd;
+       parms.getattre.in.fnum = fnum;
 
-       status = smb_raw_fileinfo(cli->tree, NULL, &parms);
+       status = smb_raw_fileinfo(tree, NULL, &parms);
 
        if (!NT_STATUS_IS_OK(status))
-               return False;
+               return status;
 
        if (size) {
                *size = parms.getattre.out.size;
@@ -505,21 +524,21 @@ BOOL cli_getattrE(struct cli_state *cli, int fd,
        }
 
        if (a_time) {
-               *a_time = &parms.getattre.out.access_time;
+               *a_time = parms.getattre.out.access_time;
        }
 
        if (m_time) {
-               *m_time = &parms.getattre.out.write_time;
+               *m_time = parms.getattre.out.write_time;
        }
 
-       return True;
+       return status;
 }
 
 /****************************************************************************
  Do a SMBgetatr call
 ****************************************************************************/
-BOOL cli_getatr(struct cli_state *cli, const char *fname, 
-               uint16 *attr, size_t *size, time_t *t)
+NTSTATUS smbcli_getatr(struct smbcli_tree *tree, const char *fname, 
+                   uint16_t *attr, size_t *size, time_t *t)
 {
        union smb_fileinfo parms;
        NTSTATUS status;
@@ -527,10 +546,10 @@ BOOL cli_getatr(struct cli_state *cli, const char *fname,
        parms.getattr.level = RAW_FILEINFO_GETATTR;
        parms.getattr.in.fname = fname;
 
-       status = smb_raw_pathinfo(cli->tree, NULL, &parms);
+       status = smb_raw_pathinfo(tree, NULL, &parms);
        
        if (!NT_STATUS_IS_OK(status)) {
-               return False;
+               return status;
        }
 
        if (size) {
@@ -545,14 +564,15 @@ BOOL cli_getatr(struct cli_state *cli, const char *fname,
                *attr = parms.getattr.out.attrib;
        }
 
-       return True;
+       return status;
 }
 
 
 /****************************************************************************
  Do a SMBsetatr call.
 ****************************************************************************/
-BOOL cli_setatr(struct cli_state *cli, const char *fname, uint16 mode, time_t t)
+NTSTATUS smbcli_setatr(struct smbcli_tree *tree, const char *fname, uint16_t mode, 
+                   time_t t)
 {
        union smb_setfileinfo parms;
        NTSTATUS status;
@@ -562,16 +582,16 @@ BOOL cli_setatr(struct cli_state *cli, const char *fname, uint16 mode, time_t t)
        parms.setattr.in.write_time = t;
        parms.setattr.file.fname = fname;
        
-       status = smb_raw_setpathinfo(cli->tree, &parms);
+       status = smb_raw_setpathinfo(tree, &parms);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
 /****************************************************************************
  Check for existence of a dir.
 ****************************************************************************/
-BOOL cli_chkpath(struct cli_state *cli, const char *path)
+NTSTATUS smbcli_chkpath(struct smbcli_tree *tree, const char *path)
 {
        struct smb_chkpath parms;
        char *path2;
@@ -586,43 +606,43 @@ BOOL cli_chkpath(struct cli_state *cli, const char *path)
 
        parms.in.path = path2;
        
-       status = smb_raw_chkpath(cli->tree, &parms);
+       status = smb_raw_chkpath(tree, &parms);
 
        free(path2);
 
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
 /****************************************************************************
  Query disk space.
 ****************************************************************************/
-BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail)
+NTSTATUS smbcli_dskattr(struct smbcli_tree *tree, int *bsize, int *total, int *avail)
 {
        union smb_fsinfo fsinfo_parms;
        TALLOC_CTX *mem_ctx;
        NTSTATUS status;
 
-       mem_ctx = talloc_init("cli_dskattr");
+       mem_ctx = talloc_init("smbcli_dskattr");
 
        fsinfo_parms.dskattr.level = RAW_QFS_DSKATTR;
-       status = smb_raw_fsinfo(cli->tree, mem_ctx, &fsinfo_parms);
+       status = smb_raw_fsinfo(tree, mem_ctx, &fsinfo_parms);
        if (NT_STATUS_IS_OK(status)) {
                *bsize = fsinfo_parms.dskattr.out.block_size;
                *total = fsinfo_parms.dskattr.out.units_total;
                *avail = fsinfo_parms.dskattr.out.units_free;
        }
 
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
        
-       return NT_STATUS_IS_OK(status);
+       return status;
 }
 
 
 /****************************************************************************
  Create and open a temporary file.
 ****************************************************************************/
-int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
+int smbcli_ctemp(struct smbcli_tree *tree, const char *path, char **tmp_path)
 {
        union smb_open open_parms;
        TALLOC_CTX *mem_ctx;
@@ -634,15 +654,15 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
        open_parms.openx.level = RAW_OPEN_CTEMP;
        open_parms.ctemp.in.attrib = 0;
        open_parms.ctemp.in.directory = path;
+       open_parms.ctemp.in.write_time = 0;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &open_parms);
+       status = smb_raw_open(tree, mem_ctx, &open_parms);
        if (tmp_path) {
                *tmp_path = strdup(open_parms.ctemp.out.name);
        }
-       talloc_destroy(mem_ctx);
+       talloc_free(mem_ctx);
        if (NT_STATUS_IS_OK(status)) {
                return open_parms.ctemp.out.fnum;
        }
        return -1;
 }
-