Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / operational.c
blobfc7b855dee7b6bed9a2ccfe3da79dfccf0ce24e1
1 /* operational.c - routines to deal with on-the-fly operational attrs */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2001-2008 The OpenLDAP Foundation.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
9 * Public License.
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 #include "portable.h"
18 #include "slap.h"
21 * helpers for on-the-fly operational attribute generation
24 Attribute *
25 slap_operational_subschemaSubentry( Backend *be )
27 Attribute *a;
29 /* The backend wants to take care of it */
30 if ( be && !SLAP_FRONTEND(be) && be->be_schemadn.bv_val ) return NULL;
32 a = attr_alloc( slap_schema.si_ad_subschemaSubentry );
34 a->a_numvals = 1;
35 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
36 ber_dupbv( a->a_vals, &frontendDB->be_schemadn );
37 a->a_vals[1].bv_len = 0;
38 a->a_vals[1].bv_val = NULL;
40 a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
41 ber_dupbv( a->a_nvals, &frontendDB->be_schemandn );
42 a->a_nvals[1].bv_len = 0;
43 a->a_nvals[1].bv_val = NULL;
45 return a;
48 Attribute *
49 slap_operational_entryDN( Entry *e )
51 Attribute *a;
53 assert( e != NULL );
54 assert( !BER_BVISNULL( &e->e_name ) );
55 assert( !BER_BVISNULL( &e->e_nname ) );
57 a = attr_alloc( slap_schema.si_ad_entryDN );
59 a->a_numvals = 1;
60 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
61 ber_dupbv( &a->a_vals[ 0 ], &e->e_name );
62 BER_BVZERO( &a->a_vals[ 1 ] );
64 a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
65 ber_dupbv( &a->a_nvals[ 0 ], &e->e_nname );
66 BER_BVZERO( &a->a_nvals[ 1 ] );
68 return a;
71 Attribute *
72 slap_operational_hasSubordinate( int hs )
74 Attribute *a;
75 struct berval val;
77 val = hs ? slap_true_bv : slap_false_bv;
79 a = attr_alloc( slap_schema.si_ad_hasSubordinates );
80 a->a_numvals = 1;
81 a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
83 ber_dupbv( &a->a_vals[0], &val );
84 a->a_vals[1].bv_val = NULL;
86 a->a_nvals = a->a_vals;
88 return a;