Merge 2610c05b5b95cc7036b3d6dfb894c6cfbdb68483 as Samba-4.0alpha16
[amitay/samba.git] / source3 / libsmb / clilist.c
index 280f876ba74f90d2d0ce670b633f14a1bd99adff..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.
@@ -318,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);
        }
@@ -384,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)) {
@@ -449,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;
        }
@@ -469,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();
@@ -504,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;
 }
 
@@ -570,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);
        }
@@ -651,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;
@@ -708,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;
@@ -733,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;
@@ -795,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)
 {
@@ -830,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;
 }
 
@@ -911,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();
@@ -952,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;
 }