Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-monitor / backend.c
blob79a8d5031ac94606af267c1a326b353b91d170ec
1 /* backend.c - deals with backend subsystem */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-monitor/backend.c,v 1.41.2.3 2008/02/11 23:26:47 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2008 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
7 * All rights reserved.
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.
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>.
17 /* ACKNOWLEDGEMENTS:
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
23 #include "portable.h"
25 #include <stdio.h>
26 #include <ac/string.h>
28 #include "slap.h"
29 #include "back-monitor.h"
32 * initializes backend subentries
34 int
35 monitor_subsys_backend_init(
36 BackendDB *be,
37 monitor_subsys_t *ms
40 monitor_info_t *mi;
41 Entry *e_backend, **ep;
42 int i;
43 monitor_entry_t *mp;
44 monitor_subsys_t *ms_database;
45 BackendInfo *bi;
47 mi = ( monitor_info_t * )be->be_private;
49 ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
50 if ( ms_database == NULL ) {
51 Debug( LDAP_DEBUG_ANY,
52 "monitor_subsys_backend_init: "
53 "unable to get "
54 "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
55 "subsystem\n",
56 0, 0, 0 );
57 return -1;
60 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_backend ) ) {
61 Debug( LDAP_DEBUG_ANY,
62 "monitor_subsys_backend_init: "
63 "unable to get entry \"%s\"\n",
64 ms->mss_ndn.bv_val, 0, 0 );
65 return( -1 );
68 mp = ( monitor_entry_t * )e_backend->e_private;
69 mp->mp_children = NULL;
70 ep = &mp->mp_children;
72 i = -1;
73 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
74 char buf[ BACKMONITOR_BUFSIZE ];
75 BackendDB *be;
76 struct berval bv;
77 int j;
78 Entry *e;
80 i++;
82 bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Backend %d", i );
83 bv.bv_val = buf;
85 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
86 mi->mi_oc_monitoredObject, mi, NULL, NULL );
88 if ( e == NULL ) {
89 Debug( LDAP_DEBUG_ANY,
90 "monitor_subsys_backend_init: "
91 "unable to create entry \"cn=Backend %d,%s\"\n",
92 i, ms->mss_ndn.bv_val, 0 );
93 return( -1 );
96 ber_str2bv( bi->bi_type, 0, 0, &bv );
97 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
98 &bv, NULL );
99 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
100 &bv, NULL );
102 attr_merge_normalize_one( e, mi->mi_ad_monitorRuntimeConfig,
103 bi->bi_cf_ocs == NULL ? (struct berval *)&slap_false_bv :
104 (struct berval *)&slap_true_bv, NULL );
106 if ( bi->bi_controls ) {
107 int j;
109 for ( j = 0; bi->bi_controls[ j ]; j++ ) {
110 ber_str2bv( bi->bi_controls[ j ], 0, 0, &bv );
111 attr_merge_one( e, slap_schema.si_ad_supportedControl,
112 &bv, &bv );
116 j = -1;
117 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
118 char buf[ SLAP_LDAPDN_MAXLEN ];
119 struct berval dn;
121 j++;
123 if ( be->bd_info != bi ) {
124 continue;
127 snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
128 j, ms_database->mss_dn.bv_val );
130 ber_str2bv( buf, 0, 0, &dn );
131 attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso,
132 &dn, NULL );
135 mp = monitor_entrypriv_create();
136 if ( mp == NULL ) {
137 return -1;
139 e->e_private = ( void * )mp;
140 mp->mp_info = ms;
141 mp->mp_flags = ms->mss_flags | MONITOR_F_SUB;
143 if ( monitor_cache_add( mi, e ) ) {
144 Debug( LDAP_DEBUG_ANY,
145 "monitor_subsys_backend_init: "
146 "unable to add entry \"cn=Backend %d,%s\"\n",
148 ms->mss_ndn.bv_val, 0 );
149 return( -1 );
152 *ep = e;
153 ep = &mp->mp_next;
156 monitor_cache_release( mi, e_backend );
158 return( 0 );