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. |