Re: REG:python-ldap able to handle unicode characters

2008-08-03 Thread deepti jawalkar
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 =
";(&(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.
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/___
Python-LDAP-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev


Re: REG:python-ldap able to handle unicode characters

2008-08-03 Thread Michael Ströder
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.

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Python-LDAP-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev