[python-win32] Error 1789 during logon, except not really called

le dahut le.dahut at laposte.net
Fri Mar 14 13:59:25 CET 2008


Sorry I forgot some informations.
The error is :
1789, 'LookupAccountName', "The trust relationship between this 
workstation and the primary domain failed."

As I said, this doesn't always happen, sometimes logon runs successfully 
and ACLs are correctly set (this is why I use 'LookupAccountName').

If I try it in command line, the try/except statement is correctly run :
 >>> import win32security as wsec
 >>> wsec.LookupAccountName('','DomainUsers') # this should be working
(<PySID object at 0x00A18A98>, u'CONDA', 2)
 >>> wsec.LookupAccountName('fakeserver','DomainUsers') # this not
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
pywintypes.error: (5, 'LookupAccountName', 'Access denied.')
 >>> try:wsec.LookupAccountName('fakeserver','DomainUsers')
... except: print 'oo'
...
oo

Thanks in advance.

le dahut wrote :
> Hello,
> 
> I'm using this code :
>      mypdc = 'mypdc'
>      dusers = 'DomName\DomainUsers'
>      obj = 'C:\\Mylogfile.log'
>      try:
>          domainusers_sid = wsec.LookupAccountName(mypdc, dusers)[0]
>          info = wsec.DACL_SECURITY_INFORMATION
>          sd = wsec.GetFileSecurity(obj, info)
>          acl = sd.GetSecurityDescriptorDacl()
>          acl.AddAccessAllowedAceEx(wsec.ACL_REVISION_DS, 
> wsec.OBJECT_INHERIT_ACE, wf.FILE_ALL_ACCESS, domainusers_sid)
>          # maj du Security Descriptor
>          sd.SetSecurityDescriptorDacl(1, acl, 0)
>          # application sur l'objet
>          wsec.SetFileSecurity(obj, info, sd)
>      except Exception, e:
>          logging.error("ACLs error %s"%([obj, dusers, e]))
>          logging.debug('Error %s'%traceback.print_exc())
> 
> At logon time, it can occur that wsec.LookupAccountName fails. The 
> except statement is called but an exception is thrown as well and I get 
> a file logon.exe.log in which I can read the traceback. And finally 
> traceback.print_exc() returns None.
> 
> Why does this produce a traceback instead of really except it ?
> 
> 
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
> 
> 


More information about the python-win32 mailing list