]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/translucent.c
check for ee == NULL
[openldap] / servers / slapd / overlays / translucent.c
index 12a2db2211db5de86ee1596ad5e61f98a736ebcb..db9079692f43fe09b21a1c796b98a66a0eb09c9f 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2004-2006 The OpenLDAP Foundation.
+ * Copyright 2004-2007 The OpenLDAP Foundation.
  * Portions Copyright 2005 Symas Corporation.
  * All rights reserved.
  *
@@ -103,9 +103,9 @@ translucent_cfadd( Operation *op, SlapReply *rs, Entry *e, ConfigArgs *ca )
        Debug(LDAP_DEBUG_TRACE, "==> translucent_cfadd\n", 0, 0, 0);
 
        /* FIXME: should not hardcode "olcDatabase" here */
-       bv.bv_len = sprintf( ca->msg, "olcDatabase=%s",
+       bv.bv_len = sprintf( ca->cr_msg, "olcDatabase=%s",
                             ov->db.bd_info->bi_type );
-       bv.bv_val = ca->msg;
+       bv.bv_val = ca->cr_msg;
        ca->be = &ov->db;
 
        /* We can only create this entry if the database is table-driven
@@ -147,6 +147,7 @@ void glue_parent(Operation *op) {
        ber_dupbv(&e->e_nname, &ndn);
 
        a = attr_alloc( slap_schema.si_ad_objectClass );
+       a->a_numvals = 2;
        a->a_vals = ch_malloc(sizeof(struct berval) * 3);
        ber_dupbv(&a->a_vals[0], &glue[0]);
        ber_dupbv(&a->a_vals[1], &glue[1]);
@@ -156,6 +157,7 @@ void glue_parent(Operation *op) {
        e->e_attrs = a;
 
        a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
+       a->a_numvals = 1;
        a->a_vals = ch_malloc(sizeof(struct berval) * 2);
        ber_dupbv(&a->a_vals[0], &glue[1]);
        ber_dupbv(&a->a_vals[1], &glue[2]);
@@ -300,9 +302,9 @@ static int translucent_modify(Operation *op, SlapReply *rs) {
 
        slap_overinst *on = (slap_overinst *) op->o_bd->bd_info;
        translucent_info *ov = on->on_bi.bi_private;
-       Entry ne, *e = NULL, *re = NULL;
+       Entry *e = NULL, *re = NULL;
        Attribute *a, *ax;
-       Modifications *m, *mm;
+       Modifications *m, **mm;
        int del, rc, erc = 0;
        slap_callback cb = { 0 };
 
@@ -343,10 +345,14 @@ static int translucent_modify(Operation *op, SlapReply *rs) {
 
        if(e && rc == LDAP_SUCCESS) {
                Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: found local entry\n", 0, 0, 0);
-               for(m = op->orm_modlist; m; m = m->sml_next) {
+               for(mm = &op->orm_modlist; *mm; ) {
+                       m = *mm;
                        for(a = e->e_attrs; a; a = a->a_next)
                                if(a->a_desc == m->sml_desc) break;
-                       if(a) continue;         /* found local attr */
+                       if(a) {
+                               mm = &m->sml_next;
+                               continue;               /* found local attr */
+                       }
                        if(m->sml_op == LDAP_MOD_DELETE) {
                                for(a = re->e_attrs; a; a = a->a_next)
                                        if(a->a_desc == m->sml_desc) break;
@@ -362,15 +368,13 @@ static int translucent_modify(Operation *op, SlapReply *rs) {
                                Debug(LDAP_DEBUG_TRACE,
                                        "=> translucent_modify: silently dropping delete: %s\n",
                                        m->sml_desc->ad_cname.bv_val, 0, 0);
-                               for(mm = op->orm_modlist; mm->sml_next != m; mm = mm->sml_next);
-                               mm->sml_next = m->sml_next;
-                               mm = m;
-                               m = m->sml_next;
-                               mm->sml_next = NULL;            /* hack */
-                               slap_mods_free(mm, 1);
-                               if(m) continue;
+                               *mm = m->sml_next;
+                               m->sml_next = NULL;
+                               slap_mods_free(m, 1);
+                               continue;
                        }
                        m->sml_op = LDAP_MOD_ADD;
+                       mm = &m->sml_next;
                }
                erc = SLAP_CB_CONTINUE;
 release:
@@ -414,6 +418,7 @@ release:
        Debug(LDAP_DEBUG_TRACE, "=> translucent_modify: fabricating local add\n", 0, 0, 0);
        a = NULL;
        for(del = 0, ax = NULL, m = op->orm_modlist; m; m = m->sml_next) {
+               Attribute atmp;
                if(((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_ADD) &&
                   ((m->sml_op & LDAP_MOD_OP) != LDAP_MOD_REPLACE)) {
                        Debug(LDAP_DEBUG_ANY,
@@ -422,15 +427,18 @@ release:
                        if((m->sml_op & LDAP_MOD_OP) == LDAP_MOD_DELETE) del++;
                        continue;
                }
-               a = attr_alloc( m->sml_desc );
-               a->a_vals  = m->sml_values;
-               a->a_nvals = m->sml_nvalues;
+               atmp.a_desc = m->sml_desc;
+               atmp.a_vals = m->sml_values;
+               atmp.a_nvals = m->sml_nvalues ? m->sml_nvalues : atmp.a_vals;
+               atmp.a_numvals = m->sml_numvals;
+               atmp.a_flags = 0;
+               a = attr_dup( &atmp );
                a->a_next  = ax;
                ax = a;
        }
 
        if(del && ov->strict) {
-               free_attr_chain(a);
+               attrs_free( a );
                send_ldap_error(op, rs, LDAP_CONSTRAINT_VIOLATION,
                        "attempt to delete attributes from local database");
                return(rs->sr_err);
@@ -448,17 +456,13 @@ release:
                return(rs->sr_err);
        }
 
-       ne.e_id         = NOID;
-       ne.e_name       = op->o_req_dn;
-       ne.e_nname      = op->o_req_ndn;
-       ne.e_attrs      = a;
-       ne.e_ocflags    = 0;
-       ne.e_bv.bv_len  = 0;
-       ne.e_bv.bv_val  = NULL;
-       ne.e_private    = NULL;
+       e = entry_alloc();
+       ber_dupbv( &e->e_name, &op->o_req_dn );
+       ber_dupbv( &e->e_nname, &op->o_req_ndn );
+       e->e_attrs = a;
 
        nop.o_tag       = LDAP_REQ_ADD;
-       nop.oq_add.rs_e = &ne;
+       nop.oq_add.rs_e = e;
 
        glue_parent(&nop);
 
@@ -467,7 +471,8 @@ release:
        cb.sc_next = nop.o_callback;
        nop.o_callback = &cb;
        rc = on->on_info->oi_orig->bi_op_add(&nop, &nrs);
-       free_attr_chain(a);
+       if ( nop.ora_e == e )
+               entry_free( e );
 
        return(rc);
 }
@@ -685,10 +690,9 @@ static int translucent_db_config(
 **
 */
 
-static int translucent_db_init(BackendDB *be) {
+static int translucent_db_init(BackendDB *be, ConfigReply *cr) {
        slap_overinst *on = (slap_overinst *) be->bd_info;
        translucent_info *ov;
-       int rc;
 
        Debug(LDAP_DEBUG_TRACE, "==> translucent_db_init\n", 0, 0, 0);
 
@@ -698,7 +702,7 @@ static int translucent_db_init(BackendDB *be) {
        ov->db.be_private = NULL;
        ov->db.be_pcl_mutexp = &ov->db.be_pcl_mutex;
 
-       if ( !backend_db_init( "ldap", &ov->db )) {
+       if ( !backend_db_init( "ldap", &ov->db, -1, NULL )) {
                Debug( LDAP_DEBUG_CONFIG, "translucent: unable to open captive back-ldap\n", 0, 0, 0);
                return 1;
        }
@@ -714,7 +718,7 @@ static int translucent_db_init(BackendDB *be) {
 **
 */
 
-static int translucent_db_open(BackendDB *be) {
+static int translucent_db_open(BackendDB *be, ConfigReply *cr) {
        slap_overinst *on = (slap_overinst *) be->bd_info;
        translucent_info *ov = on->on_bi.bi_private;
        int rc;
@@ -727,7 +731,7 @@ static int translucent_db_open(BackendDB *be) {
        ov->db.be_acl = be->be_acl;
        ov->db.be_dfltaccess = be->be_dfltaccess;
 
-       rc = backend_startup_one( &ov->db );
+       rc = backend_startup_one( &ov->db, NULL );
 
        if(rc) Debug(LDAP_DEBUG_TRACE,
                "translucent: bi_db_open() returned error %d\n", rc, 0, 0);
@@ -742,15 +746,17 @@ static int translucent_db_open(BackendDB *be) {
 **
 */
 
-static int translucent_db_close(BackendDB *be) {
+static int
+translucent_db_close( BackendDB *be, ConfigReply *cr )
+{
        slap_overinst *on = (slap_overinst *) be->bd_info;
        translucent_info *ov = on->on_bi.bi_private;
        int rc = 0;
 
        Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
 
-       if ( ov ) {
-               rc = (ov->db.bd_info && ov->db.bd_info->bi_db_close) ? ov->db.bd_info->bi_db_close(&ov->db) : 0;
+       if ( ov && ov->db.bd_info && ov->db.bd_info->bi_db_close ) {
+               rc = ov->db.bd_info->bi_db_close(&ov->db, NULL);
        }
 
        return(rc);
@@ -762,15 +768,20 @@ static int translucent_db_close(BackendDB *be) {
 **
 */
 
-static int translucent_db_destroy(BackendDB *be) {
+static int
+translucent_db_destroy( BackendDB *be, ConfigReply *cr )
+{
        slap_overinst *on = (slap_overinst *) be->bd_info;
        translucent_info *ov = on->on_bi.bi_private;
        int rc = 0;
 
-       Debug(LDAP_DEBUG_TRACE, "==> translucent_db_close\n", 0, 0, 0);
+       Debug(LDAP_DEBUG_TRACE, "==> translucent_db_destroy\n", 0, 0, 0);
 
        if ( ov ) {
-               rc = (ov->db.bd_info && ov->db.bd_info->bi_db_destroy) ? ov->db.bd_info->bi_db_destroy(&ov->db) : 0;
+               if ( ov->db.be_private != NULL ) {
+                       backend_stopdown_one( &ov->db );
+               }
+
                ch_free(ov);
                on->on_bi.bi_private = NULL;
        }