0

I am facing Unknown error (0x80005000) while adding user to LDAP server(Apache), the following is my code. Could anyone please let me know where I am doing mistake.

namespace TestMethods
{
    public class Program
    {
        static void Main(string[] args)
        {
            var ldi = new LdapDirectoryIdentifier("localhost", 10389);
            AddUser("username", "o=Company");
        }
        public static void AddUser(string username, string group)
        {
            try
            {
                DirectoryEntry dirEntry = new 
                DirectoryEntry("LDAP://localhost:10389,o=Company" + group);
                Console.WriteLine("Added to the path");// Working 
                dirEntry.Invoke("Add", new object[] { username });//Received Exception here
                dirEntry.CommitChanges();
                Console.WriteLine("Added to the path");
                dirEntry.Close();
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Have you looked at https://stackoverflow.com/questions/9993928/unknown-error-0x80005000-with-ldaps-connection – Flydog57 Jun 29 '22 at 15:53

1 Answers1

0

I believe you should use a / to separate the server name from the DN in your path:

LDAP://localhost:10389/o=Company

The constructor of DirectoryEntry doesn't make any network requests, so your path isn't validated until you actually use it.

However, if you are not using Active Directory, then I don't think Invoke will work for you. The description of DirectoryEntry.Invoke says:

Calls a method on the native Active Directory Domain Services object.

Even then, I'm not sure which Add method you're trying to use.

The way to create a new object using DirectoryEntry is like this (assuming dirEntry is pointing to a path where it can be created):

var newUser = dirEntry.Children.Add($"uid={username}", "inetOrgPerson");

// Set other attributes like this:
// newUser.Properties["someAttribute"].Value = "something";

//Save - this is where the object is actually created
newUser.CommitChanges();

I've never used Apache's LDAP server (I know AD better), so you may have to edit the schema ("inetOrgPerson") if you need to.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • Hi, Thank you for correction and suggestion. As I am new to LDAP and C#, I am referring to other random sites for coding. If possible, could you please share any documentation or kindly suggest authentic website to learn LDAP from scratch(So that I can rely on the functionality used). – user19407430 Jul 01 '22 at 10:33