EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Build 2.0.38 breaks OnSetFileAttributes for existing app

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
#7513
Posted: 09/03/2008 05:05:28
by Leontin Birsan (Standard support level)
Joined: 08/06/2008
Posts: 2

After updating to the version 2.0.38 (.NET 2.0), the callback event OnSetFileAttributes now is called several times to set the file attributes (not the timestamps) to 16, 128 and others. However, the FileHandleContext Stream property is null:

Code
FileContext ctx = (FileContext)GCHandle.FromIntPtr(fileHandleContext).Target;
FileStream fs = ctx.Stream;

(fs is null)


I had to fix the method in the following way in order to avoid code crashes:

Code
private void setFileAttributes(object sender, CbFsFileInfo fileInfo, IntPtr fileHandleContext, DateTime creationTime, DateTime lastAccessTime, DateTime lastWriteTime, uint attributes)
{
    FileContext ctx = (FileContext)GCHandle.FromIntPtr(fileHandleContext).Target;
    FileStream fs = ctx.Stream;

    SetFileAttributes(fileInfo.FileName, attributes);

    if (fs != null)
    {
        if (fs.SafeFileHandle.IsInvalid)
            throw new ECBFSError(ERROR_INVALID_HANDLE);

        long ct = (creationTime == DateTime.MinValue) ? 0 : creationTime.ToFileTime();
        long lat = (lastAccessTime == DateTime.MinValue) ? 0 : lastAccessTime.ToFileTime();
        long lwt = (lastWriteTime == DateTime.MinValue) ? 0 : lastWriteTime.ToFileTime();
        SetFileTime(fs.SafeFileHandle, ref ct, ref lat, ref lwt);
    }
}


Also, this method is called in the "nt authority\system" context when accessing from the network. Since the file stream is not assigned (probably open was not called?) there is no way to detect which user was calling the method. Is there any way to have the stream set again? This affects the security of the application and I had to deactivate it and give "system" full control in order to avoid the issue.

OS: Win 2K3 R2 32 bit
#7515
Posted: 09/03/2008 10:30:47
by Volodymyr Zinin (EldoS Corp.)

Hello,

Quote
Leontin Birsan wrote:
After updating to the version 2.0.38 (.NET 2.0), the callback event OnSetFileAttributes now is called several times to set the file attributes (not the timestamps) to 16, 128 and others. However, the FileHandleContext Stream property is null:

We'll check it up.

Quote
Leontin Birsan wrote:
Also, this method is called in the "nt authority\system" context ...
.
The good idea is to check the security only in the Create/Open callbacks. They are always called in the context of the user who originated these requests. If the Create/Open callback processes successfully then the user will obtain a handle to the file being opened and only in this case will be able to work with it.
#7521
Posted: 09/04/2008 08:53:13
by Volodymyr Zinin (EldoS Corp.)

Quote
Vladimir Zinin wrote:
the callback event OnSetFileAttributes now is called several times to set the file attributes (not the timestamps) to 16, 128 and others.

Fixed.

Quote
Leontin Birsan wrote:
However, the FileHandleContext Stream property is null

We are working on it.

BTW: In future use our Helpdesk System to report bugs. This helps us give you necessary support as soon as possible.
#7555
Posted: 09/09/2008 10:54:15
by Volodymyr Zinin (EldoS Corp.)

Quote
Leontin Birsan wrote:
However, the FileHandleContext Stream property is null:

Moved to the helpdesk.
#7568
Posted: 09/10/2008 01:41:40
by Leontin Birsan (Standard support level)
Joined: 08/06/2008
Posts: 2

Thank you for the quick response and fix. I did not know if this is a bug or not, I might just have done something wrong myself, I like to ask first.

FYI: I do check the security in open/create and I have my own "file stream" which carries along the user name and other stuff because I do special processing in the other methods. However, the security is double-checked in the rest of the callbacks too but at a different level. I will download the new build as soon as possible and I will double-ckeck what happends.
#7569
Posted: 09/10/2008 02:35:08
by Volodymyr Zinin (EldoS Corp.)

We haven't done a new build yet (where the problem with frequent OnSetFileAttributes calls was fixed). But I think it will be done in a few days. We'll notify you about the new release.
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.

Reply

Statistics

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