WindowsNT user authentication

Tim Golden mail at timgolden.me.uk
Wed Feb 14 08:19:25 EST 2007


billie wrote:
> Another question, I'm sorry.
> Do you got any idea about how to get permissions of a file/directory
> given the username?
> For example: I would like to know if C:\my_file.ext is readable/
> writable by user 'x' or not.

This is an unfortunately messy question. The easiest
answer -- and I'm quite serious -- might be to have
the user *try* to read it and to catch the exception.

Quite apart from the mildly labyrinthine techniques for
determining object security, you face a potential race
condition: by the time you've tested and got your answer,
someone could have changed the permissions. Unlikely,
you'll admit, but possible enough to the try-except
approach attractive.

There are some examples of file security both in the
CHM which comes with the pywin32 extensions and in the
demos folder, on my machine:

c:\python24\lib\site-packages\win32\demos\security

I was going to start explaining win32 security terms
in this reply, but perhaps I won't unless the try-it-and-see
approach advocated above doesn't work!

HTH somewhat
TJG



More information about the Python-list mailing list