]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/backend.c
should we touch timestamps when internally updating?
[openldap] / servers / slapd / back-monitor / backend.c
1 /* backend.c - deals with backend subsystem */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2001-2005 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
23 #include "portable.h"
24
25 #include <stdio.h>
26 #include <ac/string.h>
27
28 #include "slap.h"
29 #include "back-monitor.h"
30
31 /*
32  * initializes backend subentries
33  */
34 int
35 monitor_subsys_backend_init(
36         BackendDB               *be,
37         monitor_subsys_t        *ms
38 )
39 {
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
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                         0, 0, 0 );
56                 return -1;
57         }
58
59         if ( monitor_cache_get( mi, &ms->mss_ndn, &e_backend ) )
60         {
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 );
66         }
67
68         mp = ( monitor_entry_t * )e_backend->e_private;
69         mp->mp_children = NULL;
70         ep = &mp->mp_children;
71
72         for ( i = 0; i < nBackendInfo; i++ ) {
73                 char            buf[ BACKMONITOR_BUFSIZE ];
74                 BackendInfo     *bi;
75                 struct berval   bv;
76                 int             j;
77                 Entry           *e;
78
79                 bi = &backendInfo[ i ];
80
81                 snprintf( buf, sizeof( buf ),
82                                 "dn: cn=Backend %d,%s\n"
83                                 "objectClass: %s\n"
84                                 "structuralObjectClass: %s\n"
85                                 "cn: Backend %d\n"
86                                 "creatorsName: %s\n"
87                                 "modifiersName: %s\n"
88                                 "createTimestamp: %s\n"
89                                 "modifyTimestamp: %s\n",
90                                 i,
91                                 ms->mss_dn.bv_val,
92                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
93                                 mi->mi_oc_monitoredObject->soc_cname.bv_val,
94                                 i,
95                                 mi->mi_creatorsName.bv_val,
96                                 mi->mi_creatorsName.bv_val,
97                                 mi->mi_startTime.bv_val,
98                                 mi->mi_startTime.bv_val );
99                 
100                 e = str2entry( buf );
101                 if ( e == NULL ) {
102                         Debug( LDAP_DEBUG_ANY,
103                                 "monitor_subsys_backend_init: "
104                                 "unable to create entry \"cn=Backend %d,%s\"\n",
105                                 i, ms->mss_ndn.bv_val, 0 );
106                         return( -1 );
107                 }
108                 
109                 bv.bv_val = bi->bi_type;
110                 bv.bv_len = strlen( bv.bv_val );
111
112                 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
113                                 &bv, NULL );
114                 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
115                                 &bv, NULL );
116
117                 if ( bi->bi_controls ) {
118                         int j;
119
120                         for ( j = 0; bi->bi_controls[ j ]; j++ ) {
121                                 bv.bv_val = bi->bi_controls[ j ];
122                                 bv.bv_len = strlen( bv.bv_val );
123                                 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
124                         }
125                 }
126
127                 for ( j = 0; j < nBackendDB; j++ ) {
128                         BackendDB       *be = &backendDB[ j ];
129                         char            buf[ SLAP_LDAPDN_MAXLEN ];
130                         struct berval   dn;
131                         
132                         if ( be->bd_info != bi ) {
133                                 continue;
134                         }
135
136                         snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
137                                         j, ms_database->mss_dn.bv_val );
138                         dn.bv_val = buf;
139                         dn.bv_len = strlen( buf );
140
141                         attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
142                                         &dn, NULL );
143                 }
144                 
145                 mp = monitor_entrypriv_create();
146                 if ( mp == NULL ) {
147                         return -1;
148                 }
149                 e->e_private = ( void * )mp;
150                 mp->mp_info = ms;
151                 mp->mp_flags = ms->mss_flags | MONITOR_F_SUB;
152
153                 if ( monitor_cache_add( mi, e ) ) {
154                         Debug( LDAP_DEBUG_ANY,
155                                 "monitor_subsys_backend_init: "
156                                 "unable to add entry \"cn=Backend %d,%s\"\n",
157                                 i,
158                                 ms->mss_ndn.bv_val, 0 );
159                         return( -1 );
160                 }
161
162                 *ep = e;
163                 ep = &mp->mp_next;
164         }
165         
166         monitor_cache_release( mi, e_backend );
167
168         return( 0 );
169 }
170