Back to index

openldap  2.4.31
operational.c
Go to the documentation of this file.
00001 /* operational.c - routines to deal with on-the-fly operational attrs */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 2001-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in the file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 
00016 #include "portable.h"
00017 
00018 #include "slap.h"
00019 
00020 /*
00021  * helpers for on-the-fly operational attribute generation
00022  */
00023 
00024 Attribute *
00025 slap_operational_subschemaSubentry( Backend *be )
00026 {
00027        Attribute     *a;
00028 
00029        /* The backend wants to take care of it */
00030        if ( be && !SLAP_FRONTEND(be) && be->be_schemadn.bv_val ) return NULL;
00031 
00032        a = attr_alloc( slap_schema.si_ad_subschemaSubentry );
00033 
00034        a->a_numvals = 1;
00035        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
00036        ber_dupbv( a->a_vals, &frontendDB->be_schemadn );
00037        a->a_vals[1].bv_len = 0;
00038        a->a_vals[1].bv_val = NULL;
00039 
00040        a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
00041        ber_dupbv( a->a_nvals, &frontendDB->be_schemandn );
00042        a->a_nvals[1].bv_len = 0;
00043        a->a_nvals[1].bv_val = NULL;
00044 
00045        return a;
00046 }
00047 
00048 Attribute *
00049 slap_operational_entryDN( Entry *e )
00050 {
00051        Attribute     *a;
00052 
00053        assert( e != NULL );
00054        assert( !BER_BVISNULL( &e->e_name ) );
00055        assert( !BER_BVISNULL( &e->e_nname ) );
00056 
00057        a = attr_alloc( slap_schema.si_ad_entryDN );
00058 
00059        a->a_numvals = 1;
00060        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
00061        ber_dupbv( &a->a_vals[ 0 ], &e->e_name );
00062        BER_BVZERO( &a->a_vals[ 1 ] );
00063 
00064        a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
00065        ber_dupbv( &a->a_nvals[ 0 ], &e->e_nname );
00066        BER_BVZERO( &a->a_nvals[ 1 ] );
00067 
00068        return a;
00069 }
00070 
00071 Attribute *
00072 slap_operational_hasSubordinate( int hs )
00073 {
00074        Attribute     *a;
00075        struct berval val;
00076 
00077        val = hs ? slap_true_bv : slap_false_bv;
00078 
00079        a = attr_alloc( slap_schema.si_ad_hasSubordinates );
00080        a->a_numvals = 1;
00081        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
00082 
00083        ber_dupbv( &a->a_vals[0], &val );
00084        a->a_vals[1].bv_val = NULL;
00085 
00086        a->a_nvals = a->a_vals;
00087 
00088        return a;
00089 }
00090