]> 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-2006 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 = ch_malloc( sizeof( Attribute ) );
33         a->a_desc = slap_schema.si_ad_subschemaSubentry;
34
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;
39
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;
44
45         a->a_next = NULL;
46         a->a_flags = 0;
47
48         return a;
49 }
50
51 Attribute *
52 slap_operational_entryDN( Entry *e )
53 {
54         Attribute       *a;
55
56         assert( e != NULL );
57         assert( !BER_BVISNULL( &e->e_name ) );
58         assert( !BER_BVISNULL( &e->e_nname ) );
59
60         a = ch_malloc( sizeof( Attribute ) );
61         a->a_desc = slap_schema.si_ad_entryDN;
62
63         a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
64         ber_dupbv( &a->a_vals[ 0 ], &e->e_name );
65         BER_BVZERO( &a->a_vals[ 1 ] );
66
67         a->a_nvals = ch_malloc( 2 * sizeof( struct berval ) );
68         ber_dupbv( &a->a_nvals[ 0 ], &e->e_nname );
69         BER_BVZERO( &a->a_nvals[ 1 ] );
70
71         a->a_next = NULL;
72         a->a_flags = 0;
73
74         return a;
75 }
76
77 Attribute *
78 slap_operational_hasSubordinate( int hs )
79 {
80         Attribute       *a;
81         struct berval   val;
82
83         val = hs ? slap_true_bv : slap_false_bv;
84
85         a = ch_malloc( sizeof( Attribute ) );
86         a->a_desc = slap_schema.si_ad_hasSubordinates;
87         a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
88
89         ber_dupbv( &a->a_vals[0], &val );
90         a->a_vals[1].bv_val = NULL;
91
92         a->a_nvals = a->a_vals;
93
94         a->a_next = NULL;
95         a->a_flags = 0;
96
97         return a;
98 }
99