summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/clifile.c117
-rw-r--r--source3/libsmb/libsmb_dir.c4
2 files changed, 93 insertions, 28 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index e055a88000..54c59473e6 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -756,46 +756,111 @@ NTSTATUS cli_nt_hardlink(struct cli_state *cli, const char *fname_src, const cha
Delete a file.
****************************************************************************/
-bool cli_unlink_full(struct cli_state *cli, const char *fname, uint16_t attrs)
-{
- char *p;
+static void cli_unlink_done(struct tevent_req *subreq);
- memset(cli->outbuf,'\0',smb_size);
- memset(cli->inbuf,'\0',smb_size);
+struct cli_unlink_state {
+ uint16_t vwv[1];
+};
- cli_set_message(cli->outbuf,1, 0, true);
+struct tevent_req *cli_unlink_send(TALLOC_CTX *mem_ctx,
+ struct event_context *ev,
+ struct cli_state *cli,
+ const char *fname,
+ uint16_t mayhave_attrs)
+{
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct cli_unlink_state *state = NULL;
+ uint8_t additional_flags = 0;
+ uint8_t *bytes = NULL;
- SCVAL(cli->outbuf,smb_com,SMBunlink);
- SSVAL(cli->outbuf,smb_tid,cli->cnum);
- cli_setup_packet(cli);
+ req = tevent_req_create(mem_ctx, &state, struct cli_unlink_state);
+ if (req == NULL) {
+ return NULL;
+ }
- SSVAL(cli->outbuf,smb_vwv0, attrs);
+ SSVAL(state->vwv+0, 0, mayhave_attrs);
- p = smb_buf(cli->outbuf);
- *p++ = 4;
- p += clistr_push(cli, p, fname,
- cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
+ 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,
+ strlen(fname)+1, NULL);
- cli_setup_bcc(cli, p);
- cli_send_smb(cli);
- if (!cli_receive_smb(cli)) {
- return false;
+ if (tevent_req_nomem(bytes, req)) {
+ return tevent_req_post(req, ev);
}
- if (cli_is_error(cli)) {
- return false;
+ subreq = cli_smb_send(state, ev, cli, SMBunlink, 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_unlink_done, req);
+ return req;
+}
- return true;
+static void cli_unlink_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);
}
-/****************************************************************************
- Delete a file.
-****************************************************************************/
+NTSTATUS cli_unlink_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
-bool cli_unlink(struct cli_state *cli, const char *fname)
+NTSTATUS cli_unlink(struct cli_state *cli, const char *fname, uint16_t mayhave_attrs)
{
- return cli_unlink_full(cli, fname, aSYSTEM | aHIDDEN);
+ 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;
+ }
+
+ ev = event_context_init(frame);
+ if (ev == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto fail;
+ }
+
+ req = cli_unlink_send(frame, ev, cli, fname, mayhave_attrs);
+ 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_unlink_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 bc5e35f79b..d230275685 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -1760,7 +1760,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
}
/*d_printf(">>>unlink: resolved path as %s\n", targetpath);*/
- if (!cli_unlink(targetcli, targetpath)) {
+ if (!NT_STATUS_IS_OK(cli_unlink(targetcli, targetpath, aSYSTEM | aHIDDEN))) {
errno = SMBC_errno(context, targetcli);
@@ -1966,7 +1966,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
int eno = SMBC_errno(ocontext, targetcli1);
if (eno != EEXIST ||
- !cli_unlink(targetcli1, targetpath2) ||
+ !NT_STATUS_IS_OK(cli_unlink(targetcli1, targetpath2, aSYSTEM | aHIDDEN)) ||
!NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
errno = eno;