I've been working on an LDAP library and I've managed to work out how to
read info from Active Directory.
I'm now trying to write information back (or delete) and I can't work out
the signatures/struct to use or whether I need to allocate unmanaged memory
and pass that instead.

The LDAP API stuff and my managed definitions are:-

WINLDAPAPI ULONG LDAPAPI ldap_modifyW( LDAP *ld, PWCHAR dn, LDAPModW *mods
[] );

[DllImport("wldap32.dll", CharSet=CharSet.Auto)]
public static extern int ldap_modify_s(HandleRef pLDAPSession, /* PCHAR  */
[In] string dn, /* LDAPMod* */ [In, Out] LDAP.LDAPMod[] mods);

(I'm pretty sure that the first two parameters and the return value are
correct since I've used their values in other LDAP functions successfully)


and


typedef struct ldapmodW {
     ULONG     mod_op;
     PWCHAR    mod_type;
     union {
        PWCHAR  *modv_strvals;
        struct berval   **modv_bvals;
    } mod_vals;
} LDAPModW, *PLDAPModW;


[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class LDAPMod {
 public int ModOp;
 [MarshalAs(UnmanagedType.LPStr)]
 public string ModType;
 public object[] Values;

}

(Values will be set to a String[] for the purposes of this test - I'll work
on the binary stuff later)


The code I am using to delete an existing attribute is:-

LDAP.LDAPMod[] modifications = new LDAP.LDAPMod[modificationList.Count + 1];
modificationList.CopyTo(modifications);
modifications[modificationList.Count] = null;
int result = LDAP.API.ldap_modify_s(_session._LDAPSession, DN,
modifications);

modifications[0] is {0x02, "description", null} (0x02 is LDAP_MOD_REPLACE
and the null should delete all existing values)
modifications[1] is null (required to serve as the list terminator

I get error 0x59 which is LDAP_PARAM_ERROR


I will be grateful for any help or pointers.

Cheers
Simon

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to