On 05/09/2017 09:38 PM, Bryan Burgin wrote:
> After carefully reading your text, I won't need your program.
> I'll see if there is a different way to make a client send the
> FileRenameInfo/Passthru command.
> B.
>
FWIW, program attached.
(notice that paths are hard-coded and files are assumed to be pre-existing).
Thanks,
Uri.
> -----Original Message-----
> From: Bryan Burgin
> Sent: Tuesday, May 9, 2017 8:54 AM
> To: Uri Simchoni <u...@samba.org>
> Cc: cifs-protocol@lists.samba.org; MSSolve Case Email <casem...@microsoft.com>
> Subject: RE: [REG:117050715700170] SMB1 processing of FileRnameInfo
>
> Hi Uri,
>
> I can research this for you. Let me look at the code. Can you send me the
> source of your test program; that will save me the time of doing the same.
>
> Bryan
#include <sdkddkver.h>
#include <windows.h>
#include <cstring>
#include <iostream>
#include <memory>
int main()
{
auto const& filepath = L"Z:\\1.txt";
auto const& destpath = L"Z:\\2.txt";
// handles will be leaked but that should be irrelevant here
auto const f_handle = CreateFile(filepath,
GENERIC_READ | GENERIC_WRITE | DELETE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (f_handle == INVALID_HANDLE_VALUE)
{
auto const err = GetLastError();
std::cerr << "failed to create test file: " << err;
return err;
}
auto const destpath_bytes_withOUT_null = wcslen(destpath);
// unclear if we need to subtract the one wchar_t of FileNameLength:
auto const struct_size = sizeof(FILE_RENAME_INFO) + (destpath_bytes_withOUT_null + 1) * sizeof(WCHAR);
FILE_RENAME_INFO* fri = (FILE_RENAME_INFO*)new BYTE[struct_size];
fri->ReplaceIfExists = TRUE; // as described by Niall Douglas
fri->RootDirectory = NULL;//parent_dir_handle;
// with or without null terminator?
fri->FileNameLength = (DWORD)destpath_bytes_withOUT_null;// No include null
wcscpy(fri->FileName, destpath);
BOOL res = SetFileInformationByHandle(f_handle, FileRenameInfo,
fri, (DWORD)struct_size);
delete fri;
if (!res)
{
auto const err = GetLastError();
std::cerr << "failed to rename file: " << err;
return err;
}
else
std::cout << "success";
res = CloseHandle(f_handle);
if (!res)
{
auto const err = GetLastError();
std::cerr << "failed to close file: " << err;
return err;
}
return 0;
}
_______________________________________________
cifs-protocol mailing list
cifs-protocol@lists.samba.org
https://lists.samba.org/mailman/listinfo/cifs-protocol