[Twisted-Python] Server authentication

Volodymyr Orlenko orlenko at gmail.com
Thu Jan 18 13:12:32 MST 2007

Hi Lee,

Yes, win32security is a part of pywin32 extensions.

According to MSDN, you may be able to get user's directory by using 

Calling win32net.NetUserGetInfo(None, 'test_user', 1) returns a dictionary:
{'comment': u'',
 'flags': 513,
 'home_dir': u'',
 'name': u'test_user',
 'password': None,
 'password_age': 324,
 'priv': 1,
 'script_path': u''}

In my case, home_dir is empty. This sucks, so I tried a different way:

from win32com.shell import shellcon, shell
path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)

In this case, path is u'C:\\Documents and Settings\\<My 
Username>\\Application Data'. To get other users' data directories, you 
can either cheat and simply replace <My Username> with their usernames, 
or go the whole way honestly: get user's access token (I guess by 
impersonating him), and pass the token to the SHGetFolderPath function.

There's also a way to query Active Directory through LDAP, but it does 
not help much in my case:
 >>> adsi = win32com.client.Dispatch('ADSystemInfo')
 >>> u = win32com.client.GetObject('LDAP://%s' % adsi.UserName)
 >>> print u.homeDirectory

I guess the NetUserGetInfo and the LDAP methods rely on info in 
ActiveDirectory, which may or may not be present.


Lee Connell wrote:
> Martin,
> Glad you have a solution, I think Volodymyr's example would fit you better,
> I have not used the module, but maybe Volodymyr can reply on this, but you
> will probably want to get the users home directory once successfully logged
> in as well as the groups the user belongs too.  I'm sure pywin32 extensions
> will allow this.
> Is win32security part of pywin32 extensions?
> -----Original Message-----
> From: twisted-python-bounces at twistedmatrix.com
> [mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of Martin Evans
> Sent: Thursday, January 18, 2007 2:41 AM
> To: twisted-python at twistedmatrix.com
> Subject: RE: [Twisted-Python] Server authentication
> Many thanks to Volodymyr and Lee for the authentication pointers, 
> both the ldap and win32security modules look like suitable 
> candidates. At the end of the day it is whatever the client decides 
> so it is great to have these alternatives.
> Martin
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list