From: deepti j. <dja...@gm...> - 2008-07-26 18:26:23
|
Hi, I have been working with python ldap and ADSI modules to get my tasks done in AD and i have noticed that python ldap is able to handle unicode characters when we try to add/remove a particular user from a group who has unicode characters in his DN but the sam eis not possible in ADSI can you gime an insight as to how Python ldap is able to handle this ? -- Cheers, Deepti Jawalkar. -- Cheers, DJ. |
From: Michael S. <mi...@st...> - 2008-07-27 15:37:58
|
deepti jawalkar wrote: > > I have been working with python ldap and ADSI modules to get my tasks > done in AD and i have noticed that python ldap is able to handle unicode > characters when we try to add/remove a particular user from a group who > has unicode characters in his DN but the sam eis not possible in ADSI > can you gime an insight as to how Python ldap is able to handle this ? I'm not sure I fully understand your question. Up to now python-ldap does not have any Unicode handling. That's because the root of the API is still in pre-Unicode-Python-times. So the code using python-ldap is responsible for doing anything related to Unicode encoding/decoding and pass valid strings to python-ldap's functions and object methods. It would help if you show a concrete case maybe with data and Python code where python-ldap works and ADSI does not. (Anyway I'd recommend to use python-ldap since you can then even tweak your AD from a Linux box. ;-) Ciao, Michael. |
From: deepti j. <dja...@gm...> - 2008-08-03 20:00:20
|
well these are my 2 cases : *with python-ldap *: so in this case it works even though the object i am passing has unicode characters in it's distinguished name eg: CN=Sen-po 胡æ£(R)å?š (senpo),OU=Users,OU=TPE,OU=Offices,DC=corp,DC=google,DC=com i can print the distinguished name without encoding it in utf-8 format and also remove or add this user to a group. import ldap ldap.set_option(ldap.OPT_REFERRALS, 0) group_dn = "CN=sysops,OU=LDAPGroups,DC=corp,DC=google,DC=com" user = 'CN=goadmin sgadekal,OU=Users,OU=Administration,DC=corp,DC= google,DC=com' l = ldap.open("192.168.100.1") l.protocol_version = ldap.VERSION3 l.simple_bind_s(who=user,cred=r'*****') baseDN = 'dc=corp,dc=google,dc=com' searchScope = ldap.SCOPE_SUBTREE retrieveAttributes = ['cn','samaccountname','distinguishedname'] searchFilter = "(&(objectclass=*)(samaccountname=senpo))" ldap_result_id = l.search_ext(baseDN, searchScope, searchFilter, retrieveAttributes,sizelimit=1000) result_type, result_data = l.result(ldap_result_id, 0) if (result_type == ldap.RES_SEARCH_ENTRY): user_dn = result_data[0][1]['distinguishedName'][0] modlist = [] modlist.append((ldap.MOD_ADD,"member",user_dn)) try: l.modify_s(group_dn,modlist) except: print "user not added" *with Win32com.client:* The Same thing when i try to do it with "win32com.client module" using "adsi" i cannot print the distinguished name of the user without first encoding in utf-8 format and even if i do this i cannot add or remove user from a group it throws a error . import win32com.client from win32com.client import * conn = Dispatch('ADODB.Connection') conn.Open("Provider=ADSDSOObject") search = "<LDAP://dc=corp,dc=google,dc=com>;(&(ObjectClass=*)(sAMAccountName=senpo));cn,distinguishedname;subtree" record_set = conn.Execute(search)[0] dn = record_set.Fields("distinguishedName").value dn = dn.encode('utf-8') adsi = win32com.client.Dispatch('AdsNameSpaces') ldap = adsi.getobject("","LDAP:") logon_ex = "CN=goadmin sgadekal,OU=Users,OU=Administration,DC=corp,DC=google,DC=com" passwd = "*******" ex_path = "LDAP:// 192.168.100.1/CN=sysops,OU=LDAPGroups,DC=corp,DC=google,DC=com" myDSObject = ldap.OpenDSObject(ex_path,logon_ex,passwd,0) myDSObject.Getinfo() list_member = dn print dn append_list=[list_member] myDSObject.putEx(3,'Member',append_list) myDSObject.Setinfo() Can you let me know how exactly is this happening in python ldap and how is it able to add and remove accounts with unicode characters. It will be really helpfull for me to know it. |
From: Michael S. <mi...@st...> - 2008-08-03 20:09:32
|
deepti jawalkar wrote: > well these are my 2 cases : > > *with python-ldap *: so in this case it works even though the object i > am passing has unicode characters in it's distinguished name > eg: CN=Sen-po 胡森� > (senpo),OU=Users,OU=TPE,OU=Offices,DC=corp,DC=google,DC=com Well, *I* can't read this distinguished name. I don't have the necessary fonts and installed and I don't understand them anyway. ;-) > i can print the distinguished name without encoding it in utf-8 format > and also remove or add this user to a group. Off course you can pass around UTF-8-encoded Unicode strings. But you have to invoke .decode() and .encode() in your application code (e.g. like my web2ldap does). python-ldap does *never* invoke these methods internally. > Can you let me know how exactly is this happening in python ldap and how > is it able to add and remove accounts with unicode characters. You can always just treat the DNs opaque. ;-) Ciao, Michael. |