* Rewrite the add dn, if needed
*/
#ifdef ENABLE_REWRITE
- switch (rewrite_session( li->rwinfo, "addDn", e->e_dn, conn, &mdn.bv_val )) {
+ switch (rewrite_session( li->rwinfo, "addDn", e->e_dn, conn,
+ &mdn.bv_val )) {
case REWRITE_REGEXEC_OK:
if ( mdn.bv_val != NULL && mdn.bv_val[ 0 ] != '\0' ) {
mdn.bv_len = strlen( mdn.bv_val );
ldap_add_s(lc->ld, mdn.bv_val, attrs);
for (--i; i>= 0; --i) {
- free(attrs[i]->mod_vals.modv_bvals);
- free(attrs[i]);
+ ch_free(attrs[i]->mod_vals.modv_bvals);
+ ch_free(attrs[i]);
}
- free(attrs);
+ ch_free(attrs);
if ( mdn.bv_val != e->e_dn ) {
free( mdn.bv_val );
}
a_vals->bv_val, mattr, "" );
#endif /* !NEW_LOGGING */
- free( a_vals->bv_val );
+ /*
+ * FIXME: replacing server-allocated memory
+ * (ch_malloc) with librewrite allocated memory
+ * (malloc)
+ */
+ ch_free( a_vals->bv_val );
a_vals->bv_val = mattr;
a_vals->bv_len = strlen( mattr );
{
struct ldapinfo *li = (struct ldapinfo *) be->be_private;
int rc = 1, i, j, count, is_oc;
- Attribute *attr;
+ Attribute *attr = NULL;
BVarray abv, v;
- struct berval mapped;
- char **vs;
- LDAPMessage *result, *e;
+ struct berval mapped = { 0, NULL };
+ char **vs = NULL;
+ LDAPMessage *result = NULL, *e = NULL;
char *gattr[2];
- LDAP *ld;
+ LDAP *ld = NULL;
*vals = NULL;
- if (target != NULL && target->e_nname.bv_len == ndn->bv_len &&
- strcmp(target->e_nname.bv_val, ndn->bv_val) == 0) {
+ if (target != NULL && dn_cmp( &target->e_nname, ndn )) {
/* we already have a copy of the entry */
/* attribute and objectclass mapping has already been done */
if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
}
v[j].bv_val = NULL;
*vals = v;
- rc = 0;
+ return 0;
}
- } else {
- ldap_back_map(&li->at_map, &entry_at->ad_cname, &mapped, 0);
- if (mapped.bv_val == NULL)
- return(1);
+ }
+ ldap_back_map(&li->at_map, &entry_at->ad_cname, &mapped, 0);
+ if (mapped.bv_val == NULL) {
+ return 1;
+ }
- if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
- return(1);
- }
+ if (ldap_initialize(&ld, li->url) != LDAP_SUCCESS) {
+ return 1;
+ }
- if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) == LDAP_SUCCESS) {
- gattr[0] = mapped.bv_val;
- gattr[1] = NULL;
- if (ldap_search_ext_s(ld, ndn->bv_val, LDAP_SCOPE_BASE, "(objectclass=*)",
- gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
- LDAP_NO_LIMIT, &result) == LDAP_SUCCESS)
- {
- if ((e = ldap_first_entry(ld, result)) != NULL) {
- vs = ldap_get_values(ld, e, mapped.bv_val);
- if (vs != NULL) {
- for ( count = 0; vs[count] != NULL; count++ ) { }
- v = (BVarray) ch_calloc( (count + 1), sizeof(struct berval) );
- if (v == NULL) {
- ldap_value_free(vs);
- } else {
- is_oc = (strcasecmp("objectclass", mapped.bv_val) == 0);
- for ( i = 0, j = 0; i < count; i++) {
- ber_str2bv(vs[i], 0, 0, &v[j] );
- if (!is_oc) {
- if( v[j].bv_val == NULL )
- ch_free(vs[i]);
- else
- j++;
- } else {
- ldap_back_map(&li->oc_map, &v[j], &mapped, 1);
- if (mapped.bv_val) {
- ber_dupbv( &v[j], &mapped );
- if (v[j].bv_val)
- j++;
- }
- ch_free(vs[i]);
- }
- }
- v[j].bv_val = NULL;
- *vals = v;
- rc = 0;
- ch_free(vs);
- }
- }
- }
- ldap_msgfree(result);
+ if (ldap_bind_s(ld, li->binddn, li->bindpw, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+
+ gattr[0] = mapped.bv_val;
+ gattr[1] = NULL;
+ if (ldap_search_ext_s(ld, ndn->bv_val, LDAP_SCOPE_BASE, "(objectclass=*)",
+ gattr, 0, NULL, NULL, LDAP_NO_LIMIT,
+ LDAP_NO_LIMIT, &result) != LDAP_SUCCESS)
+ {
+ goto cleanup;
+ }
+
+ if ((e = ldap_first_entry(ld, result)) == NULL) {
+ goto cleanup;
+ }
+
+ vs = ldap_get_values(ld, e, mapped.bv_val);
+ if (vs == NULL) {
+ goto cleanup;
+ }
+
+ for ( count = 0; vs[count] != NULL; count++ ) { }
+ v = (BVarray) ch_calloc( (count + 1), sizeof(struct berval) );
+ if (v == NULL) {
+ goto cleanup;
+ }
+
+ is_oc = (strcasecmp("objectclass", mapped.bv_val) == 0);
+ for ( i = 0, j = 0; i < count; i++) {
+ ber_str2bv(vs[i], 0, 0, &v[j] );
+ if (!is_oc) {
+ if( v[j].bv_val == NULL )
+ ch_free(vs[i]);
+ else
+ j++;
+ } else {
+ ldap_back_map(&li->oc_map, &v[j], &mapped, 1);
+ if (mapped.bv_val) {
+ ber_dupbv( &v[j], &mapped );
+ if (v[j].bv_val)
+ j++;
}
+ ch_free(vs[i]);
}
- ldap_unbind(ld);
- }
+ }
+ v[j].bv_val = NULL;
+ *vals = v;
+ rc = 0;
+ ch_free(vs);
+ vs = NULL;
+
+cleanup:
+ if (vs) {
+ ldap_value_free(vs);
+ }
+ if (result) {
+ ldap_msgfree(result);
+ }
+ ldap_unbind(ld);
return(rc);
}
#ifdef ENABLE_REWRITE
if ( mfilter.bv_val != filterstr->bv_val ) {
- ldap_memfree( mfilter.bv_val );
+ free( mfilter.bv_val );
}
#endif /* ENABLE_REWRITE */
free( mmatch );
}
#endif /* ENABLE_REWRITE */
- free(match);
+ LDAP_FREE(match);
}
if ( err ) {
- free( err );
+ LDAP_FREE( err );
}
if ( mapped_attrs ) {
- free( mapped_attrs );
+ ch_free( mapped_attrs );
}
if ( mapped_filter != filterstr->bv_val ) {
- free( mapped_filter );
+ ch_free( mapped_filter );
}
if ( mbase.bv_val != base->bv_val ) {
free( mbase.bv_val );
for ( i = 0, bv = attr->a_vals; bv->bv_val; bv++, i++ ) {
ldap_back_map(&li->oc_map, bv, &mapped, 1);
if (mapped.bv_val == NULL) {
- free(bv->bv_val);
+ LBER_FREE(bv->bv_val);
bv->bv_val = NULL;
if (--last < 0)
break;
attr->a_vals[last].bv_val = NULL;
i--;
} else if ( mapped.bv_val != bv->bv_val ) {
- free(bv->bv_val);
+ /*
+ * FIXME: after LBER_FREEing
+ * the value is replaced by
+ * ch_alloc'ed memory
+ */
+ LBER_FREE(bv->bv_val);
ber_dupbv( bv, &mapped );
}
}
ent.e_attrs = attr->a_next;
if (attr->a_vals != &dummy)
bvarray_free(attr->a_vals);
- free(attr);
+ ch_free(attr);
}
if ( ent.e_dn && ent.e_dn != bdn.bv_val )