summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-04-28 16:43:16 -0700
committerJeremy Allison <jra@samba.org>2009-04-28 16:43:16 -0700
commitbd6447dcf26ec217f335784f05df304d45288850 (patch)
tree6e982a5746e120aa6e97d181e1c13916178d61c3 /source3/libsmb
parent06e404f5743d1ccce0f4c51ca3ef97927f801a42 (diff)
downloadsamba-bd6447dcf26ec217f335784f05df304d45288850.tar.gz
samba-bd6447dcf26ec217f335784f05df304d45288850.tar.bz2
samba-bd6447dcf26ec217f335784f05df304d45288850.zip
Convert cli_rename to async.
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c129
-rw-r--r--source3/libsmb/libsmb_dir.c4
2 files changed, 108 insertions, 25 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index d38b5c5014..340b9dd9aa 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -429,41 +429,124 @@ bool cli_unix_chown(struct cli_state *cli, const char *fname, uid_t uid, gid_t g
Rename a file.
****************************************************************************/
-bool cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst)
+static void cli_rename_done(struct tevent_req *subreq);
+
+struct cli_rename_state {
+ uint16_t vwv[1];
+ int dummy;
+};
+
+struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname_src,
+ const char *fname_dst)
{
- char *p;
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct cli_rename_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_rename_state);
+ if (req == NULL) {
+ return NULL;
+ }
- cli_set_message(cli->outbuf,1, 0, true);
+ SSVAL(state->vwv+0, 0, aSYSTEM | aHIDDEN | aDIR);
- SCVAL(cli->outbuf,smb_com,SMBmv);
- 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);
+ 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, SMBmv, additional_flags,
+ 1, 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_rename_done, req);
+ return req;
+}
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return false;
+static void cli_rename_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_rename_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_rename(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_rename_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_rename_recv(req);
+
+ fail:
+ TALLOC_FREE(frame);
+ if (!NT_STATUS_IS_OK(status)) {
+ cli_set_error(cli, status);
+ }
+ return status;
}
/****************************************************************************
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index 508810538f..bc5e35f79b 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -1962,12 +1962,12 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
return -1;
}
- if (!cli_rename(targetcli1, targetpath1, targetpath2)) {
+ if (!NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
int eno = SMBC_errno(ocontext, targetcli1);
if (eno != EEXIST ||
!cli_unlink(targetcli1, targetpath2) ||
- !cli_rename(targetcli1, targetpath1, targetpath2)) {
+ !NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
errno = eno;
TALLOC_FREE(frame);