summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2009-04-21 06:52:54 -0700
committerJeremy Allison <jra@samba.org>2009-04-21 06:52:54 -0700
commit5ccf58ff598cc25a64cd222d0ad593f373eacf76 (patch)
tree9f439e147a87f5ecabd5d9920bedafc69f68185e /source3/libsmb
parent4eb557bf258f2fcc771be130763634910f2a60d2 (diff)
downloadsamba-5ccf58ff598cc25a64cd222d0ad593f373eacf76.tar.gz
samba-5ccf58ff598cc25a64cd222d0ad593f373eacf76.tar.bz2
samba-5ccf58ff598cc25a64cd222d0ad593f373eacf76.zip
Make rmdir async.
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c148
-rw-r--r--source3/libsmb/libsmb_dir.c3
2 files changed, 92 insertions, 59 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 5be18366b9..f5d5ad0fda 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -596,44 +596,6 @@ bool cli_unlink(struct cli_state *cli, const char *fname)
return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN);
}
-#if 0
-/****************************************************************************
- Create a directory.
-****************************************************************************/
-
-bool cli_mkdir(struct cli_state *cli, const char *dname)
-{
- char *p;
-
- memset(cli->outbuf,'\0',smb_size);
- memset(cli->inbuf,'\0',smb_size);
-
- cli_set_message(cli->outbuf,0, 0, true);
-
- SCVAL(cli->outbuf,smb_com,SMBmkdir);
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
-
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- p += clistr_push(cli, p, dname,
- cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
-
- cli_setup_bcc(cli, p);
-
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return False;
- }
-
- if (cli_is_error(cli)) {
- return False;
- }
-
- return True;
-}
-#endif
-
/****************************************************************************
Create a directory.
****************************************************************************/
@@ -746,36 +708,108 @@ NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname)
Remove a directory.
****************************************************************************/
-bool cli_rmdir(struct cli_state *cli, const char *dname)
+static void cli_rmdir_done(struct tevent_req *subreq);
+
+struct cli_rmdir_state {
+ int dummy;
+};
+
+struct tevent_req *cli_rmdir_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *dname)
{
- char *p;
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct cli_rmdir_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_rmdir_state);
+ if (req == NULL) {
+ return NULL;
+ }
- cli_set_message(cli->outbuf,0, 0, true);
+ bytes = talloc_array(state, uint8_t, 1);
+ if (!bytes) {
+ return NULL;
+ }
+ bytes[0] = 4;
+ bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), dname,
+ strlen(dname)+1, NULL);
- SCVAL(cli->outbuf,smb_com,SMBrmdir);
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
+ }
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- p += clistr_push(cli, p, dname,
- cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
+ subreq = cli_smb_send(state, ev, cli, SMBrmdir, additional_flags,
+ 0, NULL, talloc_get_size(bytes), bytes);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, cli_rmdir_done, req);
+ return req;
+}
- cli_setup_bcc(cli, p);
+static void cli_rmdir_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ NTSTATUS status;
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return false;
+ 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_rmdir_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname)
+{
+ 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_rmdir_send(frame, ev, cli, dname);
+ 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_rmdir_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 5afc8e48b6..508810538f 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -1284,8 +1284,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
}
/*d_printf(">>>rmdir: resolved path as %s\n", targetpath);*/
-
- if (!cli_rmdir(targetcli, targetpath)) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetpath))) {
errno = SMBC_errno(context, targetcli);