Decouple clistr_pull from struct cli_state->inbuf
[metze/samba/wip.git] / source3 / libsmb / clifile.c
index dfb0ce8c111fc3854e4f7a78db8cd8c646d336fa..02cd2108bf2878af1a314720bb87617fa048860d 100644 (file)
@@ -66,7 +66,7 @@ static bool cli_link_internal(struct cli_state *cli, const char *oldname, const
                        -1, 0,                          /* fid, flags */
                        &setup, 1, 0,                   /* setup, length, max */
                        param, param_len, 2,            /* param, length, max */
-                       (char *)&data,  data_len, cli->max_xmit /* data, length, max */
+                       data,  data_len, cli->max_xmit /* data, length, max */
                        )) {
                SAFE_FREE(data);
                SAFE_FREE(param);
@@ -781,12 +781,17 @@ int cli_nt_create(struct cli_state *cli, const char *fname, uint32 DesiredAccess
                                FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0);
 }
 
-static uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
+uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
 {
-       size_t buflen = talloc_get_size(buf);
+       size_t buflen;
        char *converted;
        size_t converted_size;
 
+       if (buf == NULL) {
+               return NULL;
+       }
+
+       buflen = talloc_get_size(buf);
        /*
         * We're pushing into an SMB buffer, align odd
         */
@@ -809,6 +814,7 @@ static uint8_t *smb_bytes_push_str(uint8_t *buf, bool ucs2, const char *str)
        buf = TALLOC_REALLOC_ARRAY(NULL, buf, uint8_t,
                                   buflen + converted_size);
        if (buf == NULL) {
+               TALLOC_FREE(converted);
                return NULL;
        }
 
@@ -895,27 +901,33 @@ struct async_req *cli_open_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        }
 
        result = cli_request_send(mem_ctx, ev, cli, SMBopenX, additional_flags,
-                                 15, vwv, talloc_get_size(bytes), bytes);
+                                 15, vwv, 0, talloc_get_size(bytes), bytes);
        TALLOC_FREE(bytes);
        return result;
 }
 
 NTSTATUS cli_open_recv(struct async_req *req, int *fnum)
 {
-       struct cli_request *cli_req = cli_request_get(req);
+       uint8_t wct;
+       uint16_t *vwv;
+       uint16_t num_bytes;
+       uint8_t *bytes;
        NTSTATUS status;
 
-       SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
-       if (req->state == ASYNC_REQ_ERROR) {
-               return req->status;
+       if (async_req_is_error(req, &status)) {
+               return status;
        }
 
-       status = cli_pull_error(cli_req->inbuf);
+       status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       *fnum = SVAL(cli_req->inbuf, smb_vwv2);
+       if (wct < 3) {
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+
+       *fnum = SVAL(vwv+2, 0);
 
        return NT_STATUS_OK;
 }
@@ -968,20 +980,23 @@ struct async_req *cli_close_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
        SSVAL(vwv+0, 0, fnum);
        SIVALS(vwv+1, 0, -1);
 
-       return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv,
+       return cli_request_send(mem_ctx, ev, cli, SMBclose, 0, 3, vwv, 0,
                                0, NULL);
 }
 
 NTSTATUS cli_close_recv(struct async_req *req)
 {
-       struct cli_request *cli_req = cli_request_get(req);
+       uint8_t wct;
+       uint16_t *vwv;
+       uint16_t num_bytes;
+       uint8_t *bytes;
+       NTSTATUS status;
 
-       SMB_ASSERT(req->state >= ASYNC_REQ_DONE);
-       if (req->state == ASYNC_REQ_ERROR) {
-               return req->status;
+       if (async_req_is_error(req, &status)) {
+               return status;
        }
 
-       return cli_pull_error(cli_req->inbuf);
+       return cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
 }
 
 bool cli_close(struct cli_state *cli, int fnum)
@@ -1224,7 +1239,7 @@ bool cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len)
 ****************************************************************************/
 
 bool cli_lock64(struct cli_state *cli, int fnum,
-               SMB_BIG_UINT offset, SMB_BIG_UINT len, int timeout, enum brl_type lock_type)
+               uint64_t offset, uint64_t len, int timeout, enum brl_type lock_type)
 {
        char *p;
         int saved_timeout = cli->timeout;
@@ -1284,7 +1299,7 @@ bool cli_lock64(struct cli_state *cli, int fnum,
  Unlock a file with 64 bit offsets.
 ****************************************************************************/
 
-bool cli_unlock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len)
+bool cli_unlock64(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len)
 {
        char *p;
 
@@ -1331,7 +1346,7 @@ bool cli_unlock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_
 ****************************************************************************/
 
 static bool cli_posix_lock_internal(struct cli_state *cli, int fnum,
-               SMB_BIG_UINT offset, SMB_BIG_UINT len, bool wait_lock, enum brl_type lock_type)
+               uint64_t offset, uint64_t len, bool wait_lock, enum brl_type lock_type)
 {
        unsigned int param_len = 4;
        unsigned int data_len = POSIX_LOCK_DATA_SIZE;
@@ -1402,7 +1417,7 @@ static bool cli_posix_lock_internal(struct cli_state *cli, int fnum,
 ****************************************************************************/
 
 bool cli_posix_lock(struct cli_state *cli, int fnum,
-                       SMB_BIG_UINT offset, SMB_BIG_UINT len,
+                       uint64_t offset, uint64_t len,
                        bool wait_lock, enum brl_type lock_type)
 {
        if (lock_type != READ_LOCK && lock_type != WRITE_LOCK) {
@@ -1415,7 +1430,7 @@ bool cli_posix_lock(struct cli_state *cli, int fnum,
  POSIX Unlock a file.
 ****************************************************************************/
 
-bool cli_posix_unlock(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len)
+bool cli_posix_unlock(struct cli_state *cli, int fnum, uint64_t offset, uint64_t len)
 {
        return cli_posix_lock_internal(cli, fnum, offset, len, False, UNLOCK_LOCK);
 }
@@ -1424,7 +1439,7 @@ bool cli_posix_unlock(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_
  POSIX Get any lock covering a file.
 ****************************************************************************/
 
-bool cli_posix_getlock(struct cli_state *cli, int fnum, SMB_BIG_UINT *poffset, SMB_BIG_UINT *plen)
+bool cli_posix_getlock(struct cli_state *cli, int fnum, uint64_t *poffset, uint64_t *plen)
 {
        return True;
 }
@@ -1736,7 +1751,7 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
                if (!path2) {
                        return -1;
                }
-               clistr_pull(cli, path2, p,
+               clistr_pull(cli->inbuf, path2, p,
                            len+1, len, STR_ASCII);
                *tmp_path = path2;
        }
@@ -1882,7 +1897,7 @@ bool cli_set_ea_fnum(struct cli_state *cli, int fnum, const char *ea_name, const
 }
 
 /*********************************************************
- Get an extended attribute list tility fn.
+ Get an extended attribute list utility fn.
 *********************************************************/
 
 static bool cli_get_ea_list(struct cli_state *cli,