More elegant way to obtain ACLs / permissions for windows directories than using "cacls" dos command

D

dananrg

Is there a standard library module in Python 2.4 (Win32) that will
return directory permissions / ACLs (e.g. users, groups, and what
rights they have)?

Otherwise, I'm faced with sending "cacls dirName" commands via os.popen
as below, and then parsing and comparing the text output.

Basically, I'd like to compare what the ACLs a directory should have
against what the actual ACLs are.

Here's what I started with:

import os # Cross-platform filesystem manipulation

rootDir = "S:\someRootDirectoryHere"

print "*** Printing DIRECTORY names beneath directory " + rootDir + "
***\n"
for dirpath, dirnames, filenames in os.walk(rootDir):
for dirNm in dirnames:
theDirPath = os.path.join(dirpath, dirNm)
print '"' + theDirPath +'"'
# cacls needs double-quotes around space-containing paths
result = os.popen("cacls " + '"' + theDirPath + '"')
# Print the security info (ACLs)for specified directory
print result.read()

Thanks.
 
R

Roger Upole

Is there a standard library module in Python 2.4 (Win32) that will
return directory permissions / ACLs (e.g. users, groups, and what
rights they have)?

Otherwise, I'm faced with sending "cacls dirName" commands via os.popen
as below, and then parsing and comparing the text output.

Basically, I'd like to compare what the ACLs a directory should have
against what the actual ACLs are.

Here's what I started with:

import os # Cross-platform filesystem manipulation

rootDir = "S:\someRootDirectoryHere"

print "*** Printing DIRECTORY names beneath directory " + rootDir + "
***\n"
for dirpath, dirnames, filenames in os.walk(rootDir):
for dirNm in dirnames:
theDirPath = os.path.join(dirpath, dirNm)
print '"' + theDirPath +'"'
# cacls needs double-quotes around space-containing paths
result = os.popen("cacls " + '"' + theDirPath + '"')
# Print the security info (ACLs)for specified directory
print result.read()

Thanks.

The win32security module from Pywin32 wraps the functions used to
read and change security descriptors.

Roger
 
D

dananrg

Thanks Roger, I'll give it a shot.

Is os.walk the best way (using standard library modules) to traverse
directory trees in Python 2.4 and beyond?
 
D

dananrg

Could you give an example for listing security descriptors using the
win32security module? I looked at the documentation but found it
confusing. Thanks.
 
R

Roger Upole

Could you give an example for listing security descriptors using the
win32security module? I looked at the documentation but found it
confusing. Thanks.

There are some examples of using the security descriptor objects in
\Lib\site-packages\win32\Demos\security.
Also, searching the Python-win32 mailing list should turn up some
more code.

Roger
 
D

dananrg

There are some examples of using the security descriptor objects in
\Lib\site-packages\win32\Demos\security.
Also, searching the Python-win32 mailing list should turn up some
more code.

Thanks again Roger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top