Forked from flamencist/DotNetCore Ldap query (Novell.Directory.Ldap.NetStandard2_0)
Created
October 6, 2021 15:31
-
-
Save ptzagk/691458decba62c91d764d55f0787eca2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Novell.Directory.Ldap; | |
namespace KerberosAuth | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using (var cn = new LdapConnection()) | |
{ | |
// connect | |
cn.Connect("ldap.forumsys.com", 389); | |
// bind with an username and password | |
// this how you can verify the password of an user | |
cn.Bind("cn=read-only-admin,dc=example,dc=com", "password"); | |
int searchScope = LdapConnection.SCOPE_ONE; | |
// call ldap op | |
// cn.Delete("<<userdn>>") | |
// cn.Add(<<ldapEntryInstance>>) | |
LdapSearchResults searchResults = | |
cn.Search("dc=example,dc=com", // container to search | |
searchScope, // search scope | |
"(objectclass=*)", // search filter | |
new []{LdapConnection.NO_ATTRS}, // "1.1" returns entry name only | |
true); // no attributes are returned | |
while ( searchResults.HasMore() ) | |
{ | |
LdapEntry nextEntry = null; | |
try | |
{ | |
nextEntry = searchResults.Next(); | |
} | |
catch(LdapException e) | |
{ | |
Console.WriteLine("Error: " + e.ToString()); | |
// Exception is thrown, go for next entry | |
continue; | |
} | |
Console.WriteLine("\n" + nextEntry.DN); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment