2

I have some file shares which had problems with the permissions in the past. I need to monitor them now, daily.

For this, I wanted to build a script in Python which automates that for me.

I can't get it working. And I don't know why and can't find a solution for it.

import os

paths = [r'\\10.0.0.0\Share$', r'\\10.0.0.1\Share$']

for path in paths:
    print os.access(path, os.R_OK)

This returns True for both, but if I open them in the explorer, I can't connect to them because I don't have the rights. Both should return False.

I am also open for other solutions than os.access()

DavidG
  • 24,279
  • 14
  • 89
  • 82
Thomas B.
  • 21
  • 2
  • On Windows, `os.access(path, os.R_OK)` is bogus; it only checks whether the current user is granted the right to read the file's attributes, which is implicitly true if the user has the right to list the parent directory. – Eryk Sun Jul 12 '17 at 13:25
  • 1
    To really check for read access on a network share, first get the share's security descriptor via `GetNamedSecurityInfo`. The object type is `SE_LMSHARE`. Then pass the security descriptor and desired access to `AccessCheck`. You'll need an impersonation token, such as from `OpenProcessToken` followed by `DuplicateToken`. You can do this via ctypes only or ctypes plus PyWin32. You need ctypes to call `AccessCheck`. – Eryk Sun Jul 12 '17 at 13:26

0 Answers0