diff options
author | Jeremy Allison <jra@samba.org> | 2009-04-29 10:48:16 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-04-29 10:48:16 -0700 |
commit | edd25980b03c5fac154967e51705ac1cdb8d4091 (patch) | |
tree | 797e10e71a7f42b0593ed9b3a28dd03d5ac87fe5 /source3/libsmb | |
parent | 8aa41bdeb21d087cba1ab20bd2a4bd69cd519881 (diff) | |
download | samba-edd25980b03c5fac154967e51705ac1cdb8d4091.tar.gz samba-edd25980b03c5fac154967e51705ac1cdb8d4091.tar.bz2 samba-edd25980b03c5fac154967e51705ac1cdb8d4091.zip |
More async calls in libsmb/clifile.c
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/clifile.c | 220 |
1 files changed, 170 insertions, 50 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index 97bc4d1414..e055a88000 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -552,84 +552,204 @@ NTSTATUS cli_rename(struct cli_state *cli, const char *fname_src, const char *fn NT Rename a file. ****************************************************************************/ -bool cli_ntrename(struct cli_state *cli, const char *fname_src, const char *fname_dst) +static void cli_ntrename_done(struct tevent_req *subreq); + +struct cli_ntrename_state { + uint16_t vwv[4]; +}; + +static struct tevent_req *cli_ntrename_send_internal(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + const char *fname_src, + const char *fname_dst, + uint16_t rename_flag) { - char *p; + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_ntrename_state *state = NULL; + uint8_t additional_flags = 0; + uint8_t *bytes = NULL; - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); + req = tevent_req_create(mem_ctx, &state, struct cli_ntrename_state); + if (req == NULL) { + return NULL; + } - cli_set_message(cli->outbuf, 4, 0, true); + SSVAL(state->vwv+0, 0 ,aSYSTEM | aHIDDEN | aDIR); + SSVAL(state->vwv+1, 0, rename_flag); - SCVAL(cli->outbuf,smb_com,SMBntrename); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); + bytes = talloc_array(state, uint8_t, 1); + if (tevent_req_nomem(bytes, req)) { + return tevent_req_post(req, ev); + } + bytes[0] = 4; + bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_src, + strlen(fname_src)+1, NULL); + if (tevent_req_nomem(bytes, req)) { + return tevent_req_post(req, ev); + } - SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN | aDIR); - SSVAL(cli->outbuf,smb_vwv1, RENAME_FLAG_RENAME); + bytes = TALLOC_REALLOC_ARRAY(state, bytes, uint8_t, + talloc_get_size(bytes)+1); + if (tevent_req_nomem(bytes, req)) { + return tevent_req_post(req, ev); + } - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, fname_src, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); - *p++ = 4; - p += clistr_push(cli, p, fname_dst, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); + bytes[talloc_get_size(bytes)-1] = 4; + bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname_dst, + strlen(fname_dst)+1, NULL); + if (tevent_req_nomem(bytes, req)) { + return tevent_req_post(req, ev); + } - cli_setup_bcc(cli, p); + subreq = cli_smb_send(state, ev, cli, SMBntrename, additional_flags, + 4, state->vwv, talloc_get_size(bytes), bytes); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, cli_ntrename_done, req); + return req; +} - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return false; +struct tevent_req *cli_ntrename_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + const char *fname_src, + const char *fname_dst) +{ + return cli_ntrename_send_internal(mem_ctx, + ev, + cli, + fname_src, + fname_dst, + RENAME_FLAG_RENAME); +} + +static void cli_ntrename_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + NTSTATUS status; + + status = cli_smb_recv(subreq, 0, NULL, NULL, NULL, NULL); + TALLOC_FREE(subreq); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; } + tevent_req_done(req); +} - if (cli_is_error(cli)) { - return false; +NTSTATUS cli_ntrename_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} + +NTSTATUS cli_ntrename(struct cli_state *cli, const char *fname_src, const char *fname_dst) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev; + struct tevent_req *req; + NTSTATUS status = NT_STATUS_OK; + + 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; } - return true; + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } + + req = cli_ntrename_send(frame, ev, cli, fname_src, fname_dst); + if (req == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } + + if (!tevent_req_poll(req, ev)) { + status = map_nt_error_from_unix(errno); + goto fail; + } + + status = cli_ntrename_recv(req); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } /**************************************************************************** NT hardlink a file. ****************************************************************************/ -bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst) +struct tevent_req *cli_nt_hardlink_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli, + const char *fname_src, + const char *fname_dst) { - char *p; - - memset(cli->outbuf,'\0',smb_size); - memset(cli->inbuf,'\0',smb_size); - - cli_set_message(cli->outbuf, 4, 0, true); + return cli_ntrename_send_internal(mem_ctx, + ev, + cli, + fname_src, + fname_dst, + RENAME_FLAG_HARD_LINK); +} - SCVAL(cli->outbuf,smb_com,SMBntrename); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); +NTSTATUS cli_nt_hardlink_recv(struct tevent_req *req) +{ + return tevent_req_simple_recv_ntstatus(req); +} - SSVAL(cli->outbuf,smb_vwv0,aSYSTEM | aHIDDEN | aDIR); - SSVAL(cli->outbuf,smb_vwv1, RENAME_FLAG_HARD_LINK); +NTSTATUS cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev; + struct tevent_req *req; + NTSTATUS status = NT_STATUS_OK; - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, fname_src, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); - *p++ = 4; - p += clistr_push(cli, p, fname_dst, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); + 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; + } - cli_setup_bcc(cli, p); + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - return false; + req = cli_nt_hardlink_send(frame, ev, cli, fname_src, fname_dst); + if (req == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; } - if (cli_is_error(cli)) { - return false; + if (!tevent_req_poll(req, ev)) { + status = map_nt_error_from_unix(errno); + goto fail; } - return true; + status = cli_nt_hardlink_recv(req); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; } /**************************************************************************** |