s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / libsmb / clilist.c
index 29b16cb1c5f50e0b8be41c995e05bc1e8dbb4063..9eec97fbeb1f6bb376c87c5f54ff9ca1cce5acdd 100644 (file)
 */
 
 #include "includes.h"
+#include "libsmb/libsmb.h"
+#include "../lib/util/tevent_ntstatus.h"
+#include "async_smb.h"
+#include "trans2.h"
 
 /****************************************************************************
  Calculate a safe next_entry_offset.
@@ -317,7 +321,7 @@ static struct tevent_req *cli_list_old_send(TALLOC_CTX *mem_ctx,
        bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), mask,
                                   strlen(mask)+1, NULL);
 
-       bytes = smb_bytes_push_bytes(bytes, 5, (uint8_t *)&zero, 2);
+       bytes = smb_bytes_push_bytes(bytes, 5, (const uint8_t *)&zero, 2);
        if (tevent_req_nomem(bytes, req)) {
                return tevent_req_post(req, ev);
        }
@@ -383,7 +387,7 @@ static void cli_list_old_done(struct tevent_req *subreq)
 
                dirlist_len = talloc_get_size(state->dirlist);
 
-               tmp = TALLOC_REALLOC_ARRAY(
+               tmp = talloc_realloc(
                        state, state->dirlist, uint8_t,
                        dirlist_len + received * DIR_STRUCT_SIZE);
                if (tevent_req_nomem(tmp, req)) {
@@ -448,7 +452,7 @@ static NTSTATUS cli_list_old_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 
        num_received = talloc_array_length(state->dirlist) / DIR_STRUCT_SIZE;
 
-       finfo = TALLOC_ARRAY(mem_ctx, struct file_info, num_received);
+       finfo = talloc_array(mem_ctx, struct file_info, num_received);
        if (finfo == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -468,7 +472,7 @@ static NTSTATUS cli_list_old_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 
 NTSTATUS cli_list_old(struct cli_state *cli, const char *mask,
                      uint16 attribute,
-                     void (*fn)(const char *, struct file_info *,
+                     NTSTATUS (*fn)(const char *, struct file_info *,
                                 const char *, void *), void *state)
 {
        TALLOC_CTX *frame = talloc_stackframe();
@@ -503,13 +507,13 @@ NTSTATUS cli_list_old(struct cli_state *cli, const char *mask,
        }
        num_finfo = talloc_array_length(finfo);
        for (i=0; i<num_finfo; i++) {
-               fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+               status = fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
        }
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -569,7 +573,7 @@ static struct tevent_req *cli_list_trans_send(TALLOC_CTX *mem_ctx,
        state->setup[0] = TRANSACT2_FINDFIRST;
 
        nlen = 2*(strlen(mask)+1);
-       state->param = TALLOC_ARRAY(state, uint8_t, 12+nlen+2);
+       state->param = talloc_array(state, uint8_t, 12+nlen+2);
        if (tevent_req_nomem(state->param, req)) {
                return tevent_req_post(req, ev);
        }
@@ -618,10 +622,10 @@ static void cli_list_trans_done(struct tevent_req *subreq)
        int ff_searchcount;
        bool ff_eos;
        char *p, *p2;
-       uint32_t resume_key;
+       uint32_t resume_key = 0;
        int i;
        DATA_BLOB last_name_raw;
-       struct file_info *finfo;
+       struct file_info *finfo = NULL;
        size_t nlen, param_len;
 
        min_param = (state->first ? 6 : 4);
@@ -650,7 +654,7 @@ static void cli_list_trans_done(struct tevent_req *subreq)
 
        old_num_finfo = talloc_array_length(state->finfo);
 
-       tmp = TALLOC_REALLOC_ARRAY(state, state->finfo, struct file_info,
+       tmp = talloc_realloc(state, state->finfo, struct file_info,
                                   old_num_finfo + ff_searchcount);
        if (tevent_req_nomem(tmp, req)) {
                return;
@@ -707,7 +711,7 @@ static void cli_list_trans_done(struct tevent_req *subreq)
        /*
         * Shrink state->finfo to the real length we received
         */
-       tmp = TALLOC_REALLOC_ARRAY(state, state->finfo, struct file_info,
+       tmp = talloc_realloc(state, state->finfo, struct file_info,
                                   old_num_finfo + i);
        if (tevent_req_nomem(tmp, req)) {
                return;
@@ -732,7 +736,7 @@ static void cli_list_trans_done(struct tevent_req *subreq)
 
        nlen = 2*(strlen(state->mask) + 1);
 
-       param = TALLOC_REALLOC_ARRAY(state, state->param, uint8_t,
+       param = talloc_realloc(state, state->param, uint8_t,
                                     12 + nlen + last_name_raw.length + 2);
        if (tevent_req_nomem(param, req)) {
                return;
@@ -794,7 +798,7 @@ static NTSTATUS cli_list_trans_recv(struct tevent_req *req,
 
 NTSTATUS cli_list_trans(struct cli_state *cli, const char *mask,
                        uint16_t attribute, int info_level,
-                       void (*fn)(const char *mnt, struct file_info *finfo,
+                       NTSTATUS (*fn)(const char *mnt, struct file_info *finfo,
                                   const char *mask, void *private_data),
                        void *private_data)
 {
@@ -802,7 +806,7 @@ NTSTATUS cli_list_trans(struct cli_state *cli, const char *mask,
        struct event_context *ev;
        struct tevent_req *req;
        int i, num_finfo;
-       struct file_info *finfo;
+       struct file_info *finfo = NULL;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
 
        if (cli_has_async_calls(cli)) {
@@ -829,13 +833,13 @@ NTSTATUS cli_list_trans(struct cli_state *cli, const char *mask,
        }
        num_finfo = talloc_array_length(finfo);
        for (i=0; i<num_finfo; i++) {
-               fn(cli->dfs_mountpoint, &finfo[i], mask, private_data);
+               status = fn(cli->dfs_mountpoint, &finfo[i], mask, private_data);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
        }
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }
 
@@ -910,7 +914,7 @@ NTSTATUS cli_list_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 }
 
 NTSTATUS cli_list(struct cli_state *cli, const char *mask, uint16 attribute,
-                 void (*fn)(const char *, struct file_info *, const char *,
+                 NTSTATUS (*fn)(const char *, struct file_info *, const char *,
                             void *), void *state)
 {
        TALLOC_CTX *frame = talloc_stackframe();
@@ -951,12 +955,12 @@ NTSTATUS cli_list(struct cli_state *cli, const char *mask, uint16 attribute,
        }
 
        for (i=0; i<num_finfo; i++) {
-               fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+               status = fn(cli->dfs_mountpoint, &finfo[i], mask, state);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
        }
  fail:
        TALLOC_FREE(frame);
-       if (!NT_STATUS_IS_OK(status)) {
-               cli_set_error(cli, status);
-       }
        return status;
 }