1/* $NetBSD: operational.c,v 1.1.1.3 2010/12/12 15:22:34 adam Exp $ */ 2 3/* operational.c - routines to deal with on-the-fly operational attrs */ 4/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 2001-2010 The OpenLDAP Foundation. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted only as authorized by the OpenLDAP 11 * Public License. 12 * 13 * A copy of this license is available in the file LICENSE in the 14 * top-level directory of the distribution or, alternatively, at 15 * <http://www.OpenLDAP.org/license.html>. 16 */ 17 18#include "portable.h" 19 20#include "slap.h" 21 22/* 23 * helpers for on-the-fly operational attribute generation 24 */ 25 26Attribute * 27slap_operational_subschemaSubentry( Backend *be ) 28{ 29 Attribute *a; 30 31 /* The backend wants to take care of it */ 32 if ( be && !SLAP_FRONTEND(be) && be->be_schemadn.bv_val ) return NULL; 33 34 a = attr_alloc( slap_schema.si_ad_subschemaSubentry ); 35 36 a->a_numvals = 1; 37 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) ); 38 ber_dupbv( a->a_vals, &frontendDB->be_schemadn ); 39 a->a_vals[1].bv_len = 0; 40 a->a_vals[1].bv_val = NULL; 41 42 a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) ); 43 ber_dupbv( a->a_nvals, &frontendDB->be_schemandn ); 44 a->a_nvals[1].bv_len = 0; 45 a->a_nvals[1].bv_val = NULL; 46 47 return a; 48} 49 50Attribute * 51slap_operational_entryDN( Entry *e ) 52{ 53 Attribute *a; 54 55 assert( e != NULL ); 56 assert( !BER_BVISNULL( &e->e_name ) ); 57 assert( !BER_BVISNULL( &e->e_nname ) ); 58 59 a = attr_alloc( slap_schema.si_ad_entryDN ); 60 61 a->a_numvals = 1; 62 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) ); 63 ber_dupbv( &a->a_vals[ 0 ], &e->e_name ); 64 BER_BVZERO( &a->a_vals[ 1 ] ); 65 66 a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) ); 67 ber_dupbv( &a->a_nvals[ 0 ], &e->e_nname ); 68 BER_BVZERO( &a->a_nvals[ 1 ] ); 69 70 return a; 71} 72 73Attribute * 74slap_operational_hasSubordinate( int hs ) 75{ 76 Attribute *a; 77 struct berval val; 78 79 val = hs ? slap_true_bv : slap_false_bv; 80 81 a = attr_alloc( slap_schema.si_ad_hasSubordinates ); 82 a->a_numvals = 1; 83 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) ); 84 85 ber_dupbv( &a->a_vals[0], &val ); 86 a->a_vals[1].bv_val = NULL; 87 88 a->a_nvals = a->a_vals; 89 90 return a; 91} 92 93