Does this mean that the LDAP server isn't an Active Directory server running
on Windows, or is it even a non AD server running on Unix?
Anyway, C++ or C# what should be done is using the same Ldap library for
both Encoding and Decoding. C# uses the Windows library ber (exports in
wldap32.lib headers in winber.h) functions (implementation is in
wldap32.dll). So you can use the same library in your C++ code, else you
will have to create a C++ library using your ldap library and PInvoke these
functions from C#, just wonder why would you even use C# in this case. The
power of C# is in the FCL really, and this library sits in top of Win32 and
all of it's services (like AD services), mixing Unix and Windows has it's
own issues I would guess.
Willy.
| Thank you very much Willy. I call the encoding fucntion given to me for
the
| C++ module. Those encoding functions are written in Unix C and I just
added
| them to my C++ module. I called the Decoding functions in C++ module and
| they seem to work.
|
| So does this mean I can't call the BerConverter class in C# to decode
this?
| Do I have to now make those Unix C functions into a dll which I then
pinvok
| to decode? It's daunting just thinking of the how to figure out the
| marshalling of strings and integer.
| --
| Thanks.
|
|
| "Willy Denoyette [MVP]" wrote:
|
| > IMO your encode blob is not valid.
| > When I decode your blob on XP SP2 or W2K3 I get :
| > BerConversionException:An error occurred during the BER conversion.
| >
| > The encoded string should look libe this, notice the header 48, 132, 0,
0,
| > 0, 62 where 0,0,0,62 is the length of the blob
| >
| > 48, 132, 0, 0, 0, 62, 2, 1, 0, 2, 1, 1, 2, 1, 1, 27, 3, 53, 56, 53, 2,
1,
| > 1, 27, 0, 27, 11, 47, 98, 105, 110, 47, 115, 104, 101, 108, 108, 115,
27,
| > 16, 47, 116, 109, 112, 47, 104, 111, 109, 101, 47, 100, 105, 114, 105,
118,
| > 101, 27, 4, 49, 54, 49, 50
| >
| > Try following program using the modified blob you'll see what I mean.
| >
| > using System;
| > using System.IO;
| > using System.Threading;
| > using System.Security;
| > //
| > // csc.exe /r:System.DirectoryServices.Protocols.dll Berprobl.cs
| >
| > using System.Runtime.InteropServices;
| > using System.Collections.Generic;
| > using System.Diagnostics;
| > using System.Text;
| > using System.Globalization;
| >
| > using System.DirectoryServices.Protocols;
| > namespace Willys
| > {
| > class Tester
| > {
| > //
| > // Converts a byte[] to a hex string
| > //
| > public static string ByteArrayToStringInHex(byte[] bytes)
| > {
| > StringBuilder s = new StringBuilder(bytes.Length/2);
| > foreach(byte b in bytes)
| > {
| > s.Append(String.Format(CultureInfo.InvariantCulture,
"0x{0:X2},"
| > ,b));
| > }
| > string retStr = s.ToString();
| >
| > // remove the last comma character
| > retStr = retStr.Remove(retStr.Length-1,1);
| > return retStr;
| > }
| > static void Main()
| > {
| > byte[] berEncodedValue = {
| > 48, 132, 0, 0, 0, 62, 2, 1, 0, 2, 1, 1, 2, 1, 1, 27, 3, 53, 56, 53, 2,
1,
| > 1, 27, 0, 27, 11, 47, 98, 105, 110, 47, 115, 104, 101, 108, 108, 115,
27,
| > 16, 47, 116, 109, 112, 47, 104, 111, 109, 101, 47, 100, 105, 114, 105,
118,
| > 101, 27, 4, 49, 54, 49, 50
| > };
| > try
| > {
| > Console.WriteLine("\r\nBer decoding the byte array...");
| > object[] decodedObjects = BerConverter.Decode("{iiiaiaaaa}",
| >
berEncodedValue);
| >
| > Console.WriteLine("\r\nThe decoded objects are:");
| > foreach(object o in decodedObjects)
| > {
| > if(o is byte[])
| > {
| > Console.WriteLine(ByteArrayToStringInHex((byte[])o));
| > }
| > else if (o is byte[][])
| > {
| > byte[][] byteArrays = (byte[][])o;
| > for(int i=0;i<byteArrays.Length;i++)
| > {
| >
Console.Write(ByteArrayToStringInHex(byteArrays
)
| > + " - ");
| > }
| > Console.WriteLine();
| > }
| > else if(o is string[])
| > {
| > string[] strArray = (string[])o;
| > for(int i=0;i<strArray.Length;i++)
| > {
| > Console.Write(strArray + " - ");
| > }
| > Console.WriteLine();
| > }
| > else
| > {
| > Console.WriteLine(o);
| > }
| > }
| > }
| > catch(BerConversionException e)
| > {
| > Console.WriteLine("BerConversionException:" + e.Message);
| > }
| > catch(ArgumentException e)
| > {
| > Console.WriteLine("ArgumentException:" + e.Message);
| > }
| > }
| > }
| > }
| >
| > Seems like your problem relates to the encoding done outside the managed
| > memory space.
| >
| > Willy.
| >
| >
| > | > | Hi Willy, The meetingBlob property was encoded in my C++ application.
| > Here
| > | is the content I got during the Debug mode in C#. Thank you.
| > |
| > | - enMeetingBlob {Dimensions:[58]} byte[]
| > | [0] 96 byte
| > | [1] 56 byte
| > | [2] 2 byte
| > | [3] 1 byte
| > | [4] 0 byte
| > | [5] 2 byte
| > | [6] 1 byte
| > | [7] 1 byte
| > | [8] 2 byte
| > | [9] 1 byte
| > | [10] 1 byte
| > | [11] 27 byte
| > | [12] 3 byte
| > | [13] 53 byte
| > | [14] 56 byte
| > | [15] 53 byte
| > | [16] 2 byte
| > | [17] 1 byte
| > | [18] 1 byte
| > | [19] 27 byte
| > | [20] 0 byte
| > | [21] 27 byte
| > | [22] 11 byte
| > | [23] 47 byte
| > | [24] 98 byte
| > | [25] 105 byte
| > | [26] 110 byte
| > | [27] 47 byte
| > | [28] 115 byte
| > | [29] 104 byte
| > | [30] 101 byte
| > | [31] 108 byte
| > | [32] 108 byte
| > | [33] 115 byte
| > | [34] 27 byte
| > | [35] 16 byte
| > | [36] 47 byte
| > | [37] 116 byte
| > | [38] 109 byte
| > | [39] 112 byte
| > | [40] 47 byte
| > | [41] 104 byte
| > | [42] 111 byte
| > | [43] 109 byte
| > | [44] 101 byte
| > | [45] 47 byte
| > | [46] 100 byte
| > | [47] 105 byte
| > | [48] 114 byte
| > | [49] 105 byte
| > | [50] 118 byte
| > | [51] 101 byte
| > | [52] 27 byte
| > | [53] 4 byte
| > | [54] 49 byte
| > | [55] 54 byte
| > | [56] 49 byte
| > | [57] 50 byte
| > |
| > | --
| > | Thanks.
| > |
| > |
| > | "Willy Denoyette [MVP]" wrote:
| > |
| > | > From what you posted I see that you are simply passing the
meetingBlob
| > | > property, this property isn't ber encoded, right!
| > | > What I would like to see is the real contents of the blob (the byte
| > array);
| > | >
| > | > Willy.
| > | >
| > | >
| > | > | > | > | Hi Willy,
| > | > | Thank you for the reply and here is more information about my code
and
| > the
| > | > | problem I'm having.
| > | > |
| > | > | I'm getting the following error message in the catch
| > | > | "BerConversionException: An error occurred during the BER
conversion."
| > | > |
| > | > | Here is the calling code. I'm passing the meetingBlob attribute
of
| > the
| > | > | meeting class in Active Directory Schema to decode:
| > | > | enMeetingBlob =
| > | > | ((byte[])child.Properties["meetingBlob"].Value);
| > | > | meetingBlob =
| > | > | CUnityDS.DecodeMeetingBlob(enMeetingBlob);
| > | > |
| > | > | Here is the method that decodes it I got the error at the
following
| > line
| > | > of
| > | > | code:
| > | > | object[] decodedObjects = BerConverter.Decode("{iiiaiaaaa}",
| > | > | encodedMeetingBlob);
| > | > |
| > | > |
| > | > | public static string DecodeMeetingBlob(byte[] encodedMeetingBlob)
| > | > | {
| > | > | string meetingBlob = null;
| > | > | //Decode it
| > | > | object[] decodedObjects = BerConverter.Decode("{iiiaiaaaa}",
| > | > | encodedMeetingBlob);
| > | > | foreach (object o in decodedObjects)
| > | > | {
| > | > | if (o is byte[])
| > | > | {
| > | > | meetingBlob += (ByteArrayToStringInHex((byte[])o));
| > | > | }
| > | > | else if (o is byte[][])
| > | > | {
| > | > | byte[][] byteArrays = (byte[][])o;
| > | > | for (int i = 0; i < byteArrays.Length; i++)
| > | > | {
| > | > | meetingBlob +=
| > | > (CUnityDS.ByteArrayToStringInHex(byteArrays)
| > | > | + " - ");
| > | > | }
| > | > | //Console.WriteLine();
| > | > | }
| > | > | else if (o is string[])
| > | > | {
| > | > | string[] strArray = (string[])o;
| > | > | for (int i = 0; i < strArray.Length; i++)
| > | > | {
| > | > | meetingBlob += (strArray + " - ");
| > | > | }
| > | > | //Console.WriteLine();
| > | > | }
| > | > | else
| > | > | {
| > | > | meetingBlob += "\n";
| > | > | //Console.WriteLine(o);
| > | > | }
| > | > | }
| > | > | string test = meetingBlob;
| > | > | return meetingBlob;
| > | > | }
| > | > | }//end CUnityDS
| > | > | --
| > | > | Thanks.
| > | > |
| > | > |
| > | > | "Willy Denoyette [MVP]" wrote:
| > | > |
| > | > | > Just checked and I see no reason it should not work on W2K, mind
to
| > post
| > | > a
| > | > | > short but complete sample that illustrates your issue.
| > | > | >
| > | > | > Willy.
| > | > | >
| > | > | > | > | > | > | I'm getting an error when I tried to use this BerConverter
class
| > in my
| > | > C#
| > | > | > | code. Even though the Interent doc says that it runs on
Win2000
| > sp4,
| > | > I
| > | > | > just
| > | > | > | thgouth I'll double check. Does anyone know if BerConverter
is
| > | > supported
| > | > | > for
| > | > | > | Win2000 server?
| > | > | > |
| > | > | >
| > | >
| >
http://msdn2.microsoft.com/en-us/library/system.directoryservices.protocols.berconverter.decode.aspx
| > | > | > | --
| > | > | > | Thanks.
| > | > | >
| > | > | >
| > | > | >
| > | >
| > | >
| > | >
| >