Hi Pepe,
I already replied to the dev@ mailing list, here again.
Gaetano Pepe wrote:
> Hi
>
> I use apache directory server and I would add a new user ....I use Visual
> Studio and mx OS is windows vista.
> the code is this:
>
> public static void prova(string FullName)
> {
> DirectoryEntry container;
> DirectoryEntries ChildEntry;
>
> container = new
> DirectoryEntry("LDAP://localhost:389/ou=users,ou=system,dc=example,dc=com",
> "uid=admin,ou=system", "secret");
>
Please check if "ou=users,ou=system,dc=example,dc=com" really exists.
"ou=users,ou=system" exists in a default installation.
To do a simple bind you need to use a bind DN and specify the right
authentication type (AuthenticationTypes.None). I'm not sure if other
authentication types work with non-AD servers.
> try
> {
>
> ChildEntry = container.Children;
> DirectoryEntry NewEntry = ChildEntry.Add("cn=" + FullName,
> "user");
Apache Directory Server doesn't contain the "user" object class. So if
you haven't added it to the schema you should use another object class
(e.g. inetOrgPerson)
Before you commit the changes you need to add all the other mandatory
attributes (cn and sn for inetOrgPerson).
> NewEntry.CommitChanges();
> NewEntry.Close();
> }
> catch (Exception ex)
> {
> throw new Exception("Error " + ex.Message);
> }
> }
>
> The problem is that I have this type of error:The directory service is not
> available.
> I tried changing the port with the 10389 but I'm still the same error.
> The server I think it works, I've tested with apache directory studio.
IMHO the error message produced by the System.DirectoryServices API is
not very helpful. I'd recommend to use a network monitor like Wireshark
to find out the problems.
Here is your modified code that works for me:
try
{
DirectoryEntry Container = new DirectoryEntry(
"LDAP://192.168.2.101:10389/ou=users,ou=system",
"uid=admin,ou=system", "secret", AuthenticationTypes.None);
DirectoryEntries ChildEntries = Container.Children;
DirectoryEntry NewEntry = ChildEntries.Add(
"cn=" + FullName, "inetOrgPerson");
NewEntry.Properties["cn"].Add(FullName);
NewEntry.Properties["sn"].Add(FullName);
NewEntry.CommitChanges();
NewEntry.Close();
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.Message);
Console.Out.WriteLine(ex.StackTrace);
}
BTW: There is a much better C# LDAP API from Novell, see [1][2]. There
are also many examples available.
Kind Regards,
Stefan
[1] http://forge.novell.com/modules/xfcontent/downloads.php/ldapcsharp
[2] http://www.novell.com/coolsolutions/feature/11204.html