Re[4]: open files which are already opened in exclusi ve shared mode

Hello Primoz,

ah, so I should roll IRPs, can’t I access files by handle?


Roman Kudinov

mailto:xxxxx@rbcmail.ru

Friday, September 3, 2004, 2:27:29 PM, you wrote:

PB> //Desired Access
PB> set it to SYNCHRONIZE only. The failure is because of FILE_READ_DATA.
PB> From hFile you can get PFILE_OBJECT and roll your own (read, …) IRPs with
PB> it. Don’t forget to DereferenceObject it.
PB> WBR Primoz

PB> -----Original Message-----
PB> From: Roman Kudinov [mailto:xxxxx@rbcmail.ru]
PB> Sent: Friday, September 03, 2004 12:12 PM
PB> To: Windows File Systems Devs Interest List
PB> Subject: Re[2]: [ntfsd] open files which are already opened in exclusive
PB> shared mode

PB> Hello Tony,

PB> I tried to do like you say, but got shared access violation error (I
PB> try to open L"C:\WINDOWS\system32\config\default" which is always
PB> opened in exclusive mode). Other files are opened successfully

PB> Here is my code, it is executed in IRP_MJ_DEVICE_CONTROL

PB>
PB> RtlInitEmptyUnicodeString(&strFilename, szBuffer,
PB> sizeof(szBuffer));
PB>
PB> RtlAppendUnicodeToString(&strFilename, L"\??\“);
PB>
PB> RtlAppendUnicodeToString(&strFilename, InputBuffer);
PB> //InputBuffer =
PB> L"C:\WINDOWS\system32\config\default”

PB> //I tried both with and without OBJ_KERNEL_HANDLE
PB> InitializeObjectAttributes(&Attributes,
PB> &strFilename,
PB> OBJ_KERNEL_HANDLE |
PB> OBJ_CASE_INSENSITIVE,
PB> //Attributes,
PB> NULL,
PB> //RootDirectory
PB> NULL);
PB> //SecurityDescriptor

PB> IoStatus->Status = ZwCreateFile(&hFile,
PB> //Output handle
PB> FILE_READ_DATA |
PB> SYNCHRONIZE,
PB> //DesiredAccess
PB> &Attributes,
PB> //ObjectAttributes
PB> &IoStatusBlock,
PB> &AllocationSize,
PB> //AllocationSize
PB> FILE_ATTRIBUTE_NORMAL,
PB> //FileAttributes
PB> FILE_SHARE_READ |
PB> FILE_SHARE_WRITE |
PB> FILE_SHARE_DELETE,
PB> FILE_OPEN,
PB> FILE_SYNCHRONOUS_IO_ALERT,
PB> //CreateOptions
PB> NULL,
PB> NULL);
PB> if( !NT_SUCCESS(IoStatus->Status) )
PB> {
PB> break;
PB> }

PB> I get error code 32 (shared access violation). Do I do something
PB> wrong?

Unfortunately no, since handle is open with SYNCHRONIZE DesiredAccess (to
avoid sharing failure in open) and IO manager (or some other manager) will
fail your ZwRead by handle.
WBR Primoz

-----Original Message-----
From: Roman Kudinov [mailto:xxxxx@rbcmail.ru]
Sent: Friday, September 03, 2004 12:54 PM
To: Windows File Systems Devs Interest List
Subject: Re[4]: [ntfsd] open files which are already opened in exclusi ve
shared mode

Hello Primoz,

ah, so I should roll IRPs, can’t I access files by handle?


Roman Kudinov

mailto:xxxxx@rbcmail.ru

Friday, September 3, 2004, 2:27:29 PM, you wrote:

PB> //Desired Access
PB> set it to SYNCHRONIZE only. The failure is because of FILE_READ_DATA.
PB> From hFile you can get PFILE_OBJECT and roll your own (read, …) IRPs
with
PB> it. Don’t forget to DereferenceObject it.
PB> WBR Primoz

PB> -----Original Message-----
PB> From: Roman Kudinov [mailto:xxxxx@rbcmail.ru]
PB> Sent: Friday, September 03, 2004 12:12 PM
PB> To: Windows File Systems Devs Interest List
PB> Subject: Re[2]: [ntfsd] open files which are already opened in exclusive
PB> shared mode

PB> Hello Tony,

PB> I tried to do like you say, but got shared access violation error (I
PB> try to open L"C:\WINDOWS\system32\config\default" which is always
PB> opened in exclusive mode). Other files are opened successfully

PB> Here is my code, it is executed in IRP_MJ_DEVICE_CONTROL

PB>
PB> RtlInitEmptyUnicodeString(&strFilename, szBuffer,
PB> sizeof(szBuffer));
PB>
PB> RtlAppendUnicodeToString(&strFilename, L"\??\“);
PB>
PB> RtlAppendUnicodeToString(&strFilename, InputBuffer);
PB> //InputBuffer =
PB> L"C:\WINDOWS\system32\config\default”

PB> //I tried both with and without
OBJ_KERNEL_HANDLE
PB> InitializeObjectAttributes(&Attributes,
PB> &strFilename,
PB> OBJ_KERNEL_HANDLE |
PB> OBJ_CASE_INSENSITIVE,
PB> //Attributes,
PB> NULL,
PB> //RootDirectory
PB> NULL);
PB> //SecurityDescriptor

PB> IoStatus->Status = ZwCreateFile(&hFile,
PB> //Output handle
PB> FILE_READ_DATA |
PB> SYNCHRONIZE,
PB> //DesiredAccess
PB> &Attributes,
PB> //ObjectAttributes
PB> &IoStatusBlock,
PB> &AllocationSize,
PB> //AllocationSize
PB> FILE_ATTRIBUTE_NORMAL,
PB> //FileAttributes
PB> FILE_SHARE_READ |
PB> FILE_SHARE_WRITE |
PB> FILE_SHARE_DELETE,
PB> FILE_OPEN,
PB>
FILE_SYNCHRONOUS_IO_ALERT,
PB> //CreateOptions
PB> NULL,
PB> NULL);
PB> if( !NT_SUCCESS(IoStatus->Status) )
PB> {
PB> break;
PB> }

PB> I get error code 32 (shared access violation). Do I do something
PB> wrong?


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@hermes.si
To unsubscribe send a blank email to xxxxx@lists.osr.com