[python-win32] Extracting share permissions

Brad Tilley rtilley at vt.edu
Wed Feb 1 02:28:21 CET 2006


Quoting Roger Upole <rwupole at msn.com>:

> [Sorry, somehow I massively screwed up the format the first time]
>
> There are a couple of different options for persisting a security
> descriptor.
>
> buffer(security_descriptor)[:] retrieves the raw bytes in binary form.
> This can be passed to pywintypes.SECURITY_DESCRIPTOR to recreate the
> PySECURITY_DESCRIPTOR.
>
> Also, you can use
> win32security.ConvertSecurityDescriptorToStringSecurityDescriptor
> to create a text representation and
> win32security.ConvertStringSecurityDescriptorToSecurityDescriptor
> to recreate the PySECURITY_DESCRIPTOR.
>
> That reminds me, there's a bug in the routine in win32net that parses info
> out of dictionaries.  If you pass in None to indicate a NULL security
> descriptor,
> you get an access violation.  I'll get a fix in for that soon.
>
>         Roger

Hey guys... thanks for all of the advice. I'm still trying to bang thru this...
I've read msdn articles until I finally understand why Windows has so many
problems: it's too darn complex. Anyway, here's where I'm at. Just
experimenting. Please chip in and help me make sense of this:

import win32net, win32security, pywintypes

shares = win32net.NetShareEnum(None, 502)
for share in shares[0]:
    try:
        sd = share['security_descriptor']
        print sd.GetLength()
        print sd.IsValid()
        print type(sd)
        text =
win32security.ConvertSecurityDescriptorToStringSecurityDescriptor(sd,
win32security.SDDL_REVISION_1,                                                 
                               win32security.OWNER_SECURITY_INFORMATION)
        print text
        bytes = buffer(sd)
        print bytes, type(bytes), len(bytes)
    except Exception, e:
        print e




More information about the Python-win32 mailing list