2006-09-06 09:54:54 +08:00
|
|
|
/* monitor.c - monitor bdb backend */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2007-01-03 04:00:42 +08:00
|
|
|
* Copyright 2000-2007 The OpenLDAP Foundation.
|
2006-09-06 09:54:54 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
#include <ac/errno.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include "lutil.h"
|
|
|
|
#include "back-bdb.h"
|
2006-09-12 15:53:19 +08:00
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
#include "../back-monitor/back-monitor.h"
|
|
|
|
|
2006-11-15 09:18:37 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
static ObjectClass *oc_olmBDBDatabase;
|
|
|
|
|
2006-09-06 11:37:13 +08:00
|
|
|
static AttributeDescription *ad_olmBDBEntryCache,
|
2007-08-12 03:29:14 +08:00
|
|
|
*ad_olmBDBDNCache, *ad_olmBDBIDLCache,
|
2006-09-06 17:10:46 +08:00
|
|
|
*ad_olmDbDirectory;
|
2006-09-06 09:54:54 +08:00
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
#ifdef BDB_MONITOR_IDX
|
|
|
|
static int
|
|
|
|
bdb_monitor_idx_entry_add(
|
|
|
|
struct bdb_info *bdb,
|
|
|
|
Entry *e );
|
|
|
|
|
|
|
|
static AttributeDescription *ad_olmBDBNotIndexed;
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
/*
|
|
|
|
* NOTE: there's some confusion in monitor OID arc;
|
|
|
|
* by now, let's consider:
|
|
|
|
*
|
|
|
|
* Subsystems monitor attributes 1.3.6.1.4.1.4203.666.1.55.0
|
|
|
|
* Databases monitor attributes 1.3.6.1.4.1.4203.666.1.55.0.1
|
|
|
|
* BDB database monitor attributes 1.3.6.1.4.1.4203.666.1.55.0.1.1
|
|
|
|
*
|
|
|
|
* Subsystems monitor objectclasses 1.3.6.1.4.1.4203.666.3.16.0
|
|
|
|
* Databases monitor objectclasses 1.3.6.1.4.1.4203.666.3.16.0.1
|
|
|
|
* BDB database monitor objectclasses 1.3.6.1.4.1.4203.666.3.16.0.1.1
|
|
|
|
*/
|
|
|
|
|
2006-09-07 00:06:49 +08:00
|
|
|
static struct {
|
|
|
|
char *name;
|
|
|
|
char *oid;
|
|
|
|
} s_oid[] = {
|
|
|
|
{ "olmBDBAttributes", "olmDatabaseAttributes:1" },
|
|
|
|
{ "olmBDBObjectClasses", "olmDatabaseObjectClasses:1" },
|
|
|
|
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
static struct {
|
|
|
|
char *desc;
|
|
|
|
AttributeDescription **ad;
|
|
|
|
} s_at[] = {
|
2006-09-13 20:48:45 +08:00
|
|
|
{ "( olmBDBAttributes:1 "
|
2006-09-06 11:37:13 +08:00
|
|
|
"NAME ( 'olmBDBEntryCache' ) "
|
|
|
|
"DESC 'Number of items in Entry Cache' "
|
|
|
|
"SUP monitorCounter "
|
|
|
|
"NO-USER-MODIFICATION "
|
2006-12-08 10:30:11 +08:00
|
|
|
"USAGE dSAOperation )",
|
2006-09-06 11:37:13 +08:00
|
|
|
&ad_olmBDBEntryCache },
|
|
|
|
|
2006-09-13 20:48:45 +08:00
|
|
|
{ "( olmBDBAttributes:2 "
|
2007-08-12 03:29:14 +08:00
|
|
|
"NAME ( 'olmBDBDNCache' ) "
|
|
|
|
"DESC 'Number of items in DN Cache' "
|
2006-09-06 09:54:54 +08:00
|
|
|
"SUP monitorCounter "
|
|
|
|
"NO-USER-MODIFICATION "
|
2006-12-08 10:30:11 +08:00
|
|
|
"USAGE dSAOperation )",
|
2007-08-12 03:29:14 +08:00
|
|
|
&ad_olmBDBDNCache },
|
2006-09-06 11:37:13 +08:00
|
|
|
|
2006-09-13 20:48:45 +08:00
|
|
|
{ "( olmBDBAttributes:3 "
|
2006-09-06 11:37:13 +08:00
|
|
|
"NAME ( 'olmBDBIDLCache' ) "
|
|
|
|
"DESC 'Number of items in IDL Cache' "
|
|
|
|
"SUP monitorCounter "
|
|
|
|
"NO-USER-MODIFICATION "
|
2006-12-08 10:30:11 +08:00
|
|
|
"USAGE dSAOperation )",
|
2006-09-06 11:37:13 +08:00
|
|
|
&ad_olmBDBIDLCache },
|
2006-09-06 09:54:54 +08:00
|
|
|
|
2006-09-13 20:48:45 +08:00
|
|
|
{ "( olmBDBAttributes:4 "
|
2006-09-06 17:10:46 +08:00
|
|
|
"NAME ( 'olmDbDirectory' ) "
|
|
|
|
"DESC 'Path name of the directory "
|
|
|
|
"where the database environment resides' "
|
|
|
|
"SUP monitoredInfo "
|
|
|
|
"NO-USER-MODIFICATION "
|
2006-12-08 10:30:11 +08:00
|
|
|
"USAGE dSAOperation )",
|
2006-09-06 17:10:46 +08:00
|
|
|
&ad_olmDbDirectory },
|
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
#ifdef BDB_MONITOR_IDX
|
|
|
|
{ "( olmBDBAttributes:5 "
|
|
|
|
"NAME ( 'olmBDBNotIndexed' ) "
|
|
|
|
"DESC 'Missing indexes resulting from candidate selection' "
|
|
|
|
"SUP monitoredInfo "
|
|
|
|
"NO-USER-MODIFICATION "
|
|
|
|
"USAGE dSAOperation )",
|
|
|
|
&ad_olmBDBNotIndexed },
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
char *desc;
|
|
|
|
ObjectClass **oc;
|
|
|
|
} s_oc[] = {
|
2006-09-06 17:10:46 +08:00
|
|
|
/* augments an existing object, so it must be AUXILIARY
|
|
|
|
* FIXME: derive from some ABSTRACT "monitoredEntity"? */
|
2006-09-13 20:48:45 +08:00
|
|
|
{ "( olmBDBObjectClasses:1 "
|
2006-09-06 09:54:54 +08:00
|
|
|
"NAME ( 'olmBDBDatabase' ) "
|
2006-09-06 17:10:46 +08:00
|
|
|
"SUP top AUXILIARY "
|
2006-09-06 09:54:54 +08:00
|
|
|
"MAY ( "
|
2006-09-06 17:10:46 +08:00
|
|
|
"olmBDBEntryCache "
|
2007-08-12 03:29:14 +08:00
|
|
|
"$ olmBDBDNCache "
|
2006-09-06 17:10:46 +08:00
|
|
|
"$ olmBDBIDLCache "
|
|
|
|
"$ olmDbDirectory "
|
2007-08-08 06:36:04 +08:00
|
|
|
#ifdef BDB_MONITOR_IDX
|
|
|
|
"$ olmBDBNotIndexed "
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|
2006-09-06 09:54:54 +08:00
|
|
|
") )",
|
|
|
|
&oc_olmBDBDatabase },
|
|
|
|
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2006-09-06 17:10:46 +08:00
|
|
|
static int
|
|
|
|
bdb_monitor_update(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e,
|
|
|
|
void *priv )
|
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) priv;
|
|
|
|
Attribute *a;
|
|
|
|
|
|
|
|
char buf[ BUFSIZ ];
|
|
|
|
struct berval bv;
|
|
|
|
|
|
|
|
assert( ad_olmBDBEntryCache != NULL );
|
|
|
|
|
|
|
|
a = attr_find( e->e_attrs, ad_olmBDBEntryCache );
|
|
|
|
assert( a != NULL );
|
|
|
|
bv.bv_val = buf;
|
|
|
|
bv.bv_len = snprintf( buf, sizeof( buf ), "%d", bdb->bi_cache.c_cursize );
|
|
|
|
ber_bvreplace( &a->a_vals[ 0 ], &bv );
|
|
|
|
|
2007-08-12 03:29:14 +08:00
|
|
|
a = attr_find( e->e_attrs, ad_olmBDBDNCache );
|
2006-09-06 17:10:46 +08:00
|
|
|
assert( a != NULL );
|
|
|
|
bv.bv_len = snprintf( buf, sizeof( buf ), "%d", bdb->bi_cache.c_eiused );
|
|
|
|
ber_bvreplace( &a->a_vals[ 0 ], &bv );
|
|
|
|
|
|
|
|
a = attr_find( e->e_attrs, ad_olmBDBIDLCache );
|
|
|
|
assert( a != NULL );
|
|
|
|
bv.bv_len = snprintf( buf, sizeof( buf ), "%d", bdb->bi_idl_cache_size );
|
|
|
|
ber_bvreplace( &a->a_vals[ 0 ], &bv );
|
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
#ifdef BDB_MONITOR_IDX
|
|
|
|
bdb_monitor_idx_entry_add( bdb, e );
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|
|
|
|
|
2006-09-06 17:10:46 +08:00
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2006-12-24 23:44:56 +08:00
|
|
|
#if 0 /* uncomment if required */
|
2006-09-06 17:10:46 +08:00
|
|
|
static int
|
|
|
|
bdb_monitor_modify(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e,
|
|
|
|
void *priv )
|
|
|
|
{
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
}
|
2006-12-24 23:44:56 +08:00
|
|
|
#endif
|
2006-09-06 17:10:46 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
bdb_monitor_free(
|
|
|
|
Entry *e,
|
2006-12-24 23:44:56 +08:00
|
|
|
void **priv )
|
2006-09-06 17:10:46 +08:00
|
|
|
{
|
|
|
|
struct berval values[ 2 ];
|
|
|
|
Modification mod = { 0 };
|
|
|
|
|
|
|
|
const char *text;
|
|
|
|
char textbuf[ SLAP_TEXT_BUFLEN ];
|
|
|
|
|
|
|
|
int i, rc;
|
|
|
|
|
2006-09-14 09:05:02 +08:00
|
|
|
/* NOTE: if slap_shutdown != 0, priv might have already been freed */
|
2006-12-24 23:44:56 +08:00
|
|
|
*priv = NULL;
|
2006-09-14 09:05:02 +08:00
|
|
|
|
2006-09-06 17:10:46 +08:00
|
|
|
/* Remove objectClass */
|
|
|
|
mod.sm_op = LDAP_MOD_DELETE;
|
|
|
|
mod.sm_desc = slap_schema.si_ad_objectClass;
|
|
|
|
mod.sm_values = values;
|
2007-09-24 09:31:23 +08:00
|
|
|
mod.sm_numvals = 1;
|
2006-09-06 17:10:46 +08:00
|
|
|
values[ 0 ] = oc_olmBDBDatabase->soc_cname;
|
|
|
|
BER_BVZERO( &values[ 1 ] );
|
|
|
|
|
|
|
|
rc = modify_delete_values( e, &mod, 1, &text,
|
|
|
|
textbuf, sizeof( textbuf ) );
|
|
|
|
/* don't care too much about return code... */
|
|
|
|
|
|
|
|
/* remove attrs */
|
2007-09-24 09:31:23 +08:00
|
|
|
mod.sm_values = NULL;
|
|
|
|
mod.sm_numvals = 0;
|
2006-09-13 20:48:45 +08:00
|
|
|
for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
|
2006-09-06 17:10:46 +08:00
|
|
|
mod.sm_desc = *s_at[ i ].ad;
|
|
|
|
rc = modify_delete_values( e, &mod, 1, &text,
|
|
|
|
textbuf, sizeof( textbuf ) );
|
|
|
|
/* don't care too much about return code... */
|
|
|
|
}
|
|
|
|
|
|
|
|
return SLAP_CB_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2006-09-26 16:43:01 +08:00
|
|
|
#define bdb_monitor_initialize BDB_SYMBOL(monitor_initialize)
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
/*
|
|
|
|
* call from within bdb_initialize()
|
|
|
|
*/
|
2006-09-14 09:05:02 +08:00
|
|
|
static int
|
2006-09-06 09:54:54 +08:00
|
|
|
bdb_monitor_initialize( void )
|
|
|
|
{
|
|
|
|
int i, code;
|
2006-11-15 09:18:37 +08:00
|
|
|
ConfigArgs c;
|
|
|
|
char *argv[ 3 ];
|
2006-09-06 09:54:54 +08:00
|
|
|
|
|
|
|
static int bdb_monitor_initialized = 0;
|
|
|
|
|
2006-09-14 09:05:02 +08:00
|
|
|
if ( backend_info( "monitor" ) == NULL ) {
|
2006-09-13 19:38:51 +08:00
|
|
|
return -1;
|
2006-09-14 09:05:02 +08:00
|
|
|
}
|
2006-09-06 09:54:54 +08:00
|
|
|
|
|
|
|
if ( bdb_monitor_initialized++ ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:05:02 +08:00
|
|
|
/* register schema here */
|
|
|
|
|
2006-11-15 09:18:37 +08:00
|
|
|
argv[ 0 ] = "back-bdb/back-hdb monitor";
|
|
|
|
c.argv = argv;
|
|
|
|
c.argc = 3;
|
|
|
|
c.fname = argv[0];
|
|
|
|
|
2006-09-07 00:06:49 +08:00
|
|
|
for ( i = 0; s_oid[ i ].name; i++ ) {
|
2006-11-15 09:18:37 +08:00
|
|
|
c.lineno = i;
|
2006-09-07 00:06:49 +08:00
|
|
|
argv[ 1 ] = s_oid[ i ].name;
|
|
|
|
argv[ 2 ] = s_oid[ i ].oid;
|
|
|
|
|
2006-11-15 09:18:37 +08:00
|
|
|
if ( parse_oidm( &c, 0, NULL ) != 0 ) {
|
2007-11-12 16:34:55 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_initialize)
|
|
|
|
": unable to add "
|
2006-09-07 00:06:49 +08:00
|
|
|
"objectIdentifier \"%s=%s\"\n",
|
|
|
|
s_oid[ i ].name, s_oid[ i ].oid, 0 );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-13 20:48:45 +08:00
|
|
|
for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
|
|
|
|
code = register_at( s_at[ i ].desc, s_at[ i ].ad, 1 );
|
2006-09-06 09:54:54 +08:00
|
|
|
if ( code != LDAP_SUCCESS ) {
|
2007-11-12 16:34:55 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_initialize)
|
|
|
|
": register_at failed\n",
|
2006-09-13 20:48:45 +08:00
|
|
|
0, 0, 0 );
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
2007-09-02 00:01:29 +08:00
|
|
|
(*s_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
|
|
|
|
2006-09-13 20:48:45 +08:00
|
|
|
for ( i = 0; s_oc[ i ].desc != NULL; i++ ) {
|
|
|
|
code = register_oc( s_oc[ i ].desc, s_oc[ i ].oc, 1 );
|
2006-09-06 09:54:54 +08:00
|
|
|
if ( code != LDAP_SUCCESS ) {
|
2007-11-12 16:34:55 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_initialize)
|
|
|
|
": register_oc failed\n",
|
2006-09-13 20:48:45 +08:00
|
|
|
0, 0, 0 );
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
2007-09-02 00:01:29 +08:00
|
|
|
(*s_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE;
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call from within bdb_db_init()
|
|
|
|
*/
|
|
|
|
int
|
2006-09-14 09:05:02 +08:00
|
|
|
bdb_monitor_db_init( BackendDB *be )
|
2006-09-06 09:54:54 +08:00
|
|
|
{
|
2006-09-15 08:16:55 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
|
2007-06-09 22:14:45 +08:00
|
|
|
if ( SLAP_GLUE_SUBORDINATE( be ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-13 19:38:51 +08:00
|
|
|
if ( bdb_monitor_initialize() == LDAP_SUCCESS ) {
|
2006-09-14 09:05:02 +08:00
|
|
|
/* monitoring in back-bdb is on by default */
|
2006-09-13 19:38:51 +08:00
|
|
|
SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
|
|
|
|
}
|
2006-09-10 00:24:35 +08:00
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
#ifdef BDB_MONITOR_IDX
|
|
|
|
bdb->bi_idx = NULL;
|
|
|
|
ldap_pvt_thread_mutex_init( &bdb->bi_idx_mutex );
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call from within bdb_db_open()
|
|
|
|
*/
|
|
|
|
int
|
2006-09-14 09:05:02 +08:00
|
|
|
bdb_monitor_db_open( BackendDB *be )
|
2006-09-06 09:54:54 +08:00
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
Attribute *a, *next;
|
2006-09-10 06:15:45 +08:00
|
|
|
monitor_callback_t *cb = NULL;
|
2006-09-06 09:54:54 +08:00
|
|
|
int rc = 0;
|
2006-09-14 09:05:02 +08:00
|
|
|
BackendInfo *mi;
|
|
|
|
monitor_extra_t *mbe;
|
2007-09-15 23:34:49 +08:00
|
|
|
struct berval dummy = BER_BVC("");
|
2006-09-06 09:54:54 +08:00
|
|
|
|
2006-09-07 07:08:57 +08:00
|
|
|
if ( !SLAP_DBMONITORING( be ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2006-09-06 20:07:03 +08:00
|
|
|
|
2007-06-09 22:14:45 +08:00
|
|
|
if ( SLAP_GLUE_SUBORDINATE( be ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-14 09:05:02 +08:00
|
|
|
mi = backend_info( "monitor" );
|
|
|
|
if ( !mi || !mi->bi_extra ) {
|
|
|
|
SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
|
|
|
|
return 0;
|
2006-09-13 19:38:51 +08:00
|
|
|
}
|
2006-09-14 09:05:02 +08:00
|
|
|
mbe = mi->bi_extra;
|
2006-09-13 19:38:51 +08:00
|
|
|
|
2006-09-06 10:14:32 +08:00
|
|
|
/* don't bother if monitor is not configured */
|
2006-09-13 19:38:51 +08:00
|
|
|
if ( !mbe->is_configured() ) {
|
2006-09-06 10:14:32 +08:00
|
|
|
static int warning = 0;
|
|
|
|
|
|
|
|
if ( warning++ == 0 ) {
|
2007-11-12 16:34:55 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(bdb_monitor_db_open)
|
|
|
|
": monitoring disabled; "
|
2006-09-06 10:14:32 +08:00
|
|
|
"configure monitor database to enable\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
/* alloc as many as required (plus 1 for objectClass) */
|
2006-09-06 17:10:46 +08:00
|
|
|
a = attrs_alloc( 1 + 4 );
|
2006-09-06 09:54:54 +08:00
|
|
|
if ( a == NULL ) {
|
|
|
|
rc = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
a->a_desc = slap_schema.si_ad_objectClass;
|
2007-09-21 16:43:56 +08:00
|
|
|
attr_valadd( a, &oc_olmBDBDatabase->soc_cname, NULL, 1 );
|
2006-09-06 09:54:54 +08:00
|
|
|
next = a->a_next;
|
|
|
|
|
|
|
|
{
|
|
|
|
struct berval bv = BER_BVC( "0" );
|
|
|
|
|
2006-09-06 11:37:13 +08:00
|
|
|
next->a_desc = ad_olmBDBEntryCache;
|
2007-09-21 16:43:56 +08:00
|
|
|
attr_valadd( next, &bv, NULL, 1 );
|
2006-09-06 11:37:13 +08:00
|
|
|
next = next->a_next;
|
|
|
|
|
2007-08-12 03:29:14 +08:00
|
|
|
next->a_desc = ad_olmBDBDNCache;
|
2007-09-21 16:43:56 +08:00
|
|
|
attr_valadd( next, &bv, NULL, 1 );
|
2006-09-06 11:37:13 +08:00
|
|
|
next = next->a_next;
|
|
|
|
|
|
|
|
next->a_desc = ad_olmBDBIDLCache;
|
2007-09-21 16:43:56 +08:00
|
|
|
attr_valadd( next, &bv, NULL, 1 );
|
2006-09-06 17:10:46 +08:00
|
|
|
next = next->a_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
struct berval bv, nbv;
|
|
|
|
ber_len_t pathlen = 0, len = 0;
|
|
|
|
char path[ PATH_MAX ] = { '\0' };
|
|
|
|
char *fname = bdb->bi_dbenv_home,
|
|
|
|
*ptr;
|
|
|
|
|
|
|
|
len = strlen( fname );
|
|
|
|
if ( fname[ 0 ] != '/' ) {
|
|
|
|
/* get full path name */
|
|
|
|
getcwd( path, sizeof( path ) );
|
|
|
|
pathlen = strlen( path );
|
|
|
|
|
|
|
|
if ( fname[ 0 ] == '.' && fname[ 1 ] == '/' ) {
|
|
|
|
fname += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bv.bv_len = pathlen + STRLENOF( "/" ) + len;
|
|
|
|
ptr = bv.bv_val = ch_malloc( bv.bv_len + STRLENOF( "/" ) + 1 );
|
|
|
|
if ( pathlen ) {
|
|
|
|
ptr = lutil_strncopy( ptr, path, pathlen );
|
|
|
|
ptr[ 0 ] = '/';
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
ptr = lutil_strncopy( ptr, fname, len );
|
|
|
|
if ( ptr[ -1 ] != '/' ) {
|
|
|
|
ptr[ 0 ] = '/';
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
ptr[ 0 ] = '\0';
|
|
|
|
|
|
|
|
attr_normalize_one( ad_olmDbDirectory, &bv, &nbv, NULL );
|
|
|
|
|
|
|
|
next->a_desc = ad_olmDbDirectory;
|
|
|
|
next->a_vals = ch_calloc( sizeof( struct berval ), 2 );
|
|
|
|
next->a_vals[ 0 ] = bv;
|
2007-09-21 16:43:56 +08:00
|
|
|
next->a_numvals = 1;
|
2006-09-06 17:10:46 +08:00
|
|
|
|
|
|
|
if ( BER_BVISNULL( &nbv ) ) {
|
|
|
|
next->a_nvals = next->a_vals;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
next->a_nvals = ch_calloc( sizeof( struct berval ), 2 );
|
|
|
|
next->a_nvals[ 0 ] = nbv;
|
|
|
|
}
|
|
|
|
|
|
|
|
next = next->a_next;
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cb = ch_calloc( sizeof( monitor_callback_t ), 1 );
|
|
|
|
cb->mc_update = bdb_monitor_update;
|
2006-09-14 09:05:02 +08:00
|
|
|
#if 0 /* uncomment if required */
|
2006-09-06 09:54:54 +08:00
|
|
|
cb->mc_modify = bdb_monitor_modify;
|
2006-09-14 09:05:02 +08:00
|
|
|
#endif
|
2006-09-06 09:54:54 +08:00
|
|
|
cb->mc_free = bdb_monitor_free;
|
|
|
|
cb->mc_private = (void *)bdb;
|
|
|
|
|
2007-03-22 07:22:49 +08:00
|
|
|
/* make sure the database is registered; then add monitor attributes */
|
2007-09-15 23:34:49 +08:00
|
|
|
rc = mbe->register_database( be, &bdb->bi_monitor.bdm_ndn );
|
2007-03-22 07:22:49 +08:00
|
|
|
if ( rc == 0 ) {
|
2007-09-15 23:34:49 +08:00
|
|
|
rc = mbe->register_entry_attrs( &bdb->bi_monitor.bdm_ndn, a, cb,
|
|
|
|
&dummy, 0, &dummy );
|
2007-03-22 07:22:49 +08:00
|
|
|
}
|
2006-09-06 09:54:54 +08:00
|
|
|
|
|
|
|
cleanup:;
|
|
|
|
if ( rc != 0 ) {
|
|
|
|
if ( cb != NULL ) {
|
|
|
|
ch_free( cb );
|
2006-09-06 20:07:03 +08:00
|
|
|
cb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( a != NULL ) {
|
|
|
|
attrs_free( a );
|
|
|
|
a = NULL;
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
2006-09-06 10:06:45 +08:00
|
|
|
}
|
|
|
|
|
2006-09-06 20:07:03 +08:00
|
|
|
/* store for cleanup */
|
2006-09-09 06:10:49 +08:00
|
|
|
bdb->bi_monitor.bdm_cb = (void *)cb;
|
2006-09-06 20:07:03 +08:00
|
|
|
|
|
|
|
/* we don't need to keep track of the attributes, because
|
|
|
|
* bdb_monitor_free() takes care of everything */
|
2006-09-06 10:06:45 +08:00
|
|
|
if ( a != NULL ) {
|
|
|
|
attrs_free( a );
|
2006-09-06 09:54:54 +08:00
|
|
|
}
|
2006-09-06 20:07:03 +08:00
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call from within bdb_db_close()
|
|
|
|
*/
|
|
|
|
int
|
2006-09-14 09:05:02 +08:00
|
|
|
bdb_monitor_db_close( BackendDB *be )
|
2006-09-06 09:54:54 +08:00
|
|
|
{
|
2006-09-06 20:07:03 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
|
2007-06-09 22:14:45 +08:00
|
|
|
if ( SLAP_GLUE_SUBORDINATE( be ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-15 23:34:49 +08:00
|
|
|
if ( !BER_BVISNULL( &bdb->bi_monitor.bdm_ndn ) ) {
|
2006-09-14 09:05:02 +08:00
|
|
|
BackendInfo *mi = backend_info( "monitor" );
|
|
|
|
monitor_extra_t *mbe;
|
|
|
|
|
|
|
|
if ( mi && &mi->bi_extra ) {
|
|
|
|
mbe = mi->bi_extra;
|
2007-09-15 23:34:49 +08:00
|
|
|
mbe->unregister_entry_callback( &bdb->bi_monitor.bdm_ndn,
|
2006-09-14 09:05:02 +08:00
|
|
|
(monitor_callback_t *)bdb->bi_monitor.bdm_cb,
|
2007-09-15 23:34:49 +08:00
|
|
|
NULL, 0, NULL );
|
2006-09-06 20:07:03 +08:00
|
|
|
}
|
|
|
|
|
2006-09-09 06:10:49 +08:00
|
|
|
memset( &bdb->bi_monitor, 0, sizeof( bdb->bi_monitor ) );
|
2006-09-06 20:07:03 +08:00
|
|
|
}
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call from within bdb_db_destroy()
|
|
|
|
*/
|
|
|
|
int
|
2006-09-14 09:05:02 +08:00
|
|
|
bdb_monitor_db_destroy( BackendDB *be )
|
2006-09-06 09:54:54 +08:00
|
|
|
{
|
2007-06-09 22:14:45 +08:00
|
|
|
if ( SLAP_GLUE_SUBORDINATE( be ) ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
#ifdef BDB_MONITOR_IDX
|
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
|
|
|
|
/* TODO: free tree */
|
|
|
|
ldap_pvt_thread_mutex_destroy( &bdb->bi_idx_mutex );
|
|
|
|
avl_free( bdb->bi_idx, ch_free );
|
|
|
|
}
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BDB_MONITOR_IDX
|
2007-08-09 02:22:19 +08:00
|
|
|
|
|
|
|
#define BDB_MONITOR_IDX_TYPES (4)
|
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
typedef struct monitor_idx_t monitor_idx_t;
|
|
|
|
|
|
|
|
struct monitor_idx_t {
|
|
|
|
AttributeDescription *idx_ad;
|
2007-08-09 02:22:19 +08:00
|
|
|
unsigned long idx_count[BDB_MONITOR_IDX_TYPES];
|
2007-08-08 06:36:04 +08:00
|
|
|
};
|
|
|
|
|
2007-08-09 02:22:19 +08:00
|
|
|
static int
|
|
|
|
bdb_monitor_bitmask2key( slap_mask_t bitmask )
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
|
|
|
|
for ( key = 0; key < 8*sizeof(slap_mask_t) && !( bitmask & 0x1U ); key++ ) {
|
|
|
|
bitmask >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct berval idxbv[] = {
|
|
|
|
BER_BVC( "present=" ),
|
|
|
|
BER_BVC( "equality=" ),
|
|
|
|
BER_BVC( "approx=" ),
|
|
|
|
BER_BVC( "substr=" ),
|
|
|
|
BER_BVNULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static ber_len_t
|
|
|
|
bdb_monitor_idx2len( monitor_idx_t *idx )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ber_len_t len = 0;
|
|
|
|
|
|
|
|
for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
|
|
|
|
if ( idx->idx_count[ i ] != 0 ) {
|
|
|
|
len += idxbv[i].bv_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2007-08-08 06:36:04 +08:00
|
|
|
static int
|
|
|
|
monitor_idx_cmp( const void *p1, const void *p2 )
|
|
|
|
{
|
|
|
|
const monitor_idx_t *idx1 = (const monitor_idx_t *)p1;
|
|
|
|
const monitor_idx_t *idx2 = (const monitor_idx_t *)p2;
|
|
|
|
|
|
|
|
return SLAP_PTRCMP( idx1->idx_ad, idx2->idx_ad );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
monitor_idx_dup( void *p1, void *p2 )
|
|
|
|
{
|
|
|
|
monitor_idx_t *idx1 = (monitor_idx_t *)p1;
|
|
|
|
monitor_idx_t *idx2 = (monitor_idx_t *)p2;
|
|
|
|
|
|
|
|
return SLAP_PTRCMP( idx1->idx_ad, idx2->idx_ad ) == 0 ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
bdb_monitor_idx_add(
|
|
|
|
struct bdb_info *bdb,
|
|
|
|
AttributeDescription *desc,
|
|
|
|
slap_mask_t type )
|
|
|
|
{
|
|
|
|
monitor_idx_t idx_dummy = { 0 },
|
|
|
|
*idx;
|
2007-08-09 02:22:19 +08:00
|
|
|
int rc = 0, key;
|
2007-08-08 06:36:04 +08:00
|
|
|
|
|
|
|
idx_dummy.idx_ad = desc;
|
2007-08-09 02:22:19 +08:00
|
|
|
key = bdb_monitor_bitmask2key( type ) - 1;
|
|
|
|
if ( key >= BDB_MONITOR_IDX_TYPES ) {
|
|
|
|
/* invalid index type */
|
|
|
|
return -1;
|
2007-08-08 06:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &bdb->bi_idx_mutex );
|
|
|
|
|
|
|
|
idx = (monitor_idx_t *)avl_find( bdb->bi_idx,
|
|
|
|
(caddr_t)&idx_dummy, monitor_idx_cmp );
|
|
|
|
if ( idx == NULL ) {
|
2007-08-09 02:22:19 +08:00
|
|
|
idx = (monitor_idx_t *)ch_calloc( sizeof( monitor_idx_t ), 1 );
|
2007-08-08 06:36:04 +08:00
|
|
|
idx->idx_ad = desc;
|
2007-08-09 02:22:19 +08:00
|
|
|
idx->idx_count[ key ] = 1;
|
2007-08-08 06:36:04 +08:00
|
|
|
|
|
|
|
switch ( avl_insert( &bdb->bi_idx, (caddr_t)idx,
|
|
|
|
monitor_idx_cmp, monitor_idx_dup ) )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ch_free( idx );
|
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2007-08-09 02:22:19 +08:00
|
|
|
idx->idx_count[ key ]++;
|
2007-08-08 06:36:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_idx_mutex );
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdb_monitor_idx_apply( void *v_idx, void *v_valp )
|
|
|
|
{
|
|
|
|
monitor_idx_t *idx = (monitor_idx_t *)v_idx;
|
|
|
|
BerVarray *valp = (BerVarray *)v_valp;
|
|
|
|
|
2007-08-09 02:22:19 +08:00
|
|
|
struct berval bv;
|
2007-08-08 06:36:04 +08:00
|
|
|
char *ptr;
|
2007-08-09 02:22:19 +08:00
|
|
|
char count_buf[ BDB_MONITOR_IDX_TYPES ][ SLAP_TEXT_BUFLEN ];
|
|
|
|
ber_len_t count_len[ BDB_MONITOR_IDX_TYPES ],
|
|
|
|
idx_len;
|
|
|
|
int i, num = 0;
|
2007-08-08 06:36:04 +08:00
|
|
|
|
2007-08-09 02:22:19 +08:00
|
|
|
idx_len = bdb_monitor_idx2len( idx );
|
2007-08-08 06:36:04 +08:00
|
|
|
|
2007-08-09 02:22:19 +08:00
|
|
|
bv.bv_len = 0;
|
|
|
|
for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
|
|
|
|
if ( idx->idx_count[ i ] == 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
count_len[ i ] = snprintf( count_buf[ i ],
|
|
|
|
sizeof( count_buf[ i ] ), "%lu", idx->idx_count[ i ] );
|
|
|
|
bv.bv_len += count_len[ i ];
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bv.bv_len += idx->idx_ad->ad_cname.bv_len
|
|
|
|
+ num
|
|
|
|
+ idx_len;
|
2007-08-08 06:36:04 +08:00
|
|
|
ptr = bv.bv_val = ch_malloc( bv.bv_len + 1 );
|
|
|
|
ptr = lutil_strcopy( ptr, idx->idx_ad->ad_cname.bv_val );
|
2007-08-09 02:22:19 +08:00
|
|
|
for ( i = 0; i < BDB_MONITOR_IDX_TYPES; i++ ) {
|
|
|
|
if ( idx->idx_count[ i ] == 0 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr[ 0 ] = '#';
|
|
|
|
++ptr;
|
|
|
|
ptr = lutil_strcopy( ptr, idxbv[ i ].bv_val );
|
|
|
|
ptr = lutil_strcopy( ptr, count_buf[ i ] );
|
|
|
|
}
|
2007-08-08 06:36:04 +08:00
|
|
|
|
|
|
|
ber_bvarray_add( valp, &bv );
|
|
|
|
|
2006-09-06 09:54:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2007-08-08 06:36:04 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
bdb_monitor_idx_entry_add(
|
|
|
|
struct bdb_info *bdb,
|
|
|
|
Entry *e )
|
|
|
|
{
|
|
|
|
BerVarray vals = NULL;
|
|
|
|
Attribute *a;
|
|
|
|
|
|
|
|
a = attr_find( e->e_attrs, ad_olmBDBNotIndexed );
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &bdb->bi_idx_mutex );
|
|
|
|
|
|
|
|
avl_apply( bdb->bi_idx, bdb_monitor_idx_apply,
|
|
|
|
&vals, -1, AVL_INORDER );
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_idx_mutex );
|
|
|
|
|
|
|
|
if ( vals != NULL ) {
|
|
|
|
if ( a != NULL ) {
|
|
|
|
assert( a->a_nvals == a->a_vals );
|
|
|
|
|
|
|
|
ber_bvarray_free( a->a_vals );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Attribute **ap;
|
|
|
|
|
|
|
|
for ( ap = &e->e_attrs; *ap != NULL; ap = &(*ap)->a_next )
|
|
|
|
;
|
|
|
|
*ap = attr_alloc( ad_olmBDBNotIndexed );
|
|
|
|
a = *ap;
|
|
|
|
}
|
|
|
|
a->a_vals = vals;
|
|
|
|
a->a_nvals = a->a_vals;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* BDB_MONITOR_IDX */
|