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

Discussion in 'Python' started by dananrg@yahoo.com, Nov 7, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Roger Upole Guest

    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 =---
     
    Roger Upole, Nov 8, 2006
    #2
    1. Advertising

  3. Guest

    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, 2006
    #3
  4. Guest

    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, 2006
    #4
  5. Roger Upole Guest

    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 =---
     
    Roger Upole, Nov 8, 2006
    #5
  6. Guest

    > 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, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Curt K
    Replies:
    0
    Views:
    579
    Curt K
    Nov 3, 2006
  2. MacMan0295

    Run CACLS from an ASP page?

    MacMan0295, Jan 7, 2009, in forum: ASP General
    Replies:
    4
    Views:
    426
    Steve
    Jan 8, 2009
  3. Terry Michaels
    Replies:
    4
    Views:
    175
    w_a_x_man
    Oct 16, 2010
  4. Andrew
    Replies:
    23
    Views:
    314
    Tad McClellan
    May 9, 2004
  5. Steven D'Aprano
    Replies:
    0
    Views:
    116
    Steven D'Aprano
    Dec 23, 2013
Loading...

Share This Page