]> git.sur5r.net Git - openldap/commitdiff
fix mix memory issues and cleanup
authorPierangelo Masarati <ando@openldap.org>
Sat, 8 Jan 2005 09:59:16 +0000 (09:59 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 8 Jan 2005 09:59:16 +0000 (09:59 +0000)
servers/slapd/back-sql/bind.c
servers/slapd/back-sql/config.c
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/modify.c
servers/slapd/back-sql/util.c

index 45b60659f034758801a63131a95544c10877cbdd..6044cdf7b890a9b7f19cdc0b786e0368940b52b8 100644 (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;
 }
  
index 413bdf5f9fef20a075d501a133c247fa014aec43..9efdb0ae5216af11d0efebbc56f71a37e6234b81 100644 (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;
                        }
index 8bd0e0daee018573bf5da628466ad2021b87e002..6d17e0e19f1ab4b6b30b68513ac0c067a5204e96 100644 (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;
index b1edff898c2c81579ff860d476927c88bba572da..621899c4ac49a78dc292fc337689dd21a34c859d 100644 (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;
 
index d85058488b11e44654adabf9550b53c52c2ee21a..cf2d222ce4266b04fbd994ab98980a86fc393d52 100644 (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 */