[win32all]: Problem With Win98

Tim Daneliuk tundra at tundraware.com
Wed Jan 29 19:00:07 EST 2003


The following call works fine when applied to a Win 2000 machine, but
fails as shown when applied to a Win 98 machine.  I realize that there
is a world of difference between older and newer Win implementations
viz security, but I would have thought the API would hide these differences.

Anyone have any ideas on what the problem might be here (M: is a
Win98 shared disk space - command was issued from a PythonWin
session running on a Win 2000 machine):


 >>> GetFileSecurity("M:\\autoexec.bat", OWNER_SECURITY_INFORMATION)
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
MemoryError: allocating SECURITY_DESCRIPTOR


My overall goal here is to obtain owner and group information for
each file in a directory.  This fragment of code works just swell
on 2000 systems and samba shares from unix - 'fn' is a fully
qualified file name as in "C:\\foobar.txt" - but it fails
(thus assigning UNAVAILABLE for owner/group) on Win98:

         try:
             # Get the internal Win32 security information for this file.
             ho     = GetFileSecurity(fn, OWNER_SECURITY_INFORMATION)
             hg     = GetFileSecurity(fn, GROUP_SECURITY_INFORMATION)
             sido   = ho.GetSecurityDescriptorOwner()
             sidg   = hg.GetSecurityDescriptorGroup()

             # We have to know who is hosting the filesytem for this file

             drive = fn[0:3]
             if GetDriveType(drive) == win32con.DRIVE_REMOTE:
                 fnhost = WNetGetUniversalName(drive, 1).split('\\')[2]
             else:
                 fnhost = WIN32HOST

             # Now we can translate the sids into names

             owner  = LookupAccountSid(fnhost, sido)[0]
             group  = LookupAccountSid(fnhost, sidg)[0]

         # We assume the values are unavailable on any error
         except:
             owner = UNAVAILABLE
             group = UNAVAILABLE


------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com





More information about the Python-list mailing list