windows active directory ldap output encoding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jo3c

    windows active directory ldap output encoding

    Hi..
    Im trying to get some information out of a windows sever 2003 chinese
    active directory system
    so let's say encoding is probably big5 or utf-8

    what im doing is simliar to ldapsearch in shell with my python script
    using python ldap module

    the result is not the correct encoding..

    i've look many places and tried many different encoding on the top of
    the script #coding=big5 etc..

    below is the wrong encoding output .. any help will be much
    appreciated..

    *** ldap://2134.localhost. com:389 - SimpleLDAPObjec t.set_option ((17,
    3),{})
    CN=江,OU=2134, DC=localhost,DC =com
    {'accountExpire s': ['92233720368547 75807'],
    'badPasswordTim e': ['12856601467234 3750'],
    'badPwdCount': ['0'],
    'cn': ['\xe6\xb1\x9f\x e6\x9f\x8f\xe5\ xa3\x95'],
    'codePage': ['0'],
    'company': ['\xe8\x8f\xaf\x e8\x81\xaf\xe7\ x94\x9f
    \xe7\x89\xa9\xe 7\xa7\x91\xe6\x 8a\x80'],
    'countryCode': ['0'],
    'department': ['\xe7\x94\x9f\x e7\x89\xa9\xe7\ xa7\x91\xe6\x8a
    \x80\xe8\x99\x9 5'],
    'displayName': ['\xe6\xb1\x9f\x e6\x9f\x8f\xe5\ xa3\x95'],
    'distinguishedN ame': ['CN=\xe6\xb1\x9 f\xe6\x9f\x8f
    \xe5\xa3\x95,OU =300\xe7\xa7\x9 1\xe6\x8a
    \x80\xe8\x99\x9 5,DC=localhost, DC=com'],
    'givenName': ['\xe6\x9f\x8f\x e5\xa3\x95'],
    'homeMDB': ['CN=\xe4\xbf\xa 1\xe7\xae\xb1\x e5\x84\xb2\xe5\ xad
    \x98\xe5\x8d\x8 0 (MAIL),CN=\xe9\ xa0\x90\xe8\xa8 \xad\xe5\x84\xb 2\xe5\xad
    \x98\xe7\xbe\xa 4\xe7\xb5\x84,C N=InformationSt ore,CN=MAIL,CN= Servers,CN=
    \xe9\xa0\x90\xe 8\xa8\xad\xe7\x b3\xbb\xe7\xb5\ xb1\xe7\xae
    \xa1\xe7\x90\x8 6\xe7\xbe\xa4\x e7\xb5\x84,CN=A dministrative
    Groups,CN=local host,CN=Microso ft
    Exchange,CN=Ser vices,CN=Config uration,DC=loca lhost,DC=com'],
    'homeMTA': ['CN=Microsoft MTA,CN=MAIL,CN= Servers,CN=
    \xe9\xa0\x90\xe 8\xa8\xad\xe7\x b3\xbb\xe7\xb5\ xb1\xe7\xae
    \xa1\xe7\x90\x8 6\xe7\xbe\xa4\x e7\xb5\x84,CN=A dministrative
    Groups,CN=local host,CN=Microso ft
    Exchange,CN=Ser vices,CN=Config uration,DC=loca lhost,DC=com'],
    'instanceType': ['4'],
    'lastLogoff': ['0'],
    'lastLogon': ['12859896506671 8750'],
    'legacyExchange DN': ['/o=localhost/ou=ExchangAdmin/cn=Recipients/
    cn=joechiang'],
    'logonCount': ['33'],
    'mDBUseDefaults ': ['TRUE'],
    'mail': ['joechiang@loca lhost.com'],
    'mailNickname': ['joechiang'],
    'memberOf': ['CN=AllHQStaff, CN=Users,DC=loc alhost,DC=com'],
    'msExchALObject Version': ['60'],
    'msExchHomeServ erName': ['/o=localhost/ou=ExchangAdmin/
    cn=Configuratio n/cn=Servers/cn=MAIL'],
    'msExchMailboxG uid': ['2\x04\x116^\xf c%J\x87yi\xbdj^ \x1bl'],
    'msExchMailboxS ecurityDescript or': ['\x01\x00\x04\x 80x
    \x00\x00\x00\x9 4\x00\x00\x00\x 00\x00\x00\x00\ x14\x00\x00\x00 \x04\x00d
    \x00\x01\x00\x0 0\x00\x00\x02\x 14\x00\x03\x00\ x02\x00\x01\x01 \x00\x00\x00\x0 0\x00\x05\n
    \x00\x00\x00a\x 00n\x00x\x00/\x00C\x00N\x00= \x00C\x00o\x00n \x00f\x00i
    \x00g\x00u\x00r \x00a\x00t\x00i \x00o\x00n
    \x00\x00\x00\x0 0\x00\x00\x00\x 00\x00\x00\x00\ x00\x00\x00\x00 \x00\x00\x00\x0 0\x00\x00\x00\x 00\x00\x00\x00\ x00\x00\x00\x00 \x00\x00\x00\x0 1\x05\x00\x00\x 00\x00\x00\x05\ x15\x00\x00\x00 \xd6\xb2i
    \x1a^\xa7P\xcb\ xday
    \x88\xa9\xf4\x0 1\x00\x00\x01\x 05\x00\x00\x00\ x00\x00\x05\x15 \x00\x00\x00\xd 6\xb2i
    \x1a^\xa7P\xcb\ xday\x88\xa9\xf 4\x01\x00\x00'],
    'msExchPolicies Included': ['{C96E41C5-C5D5-411B-8672-1A3B6602437F},
    {3B6813EC-CE89-42BA-9442-D87D4AA30DBC}',
    '{C96E41C5-C5D5-411B-8672-1A3B6602437F},
    {26491CFC-9E50-4857-861B-0CB8DF22B5D7}'],
    'msExchUserAcco untControl': ['0'],
    'name': ['\xe6\xb1\x9f\x e6\x9f\x8f\xe5\ xa3\x95'],
    'objectCategory ':
    ['CN=Person,CN=S chema,CN=Config uration,DC=loca lhost,DC=com'],
    'objectClass': ['top', 'person', 'organizational Person', 'user'],
    'objectGUID': ['\x13\xfa\xc2\x bb\x9e\xee|C\x9 d\xa8_\xea]\xef
    \xc6\x90'],
    'objectSid':
    ['\x01\x05\x00\x 00\x00\x00\x00\ x05\x15\x00\x00 \x00\xd6\xb2i\x 1a^\xa7P
    \xcb\xday\x88\x a9u\x0c\x00\x00 '],
    'primaryGroupID ': ['513'],
    'proxyAddresses ':
    ['X400:c=TW;a= ;p=localhost;o= Exchange;s=joec hiang;',
    'SMTP:joechiang @localhost.com'],
    'pwdLastSet': ['12858767039656 2500'],
    'sAMAccountName ': ['joechiang'],
    'sAMAccountType ': ['805306368'],
    'showInAddressB ook': ['CN=\xe5\x85\xa 8\xe5\x9f\x9f\x e9\x80\x9a
    \xe8\xa8\x8a\xe 6\xb8\x85\xe5\x 96\xae,CN=All Global Address
    Lists,CN=Addres s Lists Container,CN=lo calhost,CN=Micr osoft
    Exchange,CN=Ser vices,CN=Config uration,DC=loca lhost,DC=com',
    'CN=\xe7\x87\x9 f\xe9\x81\x8b\x e8\x99\x95,CN=A ll
    Address Lists,CN=Addres s Lists Container,CN=lo calhost,CN=Micr osoft
    Exchange,CN=Ser vices,CN=Config uration,DC=loca lhost,DC=com',
    'CN=\xe7\x94\x9 f\xe7\x89\xa9\x e7\xa7\x91\xe6\ x8a
    \x80\xe8\x99\x9 5,CN=All Address Lists,CN=Addres s Lists
    Container,CN=lo calhost,CN=Micr osoft
    Exchange,CN=Ser vices,CN=Config uration,DC=loca lhost,DC=com',
    'CN=\xe6\x89\x8 0\xe6\x9c\x89\x e4\xbd\xbf
    \xe7\x94\xa8\xe 8\x80\x85,CN=Al l Address Lists,CN=Addres s Lists
    Container,CN=lo calhost,CN=Micr osoft
    Exchange,CN=Ser vices,CN=Config uration,DC=loca lhost,DC=com'],
    'sn': ['\xe6\xb1\x9f'],
    'textEncodedORA ddress':
    ['c=TW;a= ;p=localhost;o= Exchange;s=joec hiang;'],
    'uSNChanged': ['22943844'],
    'uSNCreated': ['21991450'],
    'userAccountCon trol': ['66048'],
    'userPrincipalN ame': ['joe@localhost. com'],
    'whenChanged': ['20080624074423 .0Z'],
    'whenCreated': ['20071205035154 .0Z']}
    None
  • =?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=

    #2
    Re: windows active directory ldap output encoding

    jo3c wrote:
    Im trying to get some information out of a windows sever 2003 chinese
    active directory system
    so let's say encoding is probably big5 or utf-8
    The Unicode encoding of LDAP attributes with syntax Directory String is
    always UTF-8 (e.g. attributes 'cn', 'sn', 'givenName' or 'displayName').
    what im doing is simliar to ldapsearch in shell with my python script
    using python ldap module
    >
    the result is not the correct encoding..
    What exactly did you expect?
    'cn': ['\xe6\xb1\x9f\x e6\x9f\x8f\xe5\ xa3\x95'],
    >>unicode('\xe6 \xb1\x9f\xe6\x9 f\x8f\xe5\xa3\x 95','utf-8')
    u'\u6c5f\u67cf\ u58d5'

    I cannot tell whether this Unicode string of length 3 is correct since I
    cannot read Chinese and I probably don't have the necessary fonts
    installed. At least it decodes as UTF-8 which is correct at the LDAP level.
    'displayName': ['\xe6\xb1\x9f\x e6\x9f\x8f\xe5\ xa3\x95'],
    >>unicode('\xe6 \xb1\x9f\xe6\x9 f\x8f\xe5\xa3\x 95','utf-8')
    u'\u6c5f\u67cf\ u58d5'

    Maybe you should provide the original Unicode string (e.g. in Python
    syntax) and tell us how you store that into your AD server. Note that
    the tools used to maintain AD are also part of the game.

    Ciao, Michael.

    Comment

    • =?UTF-8?B?TWljaGFlbCBTdHLDtmRlcg==?=

      #3
      Re: windows active directory ldap output encoding

      Michael Ströder wrote:
      jo3c wrote:
      >Im trying to get some information out of a windows sever 2003 chinese
      >active directory system
      >so let's say encoding is probably big5 or utf-8
      >
      The Unicode encoding of LDAP attributes with syntax Directory String is
      always UTF-8 (e.g. attributes 'cn', 'sn', 'givenName' or 'displayName').
      BTW: I'd be curious to see whether my web2ldap works with Chinese
      characters. Since you already have python-ldap installed it's easy to
      download (from http://www.web2ldap.de/download.html) and unpack the
      tar.gz and start it as stand-alone web server:

      python <web2ldap-dir>/sbin/web2ldap.py -d off

      Ah forgot, pyweblib needs to also be installed with usual
      python setup.py install:


      If everything is correctly configured in your browser you should the
      correct Unicode chars. Maybe you can even maintain your AD entries.

      Ciao, Michael.

      Comment

      Working...