[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
about ldap_add_s
Hi!
I installed openldap1.2.1 on SCO OpenServer5..4 and it runs right.
i turn off schemacheck and access control.
I write a little program using ldap_add_s as below:
_________________________________________________________________________
#include <stdio.h>
#include "../ldap/include/ldap.h"
#include "../ldap/include/lber.h"
main()
{
LDAP *ld;
LDAPMod *attrs[2];
int i,ret;
char *a, *dn,*binddn,*pw;
char *t1="cn";
char *v1="yeah";
char *t2="objectclass";
char *v2="person";
binddn="cn=root,o=TongTech,c=CN";
pw="pw";
attrs[0]->mod_op=LDAP_MOD_ADD;
attrs[0]->mod_type=t1;
attrs[0]->mod_values=&v1;
attrs[1]->mod_op=LDAP_MOD_ADD;
attrs[1]->mod_type=t2;
attrs[1]->mod_values=&v2;
if ( (ld = ldap_open( "127.0.0.1",LDAP_PORT))==NULL)
exit( 1 );
if ( ldap_simple_bind_s( ld,binddn,pw) != LDAP_SUCCESS )
{
ldap_perror( ld, "ldap_simple_bind_s" );
exit( 1 );
};
ret=ldap_add_s(ld,"cn=yeah,ou=sales,o=TongTech,c=CN",attrs[1]);
if (ret!=LDAP_SUCCESS)
{
ldap_perror(ld,"ldap_add_s:");
exit(1);
};
printf("ret=%d\n",ret);
ldap_unbind( ld );
}
_________________________________________________________________________
When I run the executable file,it prints "ret=0" on stdin.
But I can't see the entry by using ldapsearch.
When I run it again,it says:
"ldap_add_s:Already exists". I think it means the entry
has been added successfully.
If I use ldbmtest-td ,I can see the entry like below:
key: CN=YEAH,OU=SALES,O=TONGTECH,C=CN (len 33)
data:
19
If I use ldbmtest-te,it shows:
key: 19
data length: 41
data:
19
dn: cn=yeah,ou=sales,o=TongTech,c=CN
But other entries which were added by ldapadd command are like below:
key: 8
data length: 77
data:
8
dn: cn=pluto,ou=sales,o=TongTech,c=CN
cn: pluto
sn: k
objectclass: person
You can see the entry "cn=yeah,..." doesn't show attributes:
cn and objectclass. I think this is why ldapsearch can't find it.
But I don't know how to modify my program. If I change
"ret=ldap_add_s(ld,"cn=yeah,ou=sales,o=TongTech,c=CN",attrs[1]);" to
"ret=ldap_add_s(ld,"cn=yeah,ou=sales,o=TongTech,c=CN",attrs[2]);",it
will say "core dumped" when running.
Any hints will be appreciated!
Thank you !
----------------------------------------------
»¶ÓʹÓà 21CN µç×ÓÓʼþϵͳhttp://www.21cn.com
Thank you for using 21CN Email system