[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
AW: How to populate LDAPMod Structure?
You're berval1 variable should be a NULL terminated array.
cf : man ldap_modify ...
Please read documentation carefully before posting ...
> Hi all,
> This may be very problem for most of u all ........... but i am just getting started .please dont get irritated .
>
> Here goes the problem......
>
> We are using OpenLDAP 2.0.11, we have populated the same to hold centralized address book. Now we are trying to write a menu driven application to do all the required operations on the LDAP database. Currently we are struck in ldap_add call, which required LDAPMod ** structure as the third argument.
>
>
> We populated the LDAPMod structure as follows:-
> #include <lber.h>
> #include <ldap.h>
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
>
> struct ldapentry {
> char f_name[120];
> char m_name[120];
> char l_name[120];
> char obj_cls[120];
> char org_unit[120];
> char org[120];
> char country[120];
> char e_mail[120];
> } detail;
>
> int main()
> {
> LDAP *ld;
> LDAPMod *attrs;
> char dn[1024];
> char cn[1024];
> int ret_val;
> struct berval *berval1;
>
>
>
> init();
> accept_data();
> validate();
> ld=ldap_open("200.200.100.129",389);
> ret_val=ldap_simple_bind_s(ld,"cn=Manager,o=thbs.com,c=US","secret");
> printf("%s\n", ldap_err2string(ret_val));
> sprintf(dn,"cn=%s %s %s,ou=%s,o=%s,c=%s",detail.f_name,
> detail.m_name, detail.l_name,detail.org_unit, detail.org,
> detail.country );
> attrs = (LDAPMod *)malloc(sizeof (LDAPMod));
> /*
> attrs->mod_op = LDAP_MOD_ADD;
> attrs->mod_type = NULL ;
> */
>
> *(attrs->mod_vals.modv_bvals) = (struct berval *)malloc ( 6 * sizeof ( struct berval ) );
> if ( *(attrs->mod_vals.modv_bvals) == NULL ) {
> perror("malloc");
> }
> berval1 = *attrs->mod_vals.modv_bvals;
> sprintf(cn,"%s %s %s",detail.f_name, detail.m_name,detail.l_name );
> berval1->bv_len = strlen(cn);
> berval1->bv_val = strdup(cn);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
> /*
> berval1++;
> berval1->bv_len = strlen(detail.f_name);
> berval1->bv_val = strdup(detail.f_name);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
> */
> berval1++;
> berval1->bv_len = strlen(detail.m_name);
> berval1->bv_val = strdup(detail.m_name);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
>
> berval1++;
> berval1->bv_len = 0;
> berval1->bv_len = strlen(detail.l_name);
> printf("------------------- %d\n",berval1->bv_len);
> berval1->bv_val = strdup(detail.l_name);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
>
> berval1++;
> berval1->bv_len = strlen(detail.obj_cls);
> berval1->bv_val = strdup(detail.obj_cls);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
>
> berval1++;
> berval1->bv_len = strlen(detail.org);
> berval1->bv_val = strdup(detail.org);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
>
> berval1++;
> berval1->bv_len = strlen(detail.e_mail);
> berval1->bv_val = strdup(detail.e_mail);
> printf("%d %s\n", berval1->bv_len, berval1->bv_val );
>
> printf("Values %d = %s\n", berval1->bv_len, berval1->bv_val );
>
> /* dn:cn=Srinivas Kumar,ou=SES,o=thbs.com,c=US */
> sprintf(dn,"cn=%s,ou=%s,o=%s,c=%s",cn,detail.org_unit,
> detail.org,detail.country);
> printf("Hello\n");
> if ( ldap_add_s(ld, dn, &attrs) != LDAP_SUCCESS )
> {
> perror ( "ldap_add" );
> }
> ldap_unbind(ld);
> return 0;
>
> }
>
> This program dumps core at ldap_add .
>
> So , thought it may be a problem with the way we are populating the LDAPMod structure .....
> Please help
>
> regards,
> nagendra.
>
>
>
>
>