EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Stop read operation

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#23078
Posted: 01/08/2013 10:01:53
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Hello, i've a question about read files.

There is a way to stop an operation of reading file?

In my project I want to avoid that user can open certain files.
There is a way to do this?

Thank in advance,
Davide
#23079
Posted: 01/08/2013 10:27:00
by Volodymyr Zinin (EldoS Corp.)

Quote
Davide Baccaglini wrote:
There is a way to stop an operation of reading file?

No.

Quote
Davide Baccaglini wrote:
In my project I want to avoid that user can open certain files. There is a way to do this?

Yes. If you return from the OnCreate/OnOpen callback the "access denied" error then the originator of the open request (a program which is opening the file) doesn't obtain a handle and therefore won't be able to do operations on the file.
#23083
Posted: 01/09/2013 03:00:20
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Hi Vladimir, thanks for the response.
It works for OnCreate event but not for OnOpen.

OnOpen event is used both for open file and for get information about it.
So, if I fired an ECBFSError in this event the file is always opened and a this message appear "File not found".
I've also modified OnRead event by checking if Handle is empty (case of not open file) but the error is still appearing.

Can you help me?
#23085
Posted: 01/09/2013 03:32:08
by Eugene Mayevski (EldoS Corp.)

If I understand you right, you are saying that throwing error in OnOpenFile event handler doesn't deny the request and the file is still opened by the application. This is obviously wrong behavior. Can you reproduce it with mapper sample (by modifying it)? If yes, please post your modifications so that we could take a look of what's happening locally?

Quote
Davide Baccaglini wrote:
I've also modified OnRead event by checking if Handle is empty (case of not open file) but the error is still appearing.


OnReadFile would never be fired if the file was not opened before.


Sincerely yours
Eugene Mayevski
#23086
Posted: 01/09/2013 09:28:24
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Hello Eugene, i've modified OnOpenFile event in mapper sample.

I've added this code at the beginning of the method :
Code
private void CbFsOpenFile(object sender, string FileName, ACCESS_MASK DesiredAccess, UInt32 ShareMode, ref IntPtr FileHandleContext)
{
  try
  {
    if (FileName == "\\CBFS_Mapper.txt")
      throw new ECBFSError(5);

   ... unmodified code of example ...
  }
  catch (Exception ex)
  {
    throw ex;
  }
}


When i try to open "CBFS_Mapper.txt" Notepad is open (but the file is empty) and this message appear : "Z:\CBFS_Mapper.txt doesn't exists. Create it?"

Note : i've tried the same code in OnCreate event of mapper sample. It works fine.
#23087
Posted: 01/09/2013 09:39:51
by Eugene Mayevski (EldoS Corp.)

The behavior is generally ok - the file is not opened.

As I understand, the message itself confuses you, right? But it can be that it's notepad that handles failures to open the file in such interesting way. Did you try other applications?


Sincerely yours
Eugene Mayevski
#23089
Posted: 01/09/2013 10:06:43
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

The problem happens also with pdf and docx file. I have to change other events to do it?

In my project I want to disable to open certain file (or create new files) contained in a specific folder because this is my recycle bin folder.

Can you give me any suggestions?

Thanks you,
Davide
#23090
Posted: 01/09/2013 10:12:20
by Eugene Mayevski (EldoS Corp.)

What your *exact* problem is?


Sincerely yours
Eugene Mayevski
#23092
Posted: 01/09/2013 10:28:46
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

In my project I want to simulate the content of a filesystem in the cloud.

In addition to the file and folder contained in this filesystem I want to simulate a RecycleBin folder where files are moved after deletion.

My RecycleBin folder can only display the deleted files and user can't create/open/modify files in this folder. As suggested by Vladimir I've modified OnCreateFile event, with the code posted about OnOpenFile, and it works : when I try to create a new file in RecycleBin folder the OS showed me the correct message "Destionation Folder Access Denied, You need permission to perform this action".

But, if I add the same code (throw new ECBFSError(5)) in OnOpenFile, as suggested by Vladimir, regardless of the type of file, the file is opened (and it's empty) and this error appear : "Z:\My_File.txt doesn't exists. Create it?".

I would like to show a message similar to OnCreateFile event. It's possible?

Thanks you,
Davide
#23093
Posted: 01/09/2013 10:32:24
by Eugene Mayevski (EldoS Corp.)

Quote
Davide Baccaglini wrote:
I would like to show a message similar to OnCreateFile event. It's possible?


So *this* is the exact problem, ok... The message is shown by the application, not by CBFS. So it depends on the application how to treat certain errors. Errors you throw are passed to the kernel and then to user mode in rather unified way so if you return the same error code from different events and the application shows different messages, it's either the OS which ignores or changes the error or the application itself.

I don't understand how this message (File doesn't exist) can be reported for PDF and DOCX files - are you trying to open the PDF with Notepad?


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 3876 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!