Мне нужно смоделировать каталог LDAP для отправки предопределенных ответов одному приложению, которому для работы нужен LDAP.Я делаю некоторые тесты, используя LDAP Browser и LDAP Admin, прослушивая порт 389.Чтобы написать ответ, я бы использовал NetworkStream и StreamWriter.Из LDAP RFC у меня есть модель, показанная ниже для поискового ответа.Я не могу понять, как построить этот конверт, я должен построить последовательность байтов?
SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
objectName LDAPDN,
attributes PartialAttributeList }
PartialAttributeList ::= SEQUENCE OF SEQUENCE {
type AttributeDescription,
vals SET OF AttributeValue }
-- implementors should note that the PartialAttributeList may
-- have zero elements (if none of the attributes of that entry
-- were requested, or could be returned), and that the vals set
-- may also have zero elements (if types only was requested, or
-- all values were excluded from the result.)
SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL
-- at least one LDAPURL element must be present
SearchResultDone ::= [APPLICATION 5] LDAPResult
Я получил запрос, который отправляет клиент, я могу определить строковую часть запроса,но я не нашел правильный способ ответить.По найденным в запросе строкам я могу выяснить, какое сообщение отправляет клиент.
public static void Connect()
{
try
{
int port = 389;
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(ipAddress, port);
listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
listener.Start();
while (true)
{
LDAPLayer handler = new LDAPLayer(listener.AcceptTcpClient());
Thread thread = new Thread(new ThreadStart(handler.LDAPListener));
thread.Start();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
client.Close();
}
}
public void LDAPListener()
{
try
{
while (true)
{
string line = reader.ReadLine();
string date = DateTime.Now.ToString("yyyyMMdd_HHmmss");
while (line != null)
{
Console.WriteLine(line);
if (line.Contains("objectClass"))
{
writer.Write(0);
}
line = reader.ReadLine();
}
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
}