[Date Prev][Date Next] [Chronological] [Thread] [Top]

segmentation fault in ldap_modify()



OK, I have tried this and am not able to get it to work.

I have written a small routine to modify entries in my server.
It creates problems while modifying second entries.
It modifies 1st entry and faults at free() during the 2nd modification.

The modify function goes like this (I have attached the code below, if you
are interested)

	Making connection and authentication.
	setting the data
	ldap_modify()
	ldap_unbind

After modifying the 1st entry, it does a segmentation fault on
ldap_modify(), while modifying the 2nd entry.
The routine creates connection everytime it wants to modify an entry. The
caller program calls this routine any number of time depending on some
data.

If I remove the last statement (i.e. ldap_unbind), it works fine.
But I don't know the consequence of not using unbind, but binding it
many times, since it may be called for many times. Is this an error in
ldap_modify(0 or my ignorance.


Thanks a lot in advance
Himanshu




--------------------

> int AddMod(char Attr[25][256], char Val[25][1024]) {
> 	LDAP *ld;
> 	char *vals[2];
> 	LDAPMod mod;
> 	LDAPMod *mods[2];
> 	int  AttrNo, i;
> 	char tmp[256];
> 	char MODDN[256];
>
>
> 	if ( (ld = ldap_init( LDAPHOST, LDAPPORT)) == NULL) {
> 		printf("The dir cannot be contacted\n");
> 		perror("ldap_open");
> 		exit( 1 );
> 	}
> 	printf("The SERVER is UP\n");
>
> 	if ( ldap_simple_bind_s( ld, ENTRYDN, ENTRYPW) != LDAP_SUCCESS) {
> 		ldap_perror( ld, "ldap_simple_bind_s");
> 		exit(1);
> 	}
>
> 	printf("Authenticatiopn done\n");
> 	for (i = 1;  *Attr[i] != '\0'; i++){
> 		printf("\n Attr = %s, Val = %s\n", Attr[i], Val[i]);
> 		vals[0] = (char *)&Val[i];
> 		vals[1] = NULL;
> 		mod.mod_op = LDAP_MOD_REPLACE;
> 		mod.mod_type = (char *) &Attr[i];
> 		printf( "MOD is --------->%s<-------\n", mod.mod_type);
> 		mod.mod_values = vals;
> 		mods[0] = &mod;
> 		mods[1] = NULL;
>
> 		if ( ldap_modify( ld, MODDN, mods) < 0 ) {
> 			ldap_perror( ld, "ldap_modify_s");
> 			exit (1);
> 		}
> 	}
> 	ldap_unbind( ld);
> 	return (0);
> }
>