fix mix memory issues and cleanup

This commit is contained in:
Pierangelo Masarati 2005-01-08 09:59:16 +00:00
parent e5eaef6248
commit 9d5d9cc2ec
5 changed files with 55 additions and 38 deletions

View File

@ -32,8 +32,8 @@ int
backsql_bind( Operation *op, SlapReply *rs )
{
SQLHDBC dbh = SQL_NULL_HDBC;
AttributeDescription *password = slap_schema.si_ad_userPassword;
Entry *e, user_entry;
Entry *e = NULL,
user_entry = { 0 };
Attribute *a;
backsql_srch_info bsi;
AttributeName anlist[2];
@ -72,8 +72,8 @@ backsql_bind( Operation *op, SlapReply *rs )
return 1;
}
anlist[0].an_name = password->ad_cname;
anlist[0].an_desc = password;
anlist[0].an_name = slap_schema.si_ad_userPassword->ad_cname;
anlist[0].an_desc = slap_schema.si_ad_userPassword;
anlist[1].an_name.bv_val = NULL;
rc = backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE,
@ -100,7 +100,7 @@ backsql_bind( Operation *op, SlapReply *rs )
}
e = &user_entry;
a = attr_find( e->e_attrs, password );
a = attr_find( e->e_attrs, slap_schema.si_ad_userPassword );
if ( a == NULL ) {
rs->sr_err = LDAP_INVALID_CREDENTIALS;
goto error_return;
@ -118,12 +118,17 @@ error_return:;
(void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
}
if ( e ) {
entry_clean( e );
}
if ( rs->sr_err ) {
send_ldap_result( op, rs );
return 1;
}
Debug(LDAP_DEBUG_TRACE,"<==backsql_bind()\n",0,0,0);
return 0;
}

View File

