1 /*        $NetBSD: back-monitor.h,v 1.3 2021/08/14 16:15:00 christos Exp $      */
2 
3 /* back-monitor.h - ldap monitor back-end header file */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6  *
7  * Copyright 2001-2021 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 #ifndef _BACK_MONITOR_H_
25 #define _BACK_MONITOR_H_
26 
27 #include <ldap_pvt.h>
28 #include <ldap_pvt_thread.h>
29 #include <ldap_avl.h>
30 #include <slap.h>
31 
32 LDAP_BEGIN_DECL
33 
34 /* define if si_ad_labeledURI is removed from slap_schema */
35 #undef MONITOR_DEFINE_LABELEDURI
36 
37 typedef struct monitor_callback_t {
38           int                                     (*mc_update)( Operation *op, SlapReply *rs, Entry *e, void *priv );
39                                                             /* update callback
40                                                                for user-defined entries */
41           int                                     (*mc_modify)( Operation *op, SlapReply *rs, Entry *e, void *priv );
42                                                             /* modify callback
43                                                                for user-defined entries */
44           int                                     (*mc_free)( Entry *e, void **priv );
45                                                             /* delete callback
46                                                                for user-defined entries */
47           void                                    (*mc_dispose)( void **priv );
48                                                             /* dispose callback
49                                                                to dispose of the callback
50                                                                private data itself */
51           void                                    *mc_private;        /* opaque pointer to
52                                                                private data */
53           struct monitor_callback_t     *mc_next;
54 } monitor_callback_t;
55 
56 
57 typedef struct monitor_entry_t {
58           ldap_pvt_thread_mutex_t       mp_mutex; /* entry mutex */
59           Entry                         *mp_next; /* pointer to next sibling */
60           Entry                         *mp_children;       /* pointer to first child */
61           struct monitor_subsys_t       *mp_info; /* subsystem info */
62 #define mp_type               mp_info->mss_type
63           unsigned long                 mp_flags; /* flags */
64 
65 #define   MONITOR_F_NONE                0x0000U
66 #define MONITOR_F_SUB                   0x0001U             /* subentry of subsystem */
67 #define MONITOR_F_PERSISTENT  0x0010U             /* persistent entry */
68 #define MONITOR_F_PERSISTENT_CH         0x0020U             /* subsystem generates
69                                                                persistent entries */
70 #define MONITOR_F_VOLATILE    0x0040U             /* volatile entry */
71 #define MONITOR_F_VOLATILE_CH 0x0080U             /* subsystem generates
72                                                                volatile entries */
73 #define MONITOR_F_EXTERNAL    0x0100U             /* externally added - don't free */
74 /* NOTE: flags with 0xF0000000U mask are reserved for subsystem internals */
75 
76           struct monitor_callback_t     *mp_cb;             /* callback sequence */
77           void                *mp_private;
78 } monitor_entry_t;
79 
80 struct entry_limbo_t;                             /* in init.c */
81 
82 typedef struct monitor_info_t {
83 
84           /*
85            * Internal data
86            */
87           Avlnode                       *mi_cache;
88           ldap_pvt_thread_mutex_t       mi_cache_mutex;
89 
90           /*
91            * Config parameters
92            */
93           struct berval                 mi_startTime;                 /* don't free it! */
94           struct berval                 mi_creatorsName;    /* don't free it! */
95           struct berval                 mi_ncreatorsName;   /* don't free it! */
96 
97           /*
98            * Specific schema entities
99            */
100           ObjectClass                   *mi_oc_monitor;
101           ObjectClass                   *mi_oc_monitorServer;
102           ObjectClass                   *mi_oc_monitorContainer;
103           ObjectClass                   *mi_oc_monitorCounterObject;
104           ObjectClass                   *mi_oc_monitorOperation;
105           ObjectClass                   *mi_oc_monitorConnection;
106           ObjectClass                   *mi_oc_managedObject;
107           ObjectClass                   *mi_oc_monitoredObject;
108 
109           AttributeDescription          *mi_ad_monitoredInfo;
110           AttributeDescription          *mi_ad_managedInfo;
111           AttributeDescription          *mi_ad_monitorCounter;
112           AttributeDescription          *mi_ad_monitorOpCompleted;
113           AttributeDescription          *mi_ad_monitorOpInitiated;
114           AttributeDescription          *mi_ad_monitorConnectionNumber;
115           AttributeDescription          *mi_ad_monitorConnectionAuthzDN;
116           AttributeDescription          *mi_ad_monitorConnectionLocalAddress;
117           AttributeDescription          *mi_ad_monitorConnectionPeerAddress;
118           AttributeDescription          *mi_ad_monitorTimestamp;
119           AttributeDescription          *mi_ad_monitorOverlay;
120           AttributeDescription          *mi_ad_monitorConnectionProtocol;
121           AttributeDescription          *mi_ad_monitorConnectionOpsReceived;
122           AttributeDescription          *mi_ad_monitorConnectionOpsExecuting;
123           AttributeDescription          *mi_ad_monitorConnectionOpsPending;
124           AttributeDescription          *mi_ad_monitorConnectionOpsCompleted;
125           AttributeDescription          *mi_ad_monitorConnectionGet;
126           AttributeDescription          *mi_ad_monitorConnectionRead;
127           AttributeDescription          *mi_ad_monitorConnectionWrite;
128           AttributeDescription          *mi_ad_monitorConnectionMask;
129           AttributeDescription          *mi_ad_monitorConnectionListener;
130           AttributeDescription          *mi_ad_monitorConnectionPeerDomain;
131           AttributeDescription          *mi_ad_monitorConnectionStartTime;
132           AttributeDescription          *mi_ad_monitorConnectionActivityTime;
133           AttributeDescription          *mi_ad_monitorIsShadow;
134           AttributeDescription          *mi_ad_monitorUpdateRef;
135           AttributeDescription          *mi_ad_monitorRuntimeConfig;
136           AttributeDescription          *mi_ad_monitorSuperiorDN;
137 
138           /*
139            * Generic description attribute
140            */
141           AttributeDescription          *mi_ad_readOnly;
142           AttributeDescription          *mi_ad_restrictedOperation;
143 
144           struct entry_limbo_t          *mi_entry_limbo;
145 } monitor_info_t;
146 
147 /*
148  * DNs
149  */
150 
151 enum {
152           SLAPD_MONITOR_BACKEND = 0,
153           SLAPD_MONITOR_CONN,
154           SLAPD_MONITOR_DATABASE,
155           SLAPD_MONITOR_LISTENER,
156           SLAPD_MONITOR_LOG,
157           SLAPD_MONITOR_OPS,
158           SLAPD_MONITOR_OVERLAY,
159           SLAPD_MONITOR_SASL,
160           SLAPD_MONITOR_SENT,
161           SLAPD_MONITOR_THREAD,
162           SLAPD_MONITOR_TIME,
163           SLAPD_MONITOR_TLS,
164           SLAPD_MONITOR_RWW,
165 
166           SLAPD_MONITOR_LAST
167 };
168 
169 #define SLAPD_MONITOR_AT                "cn"
170 
171 #define SLAPD_MONITOR_BACKEND_NAME      "Backends"
172 #define SLAPD_MONITOR_BACKEND_RDN       \
173           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_BACKEND_NAME
174 #define SLAPD_MONITOR_BACKEND_DN        \
175           SLAPD_MONITOR_BACKEND_RDN "," SLAPD_MONITOR_DN
176 
177 #define SLAPD_MONITOR_CONN_NAME                   "Connections"
178 #define SLAPD_MONITOR_CONN_RDN          \
179           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_CONN_NAME
180 #define SLAPD_MONITOR_CONN_DN \
181           SLAPD_MONITOR_CONN_RDN "," SLAPD_MONITOR_DN
182 
183 #define SLAPD_MONITOR_DATABASE_NAME     "Databases"
184 #define SLAPD_MONITOR_DATABASE_RDN      \
185           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_DATABASE_NAME
186 #define SLAPD_MONITOR_DATABASE_DN       \
187           SLAPD_MONITOR_DATABASE_RDN "," SLAPD_MONITOR_DN
188 
189 #define SLAPD_MONITOR_LISTENER_NAME     "Listeners"
190 #define SLAPD_MONITOR_LISTENER_RDN      \
191           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LISTENER_NAME
192 #define SLAPD_MONITOR_LISTENER_DN       \
193           SLAPD_MONITOR_LISTENER_RDN "," SLAPD_MONITOR_DN
194 
195 #define SLAPD_MONITOR_LOG_NAME                    "Log"
196 #define SLAPD_MONITOR_LOG_RDN \
197           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_LOG_NAME
198 #define SLAPD_MONITOR_LOG_DN  \
199           SLAPD_MONITOR_LOG_RDN "," SLAPD_MONITOR_DN
200 
201 #define SLAPD_MONITOR_OPS_NAME                    "Operations"
202 #define SLAPD_MONITOR_OPS_RDN \
203           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OPS_NAME
204 #define SLAPD_MONITOR_OPS_DN  \
205           SLAPD_MONITOR_OPS_RDN "," SLAPD_MONITOR_DN
206 
207 #define SLAPD_MONITOR_OVERLAY_NAME      "Overlays"
208 #define SLAPD_MONITOR_OVERLAY_RDN  \
209           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_OVERLAY_NAME
210 #define SLAPD_MONITOR_OVERLAY_DN   \
211           SLAPD_MONITOR_OVERLAY_RDN "," SLAPD_MONITOR_DN
212 
213 #define SLAPD_MONITOR_SASL_NAME                   "SASL"
214 #define SLAPD_MONITOR_SASL_RDN          \
215           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SASL_NAME
216 #define SLAPD_MONITOR_SASL_DN \
217           SLAPD_MONITOR_SASL_RDN "," SLAPD_MONITOR_DN
218 
219 #define SLAPD_MONITOR_SENT_NAME                   "Statistics"
220 #define SLAPD_MONITOR_SENT_RDN          \
221           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_SENT_NAME
222 #define SLAPD_MONITOR_SENT_DN \
223           SLAPD_MONITOR_SENT_RDN "," SLAPD_MONITOR_DN
224 
225 #define SLAPD_MONITOR_THREAD_NAME       "Threads"
226 #define SLAPD_MONITOR_THREAD_RDN        \
227           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_THREAD_NAME
228 #define SLAPD_MONITOR_THREAD_DN         \
229           SLAPD_MONITOR_THREAD_RDN "," SLAPD_MONITOR_DN
230 
231 #define SLAPD_MONITOR_TIME_NAME                   "Time"
232 #define SLAPD_MONITOR_TIME_RDN  \
233           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TIME_NAME
234 #define SLAPD_MONITOR_TIME_DN   \
235           SLAPD_MONITOR_TIME_RDN "," SLAPD_MONITOR_DN
236 
237 #define SLAPD_MONITOR_TLS_NAME                    "TLS"
238 #define SLAPD_MONITOR_TLS_RDN \
239           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_TLS_NAME
240 #define SLAPD_MONITOR_TLS_DN  \
241           SLAPD_MONITOR_TLS_RDN "," SLAPD_MONITOR_DN
242 
243 #define SLAPD_MONITOR_RWW_NAME                    "Waiters"
244 #define SLAPD_MONITOR_RWW_RDN \
245           SLAPD_MONITOR_AT "=" SLAPD_MONITOR_RWW_NAME
246 #define SLAPD_MONITOR_RWW_DN  \
247           SLAPD_MONITOR_RWW_RDN "," SLAPD_MONITOR_DN
248 
249 typedef struct monitor_subsys_t {
250           char                *mss_name;
251           struct berval       mss_rdn;
252           struct berval       mss_dn;
253           struct berval       mss_ndn;
254           struct berval       mss_desc[ 3 ];
255           int                 mss_flags;
256 #define MONITOR_F_OPENED      0x10000000U
257 
258 #define MONITOR_HAS_VOLATILE_CH( mp ) \
259           ( ( mp )->mp_flags & MONITOR_F_VOLATILE_CH )
260 #define MONITOR_HAS_CHILDREN( mp ) \
261           ( ( mp )->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
262 
263           /* initialize entry and subentries */
264           int                 ( *mss_open )( BackendDB *, struct monitor_subsys_t *ms );
265           /* destroy structure */
266           int                 ( *mss_destroy )( BackendDB *, struct monitor_subsys_t *ms );
267           /* update existing dynamic entry and subentries */
268           int                 ( *mss_update )( Operation *, SlapReply *, Entry * );
269           /* create new dynamic subentries */
270           int                 ( *mss_create )( Operation *, SlapReply *,
271                                         struct berval *ndn, Entry *, Entry ** );
272           /* modify entry and subentries */
273           int                 ( *mss_modify )( Operation *, SlapReply *, Entry * );
274 
275           void                *mss_private;
276 } monitor_subsys_t;
277 
278 extern BackendDB *be_monitor;
279 
280 /* increase this bufsize if entries in string form get too big */
281 #define BACKMONITOR_BUFSIZE   8192
282 
283 typedef int (monitor_cbfunc)( struct berval *ndn, monitor_callback_t *cb,
284           struct berval *base, int scope, struct berval *filter );
285 
286 typedef int (monitor_cbafunc)( struct berval *ndn, Attribute *a,
287           monitor_callback_t *cb,
288           struct berval *base, int scope, struct berval *filter );
289 
290 typedef struct monitor_extra_t {
291           int (*is_configured)(void);
292           monitor_subsys_t * (*get_subsys)( const char *name );
293           monitor_subsys_t * (*get_subsys_by_dn)( struct berval *ndn, int sub );
294 
295           int (*register_subsys)( monitor_subsys_t *ms );
296           int (*register_backend)( BackendInfo *bi );
297           int (*register_database)( BackendDB *be, struct berval *ndn_out );
298           int (*register_overlay_info)( slap_overinst *on );
299           int (*register_overlay)( BackendDB *be, slap_overinst *on, struct berval *ndn_out );
300           int (*register_entry)( Entry *e, monitor_callback_t *cb,
301                     monitor_subsys_t *ms, unsigned long flags );
302           int (*register_entry_parent)( Entry *e, monitor_callback_t *cb,
303                     monitor_subsys_t *ms, unsigned long flags,
304                     struct berval *base, int scope, struct berval *filter );
305           monitor_cbafunc *register_entry_attrs;
306           monitor_cbfunc *register_entry_callback;
307 
308           int (*unregister_entry)( struct berval *ndn );
309           monitor_cbfunc *unregister_entry_parent;
310           monitor_cbafunc *unregister_entry_attrs;
311           monitor_cbfunc *unregister_entry_callback;
312           Entry * (*entry_stub)( struct berval *pdn,
313                     struct berval *pndn,
314                     struct berval *rdn,
315                     ObjectClass *oc,
316                     struct berval *create,
317                     struct berval *modify );
318           monitor_entry_t * (*entrypriv_create)( void );
319           int (*register_subsys_late)( monitor_subsys_t *ms );
320           Entry * (*entry_get_unlocked)( struct berval *ndn );
321 } monitor_extra_t;
322 
323 LDAP_END_DECL
324 
325 #include "proto-back-monitor.h"
326 
327 #endif /* _back_monitor_h_ */
328 
329