summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-03-29 20:00:58 +0200
committerVolker Lendecke <vl@samba.org>2009-04-06 21:32:07 +0200
commitca7cd350a6ac47b981d6c9a8b671f4c18642a9f2 (patch)
tree38989acd99ebb4029b6e0f107099b3828a8f4ab1 /source3
parent807328ce6d9dea481995a9f6e86f2b60f4ca4c00 (diff)
downloadsamba-ca7cd350a6ac47b981d6c9a8b671f4c18642a9f2.tar.gz
samba-ca7cd350a6ac47b981d6c9a8b671f4c18642a9f2.tar.bz2
samba-ca7cd350a6ac47b981d6c9a8b671f4c18642a9f2.zip
Convert cli_ntcreate to tevent_req
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h24
-rw-r--r--source3/libsmb/clifile.c106
-rw-r--r--source3/rpc_client/rpc_transport_np.c15
3 files changed, 88 insertions, 57 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index b8ea5d6adc..b8353d51c9 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2488,18 +2488,18 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname,
uint32 FileAttributes, uint32 ShareAccess,
uint32 CreateDisposition, uint32 CreateOptions,
uint8 SecuityFlags);
-struct async_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
- struct cli_state *cli,
- const char *fname,
- uint32_t CreatFlags,
- uint32_t DesiredAccess,
- uint32_t FileAttributes,
- uint32_t ShareAccess,
- uint32_t CreateDisposition,
- uint32_t CreateOptions,
- uint8_t SecurityFlags);
-NTSTATUS cli_ntcreate_recv(struct async_req *req, uint16_t *pfnum);
+struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname,
+ uint32_t CreatFlags,
+ uint32_t DesiredAccess,
+ uint32_t FileAttributes,
+ uint32_t ShareAccess,
+ uint32_t CreateDisposition,
+ uint32_t CreateOptions,
+ uint8_t SecurityFlags);
+NTSTATUS cli_ntcreate_recv(struct tevent_req *req, uint16_t *pfnum);
NTSTATUS cli_ntcreate(struct cli_state *cli,
const char *fname,
uint32_t CreatFlags,
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 0703f04c5f..3d0e3ec957 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -771,22 +771,36 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname,
return SVAL(cli->inbuf,smb_vwv2 + 1);
}
-struct async_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
- struct event_context *ev,
- struct cli_state *cli,
- const char *fname,
- uint32_t CreatFlags,
- uint32_t DesiredAccess,
- uint32_t FileAttributes,
- uint32_t ShareAccess,
- uint32_t CreateDisposition,
- uint32_t CreateOptions,
- uint8_t SecurityFlags)
+struct cli_ntcreate_state {
+ uint16_t vwv[24];
+ uint16_t fnum;
+};
+
+static void cli_ntcreate_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname,
+ uint32_t CreatFlags,
+ uint32_t DesiredAccess,
+ uint32_t FileAttributes,
+ uint32_t ShareAccess,
+ uint32_t CreateDisposition,
+ uint32_t CreateOptions,
+ uint8_t SecurityFlags)
{
- struct async_req *result;
+ struct tevent_req *req, *subreq;
+ struct cli_ntcreate_state *state;
+ uint16_t *vwv;
uint8_t *bytes;
size_t converted_len;
- uint16_t vwv[24];
+
+ req = tevent_req_create(mem_ctx, &state, struct cli_ntcreate_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ vwv = state->vwv;
SCVAL(vwv+0, 0, 0xFF);
SCVAL(vwv+0, 1, 0);
@@ -808,7 +822,7 @@ struct async_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
SIVAL(vwv+21, 1, 0x02); /* ImpersonationLevel */
SCVAL(vwv+23, 1, SecurityFlags);
- bytes = talloc_array(talloc_tos(), uint8_t, 0);
+ bytes = talloc_array(state, uint8_t, 0);
bytes = smb_bytes_push_str(bytes, cli_ucs2(cli),
fname, strlen(fname)+1,
&converted_len);
@@ -816,41 +830,53 @@ struct async_req *cli_ntcreate_send(TALLOC_CTX *mem_ctx,
/* sigh. this copes with broken netapp filer behaviour */
bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), "", 1, NULL);
- if (bytes == NULL) {
- return NULL;
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
}
SIVAL(vwv+2, 1, converted_len);
- result = cli_request_send(mem_ctx, ev, cli, SMBntcreateX, 0,
- 24, vwv, 0, talloc_get_size(bytes), bytes);
- TALLOC_FREE(bytes);
- return result;
+ subreq = cli_smb_send(state, ev, cli, SMBntcreateX, 0, 24, vwv,
+ talloc_get_size(bytes), bytes);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, cli_ntcreate_done, req);
+ return req;
}
-NTSTATUS cli_ntcreate_recv(struct async_req *req, uint16_t *pfnum)
+static void cli_ntcreate_done(struct tevent_req *subreq)
{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cli_ntcreate_state *state = tevent_req_data(
+ req, struct cli_ntcreate_state);
uint8_t wct;
uint16_t *vwv;
- uint16_t num_bytes;
+ uint32_t num_bytes;
uint8_t *bytes;
NTSTATUS status;
- if (async_req_is_nterror(req, &status)) {
- return status;
- }
-
- status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
+ status = cli_smb_recv(subreq, 3, &wct, &vwv, &num_bytes, &bytes);
if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- if (wct < 3) {
- return NT_STATUS_INVALID_NETWORK_RESPONSE;
+ TALLOC_FREE(subreq);
+ tevent_req_nterror(req, status);
+ return;
}
+ state->fnum = SVAL(vwv+2, 1);
+ tevent_req_done(req);
+}
- *pfnum = SVAL(vwv+2, 1);
+NTSTATUS cli_ntcreate_recv(struct tevent_req *req, uint16_t *pfnum)
+{
+ struct cli_ntcreate_state *state = tevent_req_data(
+ req, struct cli_ntcreate_state);
+ NTSTATUS status;
+ if (tevent_req_is_nterror(req, &status)) {
+ return status;
+ }
+ *pfnum = state->fnum;
return NT_STATUS_OK;
}
@@ -867,10 +893,10 @@ NTSTATUS cli_ntcreate(struct cli_state *cli,
{
TALLOC_CTX *frame = talloc_stackframe();
struct event_context *ev;
- struct async_req *req;
- NTSTATUS status;
+ struct tevent_req *req;
+ NTSTATUS status = NT_STATUS_OK;
- if (cli->fd_event != NULL) {
+ if (cli_has_async_calls(cli)) {
/*
* Can't use sync call while an async call is in flight
*/
@@ -893,13 +919,17 @@ NTSTATUS cli_ntcreate(struct cli_state *cli,
goto fail;
}
- while (req->state < ASYNC_REQ_DONE) {
- event_loop_once(ev);
+ if (!tevent_req_poll(req, ev)) {
+ status = map_nt_error_from_unix(errno);
+ goto fail;
}
status = cli_ntcreate_recv(req, pfid);
fail:
TALLOC_FREE(frame);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli_set_error(cli, status);
+ }
return status;
}
diff --git a/source3/rpc_client/rpc_transport_np.c b/source3/rpc_client/rpc_transport_np.c
index 2a277a2462..e6de8396a8 100644
--- a/source3/rpc_client/rpc_transport_np.c
+++ b/source3/rpc_client/rpc_transport_np.c
@@ -278,14 +278,15 @@ struct rpc_transport_np_init_state {
struct rpc_transport_np_state *transport_np;
};
-static void rpc_transport_np_init_pipe_open(struct async_req *subreq);
+static void rpc_transport_np_init_pipe_open(struct tevent_req *subreq);
struct async_req *rpc_transport_np_init_send(TALLOC_CTX *mem_ctx,
struct event_context *ev,
struct cli_state *cli,
const struct ndr_syntax_id *abstract_syntax)
{
- struct async_req *result, *subreq;
+ struct async_req *result;
+ struct tevent_req *subreq;
struct rpc_transport_np_init_state *state;
if (!async_req_setup(mem_ctx, &result, &state,
@@ -315,8 +316,8 @@ struct async_req *rpc_transport_np_init_send(TALLOC_CTX *mem_ctx,
if (subreq == NULL) {
goto fail;
}
- subreq->async.fn = rpc_transport_np_init_pipe_open;
- subreq->async.priv = result;
+ tevent_req_set_callback(subreq, rpc_transport_np_init_pipe_open,
+ result);
return result;
fail:
@@ -324,10 +325,10 @@ struct async_req *rpc_transport_np_init_send(TALLOC_CTX *mem_ctx,
return NULL;
}
-static void rpc_transport_np_init_pipe_open(struct async_req *subreq)
+static void rpc_transport_np_init_pipe_open(struct tevent_req *subreq)
{
- struct async_req *req = talloc_get_type_abort(
- subreq->async.priv, struct async_req);
+ struct async_req *req = tevent_req_callback_data(
+ subreq, struct async_req);
struct rpc_transport_np_init_state *state = talloc_get_type_abort(
req->private_data, struct rpc_transport_np_init_state);
NTSTATUS status;