EldoS | Feel safer!

Software components for data protection, secure storage and transfer

What is the proper way to present read only files

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#22547
Posted: 11/20/2012 11:12:34
by Michael Grimes (Priority Standard support level)
Joined: 08/08/2012
Posts: 14

I am trying to implement read only file sin my CBFS. I have tried many things:

1. throw ERROR_FILE_READ_ONLY in open file callback when write access is desired
2. throw ERROR_FILE_READ_ONLY in delete file callback
3. throw ERROR_ACCESS_DENIED in create file callback
4. Other similar functionality in other callbacks.

I am successful in that the user cannot do anything to these files, but explorer never presents
an error of "Read Only" or the like. I get very strange errors from explorer:

"Can't read from the source file or disk"
"File is open by another process"

So, what is the proper responses from the callback functions to handle read only files?

Thanks...
#22552
Posted: 11/20/2012 12:04:06
by Volodymyr Zinin (EldoS Corp.)

When you return ERROR_FILE_READ_ONLY then CallbackFS converts it just to STATUS_UNSUCCESSFUL. Because there is no something like STATUS_FILE_READ_ONLY error.
The "standard" file systems (FAT, NTFS) return the "access denied" error in this case. So it's better to do in the same way. I.e. return ERROR_ACCESS_DENIED from OnOpen and OnCanFileBeDeleted callbacks.
Throwing any errors from OnDelete callback is ignored. This is because how file/folder deletion is implemented in Windows. When a file is deleted the system performs the following:
1. Opens the file (with DELETE access right). In this case the OnOpen callback is called by CallbackFS.
2. Sends special request to mark the file as "delete on close". The OnCanFileBeDeleted callback is called.
3. Closes the file. The OnClose callback is called and if there is no any other opened handles for the file then the OnDelete callback is called.
BTW Windows, when it moves a file to recycle bin, tries it to mark as "delete on close" and if it's successful then unmark it and only then moves to recycle bin.
#22562
Posted: 11/20/2012 13:17:42
by Michael Grimes (Priority Standard support level)
Joined: 08/08/2012
Posts: 14

So what would be the proper way to handle the create file callback for read only? Throw access denied?
#22563
Posted: 11/20/2012 13:21:57
by Michael Grimes (Priority Standard support level)
Joined: 08/08/2012
Posts: 14

Also, for OnCanFileBeDeleted, should I throw access denied or just set the boolean canBeDeleted to false. Thanks...
#22576
Posted: 11/21/2012 01:54:57
by Volodymyr Zinin (EldoS Corp.)

Quote
megrimes wrote:
So what would be the proper way to handle the create file callback for read only? Throw access denied?

Yes.

Quote
megrimes wrote:
Also, for OnCanFileBeDeleted, should I throw access denied or just set the boolean canBeDeleted to false.

In the case you set canBeDeleted to false and finishes the callback without throwing an error the final result will be the same as you just throw the ERROR_ACCESS_DENIED error.
#22598
Posted: 11/21/2012 10:13:54
by Michael Grimes (Priority Standard support level)
Joined: 08/08/2012
Posts: 14

Thank you for the help - much appreciated.
Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.

Reply

Statistics

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