i am trying to modify the AD attribute value using ldap_modify function…
the code is below…
LDAPMod *list_of_attrs[1]={0};
char *Password[] = {"Password2"};
LDAPMessage *result=NULL;
int msgid;
int rc=0;
LDAPMod attribute2;
attribute2.mod_type = (PCHAR)"Password number";
attribute2.mod_op = LDAP_MOD_REPLACE;
attribute2.mod_vals.modv_strvals=Password;
list_of_attrs[0] = &attribute2;
wchar_t dnName[100]={0};
char *dn = "CN=test,CN=Users,DC=raja,DC=com";
mbstowcs(dnName,dn, 100);
PWCHAR dnNameval = (PWCHAR)malloc(sizeof(PWCHAR) * 20);
wcscpy(dnNameval,dnName);
msgid=ldap_modify(pLdapConnection,(const PCHAR)dnNameval, list_of_attrs);
but,when it comes to last line(msgid)access violation exception occured..
*Unhandled exception at 0x76f693ac in AD2.exe: 0xC0000005: Access violation reading location 0xcccccccc.*
kindly help me to resolve that…
thanks in advance.
I may guess from location 0xcccccccc that the crash occurs due to an uninitialized pointer. When reading the code,
pLdapConnectionappears to be that pointer.Update
After reading the OP comment, now I can see that the problem is in the 3rd argument which is, quoting MSDN, a null-terminated array of modifications to make to the entry.
Therefore, the correct usage should be e.g.
That is, the size of the array should be one more than the number of entries you’d like to define and the last array item should be NULL.