Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flamencist/ce3701af70bed917e9c5f737e599d47d to your computer and use it in GitHub Desktop.
Save flamencist/ce3701af70bed917e9c5f737e599d47d to your computer and use it in GitHub Desktop.
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