return tevent_req_simple_recv_ntstatus(req);
}
-NTSTATUS cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_dst)
+NTSTATUS cli_rename(struct cli_state *cli,
+ const char *fname_src,
+ const char *fname_dst,
+ bool replace)
{
TALLOC_CTX *frame = NULL;
struct tevent_context *ev;
NTSTATUS status = NT_STATUS_OK;
if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
- return cli_smb2_rename(cli, fname_src, fname_dst, false);
+ return cli_smb2_rename(cli, fname_src, fname_dst, replace);
}
frame = talloc_stackframe();
goto fail;
}
+ if (replace) {
+ /*
+ * SMB1 doesn't support replace
+ */
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+
ev = samba_tevent_context_init(frame);
if (ev == NULL) {
status = NT_STATUS_NO_MEMORY;
return -1;
}
- if (!NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
+ if (!NT_STATUS_IS_OK(
+ cli_rename(targetcli1, targetpath1, targetpath2, false))) {
int eno = SMBC_errno(ocontext, targetcli1);
if (eno != EEXIST ||
- !NT_STATUS_IS_OK(cli_unlink(targetcli1, targetpath2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)) ||
- !NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) {
+ !NT_STATUS_IS_OK(cli_unlink(targetcli1, targetpath2,
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_HIDDEN)) ||
+ !NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1,
+ targetpath2, false))) {
errno = eno;
TALLOC_FREE(frame);
return False;
}
- status = cli_rename(cli1, fname, fname1);
+ status = cli_rename(cli1, fname, fname1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status));
} else {
return False;
}
- status = cli_rename(cli1, fname, fname1);
+ status = cli_rename(cli1, fname, fname1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status));
correct = False;
}
#endif
- status = cli_rename(cli1, fname, fname1);
+ status = cli_rename(cli1, fname, fname1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
correct = False;
return False;
}
- status = cli_rename(cli1, fname, fname1);
+ status = cli_rename(cli1, fname, fname1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status));
} else {
return False;
}
- status = cli_rename(cli1, fname, fname1);
+ status = cli_rename(cli1, fname, fname1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status));
correct = False;
* dst directory should fail.
*/
- status = cli_rename(cli, src, dst);
+ status = cli_rename(cli, src, dst, false);
if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
printf("rename of %s -> %s should be ACCESS denied, was %s\n",
src, dst, nt_errstr(status));
goto fail;
}
- status = cli_rename(cli, dsrc, ddst);
+ status = cli_rename(cli, dsrc, ddst, false);
if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
printf("rename of %s -> %s should be ACCESS denied, was %s\n",
src, dst, nt_errstr(status));