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