]> git.sur5r.net Git - openldap/commitdiff
Add support for virtual operational attribute plugin type
authorLuke Howard <lukeh@openldap.org>
Tue, 21 Jan 2003 14:00:25 +0000 (14:00 +0000)
committerLuke Howard <lukeh@openldap.org>
Tue, 21 Jan 2003 14:00:25 +0000 (14:00 +0000)
servers/slapd/result.c
servers/slapd/slapi/slapi_utils.c

index 341040f8f4f8c2756a0b7b006bc63403027d41ed..c9ae4c70d2c3a0e0d55f726909471243ce2bd37d 100644 (file)
@@ -686,6 +686,11 @@ slap_send_search_entry(
        int             userattrs;
        int             opattrs;
        AccessControlState acl_state = ACL_STATE_INIT;
+#ifdef LDAP_SLAPI
+       /* Support virtual attribute plugins. */
+       Slapi_PBlock *pb = op->o_pb;
+       Slapi_AttrSet *vattrs = NULL;
+#endif
 
        AttributeDescription *ad_entry = slap_schema.si_ad_entry;
 
@@ -1143,6 +1148,150 @@ slap_send_search_entry(
                }
        }
 
+#if defined( LDAP_SLAPI )
+       /* Add virtual attributes */
+       vattrs = slapi_x_attrset_new();
+       slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY, (void *)e );
+       slapi_pblock_set( pb, SLAPI_PLUGIN_OPATTR_COALESCE_DATA, (void *)vattrs );
+       rc = doPluginFNs( be, SLAPI_PLUGIN_OPATTR_COALESCE_FN, pb );
+       if ( rc == 0 ) {
+               /*
+                * Re-fetch this to be safe; plugin could have freed and
+                * changed it, although it shouldn't.
+                */
+               rc = slapi_pblock_get( pb, SLAPI_PLUGIN_OPATTR_COALESCE_DATA, (void **)&vattrs );
+               if ( rc != 0 ) {
+                       /* Something bad happened. */
+                       vattrs = NULL;
+               }
+       }
+
+       /* Now, send the virtual attributes. */
+       if ( vattrs != NULL ) {
+               for (a = *vattrs, j = 0; a != NULL; a = a->a_next, j++ ) {
+                       AttributeDescription *desc = a->a_desc;
+       
+                       if ( attrs == NULL ) {
+                               /* all attrs request, skip operational attributes */
+                               if( is_at_operational( desc->ad_type ) ) {
+                                       continue;
+                               }
+       
+                       } else {
+                               /* specific attrs requested */
+                               if( is_at_operational( desc->ad_type ) ) {
+                                       if( !opattrs && !ad_inlist( desc, attrs ) ) {
+                                               continue;
+                                       }
+                               } else {
+                                       if (!userattrs && !ad_inlist( desc, attrs ) )
+                                       {
+                                               continue;
+                                       }
+                               }
+                       }
+       
+                       if ( ! access_allowed( be, conn, op, e, desc, NULL,
+                               ACL_READ, &acl_state ) )
+                       {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( ACL, INFO, 
+                                       "send_search_entry: conn %lu "
+                                       "access to attribute %s not allowed\n",
+                                       op->o_connid, desc->ad_cname.bv_val, 0 );
+#else
+                               Debug( LDAP_DEBUG_ACL, "acl: access to attribute %s "
+                                               "not allowed\n",
+                                               desc->ad_cname.bv_val, 0, 0 );
+#endif
+       
+                               continue;
+                       }
+       
+                       rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname );
+                       if ( rc == -1 ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( OPERATION, ERR, 
+                                       "send_search_entry: conn %lu  "
+                                       "ber_printf failed\n", op->o_connid, 0, 0 );
+#else
+                               Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
+#endif
+       
+                               ber_free_buf( ber );
+                               send_ldap_result( conn, op, LDAP_OTHER,
+                                   NULL, "encoding description error", NULL, NULL );
+       
+                               attrs_free( aa );
+                               goto error_return;
+                       }
+       
+                       if ( ! attrsonly ) {
+                               for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
+                                       if ( ! access_allowed( be, conn, op, e,
+                                               desc, &a->a_vals[i], ACL_READ, &acl_state ) )
+                                       {
+#ifdef NEW_LOGGING
+                                               LDAP_LOG( ACL, INFO, 
+                                                       "send_search_entry: conn %lu "
+                                                       "access to %s, value %d not allowed\n",
+                                                       op->o_connid, desc->ad_cname.bv_val, i );
+#else
+                                               Debug( LDAP_DEBUG_ACL,
+                                                       "acl: access to attribute %s, "
+                                                       "value %d not allowed\n",
+                                                       desc->ad_cname.bv_val, i, 0 );
+#endif
+       
+                                               continue;
+                                       }
+       
+                                       if ( op->vrFilter && e_flags[j][i] == 0 ){
+                                               continue;
+                                       }
+       
+                                       if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
+#ifdef NEW_LOGGING
+                                               LDAP_LOG( OPERATION, ERR, 
+                                                       "send_search_entry: conn %lu  ber_printf failed\n", 
+                                                       op->o_connid, 0, 0 );
+#else
+                                               Debug( LDAP_DEBUG_ANY,
+                                                   "ber_printf failed\n", 0, 0, 0 );
+#endif
+       
+                                               ber_free_buf( ber );
+                                               send_ldap_result( conn, op, LDAP_OTHER,
+                                                       NULL, "encoding values error", 
+                                                       NULL, NULL );
+
+                                               attrs_free( aa );
+                                               goto error_return;
+                                       }
+                               }
+                       }
+
+                       if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( OPERATION, ERR, 
+                                       "send_search_entry: conn %lu  ber_printf failed\n",
+                                       op->o_connid, 0, 0 );
+#else
+                               Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
+#endif
+
+                               ber_free_buf( ber );
+                               send_ldap_result( conn, op, LDAP_OTHER,
+                                   NULL, "encode end error", NULL, NULL );
+
+                               attrs_free( aa );
+                               goto error_return;
+                       }
+               }
+               slapi_x_attrset_free( &vattrs );
+       }
+#endif /* LDAP_SLAPI */
+
        /* free e_flags */
        if ( e_flags ) {
                free( e_flags );
index 2af2e49f1dabfc2784fdc2161d6a748f0f9d5acc..eefea533419646635bce3a2525f943738671b103 100644 (file)
@@ -2092,8 +2092,7 @@ void slapi_x_attrset_free( Slapi_AttrSet **pAs )
 
        if ( as != NULL ) {
                attrs_free( *as );
-               slapi_ch_free( (void **)&as );
-               *pAs = NULL;
+               slapi_ch_free( (void **)pAs );
        }
 #endif
 }