summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-04-29 10:48:16 -0700
committerJeremy Allison <jra@samba.org>2009-04-29 10:48:16 -0700
commitedd25980b03c5fac154967e51705ac1cdb8d4091 (patch)
tree797e10e71a7f42b0593ed9b3a28dd03d5ac87fe5 /source3
parent8aa41bdeb21d087cba1ab20bd2a4bd69cd519881 (diff)
downloadsamba-edd25980b03c5fac154967e51705ac1cdb8d4091.tar.gz
samba-edd25980b03c5fac154967e51705ac1cdb8d4091.tar.bz2
samba-edd25980b03c5fac154967e51705ac1cdb8d4091.zip
More async calls in libsmb/clifile.c
Jeremy.
Diffstat (limited to 'source3')
-rw-r--r--source3/client/client.c2
-rw-r--r--source3/include/proto.h19
-rw-r--r--source3/libsmb/clifile.c220
3 files changed, 188 insertions, 53 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index 4735e8cc7a..0271b456c3 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -3370,7 +3370,7 @@ static int cmd_hardlink(void)
return 1;
}
- if (!cli_nt_hardlink(targetcli, targetname, dest)) {
+ if (!NT_STATUS_IS_OK(cli_nt_hardlink(targetcli, targetname, dest))) {
d_printf("%s doing an NT hard link of files\n",cli_errstr(targetcli));
return 1;
}
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 2eb838fd2a..962215b79f 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2339,10 +2339,25 @@ struct tevent_req *cli_rename_send(TALLOC_CTX *mem_ctx,
const char *fname_dst);
NTSTATUS cli_rename_recv(struct tevent_req *req);
NTSTATUS cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst);
-bool cli_ntrename(struct cli_state *cli, const char *fname_src, const char *fname_dst);
-bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst);
+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);
+NTSTATUS cli_ntrename_recv(struct tevent_req *req);
+NTSTATUS cli_ntrename(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);
+NTSTATUS cli_nt_hardlink_recv(struct tevent_req *req);
+NTSTATUS cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *fname_dst);
+
bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16_t attrs);
bool cli_unlink(struct cli_state *cli, const char *fname);
+
struct tevent_req *cli_mkdir_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 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;
}
/****************************************************************************