【问题标题】:LDAP search DelphiLDAP 搜索 Delphi
【发布时间】:2014-02-13 20:28:42
【问题描述】:

我正在尝试使用标识号在 LDAP 数据库搜索中获取名称。我在 linux 上使用这个查询得到了这个:

 ldapsearch -x -v -w *username* -D uid=xxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xxx,dc=xxx -b ou=xxx,dc=xxx,dc=xxx,dc=xxx -h xxx.xxx.xxx.xxx  "uid=xxxxxxxxx" cn

有了这个我可以得到uid xxxxx的cn(名字)。我想要在 Delphi 2007 上使用类似的东西。

我正在搜索,但很多只是试图连接或验证某些东西,我不明白。

我下载了库ActiveDs_TLB.pas,但不知道如何正确使用。如果有人可以帮我粘贴代码或类似的东西,那将非常有帮助。

谢谢。

【问题讨论】:

  • 抱歉,Stack Overflow 不是让人们为你做作业的地方。联系图书馆的供应商,了解其实施过程中的问题。或者,如果它与 Delphi 编程相关,则包含我们可以用来重新创建您的问题的相关代码。
  • 这是一个不太容易的话题。您可以使用来自here 的 ADHelper.pas 单元。
  • 好的,杰里道奇,我在这里问过,因为我已经尝试过,但一无所获。 Tnks,whosrdaddy,我试试看。

标签: delphi ldap


【解决方案1】:

经过一些研究并下载了一些库,我找到了答案。我为测试和帮助需要的人制作了这个基本功能。

在这里对这个问题感到抱歉,但我希望有一天它对某人有所帮助。

    procedure TForm1.OnClick2(Sender: TObject);
    var
      ldap: TLDAPsend;
      l: TStringList;
      host, username, psswd, base, cpf, result : string;
    begin
      ldap     := TLDAPsend.Create;
      l        := TStringList.Create;
      host     := teHost.text;
      username := teUser.text;
      psswd    := tePsswd.text;
      base     := teBase.text; //The base that you want to make the research.
      cpf      := teCpf.text;
      result   := '';
      try
        ldap.TargetHost := host; //like an IP. xxx.xxx.xxx.xxx
    //next line is the key to getting AD authentication working
        ldap.UserName   := username; //like 'uid=_user_,ou=blabla,ou=blabla,ou=blabla,dc=bla,dc=bla,dc=bla'
        ldap.Password   := psswd;
        ldap.Login;
        Label1.Caption  := 'Logged...';
        ldap.BindSasl; // BindSasl have more security than Bind.
        Label1.caption  := 'Bind...';
        l.Add('cn'); //I want just the name, so search the 'cn'. If want more just add.
        ldap.Search(base, False, 'uid=' + cpf, l); //search with the CPF (an kind of documentation number)
        Label1.Caption  := 'Success !';
{The next line have a function "getLastLine" cause the LDAPResult print something like this:
Results: 1

Result: 0
  Object: uid=xxxxxxxx,ou=xxx,ou=xxx,ou=xxx,dc=xxx,dc=xxx,dc=xxx
  Attribute: cn
    Fulano Ciclano de Tal
}
        result          := getLastLine(LDAPResultdump(ldap.SearchResult), #$D#$A);
        if (result <> '') and (result<> 'Results: 0') then
        begin
          teName.visible := true;
          teName.text    := result;
        end
        else
        begin
          Label1.Caption := 'No Result...';
          teName.Visible := false;
        end;
        ldap.Logout;
      finally
        ldap.Free;
        l.Free;
      end;
    end;

PS:这需要一些库,主要是“ldapsend”,其他的比如asn1util和blcksock。所有都可以在突触包上找到。一些库有错误,但只需将其删除。

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 2015-09-02
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多