Created
February 14, 2018 21:01
-
-
Save flamencist/ce3701af70bed917e9c5f737e599d47d to your computer and use it in GitHub Desktop.
This file contains 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