~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to servers/slapd/back-monitor/database.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-09-07 13:41:10 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20090907134110-jsdrvn0atu1fex4m
Tags: upstream-2.4.18
ImportĀ upstreamĀ versionĀ 2.4.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* database.c - deals with database subsystem */
2
 
/* $OpenLDAP: pkg/ldap/servers/slapd/back-monitor/database.c,v 1.80.2.13 2009/04/27 22:50:10 quanah Exp $ */
 
2
/* $OpenLDAP: pkg/ldap/servers/slapd/back-monitor/database.c,v 1.80.2.15 2009/08/25 22:48:09 quanah Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
4
 *
5
5
 * Copyright 2001-2009 The OpenLDAP Foundation.
100
100
}
101
101
 
102
102
static int
 
103
monitor_subsys_overlay_init_one(
 
104
        monitor_info_t          *mi,
 
105
        BackendDB               *be,
 
106
        monitor_subsys_t        *ms,
 
107
        monitor_subsys_t        *ms_overlay,
 
108
        slap_overinst           *on,
 
109
        Entry                   *e_database,
 
110
        Entry                   **ep_overlay )
 
111
{
 
112
        char                    buf[ BACKMONITOR_BUFSIZE ];
 
113
        int                     j, o;
 
114
        Entry                   *e_overlay;
 
115
        slap_overinst           *on2;
 
116
        slap_overinfo           *oi = NULL;
 
117
        BackendInfo             *bi;
 
118
        monitor_entry_t         *mp_overlay;
 
119
        struct berval           bv;
 
120
 
 
121
        assert( overlay_is_over( be ) );
 
122
 
 
123
        oi = (slap_overinfo *)be->bd_info->bi_private;
 
124
        bi = oi->oi_orig;
 
125
 
 
126
        /* find the overlay number, o */
 
127
        for ( o = 0, on2 = oi->oi_list; on2 && on2 != on; on2 = on2->on_next, o++ )
 
128
                ;
 
129
 
 
130
        if ( on2 == NULL ) {
 
131
                return -1;
 
132
        }
 
133
 
 
134
        /* find the overlay type number, j */
 
135
        for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
 
136
                if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
 
137
                        break;
 
138
                }
 
139
        }
 
140
        assert( on2 != NULL );
 
141
 
 
142
        bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o );
 
143
        bv.bv_val = buf;
 
144
 
 
145
        e_overlay = monitor_entry_stub( &e_database->e_name, &e_database->e_nname, &bv,
 
146
                mi->mi_oc_monitoredObject, mi, NULL, NULL );
 
147
 
 
148
        if ( e_overlay == NULL ) {
 
149
                Debug( LDAP_DEBUG_ANY,
 
150
                        "monitor_subsys_overlay_init_one: "
 
151
                        "unable to create entry "
 
152
                        "\"cn=Overlay %d,%s\"\n",
 
153
                        o, e_database->e_name.bv_val, 0 );
 
154
                return( -1 );
 
155
        }
 
156
        ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
 
157
        attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL );
 
158
 
 
159
        bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s",
 
160
                j, ms_overlay->mss_dn.bv_val );
 
161
        bv.bv_val = buf;
 
162
        attr_merge_normalize_one( e_overlay, slap_schema.si_ad_seeAlso,
 
163
                &bv, NULL );
 
164
 
 
165
        if ( SLAP_MONITOR( be ) ) {
 
166
                attr_merge( e_overlay, slap_schema.si_ad_monitorContext,
 
167
                                be->be_suffix, be->be_nsuffix );
 
168
 
 
169
        } else {
 
170
                attr_merge( e_overlay, slap_schema.si_ad_namingContexts,
 
171
                                be->be_suffix, NULL );
 
172
        }
 
173
 
 
174
        mp_overlay = monitor_entrypriv_create();
 
175
        if ( mp_overlay == NULL ) {
 
176
                return -1;
 
177
        }
 
178
        e_overlay->e_private = ( void * )mp_overlay;
 
179
        mp_overlay->mp_info = ms;
 
180
        mp_overlay->mp_flags = ms->mss_flags | MONITOR_F_SUB;
 
181
        
 
182
        if ( monitor_cache_add( mi, e_overlay ) ) {
 
183
                Debug( LDAP_DEBUG_ANY,
 
184
                        "monitor_subsys_overlay_init_one: "
 
185
                        "unable to add entry "
 
186
                        "\"cn=Overlay %d,%s\"\n",
 
187
                        o, e_database->e_name.bv_val, 0 );
 
188
                return -1;
 
189
        }
 
190
 
 
191
        *ep_overlay = e_overlay;
 
192
        ep_overlay = &mp_overlay->mp_next;
 
193
 
 
194
        return 0;
 
195
}
 
