Back to index

openldap  2.4.31
Functions | Variables
monitor.c File Reference
#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-mdb.h"
#include "../back-monitor/back-monitor.h"
#include "config.h"

Go to the source code of this file.

Functions

static int mdb_monitor_update (Operation *op, SlapReply *rs, Entry *e, void *priv)
static int mdb_monitor_free (Entry *e, void **priv)
static int mdb_monitor_initialize (void)
int mdb_monitor_db_init (BackendDB *be)
int mdb_monitor_db_open (BackendDB *be)
int mdb_monitor_db_close (BackendDB *be)
int mdb_monitor_db_destroy (BackendDB *be)

Variables

static ObjectClassoc_olmMDBDatabase
static AttributeDescriptionad_olmDbDirectory
struct {
char * name
char * oid
s_oid []
struct {
char * desc
AttributeDescription ** ad
s_at []
struct {
char * desc
ObjectClass ** oc
s_oc []

Function Documentation

Definition at line 422 of file monitor.c.

{
       struct mdb_info             *mdb = (struct mdb_info *) be->be_private;

       if ( !BER_BVISNULL( &mdb->mi_monitor.mdm_ndn ) ) {
              BackendInfo          *mi = backend_info( "monitor" );
              monitor_extra_t             *mbe;

              if ( mi && &mi->bi_extra ) {
                     mbe = mi->bi_extra;
                     mbe->unregister_entry_callback( &mdb->mi_monitor.mdm_ndn,
                            (monitor_callback_t *)mdb->mi_monitor.mdm_cb,
                            NULL, 0, NULL );
              }

              memset( &mdb->mi_monitor, 0, sizeof( mdb->mi_monitor ) );
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 447 of file monitor.c.

{
#ifdef MDB_MONITOR_IDX
       struct mdb_info             *mdb = (struct mdb_info *) be->be_private;

       /* TODO: free tree */
       ldap_pvt_thread_mutex_destroy( &mdb->mi_idx_mutex );
       avl_free( mdb->mi_idx, ch_free );
#endif /* MDB_MONITOR_IDX */

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 260 of file monitor.c.

{
       struct mdb_info             *mdb = (struct mdb_info *) be->be_private;

       if ( mdb_monitor_initialize() == LDAP_SUCCESS ) {
              /* monitoring in back-mdb is on by default */
              SLAP_DBFLAGS( be ) |= SLAP_DBFLAG_MONITORING;
       }

#ifdef MDB_MONITOR_IDX
       mdb->mi_idx = NULL;
       ldap_pvt_thread_mutex_init( &mdb->mi_idx_mutex );
#endif /* MDB_MONITOR_IDX */

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 281 of file monitor.c.

{
       struct mdb_info             *mdb = (struct mdb_info *) be->be_private;
       Attribute            *a, *next;
       monitor_callback_t   *cb = NULL;
       int                  rc = 0;
       BackendInfo          *mi;
       monitor_extra_t             *mbe;
       struct berval dummy = BER_BVC("");

       if ( !SLAP_DBMONITORING( be ) ) {
              return 0;
       }

       mi = backend_info( "monitor" );
       if ( !mi || !mi->bi_extra ) {
              SLAP_DBFLAGS( be ) ^= SLAP_DBFLAG_MONITORING;
              return 0;
       }
       mbe = mi->bi_extra;

       /* don't bother if monitor is not configured */
       if ( !mbe->is_configured() ) {
              static int warning = 0;

              if ( warning++ == 0 ) {
                     Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(mdb_monitor_db_open)
                            ": monitoring disabled; "
                            "configure monitor database to enable\n",
                            0, 0, 0 );
              }

              return 0;
       }

       /* alloc as many as required (plus 1 for objectClass) */
       a = attrs_alloc( 1 + 1 );
       if ( a == NULL ) {
              rc = 1;
              goto cleanup;
       }

       a->a_desc = slap_schema.si_ad_objectClass;
       attr_valadd( a, &oc_olmMDBDatabase->soc_cname, NULL, 1 );
       next = a->a_next;

       {
              struct berval bv, nbv;
              ber_len_t     pathlen = 0, len = 0;
              char          path[ MAXPATHLEN ] = { '\0' };
              char          *fname = mdb->mi_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;
              next->a_numvals = 1;

              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;
       }

       cb = ch_calloc( sizeof( monitor_callback_t ), 1 );
       cb->mc_update = mdb_monitor_update;
#if 0  /* uncomment if required */
       cb->mc_modify = mdb_monitor_modify;
#endif
       cb->mc_free = mdb_monitor_free;
       cb->mc_private = (void *)mdb;

       /* make sure the database is registered; then add monitor attributes */
       rc = mbe->register_database( be, &mdb->mi_monitor.mdm_ndn );
       if ( rc == 0 ) {
              rc = mbe->register_entry_attrs( &mdb->mi_monitor.mdm_ndn, a, cb,
                     &dummy, 0, &dummy );
       }

cleanup:;
       if ( rc != 0 ) {
              if ( cb != NULL ) {
                     ch_free( cb );
                     cb = NULL;
              }

              if ( a != NULL ) {
                     attrs_free( a );
                     a = NULL;
              }
       }

       /* store for cleanup */
       mdb->mi_monitor.mdm_cb = (void *)cb;

       /* we don't need to keep track of the attributes, because
        * mdb_monitor_free() takes care of everything */
       if ( a != NULL ) {
              attrs_free( a );
       }

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int mdb_monitor_free ( Entry e,
void **  priv 
) [static]

Definition at line 143 of file monitor.c.

{
       struct berval values[ 2 ];
       Modification  mod = { 0 };

       const char    *text;
       char          textbuf[ SLAP_TEXT_BUFLEN ];

       int           i, rc;

       /* NOTE: if slap_shutdown != 0, priv might have already been freed */
       *priv = NULL;

       /* Remove objectClass */
       mod.sm_op = LDAP_MOD_DELETE;
       mod.sm_desc = slap_schema.si_ad_objectClass;
       mod.sm_values = values;
       mod.sm_numvals = 1;
       values[ 0 ] = oc_olmMDBDatabase->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 */
       mod.sm_values = NULL;
       mod.sm_numvals = 0;
       for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
              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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int mdb_monitor_initialize ( void  ) [static]

Definition at line 187 of file monitor.c.

{
       int           i, code;
       ConfigArgs c;
       char   *argv[ 3 ];

       static int    mdb_monitor_initialized = 0;

       /* set to 0 when successfully initialized; otherwise, remember failure */
       static int    mdb_monitor_initialized_failure = 1;

       if ( mdb_monitor_initialized++ ) {
              return mdb_monitor_initialized_failure;
       }

       if ( backend_info( "monitor" ) == NULL ) {
              return -1;
       }

       /* register schema here */

       argv[ 0 ] = "back-mdb monitor";
       c.argv = argv;
       c.argc = 3;
       c.fname = argv[0];

       for ( i = 0; s_oid[ i ].name; i++ ) {
              c.lineno = i;
              argv[ 1 ] = s_oid[ i ].name;
              argv[ 2 ] = s_oid[ i ].oid;

              if ( parse_oidm( &c, 0, NULL ) != 0 ) {
                     Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(mdb_monitor_initialize)
                            ": unable to add "
                            "objectIdentifier \"%s=%s\"\n",
                            s_oid[ i ].name, s_oid[ i ].oid, 0 );
                     return 2;
              }
       }

       for ( i = 0; s_at[ i ].desc != NULL; i++ ) {
              code = register_at( s_at[ i ].desc, s_at[ i ].ad, 1 );
              if ( code != LDAP_SUCCESS ) {
                     Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(mdb_monitor_initialize)
                            ": register_at failed for attributeType (%s)\n",
                            s_at[ i ].desc, 0, 0 );
                     return 3;

              } else {
                     (*s_at[ i ].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
              }
       }

       for ( i = 0; s_oc[ i ].desc != NULL; i++ ) {
              code = register_oc( s_oc[ i ].desc, s_oc[ i ].oc, 1 );
              if ( code != LDAP_SUCCESS ) {
                     Debug( LDAP_DEBUG_ANY, LDAP_XSTRING(mdb_monitor_initialize)
                            ": register_oc failed for objectClass (%s)\n",
                            s_oc[ i ].desc, 0, 0 );
                     return 4;

              } else {
                     (*s_oc[ i ].oc)->soc_flags |= SLAP_OC_HIDE;
              }
       }

       return ( mdb_monitor_initialized_failure = LDAP_SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int mdb_monitor_update ( Operation op,
SlapReply rs,
Entry e,
void priv 
) [static]

Definition at line 115 of file monitor.c.

{
       struct mdb_info             *mdb = (struct mdb_info *) priv;

#ifdef MDB_MONITOR_IDX
       mdb_monitor_idx_entry_add( mdb, e );
#endif /* MDB_MONITOR_IDX */

       return SLAP_CB_CONTINUE;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 34 of file monitor.c.

Definition at line 32 of file monitor.c.

struct { ... } s_at[] [static]
struct { ... } s_oc[] [static]
struct { ... } s_oid[] [static]