Howto create PrincipalContext to Synology LDAP Server

482 views Asked by At

I get stuck with following problem:

I want to use Synologys LDAP Service. Works fine. My config is:

  • FDQN: "ldap.local"
  • Base DN: "dc=ldap,dc=local"
  • Bind DN: "uid=root,cn=users,dc=ldap,dc=local"
  • allow anonymous (only for test !) don't force SSL

Now I have to check credentials from my c# .net application (.net 6). I would prefer using PrincipalContext rather than ldapconnection. But Whatever I do to create the PrincipalContext I always get errors. My code is:

string Domain = "192.168.178.79:389";//"192.168.178.79:636";
string dn = "dc=ldap,dc=local";
string User = "uid=admin,cn=users,dc=ldap,dc=local";
string Password = "iWillNotTellYouHere";
ContextOptions options = ContextOptions.SimpleBind;// | ContextOptions.SecureSocketLayer;
PrincipalContext context = new PrincipalContext(ContextType.Domain, Domain, dn, options, User, Password);

The constructor crashes with NullReferenceException

I checked connection with Softerra LDAP Browser and it works fine with and without SSL. Using following params:

  • Host and base DN from above, default port
  • URL = "ldaps://192.168.178.79:636/dc=ldap,dc=local"
  • Auth simple
  • Principal = "uid=admin,cn=users,dc=ldap,dc=local"
  • the global LDAP password, which I wont tell here

Any Ideas ???

The stack trace is:

System.NullReferenceException
  HResult=0x80004003
  Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
  Quelle = System.DirectoryServices.AccountManagement
  Stapelüberwachung:
   at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
   at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
   at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
   at DomainTest.Form1.button3_Click(Object sender, EventArgs e) in N:\Matthias\source\repos\DomainTest\DomainTest\Form1.cs:line 35
1

There are 1 answers

0
Lama On

OK now I know the problem source:

PrincipalContext can't handle OpenLDAP connections

I will have to use DirectoryEntry