Giter Site home page Giter Site logo

lockcheck's Issues

Check against working directories of all running processes

I've learned an interesting thing today:

you can't delete a directory which is a working directory of some running process on Windows. So if you get Access Denied when trying to delete a directory, check for a running process whose current directory is it.

We should consider extending LockCheck to iterate over running processes and check if there's a process whose current directory is the one we're asking about (or a subdirectory thereof).

Windows NtDll.cs requires `FILE_FLAG_BACKUP_SEMANTICS` for directories

Current behaviour

GetLockingProcessInfos with LockManagerFeatures.UseLowLevelApi does not work if the path is a directory on windows.
The simplest example is getting the locks of a directory that is the working directory of a cmd/powershell window.

Environment info

Windows 10 x64 on .NET 7

Possible solution

I've found this line from the documentation:
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea

Flag Meaning
FILE_FLAG_BACKUP_SEMANTICS
0x02000000
You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead of a file handle. For more information, see the Remarks section.

And then later in the same docs:

To open a directory using CreateFile, specify the FILE_FLAG_BACKUP_SEMANTICS flag as part of dwFlagsAndAttributes. Appropriate security checks still apply when this flag is used without SE_BACKUP_NAME and SE_RESTORE_NAME privileges.

So I think we should be using this flag if the path is a directory ๐Ÿ‘

Other notes

I would be interested to know how this compares to the approach mentioned by @KirillOsenkov in #6. The only case I can think of is that it would also be able to find locks on children of the directory, whereas this approach would not. Finding the lock of a child of a directory seems to be outside the scope of this library though.

Additionally, Restart Manager seems to not support finding locks on directories. Seems like another problem, but I thought I would mention it here.

I am interested in fixing it here because I'm currently using my fork of LockCheck in https://github.com/domsleee/ForceOps. For directories, I am currently just using NtDll (with UseLowLevelApi).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.