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