196
 
 
197
static int
103
198
monitor_subsys_database_init_one(
104
199
        monitor_info_t          *mi,
105
200
        BackendDB               *be,
126
221
                bi = oi->oi_orig;
127
222
        }
128
223
 
129
 
        /* Subordinates are not exposed as their own naming context */
130
 
        if ( SLAP_GLUE_SUBORDINATE( be ) ) {
131
 
                return 0;
132
 
        }
133
 
 
134
224
        e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, rdn,
135
225
                mi->mi_oc_monitoredObject, mi, NULL, NULL );
136
226
 
137
227
        if ( e == NULL ) {
138
228
                Debug( LDAP_DEBUG_ANY,
139
 
                        "monitor_subsys_database_init: "
 
229
                        "monitor_subsys_database_init_one: "
140
230
                        "unable to create entry \"%s,%s\"\n",
141
231
                        rdn->bv_val, ms->mss_dn.bv_val, 0 );
142
232
                return( -1 );
157
247
        } else {
158
248
                if ( be->be_suffix == NULL ) {
159
249
                        Debug( LDAP_DEBUG_ANY,
160
 
                                "monitor_subsys_database_init: "
 
250
                                "monitor_subsys_database_init_one: "
161
251
                                "missing suffix for %s\n",
162
252
                                rdnval, 0, 0 );
163
253
                } else {
166
256
                        attr_merge( e_database, slap_schema.si_ad_namingContexts,
167
257
                                be->be_suffix, NULL );
168
258
                }
 
259
 
 
260
                if ( SLAP_GLUE_SUBORDINATE( be ) ) {
 
261
                        BackendDB *sup_be = select_backend( &be->be_nsuffix[ 0 ], 1 );
 
262
                        if ( sup_be == NULL ) {
 
263
                                Debug( LDAP_DEBUG_ANY,
 
264
                                        "monitor_subsys_database_init: "
 
265
                                        "unable to get superior for %s\n",
 
266
                                        be->be_suffix[ 0 ].bv_val, 0, 0 );
 
267
 
 
268
                        } else {
 
269
                                attr_merge( e, mi->mi_ad_monitorSuperiorDN,
 
270
                                        sup_be->be_suffix, sup_be->be_nsuffix );
 
271
                        }
 
272
                }
169
273
        }
170
274
 
171
275
        (void)init_readOnly( mi, e, be->be_restrictops );
244
348
 
245
349
        if ( monitor_cache_add( mi, e ) ) {
246
350
                Debug( LDAP_DEBUG_ANY,
247
 
                        "monitor_subsys_database_init: "
 
351
                        "monitor_subsys_database_init_one: "
248
352
                        "unable to add entry \"%s,%s\"\n",
249
353
                        rdn->bv_val, ms->mss_dn.bv_val, 0 );
250
354
                return( -1 );
256
360
 
257
361
        if ( oi != NULL ) {
258
362
                Entry           **ep_overlay = &mp->mp_children;
259
 
                monitor_entry_t *mp_overlay;
260
363
                slap_overinst   *on = oi->oi_list;
261
 
                int             o;
262
 
 
263
 
                for ( o = 0; on; o++, on = on->on_next ) {
264
 
                        Entry                   *e_overlay;
265
 
                        slap_overinst           *on2;
266
 
 
267
 
                        /* find the overlay number, j */
268
 
                        for ( on2 = overlay_next( NULL ), j = 0; on2; on2 = overlay_next( on2 ), j++ ) {
269
 
                                if ( on2->on_bi.bi_type == on->on_bi.bi_type ) {
270
 
                                        break;
271
 
                                }
272
 
                        }
273
 
                        assert( on2 != NULL );
274
 
 
275
 
                        bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o );
276
 
                        bv.bv_val = buf;
277
 
 
278
 
                        e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv,
279
 
                                mi->mi_oc_monitoredObject, mi, NULL, NULL );
280
 
 
281
 
                        if ( e_overlay == NULL ) {
282
 
                                Debug( LDAP_DEBUG_ANY,
283
 
                                        "monitor_subsys_database_init: "
284
 
                                        "unable to create entry "
285
 
                                        "\"cn=Overlay %d,%s,%s\"\n",
286
 
                                        o, rdn->bv_val, ms->mss_dn.bv_val );
287
 
                                return( -1 );
288
 
                        }
289
 
                        ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
290
 
                        attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo, &bv, NULL );
291
 
 
292
 
                        bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s",
293
 
                                j, ms_overlay->mss_dn.bv_val );
294
 
                        bv.bv_val = buf;
295
 
                        attr_merge_normalize_one( e_overlay, slap_schema.si_ad_seeAlso,
296
 
                                &bv, NULL );
297
 
 
298
 
                        if ( SLAP_MONITOR( be ) ) {
299
 
                                attr_merge( e_overlay, slap_schema.si_ad_monitorContext,
300
 
                                                be->be_suffix, be->be_nsuffix );
301
 
 
302
 
                        } else {
303
 
                                attr_merge( e_overlay, slap_schema.si_ad_namingContexts,
304
 
                                                be->be_suffix, NULL );
305
 
                        }
306
 
 
307
 
                        mp_overlay = monitor_entrypriv_create();
308
 
                        if ( mp_overlay == NULL ) {
309
 
                                return -1;
310
 
                        }
311
 
                        e_overlay->e_private = ( void * )mp_overlay;
312
 
                        mp_overlay->mp_info = ms;
313
 
                        mp_overlay->mp_flags = ms->mss_flags
314
 
                                | MONITOR_F_SUB;
315
 
        
316
 
                        if ( monitor_cache_add( mi, e_overlay ) ) {
317
 
                                Debug( LDAP_DEBUG_ANY,
318
 
                                        "monitor_subsys_database_init: "
319
 
                                        "unable to add entry "
320
 
                                        "\"cn=Overlay %d,%s,%s\"\n",
321
 
                                        o, rdn->bv_val, ms->mss_dn.bv_val );
322
 
                                return( -1 );
323
 
                        }
324
 
 
325
 
                        *ep_overlay = e_overlay;
326
 
                        ep_overlay = &mp_overlay->mp_next;
 
364
 
 
365
                for ( ; on; on = on->on_next ) {
 
366
                        monitor_subsys_overlay_init_one( mi, be,
 
367
                                ms, ms_overlay, on, e, ep_overlay );
327
368
                }
328
369
        }
329
370
 
333
374
        return 0;
334
375
}
335
376
 
336
 
int
337
 
monitor_back_register_database(
 
377
static int
 
378
monitor_back_register_database_and_overlay(
338
379
        BackendDB               *be,
339
 
        struct berval   *ndn )
 
380
        struct slap_overinst    *on,
 
381
        struct berval           *ndn_out )
340
382
{
341
383
        monitor_info_t          *mi;
342
384
        Entry                   *e_database, **ep;
351
393
        assert( be_monitor != NULL );
352
394
 
353
395
        if ( !monitor_subsys_is_opened() ) {
354
 
                return monitor_back_register_database_limbo( be, ndn );
 
396
                if ( on ) {
 
397
                        return monitor_back_register_overlay_limbo( be, on, ndn_out );
 
398
 
 
399
                } else {
 
400
                        return monitor_back_register_database_limbo( be, ndn_out );
 
401
                }
355
402
        }
356
403
 
357
404
        mi = ( monitor_info_t * )be_monitor->be_private;
446
493
 
447
494
done:;
448
495
        monitor_cache_release( mi, e_database );
449
 
        if ( rc == 0 && ndn && ep && *ep ) {
450
 
                *ndn = (*ep)->e_nname;
 
496
        if ( rc == 0 && ndn_out && ep && *ep ) {
 
497
                if ( on ) {
 
498
                        Entry *e_ov;
 
499
                        struct berval ov_type;
 
500
 
 
501
                        ber_str2bv( on->on_bi.bi_type, 0, 0, &ov_type );
 
502
 
 
503
                        mp = ( monitor_entry_t * ) (*ep)->e_private;
 
504
                        for ( e_ov = mp->mp_children; e_ov; ) {
 
505
                                Attribute *a = attr_find( e_ov->e_attrs, mi->mi_ad_monitoredInfo );
 
506
 
 
507
                                if ( a != NULL && bvmatch( &a->a_nvals[ 0 ], &ov_type ) ) {
 
508
                                        *ndn_out = e_ov->e_nname;
 
509
                                        break;
 
510
                                }
 
511
 
 
512
                                mp = ( monitor_entry_t * ) e_ov->e_private;
 
513
                                e_ov = mp->mp_next;
 
514
                        }
 
515
                        
 
516
                } else {
 
517
                        *ndn_out = (*ep)->e_nname;
 
518
                }
451
519
        }
452
520
 
453
521
        return rc;
454
522
}
455
523
 
456
524
int
 
525
monitor_back_register_database(
 
526
        BackendDB               *be,
 
527
        struct berval           *ndn_out )
 
528
{
 
529
        return monitor_back_register_database_and_overlay( be, NULL, ndn_out );
 
530
}
 
531
 
 
532
int
 
533
monitor_back_register_overlay(
 
534
        BackendDB               *be,
 
535
        struct slap_overinst    *on,
 
536
        struct berval           *ndn_out )
 
537
{
 
538
        return monitor_back_register_database_and_overlay( be, on, ndn_out );
 
539
}
 
540
 
 
541
int
457
542
monitor_subsys_database_init(
458
543
        BackendDB               *be,
459
544
        monitor_subsys_t        *ms )