Directorysearcher problems with charactersets

  • Thread starter Thread starter Peter Aragon
  • Start date Start date
P

Peter Aragon

Hi

I have a problem reading from our ldap server with DirectorySearcher.
For example when I'm retrieving data of people with a names like "René" or
"Jerôme" they appear in the SearchResult as "Ren" and "Jerme".
With a third party tool I can see that René is stored as "52 65 6E E9".
Because E9 >128 I'm affraid something is wrong with the DirectorySearcher
implementation, as I cannot retrieve those characters, even with the
Encoding GetString methods.

Anyone who knows a workaround?
Thanks,
Peter Aragon
 
I see it is stored as a binary attribute in stead of a text attribute, maybe
this helps?
 
Hi Peter,
From your description, you found that Ren is stored as "52 65 6E E9" in a 3rd party tool. Since E9 > 128, so you
thought there might be some error in the DirectorySearcher implementation.

Before we go further, could you answer the following questions please:
1>How did you use the DirectorySearcher in your code? And what attribute are you trying to retrieve? Could
you post a code snippet on it?
2>what's that 3rd tool? And how can I get the problem value from it?

Thanks. I am looking forward to hearing from you.

Have a great weekend!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Hi Rhett

The third party tool I used to find this out is Softerra LDAP Browser (2.5).
The name is stored in the "CN" property. For retrieving purposes this CN can be an array of names, so if you look for René you can also find him with Rene.
The following code is used.... I illimitated the need of a DirectorySearcher just to make sure the flaw isn't in DirectorySearcher.
strPath is a correct LDAP path that will uniquely point to one object.
The PrintObject function is from an MSDN article about setting Binary Properies Using System.DirectoryServices, but it says nothing about retrieving them correctly. I only get strings back instead of a byte array or something so I can use a Text decoder with the proper codepage to convert it to UTF8.
(http://msdn.microsoft.com/library/d...icate_hash_using_system_directoryservices.asp)

DirectoryEntry objDE = new DirectoryEntry(strPath, "", "", AuthenticationTypes.Anonymous);

PropertyValueCollection values = objDE.Properties["cn"];

object x = values.Value;

PrintObject(x, "hash");


static void PrintObject(object x, string name)

{

object[] a = x as object[];

System.Diagnostics.Debug.WriteLine(x.GetType());

System.Diagnostics.Debug.WriteLine(a[0].GetType());

System.Diagnostics.Debug.WriteLine(a.Length);

for (int i = 0; i < a.Length; ++i)

{

System.Diagnostics.Debug.WriteLine(name + "[" + i + "] = " + a);

}

}

Thanks for the quick reply,

Peter Aragon
 
Hi,
1> use following lines (unmanaged code) to see if you can get the full charaters especially 0xE9 returned at your client with different locale setting.
//---------------------------------------------------------------------------------
hr = ADsGetObject(L"LDAP://test.microsoft.com/CN=Ren¨¦,CN=Users,DC=Test,DC=microsoft,DC=com",IID_IADs, (void **) & oUsr);
oUsr->Get(L"cn",&pProp);
//---------------------------------------------------------------------------------

2> using .net DirectoryServices: apply this code to see if it could resolve your problem,
//-----------------------------------------------------------------
// negotiate with ldap server what locale it used. Assume it is Franch, then try following code.
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr",true);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr",true);
//-----------------------------------------------------------------------

Please apply my suggestions and let me know your result. Thanks.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Hi Rhett

To no avail.
Setting the CultureInfo to fr got me the error: Culture "fr" is a neutral
culture. It can not be used in formatting and parsing and therefore cannot
be set as the thread's current culture. So I set it to "fr-FR" just to prove
setting the culture is not the right solution, and I get the same results .
It's not how the strings are put on screen, even in Debug mode when
switching to binary mode I don't see 4 but 3 characters for René (Ren). ,
and unless I get a byte array back or am able to set the encoding for the
string conversion of DirectoryServices Using ADsGetObject will certainly
work, it's just that the .NET way shows regression or less functionality and
it is a reason not to switch to .NET. I'm looking at a showstopper for this
project. The strings in the LDAP are encoded in UTF7. Changing the LDAP to
UTF8 is also no option, as a lot of legacy application still rely on UTF7
and don't understand UTF8.

So could you please forward this to the people within the .NET group
responsible for DirectoryServices as a feature request/bug report? Too bad
me or others haven't spotted this behavior during the last 2 beta trails of
..NET 1.0 and 1.1. So what I would want is the raw Byte array in stead of a
wrongly decoded string value, or give a hint to DirectoryServices on the
decoding scheme. Else how could you retrieve binary information from LDAP
with .NET if you would only get back a string?

Thanks,
Peter Aragon



Rhett Gong said:
Hi,
1> use following lines (unmanaged code) to see if you can get the full
charaters especially 0xE9 returned at your client with different locale
setting.
//--------------------------------------------------------------------------
ADsGetObject(L"LDAP://test.microsoft.com/CN=Ren¨¦,CN=Users,DC=Test,DC=micros
oft,DC=com",IID_IADs, (void **) & oUsr);
oUsr->Get(L"cn",&pProp);
//--------------------------------------------------------------------------
-------

2> using .net DirectoryServices: apply this code to see if it could resolve your problem,
//-----------------------------------------------------------------
// negotiate with ldap server what locale it used. Assume it is Franch, then try following code.
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr",true);
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr",true);
//-----------------------------------------------------------------------

Please apply my suggestions and let me know your result. Thanks.

Have a nice day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Else how could you retrieve binary information from LDAP
with .NET if you would only get back a string?
It seems that the "raw Byte array" is marshalled as an object. So this problem is more related with com interop. So far
as I know, there is no supported way to get back the "raw Byte array" at present.
So could you please forward this to the people within the .NET group
responsible for DirectoryServices as a feature request/bug report?
I have sent an email to them. If I get any answer for this problem, I will post it here.

Thanks and have a good day!
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
Back
Top