Skip to content

System.UnauthorizedAccessException: 'Access to the path is denied.' When Create Publisher #6

Open

Description

@cbfrank

Hi
On windows, there is System.UnauthorizedAccessException: 'Access to the path is denied.' if the publisher and subscriber are created by different accounts in different processes.
for example, a windows service process create a subscriber, later, when an user application try to create the publisher, the exception will be thrown. Can we create the memory mapped file that can be accessed by all everyone?

Thanks

Activity

  1. fabalo76 commented on Jun 3, 2021

    @fabalo76

    @cbfrank . Same problem here, when running the Main application as Windows Service under LocalSystem Account. The other apps running under a normal account can't access the Queue Semaphore with Access denied error.
    I made a patch to Cloudtoid.Interprocess package to make the Named Semaphore accessible to Everyone..
    Check the solution here
    https://github.com/fabalo76/interprocess/tree/WinSemaphoreACLs

    As this is an unofficial branch (pending to merge with official branch) and only tested in Windows ,you have to install the package manually in your visual studio.
    You could compile it by yourself or try my binary package
    Cloudtoid.Interprocess.1.0.156.zip

    Check the source code for Semaphore/Windows/SemaphoreWindows.cs
    image

  2. cocowalla commented on Jun 3, 2021

    @cocowalla

    @fabalo76 I'm not sure giving the Everyone account full control is the best idea from a security perspective. Ideally, you'd be able to configure it, so you can grant the required access rights only for the actual accounts at either end of the pipe.

  3. prezaei commented on Jul 11, 2021

    @prezaei
    Member

    Hey folks, any suggestions on the best way to provide a solution here? I'd be happy to implement it.

  4. self-assigned this
    on Nov 19, 2022
  5. MacKey-255 commented on Aug 14, 2025

    @MacKey-255

    Any update? I have the same problem in Linux with semaphore and MemoryFile permissions. Errors:

    MemoryFile

    System.UnauthorizedAccessException: Access to the path '/tmp/.cloudtoid/interprocess/mmf/test.qu' is denied.
     ---> System.IO.IOException: Permission denied
       --- End of inner exception stack trace ---
       at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
       at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
       at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
       at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
       at Cloudtoid.Interprocess.Memory.Unix.MemoryFileUnix..ctor(QueueOptions options, ILoggerFactory loggerFactory)
       at Cloudtoid.Interprocess.MemoryView..ctor(QueueOptions options, ILoggerFactory loggerFactory)
       at Cloudtoid.Interprocess.Queue..ctor(QueueOptions options, ILoggerFactory loggerFactory)
       at Cloudtoid.Interprocess.Subscriber..ctor(QueueOptions options, ILoggerFactory loggerFactory)
       at Cloudtoid.Interprocess.QueueFactory.CreateSubscriber(QueueOptions options)
    

    Semaphore

    Cloudtoid.Interprocess.Semaphore.Posix.PosixSemaphoreUnauthorizedAccessException: The semaphore exists, but the caller does not have permission to open it.
       at Cloudtoid.Interprocess.Semaphore.Linux.Interop.CreateOrOpenSemaphore(String name, UInt32 initialCount)
       at Cloudtoid.Interprocess.Semaphore.Linux.SemaphoreLinux..ctor(String name, Boolean deleteOnDispose)
       at Cloudtoid.Interprocess.InterprocessSemaphore.CreateReleaser(String name)
       at Cloudtoid.Interprocess.Publisher..ctor(QueueOptions options, ILoggerFactory loggerFactory)
       at Cloudtoid.Interprocess.QueueFactory.CreatePublisher(QueueOptions options)
    

    To reproduce

    First create a subscriber in a program with root (Uid: 0) and a publisher like user (Uid; 1000). The MemoryFile and base folder set the permissions by default, the same in case of semaphore

    Solution

    Set permissions to base folder when I create a subscriber from root but I cannot have control of the semaphore :/ so the Semaphore problem is still happend. I going to try create a pull request with a permission options to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions