Hi all,
I’m getting strange results from ZwCreateFile when opening folders over a
network.
I have a routine to check if a file exists, and to ensure that the file is
not a folder. It does this by calling ZwCreateFile, specifying the
FILE_NON_DIRECTORY_FILE flag. On local drives, this works fine, as it
returns STATUS_FILE_IS_A_DIRECTORY if it encounters a folder. However, on
a network share, it returns STATUS_SUCCESS. Is this a bug in the network
code, or do I have something badly wrong?
Thanks,
- Andy
With usTestName =
Device\LanmanRedirector;Z:000000000000aeaa\machine\share
CheckIfFileExists returns true, with bWasAFolder set to false
“machine” is the name of my test workstation
“share” is the name of the share on “machine”
bool CheckIfFileExists(
UNICODE_STRING & usTestName,
bool bCaseSensitive,
bool * pbWasAFolder = 0 )
{
OBJECT_ATTRIBUTES oa;
InitializeObjectAttributes(
&oa,
&usTestName,
bCaseSensitive ? 0 : OBJ_CASE_INSENSITIVE, 0, 0 );
NTSTATUS rc;
IO_STATUS_BLOCK ioStatus;
HANDLE hFile;
rc = ZwCreateFile(
&hFile,
0,
&oa,
&ioStatus,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
0, 0 );
if ( NT_SUCCESS(rc) )
ZwClose( rc );
if ( pbWasAFolder )
*pbWasAFolder = (STATUS_FILE_IS_A_DIRECTORY == rc);
return (
(STATUS_SUCCESS == rc) ||
(STATUS_SHARING_VIOLATION == rc) ||
(STATUS_DELETE_PENDING == rc) );
}