473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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.

Nov 7 '06 #1
5 9702

da*****@yahoo.com wrote:
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

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Nov 8 '06 #2
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?

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

Nov 8 '06 #4

da*****@yahoo.com wrote:
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


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Nov 8 '06 #5
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.

Nov 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jiing.deng | last post by:
I want to use the system command to set user's priority $cmd = "cacls d:\\appserv\\www\\accountMng\\$userName /G $userName:F"; system($cmd); Then it appears Are you sure (Y/N)? How can I...
7
by: barney | last post by:
I'm trying to write to an existing file under windows XP (home). The files are in 'My Music' which I think may be treated in some special way under XP. The relevant python code is as follows: ...
4
by: ewallig | last post by:
Hi all, need help - As part of a ASP-based AD account creation tool, I need to set file permissions on the newly-created user's home folders. I'm using CACLS to do this and calling it from...
1
by: Matt | last post by:
I used to execute a command line script in IIS 4 using Dynuexec. This is a third part server object I installed on the server (http://www.dynu.com/dynuexec.asp). I installed this object onto my...
0
by: Jeff Knudson | last post by:
I am looking for the C# equivalent of invoking the CACLS command in VBScript to set the permissions on a new user account HomeDirectory. I think I'm close, but my permissions are listed under...
4
by: Dave Kolb | last post by:
If I make ASPNET a member of the admins group it can launch my COM+ object but I do not want to do that. What permissions do I need to set for the lowly ASPNET user so that it can launch a COM+...
4
by: Ram | last post by:
Hey, I'v managed to find a way of adding NTFS permissions to a certain folder, But the problem is, the folder has a couple of inherited permissions which I want to delete. How can I remove the...
1
by: Jeremy Winchell | last post by:
I have an applications that imports new AD users. It creates a folder to store the user profile information, and a folder for their home directory. I would like to set the Permissions on these...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.