]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/entry.c
tolerate that config_get_vals() returns success with no values (ITS#4341)
[openldap] / servers / slapd / back-monitor / entry.c
1 /* entry.c - monitor backend entry handling routines */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2006 The OpenLDAP Foundation.
6  * Portions Copyright 2001-2003 Pierangelo Masarati.
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 file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Pierangelo Masarati for inclusion
19  * in OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #include <slap.h>
25 #include "back-monitor.h"
26
27 int
28 monitor_entry_update(
29         Operation               *op,
30         SlapReply               *rs,
31         Entry                   *e
32 )
33 {
34         monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
35         monitor_entry_t *mp;
36
37         int             rc = SLAP_CB_CONTINUE;
38
39         assert( mi != NULL );
40         assert( e != NULL );
41         assert( e->e_private != NULL );
42
43         mp = ( monitor_entry_t * )e->e_private;
44
45         if ( mp->mp_info && mp->mp_info->mss_update ) {
46                 rc = mp->mp_info->mss_update( op, rs, e );
47         }
48
49         if ( rc == SLAP_CB_CONTINUE && mp->mp_cb ) {
50                 struct monitor_callback_t       *mc;
51
52                 for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
53                         if ( mc->mc_update ) {
54                                 rc = mc->mc_update( op, rs, e, mc->mc_private );
55                                 if ( rc != SLAP_CB_CONTINUE ) {
56                                         break;
57                                 }
58                         }
59                 }
60         }
61
62         if ( rc == SLAP_CB_CONTINUE ) {
63                 rc = LDAP_SUCCESS;
64         }
65
66         return rc;
67 }
68
69 int
70 monitor_entry_create(
71         Operation               *op,
72         SlapReply               *rs,
73         struct berval           *ndn,
74         Entry                   *e_parent,
75         Entry                   **ep )
76 {
77         monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
78         monitor_entry_t *mp;
79
80         int             rc = SLAP_CB_CONTINUE;
81
82         assert( mi != NULL );
83         assert( e_parent != NULL );
84         assert( e_parent->e_private != NULL );
85         assert( ep != NULL );
86
87         mp = ( monitor_entry_t * )e_parent->e_private;
88
89         if ( mp->mp_info && mp->mp_info->mss_create ) {
90                 rc = mp->mp_info->mss_create( op, rs, ndn, e_parent, ep );
91         }
92
93         if ( rc == SLAP_CB_CONTINUE ) {
94                 rc = LDAP_SUCCESS;
95         }
96         
97         return rc;
98 }
99
100 int
101 monitor_entry_modify(
102         Operation               *op,
103         SlapReply               *rs,
104         Entry                   *e
105 )
106 {
107         monitor_info_t  *mi = ( monitor_info_t * )op->o_bd->be_private;
108         monitor_entry_t *mp;
109
110         int             rc = SLAP_CB_CONTINUE;
111
112         assert( mi != NULL );
113         assert( e != NULL );
114         assert( e->e_private != NULL );
115
116         mp = ( monitor_entry_t * )e->e_private;
117
118         if ( mp->mp_info && mp->mp_info->mss_modify ) {
119                 rc = mp->mp_info->mss_modify( op, rs, e );
120         }
121
122         if ( rc == SLAP_CB_CONTINUE && mp->mp_cb ) {
123                 struct monitor_callback_t       *mc;
124
125                 for ( mc = mp->mp_cb; mc; mc = mc->mc_next ) {
126                         if ( mc->mc_modify ) {
127                                 rc = mc->mc_modify( op, rs, e, mc->mc_private );
128                                 if ( rc != SLAP_CB_CONTINUE ) {
129                                         break;
130                                 }
131                         }
132                 }
133         }
134
135         if ( rc == SLAP_CB_CONTINUE ) {
136                 rc = LDAP_SUCCESS;
137         }
138
139         return rc;
140 }
141
142 int
143 monitor_entry_test_flags(
144         monitor_entry_t         *mp,
145         int                     cond
146 )
147 {
148         assert( mp != NULL );
149
150         return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) );
151 }
152
153 monitor_entry_t *
154 monitor_entrypriv_create( void )
155 {
156         monitor_entry_t *mp;
157
158         mp = ( monitor_entry_t * )ch_calloc( sizeof( monitor_entry_t ), 1 );
159
160         mp->mp_next = NULL;
161         mp->mp_children = NULL;
162         mp->mp_info = NULL;
163         mp->mp_flags = MONITOR_F_NONE;
164         mp->mp_cb = NULL;
165
166         return mp;
167 }
168
169 Entry *
170 monitor_entry_stub(
171         struct berval *pdn,
172         struct berval *pndn,
173         struct berval *rdn,
174         ObjectClass *oc,
175         monitor_info_t  *mi,
176         struct berval *create,
177         struct berval *modify
178 )
179 {
180         AttributeDescription *nad = NULL;
181         Entry *e;
182         struct berval nat;
183         char *ptr;
184         const char *text;
185         int rc;
186
187         nat = *rdn;
188         ptr = strchr( nat.bv_val, '=' );
189         nat.bv_len = ptr - nat.bv_val;
190         rc = slap_bv2ad( &nat, &nad, &text );
191         if ( rc )
192                 return NULL;
193
194         e = ch_calloc( 1, sizeof( Entry ));
195         if ( e ) {
196                 struct berval nrdn;
197
198                 rdnNormalize( 0, NULL, NULL, rdn, &nrdn, NULL );
199                 build_new_dn( &e->e_name, pdn, rdn, NULL );
200                 build_new_dn( &e->e_nname, pndn, &nrdn, NULL );
201                 nat.bv_val = ptr + 1;
202                 nat.bv_len = rdn->bv_len - ( nat.bv_val - rdn->bv_val );
203                 attr_merge_normalize_one( e, slap_schema.si_ad_objectClass,
204                         &oc->soc_cname, NULL );
205                 attr_merge_normalize_one( e, slap_schema.si_ad_structuralObjectClass,
206                         &oc->soc_cname, NULL );
207                 attr_merge_normalize_one( e, nad, &nat, NULL );
208                 attr_merge_one( e, slap_schema.si_ad_creatorsName, &mi->mi_creatorsName,
209                         &mi->mi_ncreatorsName );
210                 attr_merge_one( e, slap_schema.si_ad_modifiersName, &mi->mi_creatorsName,
211                         &mi->mi_ncreatorsName );
212                 attr_merge_normalize_one( e, slap_schema.si_ad_createTimestamp,
213                         create ? create : &mi->mi_startTime, NULL );
214                 attr_merge_normalize_one( e, slap_schema.si_ad_modifyTimestamp,
215                         modify ? modify : &mi->mi_startTime, NULL );
216         }
217         return e;
218 }