]> git.sur5r.net Git - openldap/blob - servers/slapd/operational.c
happy new year
[openldap] / servers / slapd / operational.c
1 /* operational.c - routines to deal with on-the-fly operational attrs */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 2001-2007 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
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.
10  *
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>.
14  */
15
16 #include "portable.h"
17
18 #include "slap.h"
19
20 /*
21  * helpers for on-the-fly operational attribute generation
22  */
23
24 Attribute *
25 slap_operational_subschemaSubentry( Backend *be )
26 {
27         Attribute       *a;
28
29         /* The backend wants to take care of it */
30         if ( be && !SLAP_FRONTEND(be) && be->be_schemadn.bv_val ) return NULL;
31
32         a = attr_alloc( slap_schema.si_ad_subschemaSubentry );
33
34         a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
35         ber_dupbv( a->a_vals, &frontendDB->be_schemadn );
36         a->a_vals[1].bv_len = 0;
37         a->a_vals[1].bv_val = NULL;
38
39         a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
40         ber_dupbv( a->a_nvals, &frontendDB->be_schemandn );
41         a->a_nvals[1].bv_len = 0;
42         a->a_nvals[1].bv_val = NULL;
43
44         return a;
45 }
46
47 Attribute *
48 slap_operational_entryDN( Entry *e )
49 {
50         Attribute       *a;
51
52         assert( e != NULL );
53         assert( !BER_BVISNULL( &e->e_name ) );
54         assert( !BER_BVISNULL( &e->e_nname ) );
55
56         a = attr_alloc( slap_schema.si_ad_entryDN );
57
58         a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
59         ber_dupbv( &a->a_vals[ 0 ], &e->e_name );
60         BER_BVZERO( &a->a_vals[ 1 ] );
61
62         a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
63         ber_dupbv( &a->a_nvals[ 0 ], &e->e_nname );
64         BER_BVZERO( &a->a_nvals[ 1 ] );
65
66         return a;
67 }
68
69 Attribute *
70 slap_operational_hasSubordinate( int hs )
71 {
72         Attribute       *a;
73         struct berval   val;
74
75         val = hs ? slap_true_bv : slap_false_bv;
76
77         a = attr_alloc( slap_schema.si_ad_hasSubordinates );
78         a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
79
80         ber_dupbv( &a->a_vals[0], &val );
81         a->a_vals[1].bv_val = NULL;
82
83         a->a_nvals = a->a_vals;
84
85         return a;
86 }
87