EldoS | Feel safer!

Software components for data protection, secure storage and transfer

File attributes wrong for some folders

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
Posted: 09/10/2013 09:11:16
by Franck Legardien (Basic support level)
Joined: 09/06/2013
Posts: 2

Using the c++ xor encrypt sample, i have noticed that in some cases the 'FileAttributes' parameter was wrong in the OpenFile filter callback:

void CbFltOpenFileC(
CallbackFilter* i_CallbackFilterPtr,
LPWSTR FileName,
PACCESS_MASK DesiredAccess,
PWORD FileAttributes,
PWORD ShareMode,
PDWORD CreateOptions,
PWORD CreateDisposition,
LPBOOL RequestAccepted)
*RequestAccepted = TRUE;
WCHAR text[MAX_PATH * 2];
if (0 == (*FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
wsprintfW(text, L"OpenFileC - not a folder [File=%s]", FileName);
else {
wsprintfW(text, L"OpenFileC - it is a folder [File=%s]", FileName);

Which generates the following result:
OpenFileC - not a folder [File=C:\Users\PocEldos\Sample1_Crypt]

With the following files tree:
|-- C:\Users\PocEldos\Sample1_Crypt\A1.txt
|-- C:\Users\PocEldos\Sample1_Crypt\A2.txt

How can it happen ?
Could you fix the issue please ?
Is there another way to get the file attributes reliably ?
Posted: 09/10/2013 09:34:50
by Vladimir Cherniga (EldoS Corp.)

How can it happen ?

You should understand that file attributes specified in (Pre)CbFltOpenFileC call only valid for the newly created files, they are ignored for the files already exists. FileAttributes is a parameter that is stored with a file metadata on the disk storage. They are not available in open callback, and current value is copied from the requested FlagsAndAttributes value specified in CreateFile win32 api or from CreateDirectory win32 api. To know the real file attributes, you should request it manually, using GetFileAttributes win32 api. It possible to find FILE_ATTRIBUTE_DIRECTORY flag in PostOpen/PostCreate callback, as it is already known, what type of file object was opened. There is another flags:
#define FILE_DIRECTORY_FILE                     0x00000001
#define FILE_NON_DIRECTORY_FILE                 0x00000040

that may help to identify the requested file object set in CreateOption callback parameter.
Posted: 10/21/2013 23:31:52
by mark better (Basic support level)
Joined: 10/21/2013
Posts: 1

I modifed NewFileName parameter in ReparseCallback and It works good.
But I want to rename only file's extension not folder.

How can I pass the folder in Reparsecallback when folder is created.
Posted: 10/22/2013 02:48:25
by Vladimir Cherniga (EldoS Corp.)

Not sure what is your final goal, but you may skip a redirection in reparse callback by throwing an exception. In this way reparse will be rejected an the file name will be opened by the original file system path.



Topic viewed 3180 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!