diff options
author | Volker Lendecke <vl@samba.org> | 2010-07-26 10:35:15 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-07-26 23:01:38 +0200 |
commit | 2ad4b4f63ef6e8fa8f875135a4fa5764ef57c6ac (patch) | |
tree | 4aa534270efe780fe93470c9f17f105acacc2150 /source3 | |
parent | 27fb920ee8caade141cf0fd39e75afac7f4b5d0b (diff) | |
download | samba-2ad4b4f63ef6e8fa8f875135a4fa5764ef57c6ac.tar.gz samba-2ad4b4f63ef6e8fa8f875135a4fa5764ef57c6ac.tar.bz2 samba-2ad4b4f63ef6e8fa8f875135a4fa5764ef57c6ac.zip |
s3: Convert cli_qpathinfo_streams to cli_qpathinfo_send
Diffstat (limited to 'source3')
-rw-r--r-- | source3/client/client.c | 9 | ||||
-rw-r--r-- | source3/include/proto.h | 16 | ||||
-rw-r--r-- | source3/libsmb/clirap.c | 135 |
3 files changed, 110 insertions, 50 deletions
diff --git a/source3/client/client.c b/source3/client/client.c index efe733e7f4..cd41699da3 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -1598,10 +1598,11 @@ static int do_allinfo(const char *name) d_printf("attributes: %s\n", attr_str(talloc_tos(), mode)); - if (!cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams, - &streams)) { - d_printf("%s getting streams for %s\n", - cli_errstr(cli),name); + status = cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams, + &streams); + if (!NT_STATUS_IS_OK(status)) { + d_printf("%s getting streams for %s\n", nt_errstr(status), + name); return false; } diff --git a/source3/include/proto.h b/source3/include/proto.h index 03b2277fd5..16110f2cde 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2683,10 +2683,18 @@ NTSTATUS cli_qpathinfo2(struct cli_state *cli, const char *fname, struct timespec *change_time, SMB_OFF_T *size, uint16 *mode, SMB_INO_T *ino); -bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname, - TALLOC_CTX *mem_ctx, - unsigned int *pnum_streams, - struct stream_struct **pstreams); +struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + const char *fname); +NTSTATUS cli_qpathinfo_streams_recv(struct tevent_req *req, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams); +NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams); bool cli_qfilename(struct cli_state *cli, uint16_t fnum, char *name, size_t namelen); bool cli_qfileinfo(struct cli_state *cli, uint16_t fnum, uint16 *mode, SMB_OFF_T *size, diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c index f94c16d55f..56d6375973 100644 --- a/source3/libsmb/clirap.c +++ b/source3/libsmb/clirap.c @@ -905,58 +905,109 @@ static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *data, unsigned int *pnum_streams, struct stream_struct **pstreams); -bool cli_qpathinfo_streams(struct cli_state *cli, const char *fname, - TALLOC_CTX *mem_ctx, - unsigned int *pnum_streams, - struct stream_struct **pstreams) +struct cli_qpathinfo_streams_state { + uint32_t num_data; + uint8_t *data; +}; + +static void cli_qpathinfo_streams_done(struct tevent_req *subreq); + +struct tevent_req *cli_qpathinfo_streams_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct cli_state *cli, + const char *fname) { - unsigned int data_len = 0; - unsigned int param_len = 0; - uint16 setup = TRANSACT2_QPATHINFO; - char *param; - char *rparam=NULL, *rdata=NULL; - char *p; - size_t namelen = 2*(strlen(fname)+1); - bool ret; + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_qpathinfo_streams_state *state = NULL; - param = SMB_MALLOC_ARRAY(char, 6+namelen+2); - if (param == NULL) { - return false; + req = tevent_req_create(mem_ctx, &state, + struct cli_qpathinfo_streams_state); + if (req == NULL) { + return NULL; } - p = param; - memset(p, 0, 6); - SSVAL(p, 0, SMB_FILE_STREAM_INFORMATION); - p += 6; - p += clistr_push(cli, p, fname, namelen, STR_TERMINATE); + subreq = cli_qpathinfo_send(state, ev, cli, fname, + SMB_FILE_STREAM_INFORMATION, + 0, cli->max_xmit); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_qpathinfo_streams_done, req); + return req; +} - param_len = PTR_DIFF(p, param); +static void cli_qpathinfo_streams_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct cli_qpathinfo_streams_state *state = tevent_req_data( + req, struct cli_qpathinfo_streams_state); + NTSTATUS status; - if (!cli_send_trans(cli, SMBtrans2, - NULL, /* name */ - -1, 0, /* fid, flags */ - &setup, 1, 0, /* setup, len, max */ - param, param_len, 10, /* param, len, max */ - NULL, data_len, cli->max_xmit /* data, len, max */ - )) { - return false; + 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); +} - if (!cli_receive_trans(cli, SMBtrans2, - &rparam, ¶m_len, - &rdata, &data_len)) { - return false; - } +NTSTATUS cli_qpathinfo_streams_recv(struct tevent_req *req, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams) +{ + struct cli_qpathinfo_streams_state *state = tevent_req_data( + req, struct cli_qpathinfo_streams_state); + NTSTATUS status; - if (!rdata) { - SAFE_FREE(rparam); - return false; + if (tevent_req_is_nterror(req, &status)) { + return status; + } + if (!parse_streams_blob(mem_ctx, state->data, state->num_data, + pnum_streams, pstreams)) { + return NT_STATUS_INVALID_NETWORK_RESPONSE; } + return NT_STATUS_OK; +} - ret = parse_streams_blob(mem_ctx, (uint8_t *)rdata, data_len, - pnum_streams, pstreams); - SAFE_FREE(rdata); - SAFE_FREE(rparam); - return ret; +NTSTATUS cli_qpathinfo_streams(struct cli_state *cli, const char *fname, + TALLOC_CTX *mem_ctx, + unsigned int *pnum_streams, + struct stream_struct **pstreams) +{ + 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_qpathinfo_streams_send(frame, ev, cli, fname); + if (req == NULL) { + goto fail; + } + if (!tevent_req_poll_ntstatus(req, ev, &status)) { + goto fail; + } + status = cli_qpathinfo_streams_recv(req, mem_ctx, pnum_streams, + pstreams); + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } static bool parse_streams_blob(TALLOC_CTX *mem_ctx, const uint8_t *rdata, |