Debian Codegraph @

servers/slapd/back-monitor/overlay.c

raw
1 /* overlay.c - deals with overlay subsystem */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 *
4 * Copyright 2001-2024 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
11 *
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
15 */
16 /* ACKNOWLEDGEMENTS:
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
19 */
20
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "slap.h"
28 #include "back-monitor.h"
29
30 /*
31 * initializes overlay subentries
32 */
33 int
34 monitor_subsys_overlay_init(
35 BackendDB *be,
36 monitor_subsys_t *ms
37 )
38 {
39 monitor_info_t *mi;
40 Entry *e_overlay;
41 int i;
42 monitor_entry_t *mp;
43 slap_overinst *on;
44 monitor_subsys_t *ms_database;
45
46 mi = ( monitor_info_t * )be->be_private;
47
48 ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
49 if ( ms_database == NULL ) {
50 Debug( LDAP_DEBUG_ANY,
51 "monitor_subsys_backend_init: "
52 "unable to get "
53 "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
54 "subsystem\n" );
55 return -1;
56 }
57
58 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_overlay ) ) {
59 Debug( LDAP_DEBUG_ANY,
60 "monitor_subsys_overlay_init: "
61 "unable to get entry \"%s\"\n",
62 ms->mss_ndn.bv_val );
63 return( -1 );
64 }
65
66 for ( on = overlay_next( NULL ), i = 0; on; on = overlay_next( on ), i++ ) {
67 char buf[ BACKMONITOR_BUFSIZE ];
68 struct berval bv;
69 int j;
70 Entry *e;
71 BackendDB *be;
72
73 bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", i );
74 bv.bv_val = buf;
75 e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
76 mi->mi_oc_monitoredObject, NULL, NULL );
77 if ( e == NULL ) {
78 Debug( LDAP_DEBUG_ANY,
79 "monitor_subsys_overlay_init: "
80 "unable to create entry \"cn=Overlay %d,%s\"\n",
81 i, ms->mss_ndn.bv_val );
82 return( -1 );
83 }
84 ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
85 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
86 attr_merge_normalize_one( e, mi->mi_ad_monitorRuntimeConfig,
87 on->on_bi.bi_cf_ocs ? (struct berval *)&slap_true_bv :
88 (struct berval *)&slap_false_bv, NULL );
89
90 attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo,
91 &bv, NULL );
92
93 j = -1;
94 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
95 char buf[ SLAP_LDAPDN_MAXLEN ];
96 struct berval dn;
97
98 j++;
99 if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) {
100 continue;
101 }
102
103 snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
104 j, ms_database->mss_dn.bv_val );
105
106 ber_str2bv( buf, 0, 0, &dn );
107 attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso,
108 &dn, NULL );
109 }
110
111 mp = monitor_entrypriv_create();
112 if ( mp == NULL ) {
113 return -1;
114 }
115 e->e_private = ( void * )mp;
116 mp->mp_info = ms;
117 mp->mp_flags = ms->mss_flags
118 | MONITOR_F_SUB;
119
120 if ( monitor_cache_add( mi, e, e_overlay ) ) {
121 Debug( LDAP_DEBUG_ANY,
122 "monitor_subsys_overlay_init: "
123 "unable to add entry \"cn=Overlay %d,%s\"\n",
124 i, ms->mss_ndn.bv_val );
125 return( -1 );
126 }
127 }
128
129 monitor_cache_release( mi, e_overlay );
130
131 return( 0 );
132 }
133