summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/client/client.c2
-rw-r--r--source3/include/proto.h2
-rw-r--r--source3/libsmb/clifile.c148
-rw-r--r--source3/libsmb/libsmb_dir.c3
-rw-r--r--source3/torture/mangle_test.c2
-rw-r--r--source3/torture/nbio.c2
-rw-r--r--source3/torture/torture.c2
7 files changed, 97 insertions, 64 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index d74de35bc5..54ff755ed3 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -2675,7 +2675,7 @@ static int cmd_rmdir(void)
return 1;
}
- if (!cli_rmdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetname))) {
d_printf("%s removing remote directory file %s\n",
cli_errstr(targetcli),mask);
}
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 3ddbf6f3b9..3a706e4725 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2339,7 +2339,7 @@ bool cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const char *f
bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16 attrs);
bool cli_unlink(struct cli_state *cli, const char *fname);
NTSTATUS cli_mkdir(struct cli_state *cli, const char *dname);
-bool cli_rmdir(struct cli_state *cli, const char *dname);
+NTSTATUS cli_rmdir(struct cli_state *cli, const char *dname);
int cli_nt_delete_on_close(struct cli_state *cli, int fnum, bool flag);
int cli_nt_create_full(struct cli_state *cli, const char *fname,
uint32 CreatFlags, uint32 DesiredAccess,
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);
diff --git a/source3/torture/mangle_test.c b/source3/torture/mangle_test.c
index 525a1eb3c3..81bdbce04d 100644
--- a/source3/torture/mangle_test.c
+++ b/source3/torture/mangle_test.c
@@ -202,7 +202,7 @@ bool torture_mangle(int dummy)
}
cli_unlink(cli, "\\mangle_test\\*");
- if (!cli_rmdir(cli, "\\mangle_test")) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(cli, "\\mangle_test"))) {
printf("ERROR: Failed to remove directory\n");
return False;
}
diff --git a/source3/torture/nbio.c b/source3/torture/nbio.c
index a010c80985..998adac4e0 100644
--- a/source3/torture/nbio.c
+++ b/source3/torture/nbio.c
@@ -220,7 +220,7 @@ void nb_close(int handle)
void nb_rmdir(const char *fname)
{
- if (!cli_rmdir(c, fname)) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(c, fname))) {
printf("ERROR: rmdir %s failed (%s)\n",
fname, cli_errstr(c));
exit(1);
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 0328cfe545..7e2b3a56e5 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -4500,7 +4500,7 @@ static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *st
return;
if (finfo->mode & aDIR) {
- if (!cli_rmdir(pcli, fname))
+ if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
printf("del_fn: failed to rmdir %s\n,", fname );
} else {
if (!cli_unlink(pcli, fname))