[Mono-list] DirectoryServices class

Arnaud Bienvenu arnaud.bienvenu@makina-corpus.org
Fri, 29 Oct 2004 13:16:10 +0200


This is a multi-part message in MIME format.
--------------000405030306010303050805
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Nigel Benns a écrit :
> I've had quite a bit of success working with some test programs and
> OpenLdap, but the only thing I cannot do is write to the directory store.
> 
> DirectoryEntry.CommitChanges() runs and exits ok, but doesn't seem to
> really do anything. Then next time I run it, or read the directory in GQ
> the entry is still exactly the same.

CommitChanges() works fine for me from mono-1.0.0 to mono-1.1.1, and I
can write to OpenLDAP (2.0 and 2.1). Are you sure there is no exception
? Maybe your binding is wrong, or you do not respect the LDAP schema...

Attached is an example code of mine that creates a user entry. You could
also send me your code so I can test it.

> Right now I'm using Mono-1.0 with Linux Mandrake 10.1 (actually Cooker,
> I'm going to redo my Laptop with 10.1 PowerPack now that its out)

I use Mandrake 10.0 and Debian Sarge.

-- 
Arnaud Bienvenu
Makina Corpus


--------------000405030306010303050805
Content-Type: text/x-csharp;
 name="writeldap.cs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="writeldap.cs"

using System;
using System.DirectoryServices;

public class Client
{
  public static void Main()
  {
    try
    {
      DirectoryEntry DirEntry = new DirectoryEntry("LDAP://ldap.makina-corpus.org/ou=People,dc=mcjam,dc=org", "cn=admin,dc=makinacorpus,dc=org", "*********");
      DirectoryEntries people = DirEntry.Children;

      DirectoryEntry newentry = people.Add("uid=essai", "top");
      newentry.Properties["objectClass"].Add("posixAccount");
      newentry.Properties["objectClass"].Add("shadowAccount");
      newentry.Properties["objectClass"].Add("person");
      newentry.Properties["objectClass"].Add("organizationalPerson");
      newentry.Properties["objectClass"].Add("inetOrgPerson");

      newentry.Properties["userid"].Value = "essai";
      newentry.Properties["cn"].Value = "Ceci est un essai";
      newentry.Properties["uidNumber"].Value = "65534";
      newentry.Properties["gidNumber"].Value = "65534";
      newentry.Properties["homeDirectory"].Value = "/home/users/essai";
      newentry.Properties["sn"].Value = "Essai";
      newentry.CommitChanges();
    }
    catch (Exception ex)
    {
      Console.WriteLine("Exception : " + ex.Message);
    }
  }
}


--------------000405030306010303050805--