diff options
author | Volker Lendecke <vl@samba.org> | 2010-10-23 09:35:49 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-10-24 11:39:30 +0200 |
commit | 94232578064e146b810f1320f67e1ab485737a17 (patch) | |
tree | 346f2cdfa0d817551a62a234e6062c316cd17e71 | |
parent | 03333fc68cf596a85fb81d202b5fdc1879928f76 (diff) | |
download | samba-94232578064e146b810f1320f67e1ab485737a17.tar.gz samba-94232578064e146b810f1320f67e1ab485737a17.tar.bz2 samba-94232578064e146b810f1320f67e1ab485737a17.zip |
s3: Add async cli_qfileinfo
-rw-r--r-- | source3/include/proto.h | 12 | ||||
-rw-r--r-- | source3/libsmb/clifile.c | 133 |
2 files changed, 145 insertions, 0 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index f935df7e3b..55e4e1b9e9 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2357,6 +2357,18 @@ NTSTATUS cli_qpathinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli, uint32_t max_rdata, uint8_t **rdata, uint32_t *num_rdata); +struct tevent_req *cli_qfileinfo_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, uint16_t fnum, + uint16_t level, uint32_t min_rdata, + uint32_t max_rdata); +NTSTATUS cli_qfileinfo_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + uint8_t **rdata, uint32_t *num_rdata); +NTSTATUS cli_qfileinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli, + uint16_t fnum, uint16_t level, uint32_t min_rdata, + uint32_t max_rdata, + uint8_t **rdata, uint32_t *num_rdata); + struct tevent_req *cli_flush_send(TALLOC_CTX *mem_ctx, struct event_context *ev, struct cli_state *cli, diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index ce8d7a593b..75762f119a 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -5265,6 +5265,139 @@ NTSTATUS cli_qpathinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli, return status; } +struct cli_qfileinfo_state { + uint16_t setup[1]; + uint8_t param[4]; + uint8_t *data; + uint32_t min_rdata; + uint8_t *rdata; + uint32_t num_rdata; +}; + +static void cli_qfileinfo_done(struct tevent_req *subreq); + +struct tevent_req *cli_qfileinfo_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, uint16_t fnum, + uint16_t level, uint32_t min_rdata, + uint32_t max_rdata) +{ + struct tevent_req *req, *subreq; + struct cli_qfileinfo_state *state; + + req = tevent_req_create(mem_ctx, &state, struct cli_qfileinfo_state); + if (req == NULL) { + return NULL; + } + state->min_rdata = min_rdata; + SSVAL(state->param, 0, fnum); + SSVAL(state->param, 2, level); + SSVAL(state->setup, 0, TRANSACT2_QFILEINFO); + + subreq = cli_trans_send( + state, /* mem ctx. */ + ev, /* event ctx. */ + cli, /* cli_state. */ + SMBtrans2, /* cmd. */ + NULL, /* pipe name. */ + -1, /* fid. */ + 0, /* function. */ + 0, /* flags. */ + state->setup, /* setup. */ + 1, /* num setup uint16_t words. */ + 0, /* max returned setup. */ + state->param, /* param. */ + sizeof(state->param), /* num param. */ + 2, /* max returned param. */ + NULL, /* data. */ + 0, /* num data. */ + max_rdata); /* max returned data. */ + + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_qfileinfo_done, req); + return req; +} + +static void cli_qfileinfo_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct cli_qfileinfo_state *state = tevent_req_data( + req, struct cli_qfileinfo_state); + NTSTATUS status; + + status = cli_trans_recv(subreq, state, NULL, NULL, 0, NULL, + NULL, 0, NULL, + &state->rdata, state->min_rdata, + &state->num_rdata); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; + } + tevent_req_done(req); +} + +NTSTATUS cli_qfileinfo_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + uint8_t **rdata, uint32_t *num_rdata) +{ + struct cli_qfileinfo_state *state = tevent_req_data( + req, struct cli_qfileinfo_state); + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + return status; + } + if (rdata != NULL) { + *rdata = talloc_move(mem_ctx, &state->rdata); + } else { + TALLOC_FREE(state->rdata); + } + if (num_rdata != NULL) { + *num_rdata = state->num_rdata; + } + return NT_STATUS_OK; +} + +NTSTATUS cli_qfileinfo(TALLOC_CTX *mem_ctx, struct cli_state *cli, + uint16_t fnum, uint16_t level, uint32_t min_rdata, + uint32_t max_rdata, + uint8_t **rdata, uint32_t *num_rdata) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev; + struct tevent_req *req; + NTSTATUS status = NT_STATUS_NO_MEMORY; + + 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; + } + ev = event_context_init(frame); + if (ev == NULL) { + goto fail; + } + req = cli_qfileinfo_send(frame, ev, cli, fnum, level, min_rdata, + max_rdata); + if (req == NULL) { + goto fail; + } + if (!tevent_req_poll_ntstatus(req, ev, &status)) { + goto fail; + } + status = cli_qfileinfo_recv(req, mem_ctx, rdata, num_rdata); + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; +} + struct cli_flush_state { uint16_t vwv[1]; }; |