]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/accesslog.c
check for ee == NULL
[openldap] / servers / slapd / overlays / accesslog.c
index 6ee3380cb71bcf236269382e4b7988f0ef558138..e0b0e8bb024dd01c5181d9f98b5bddee7803da7a 100644 (file)
@@ -162,7 +162,8 @@ enum {
        LOG_EN__COUNT
 };
 
-static ObjectClass *log_ocs[LOG_EN__COUNT], *log_container;
+static ObjectClass *log_ocs[LOG_EN__COUNT], *log_container,
+       *log_oc_read, *log_oc_write;
 
 #define LOG_SCHEMA_ROOT        "1.3.6.1.4.1.4203.666.11.5"
 
@@ -400,10 +401,10 @@ static struct {
                                &log_ocs[LOG_EN_UNBIND] },
        { "( " LOG_SCHEMA_OC ".2 NAME 'auditReadObject' "
                "DESC 'OpenLDAP read request record' "
-               "SUP auditObject STRUCTURAL )", NULL },
+               "SUP auditObject STRUCTURAL )", &log_oc_read },
        { "( " LOG_SCHEMA_OC ".3 NAME 'auditWriteObject' "
                "DESC 'OpenLDAP write request record' "
-               "SUP auditObject STRUCTURAL )", NULL },
+               "SUP auditObject STRUCTURAL )", &log_oc_write },
        { "( " LOG_SCHEMA_OC ".4 NAME 'auditAbandon' "
                "DESC 'Abandon operation' "
                "SUP auditObject STRUCTURAL "
@@ -595,7 +596,7 @@ accesslog_purge( void *ctx, void *arg )
        SlapReply rs = {REP_RESULT};
        slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
        Filter f;
-       AttributeAssertion ava = {0};
+       AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
        purge_data pd = {0};
        char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
        char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
@@ -1364,11 +1365,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                /* count all the vals */
                i = 0;
                for ( a=e2->e_attrs; a; a=a->a_next ) {
-                       if ( a->a_vals ) {
-                               for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
-                                       i++;
-                               }
-                       }
+                       i += a->a_numvals;
                }
                vals = ch_malloc( (i+1) * sizeof( struct berval ));
                i = 0;
@@ -1382,6 +1379,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                vals[i].bv_val = NULL;
                vals[i].bv_len = 0;
                a = attr_alloc( logop == LOG_EN_ADD ? ad_reqMod : ad_reqOld );
+               a->a_numvals = i;
                a->a_vals = vals;
                a->a_nvals = vals;
                last_attr->a_next = a;
@@ -1394,9 +1392,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                i = 0;
                for ( m = op->orm_modlist; m; m = m->sml_next ) {
                        if ( m->sml_values ) {
-                               for ( b = m->sml_values; !BER_BVISNULL( b ); b++ ) {
-                                       i++;
-                               }
+                               i += m->sml_numvals;
                        } else if ( m->sml_op == LDAP_MOD_DELETE ||
                                m->sml_op == LDAP_MOD_REPLACE )
                        {
@@ -1477,6 +1473,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                if ( i > 0 ) {
                        BER_BVZERO( &vals[i] );
                        a = attr_alloc( ad_reqMod );
+                       a->a_numvals = i;
                        a->a_vals = vals;
                        a->a_nvals = vals;
                        last_attr->a_next = a;
@@ -1491,9 +1488,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                        i = 0;
                        for ( a = old->e_attrs; a != NULL; a = a->a_next ) {
                                if ( a->a_vals && a->a_flags ) {
-                                       for ( b = a->a_vals; !BER_BVISNULL( b ); b++ ) {
-                                               i++;
-                                       }
+                                       i += a->a_numvals;
                                }
                        }
                        vals = ch_malloc( (i + 1) * sizeof( struct berval ) );
@@ -1508,6 +1503,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                        vals[i].bv_val = NULL;
                        vals[i].bv_len = 0;
                        a = attr_alloc( ad_reqOld );
+                       a->a_numvals = i;
                        a->a_vals = vals;
                        a->a_nvals = vals;
                        last_attr->a_next = a;
@@ -1787,10 +1783,9 @@ accesslog_operational( Operation *op, SlapReply *rs )
                                ad_inlist( ad_auditContext, rs->sr_attrs ) )
                {
                        *ap = attr_alloc( ad_auditContext );
-                       value_add_one( &(*ap)->a_vals,
-                               &li->li_db->be_suffix[0] );
-                       value_add_one( &(*ap)->a_nvals,
-                               &li->li_db->be_nsuffix[0] );
+                       attr_valadd( *ap,
+                               &li->li_db->be_suffix[0],
+                               &li->li_db->be_nsuffix[0], 1 );
                }
        }
 
@@ -1906,8 +1901,11 @@ accesslog_db_root(
 
                        a = attr_find( e_ctx->e_attrs, slap_schema.si_ad_contextCSN );
                        if ( a ) {
-                               attr_merge( e, slap_schema.si_ad_entryCSN, a->a_vals, NULL );
-                               attr_merge( e, a->a_desc, a->a_vals, NULL );
+                               /* FIXME: contextCSN could have multiple values!
+                                * should select the one with the server's SID */
+                               attr_merge_one( e, slap_schema.si_ad_entryCSN,
+                                       &a->a_vals[0], &a->a_nvals[0] );
+                               attr_merge( e, a->a_desc, a->a_vals, a->a_nvals );
                        }
                        be_entry_release_rw( op, e_ctx, 0 );
                }
@@ -2029,6 +2027,9 @@ int accesslog_initialize()
                                0, 0, 0 );
                        return -1;
                }
+#ifndef LDAP_DEVEL
+               (*lattrs[i].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
+#endif
        }
 
        for ( i=0; locs[i].ot; i++ ) {
@@ -2041,6 +2042,9 @@ int accesslog_initialize()
                                0, 0, 0 );
                        return -1;
                }
+#ifndef LDAP_DEVEL
+               (*locs[i].oc)->soc_flags |= SLAP_OC_HIDE;
+#endif
        }
 
        return overlay_register(&accesslog);