[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
ldap_add_s()?
I installed openldap1.2 on my SCO OpenServer5.0 and I write a program using
ldap_add_s() as below:
***********
#include \"lber.h\"
#include \"ldap.h\"
#include <stdio.h>
main()
{ LDAP *ld;
int i,err;
char *dn,*passwd;
LDAPMod *attrs[2];
attrs[0]=(LDAPMod*)ch_calloc(1,sizeof(LDAPMod));
attrs[1]=(LDAPMod*)ch_calloc(1,sizeof(LDAPMod));
attrs[0]->mod_op=0;
attrs[0]->mod_type=\"cn\";
attrs[0]->mod_vals.modv_strvals=\"child1\";
attrs[0]->mod_next=0;
attrs[1]->mod_op=0;
attrs[1]->mod_type=\"objectclass\";
attrs[1]->mod_vals.modv_strvals=\"person\";
attrs[1]->mod_next=0;
dn=\"ou=R&D,o=SED,c=CN\";
passwd=\"secret\";
ld=ldap_open(\"100.100.200.1\",LDAP_PORT);
if (ld==NULL)
exit(1);
err=ldap_simple_bind_s(ld,dn,passwd);
if (err!=LDAP_SUCCESS)
{
ldap_perror(ld,\"ldap_simple_bind_s\");
exit(1);
}
err=ldap_add_s(ld,dn,*attrs);
if (err!=LDAP_SUCCESS)
{
ldap_perror(ld,\"ldap_add_s\");
exit(1);
}
printf(\"Adding new entry...\\n\");
ldap_unbind(ld);
}
*******************
The return value of ldap_add_s is 68.When I run this program,it shows:
\"ldap_add_s:Already Exists\".Then I change \"ldap_add_s\" to \"ldap_modify_s\", the
return value is 0 ,which means success add operation.When I run it,it shows
\"Adding new entry...\". But when using command \' ldapsearch \'objectclass=*\'
\',there is no this new entry .
If I use command \"ldapadd -f file -D \"ou=R&D,o=SED,c=CN\" -w secret\",it can add
successfully.
Who can tell me what\'s wrong with my program? Thanks in advance.
-----------------------------------------------------
Ãâ·ÑÓÊÏä¿ÉÒÔ´Ó http://mail.777.net.cn/ ´¦»ñµÃ.