@ -493,7 +493,8 @@ backsql_db_config(
}
Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
"use_subtree_shortcut=%s\n",
BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no", 0, 0 );
BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no",
0, 0 );
} else {
return SLAP_CONF_UNKNOWN;
@ -523,7 +524,8 @@ read_baseObject(
fp = fopen( fname, "r" );
if ( fp == NULL ) {
Debug( LDAP_DEBUG_ANY,
"could not open back-sql baseObject attr file \"%s\" - absolute path?\n",
"could not open back-sql baseObject "
"attr file \"%s\" - absolute path?\n",
fname, 0, 0 );
perror( fname );
return LDAP_OTHER;
@ -545,8 +547,9 @@ read_baseObject(
Attribute *a;
if( e == NULL ) {
fprintf( stderr, "back-sql baseObject: could not parse entry (line=%d)\n",
lineno );
fprintf( stderr, "back-sql baseObject: "
"could not parse entry (line=%d)\n",
lineno );
rc = LDAP_OTHER;
break;
}
@ -554,8 +557,9 @@ read_baseObject(
/* make sure the DN is the database's suffix */
if ( !be_issuffix( be, &e->e_nname ) ) {
fprintf( stderr,
"back-sql: invalid baseObject - dn=\"%s\" (line=%d)\n",
e->e_dn, lineno );
"back-sql: invalid baseObject - "
"dn=\"%s\" (line=%d)\n",
e->e_name.bv_val, lineno );
entry_free( e );
rc = EXIT_FAILURE;
break;
@ -566,8 +570,10 @@ read_baseObject(
* entry, and add each attribute type and description to baseObject
*/
for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
if ( attr_merge( bi->sql_baseObject, a->a_desc, a->a_vals,
( a->a_nvals == a->a_vals ) ? NULL : a->a_nvals ) )
if ( attr_merge( bi->sql_baseObject, a->a_desc,
a->a_vals,
( a->a_nvals == a->a_vals ) ?
NULL : a->a_nvals ) )
{
rc = LDAP_OTHER;
break;
@ -589,7 +595,8 @@ read_baseObject(
fclose( fp );
Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n", fname, 0, 0 );
Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n",
fname, 0, 0 );
return rc;
}
@ -610,9 +617,11 @@ create_baseObject(
"dn: %s\n"
"objectClass: extensibleObject\n"
"description: builtin baseObject for back-sql\n"
"description: all entries mapped in the \"ldap_entries\" table\n"
"description: must have \"" BACKSQL_BASEOBJECT_IDSTR "\" "
"in the \"parent\" column",
"description: all entries mapped "
"in the \"ldap_entries\" table\n"
"description: must have "
"\"" BACKSQL_BASEOBJECT_IDSTR "\" "
"in the \"parent\" column",
be->be_suffix[0].bv_val );
bi->sql_baseObject = str2entry( buf );
@ -628,11 +637,14 @@ create_baseObject(
return 0;
}
rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **) &p, LDAP_DN_FORMAT_LDAP );
rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **)&p,
LDAP_DN_FORMAT_LDAP );
if ( rc != LDAP_SUCCESS ) {
snprintf( buf, sizeof(buf),
"unable to extract RDN from baseObject DN \"%s\" (%d: %s)",
be->be_suffix[ 0 ].bv_val, rc, ldap_err2string( rc ) );
"unable to extract RDN "
"from baseObject DN \"%s\" (%d: %s)",
be->be_suffix[ 0 ].bv_val,
rc, ldap_err2string( rc ) );
Debug( LDAP_DEBUG_TRACE,
"<==backsql_db_config (%s line %d): %s\n",
fname, lineno, buf );
@ -676,12 +688,14 @@ create_baseObject(
if ( rc != LDAP_SUCCESS ) {
snprintf( buf, sizeof(buf),
"prettying of attribute #%d from baseObject "
"prettying of attribute #%d "
"from baseObject "
"DN \"%s\" failed: %d: %s",
iAVA, be->be_suffix[ 0 ].bv_val,
rc, ldap_err2string( rc ) );
Debug( LDAP_DEBUG_TRACE,
"<==backsql_db_config (%s line %d): %s\n",
"<==backsql_db_config (%s line %d): "
"%s\n",
fname, lineno, buf );
return 1;
}

View File

@ -506,7 +506,6 @@ backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid )
backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
int i;
int rc;
AttributeDescription *ad_oc = slap_schema.si_ad_objectClass;
Debug( LDAP_DEBUG_TRACE, "==>backsql_id2entry()\n", 0, 0, 0 );
@ -527,8 +526,8 @@ backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid )
goto done;
}
ber_dupbv_x( &bsi->bsi_e->e_name, &eid->eid_dn, bsi->bsi_op->o_tmpmemctx );
ber_dupbv_x( &bsi->bsi_e->e_nname, &eid->eid_ndn, bsi->bsi_op->o_tmpmemctx );
ber_dupbv( &bsi->bsi_e->e_name, &eid->eid_dn );
ber_dupbv( &bsi->bsi_e->e_nname, &eid->eid_ndn );
bsi->bsi_e->e_attrs = NULL;
bsi->bsi_e->e_private = NULL;
@ -541,9 +540,10 @@ backsql_id2entry( backsql_srch_info *bsi, backsql_entryID *eid )
bsi->bsi_e->e_id = eid->eid_id;
#endif /* ! BACKSQL_ARBITRARY_KEY */
rc = attr_merge_normalize_one( bsi->bsi_e, ad_oc,
&bsi->bsi_oc->bom_oc->soc_cname,
bsi->bsi_op->o_tmpmemctx );
rc = attr_merge_normalize_one( bsi->bsi_e,
slap_schema.si_ad_objectClass,
&bsi->bsi_oc->bom_oc->soc_cname,
bsi->bsi_op->o_tmpmemctx );
if ( rc != LDAP_SUCCESS ) {
entry_clean( bsi->bsi_e );
return rc;

View File

@ -113,9 +113,6 @@ backsql_modify( Operation *op, SlapReply *rs )
goto done;
}
e.e_attrs = NULL;
e.e_name = op->o_req_dn;
e.e_nname = op->o_req_ndn;
if ( !acl_check_modlist( op, &e, op->oq_modify.rs_modlist ) ) {
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;

View File

@ -533,7 +533,7 @@ backsql_entryUUID(
snprintf( uuidbuf, sizeof( uuidbuf ),
"%08x-%04x-%04x-0000-000000000000",
( id->eid_oc_id & 0xFFFFFFFF ),
( ( id->eid_keyval & 0xFFFF0000 ) >> 16 ),
( ( id->eid_keyval & 0xFFFF0000 ) >> 020 /* 16 */ ),
( id->eid_keyval & 0xFFFF ) );
#endif /* ! BACKSQL_ARBITRARY_KEY */
@ -558,16 +558,17 @@ backsql_entryUUID_decode(
{
fprintf( stderr, "==> backsql_entryUUID_decode()\n" );
*oc_id = ( entryUUID->bv_val[0] << 3 )
+ ( entryUUID->bv_val[1] << 2 )
+ ( entryUUID->bv_val[2] << 1 )
*oc_id = ( entryUUID->bv_val[0] << 030 /* 24 */ )
+ ( entryUUID->bv_val[1] << 020 /* 16 */ )
+ ( entryUUID->bv_val[2] << 010 /* 8 */ )
+ entryUUID->bv_val[3];
#ifdef BACKSQL_ARBITRARY_KEY
/* FIXME */
#else /* ! BACKSQL_ARBITRARY_KEY */
*keyval = ( entryUUID->bv_val[4] << 3 )
+ ( entryUUID->bv_val[5] << 2 )
+ ( entryUUID->bv_val[6] << 1 )
*keyval = ( entryUUID->bv_val[4] << 030 /* 24 */ )
+ ( entryUUID->bv_val[5] << 020 /* 16 */ )
+ ( entryUUID->bv_val[6] << 010 /* 8 */ )
+ entryUUID->bv_val[7];
#endif /* ! BACKSQL_ARBITRARY_KEY */