s3: Convert cli_get_ea_list_path to cli_qpathinfo_send
authorVolker Lendecke <vl@samba.org>
Sun, 25 Jul 2010 19:32:13 +0000 (21:32 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 25 Jul 2010 20:29:44 +0000 (22:29 +0200)
source3/include/proto.h
source3/libsmb/clifile.c
source3/torture/torture.c

index 51d0c1788d9370505743be392b3dbac679f38b3b..3759a78c723e4cf38583a0d957794329d98800e6 100644 (file)
@@ -2466,7 +2466,13 @@ NTSTATUS cli_ctemp(struct cli_state *cli,
 NTSTATUS cli_raw_ioctl(struct cli_state *cli, uint16_t fnum, uint32_t code, DATA_BLOB *blob);
 bool cli_set_ea_path(struct cli_state *cli, const char *path, const char *ea_name, const char *ea_val, size_t ea_len);
 bool cli_set_ea_fnum(struct cli_state *cli, uint16_t fnum, const char *ea_name, const char *ea_val, size_t ea_len);
-bool cli_get_ea_list_path(struct cli_state *cli, const char *path,
+struct tevent_req *cli_get_ea_list_path_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct cli_state *cli,
+                                            const char *fname);
+NTSTATUS cli_get_ea_list_path_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                  size_t *pnum_eas, struct ea_struct **peas);
+NTSTATUS cli_get_ea_list_path(struct cli_state *cli, const char *path,
                TALLOC_CTX *ctx,
                size_t *pnum_eas,
                struct ea_struct **pea_list);
index 93e926492b6751e65914516bb9d28afbf75b2f2b..319812357ab1ace81c850e1d632cf803c6d85897 100644 (file)
@@ -4329,32 +4329,106 @@ fail:
  Get an extended attribute list from a pathname.
 *********************************************************/
 
-bool cli_get_ea_list_path(struct cli_state *cli, const char *path,
+struct cli_get_ea_list_path_state {
+       uint32_t num_data;
+       uint8_t *data;
+};
+
+static void cli_get_ea_list_path_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_get_ea_list_path_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct cli_state *cli,
+                                            const char *fname)
+{
+       struct tevent_req *req, *subreq;
+       struct cli_get_ea_list_path_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct cli_get_ea_list_path_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       subreq = cli_qpathinfo_send(state, ev, cli, fname,
+                                   SMB_INFO_QUERY_ALL_EAS, 4,
+                                   cli->max_xmit);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, cli_get_ea_list_path_done, req);
+       return req;
+}
+
+static void cli_get_ea_list_path_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                               subreq, struct tevent_req);
+       struct cli_get_ea_list_path_state *state = tevent_req_data(
+               req, struct cli_get_ea_list_path_state);
+       NTSTATUS status;
+
+       status = cli_qpathinfo_recv(subreq, state, &state->data,
+                                   &state->num_data);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS cli_get_ea_list_path_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
+                                  size_t *pnum_eas, struct ea_struct **peas)
+{
+       struct cli_get_ea_list_path_state *state = tevent_req_data(
+               req, struct cli_get_ea_list_path_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               return status;
+       }
+       if (!parse_ea_blob(mem_ctx, state->data, state->num_data,
+                          pnum_eas, peas)) {
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+       return NT_STATUS_OK;
+}
+
+NTSTATUS cli_get_ea_list_path(struct cli_state *cli, const char *path,
                TALLOC_CTX *ctx,
                size_t *pnum_eas,
                struct ea_struct **pea_list)
 {
-       uint16_t setup = TRANSACT2_QPATHINFO;
-       unsigned int param_len = 0;
-       char *param;
-       char *p;
-       size_t srclen = 2*(strlen(path)+1);
-       bool ret;
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct event_context *ev = NULL;
+       struct tevent_req *req = NULL;
+       NTSTATUS status = NT_STATUS_NO_MEMORY;
 
-       param = SMB_MALLOC_ARRAY(char, 6+srclen+2);
-       if (!param) {
-               return false;
+       if (cli_has_async_calls(cli)) {
+               /*
+                * Can't use sync call while an async call is in flight
+                */
+               status = NT_STATUS_INVALID_PARAMETER;
+               goto fail;
        }
-       p = param;
-       memset(p, 0, 6);
-       SSVAL(p, 0, SMB_INFO_QUERY_ALL_EAS);
-       p += 6;
-       p += clistr_push(cli, p, path, srclen, STR_TERMINATE);
-       param_len = PTR_DIFF(p, param);
-
-       ret = cli_get_ea_list(cli, setup, param, param_len, ctx, pnum_eas, pea_list);
-       SAFE_FREE(param);
-       return ret;
+       ev = event_context_init(frame);
+       if (ev == NULL) {
+               goto fail;
+       }
+       req = cli_get_ea_list_path_send(frame, ev, cli, path);
+       if (req == NULL) {
+               goto fail;
+       }
+       if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+               goto fail;
+       }
+       status = cli_get_ea_list_path_recv(req, ctx, pnum_eas, pea_list);
+ fail:
+       TALLOC_FREE(frame);
+       if (!NT_STATUS_IS_OK(status)) {
+               cli_set_error(cli, status);
+       }
+       return status;
 }
 
 /*********************************************************
index be9cfccf98fc2966b56329a66cb56a610ac27f40..f958817320dbdbf3b04020652ae8cb7f93d6d841 100644 (file)
@@ -5009,6 +5009,7 @@ static bool run_eatest(int dummy)
        size_t num_eas;
        struct ea_struct *ea_list = NULL;
        TALLOC_CTX *mem_ctx = talloc_init("eatest");
+       NTSTATUS status;
 
        printf("starting eatest\n");
 
@@ -5052,8 +5053,9 @@ static bool run_eatest(int dummy)
                }
        }
 
-       if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
-               printf("ea_get list failed - %s\n", cli_errstr(cli));
+       status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ea_get list failed - %s\n", nt_errstr(status));
                correct = False;
        }
 
@@ -5087,8 +5089,9 @@ static bool run_eatest(int dummy)
        }
 #endif
 
-       if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
-               printf("ea_get list failed - %s\n", cli_errstr(cli));
+       status = cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("ea_get list failed - %s\n", nt_errstr(status));
                correct = False;
        }