NTFS permissions

Chris Gonnerman chris.gonnerman at usa.net
Tue Apr 24 09:00:37 EDT 2001


----- Original Message -----
From: "Tim Howarth" <tim at worthy.demon.co.uk>
Subject: Re: NTFS permissions


> In message <3AE4BAB0.3090204 at ActiveState.com>
>           Mark Hammond <MarkH at ActiveState.com> wrote:
>
> > Tim Howarth wrote:
> >
> > > My problem with directories not accepting security descriptors was
> > > not quite correct.
>
> > > So next problem how do I turn them on programmatically ?
> >
> >
> > It appears the win32 extensions lack this capability.
>
> Thanks, again, nice to know it's not me !
>
> I guess I'll have to stick to cacls.exe for now.
>
> (Except, that echoes output to my user creator web page, need to sort
> that out....change stdout whilst calling cacls ?)

Use the os module to manipulate the "real" stdout/stderr before running
your ill-behaved program.  Assuming you want the external program's output
hidden:

    import sys, os

    # save my real stdout for my use later.
    sys.stdout = os.fdopen(os.dup(1), "w")

    # might also want:
    #    sys.stderr = sys.stdout
    # or alternately:
    #    sys.stderr = os.fdopen(os.dup(2), "w")
    # or you might not.

    # close real stdout and stderr
    os.close(1)
    os.close(2)

    # protect against accidents:
    os.open("nul", "w")
    os.open("nul", "w")

As file descriptors (even under Windoze) are allocated on a first-available
basis, the NUL device gets the fd #1 and #2 positions.  This is to prevent
us from opening another file later and accidentally getting the real stdout
or stderr munged.

> > My MSDN CD has an article "HOWTO: Set Security on a NTFS Folder
> > Programmatically" that shows exactly what you want (although in VB
code!).
>
> Yes, that's probably what I found when trying to work out how to do this
> - VB being more readable to me than similar things in C.
>
> > It would be cool to add this support, and not _too_ much work - I would
> > be happy to help, but don't have the time to do it all right now...
>
> Is there any way to do a generalised API call with win32 ? (Staying in
> Python, I've no/very little knowledge C-wise and certainly none about
> compiling win32 from sources.)

There is a calldll module.  I don't remember where it's from, but you can
find
it on Parnassus.






More information about the Python-list mailing list