]> git.sur5r.net Git - openldap/commitdiff
reject registrations when back-monitor is not configured
authorPierangelo Masarati <ando@openldap.org>
Thu, 8 Sep 2005 14:23:35 +0000 (14:23 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 8 Sep 2005 14:23:35 +0000 (14:23 +0000)
servers/slapd/back-monitor/init.c
servers/slapd/back-monitor/proto-back-monitor.h

index 293d543535a1f9672b6fe87f6e98ae438a25fec1..c56bb7b415a714aee2cd008ee3b105b71887f96f 100644 (file)
@@ -261,12 +261,28 @@ typedef struct entry_limbo_t {
        struct entry_limbo_t    *el_next;
 } entry_limbo_t;
 
+int
+monitor_back_is_configured( void )
+{
+       return be_monitor != NULL;
+}
+
 int
 monitor_back_register_entry(
        Entry                   *e,
        monitor_callback_t      *cb )
 {
-       monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
+       monitor_info_t  *mi;
+
+       if ( be_monitor == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_entry(\"%s\"): "
+                       "monitor backend not configured.\n",
+                       e->e_name.bv_val, 0, 0 );
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
 
        assert( mi != NULL );
        assert( e != NULL );
@@ -413,9 +429,21 @@ monitor_back_register_entry_parent(
        int                     scope,
        struct berval           *filter )
 {
-       monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
+       monitor_info_t  *mi;
        struct berval   ndn = BER_BVNULL;
 
+       if ( be_monitor == NULL ) {
+               Debug( LDAP_DEBUG_ANY,
+                       "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): "
+                       "monitor backend not configured.\n",
+                       BER_BVISNULL( base ) ? "" : base->bv_val,
+                       scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ),
+                       BER_BVISNULL( filter ) ? "" : filter->bv_val );
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
+
        assert( mi != NULL );
        assert( e != NULL );
        assert( e->e_private == NULL );
@@ -712,8 +740,26 @@ monitor_back_register_entry_attrs(
        int                     scope,
        struct berval           *filter )
 {
-       monitor_info_t  *mi = ( monitor_info_t * )be_monitor->be_private;
+       monitor_info_t  *mi;
        struct berval   ndn = BER_BVNULL;
+       char            *fname = ( a == NULL ? "callback" : "attrs" );
+
+       if ( be_monitor == NULL ) {
+               char            buf[ SLAP_TEXT_BUFLEN ];
+
+               snprintf( buf, sizeof( buf ),
+                       "monitor_back_register_entry_%s(base=\"%s\" scope=%s filter=\"%s\"): "
+                       "monitor backend not configured.\n",
+                       fname,
+                       BER_BVISNULL( base ) ? "" : base->bv_val,
+                       scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ),
+                       BER_BVISNULL( filter ) ? "" : filter->bv_val );
+               Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
+
+               return -1;
+       }
+
+       mi = ( monitor_info_t * )be_monitor->be_private;
 
        assert( mi != NULL );
 
@@ -731,9 +777,9 @@ monitor_back_register_entry_attrs(
        {
                /* need a filter */
                Debug( LDAP_DEBUG_ANY,
-                       "monitor_back_register_entry_*(\"\"): "
+                       "monitor_back_register_entry_%s(\"\"): "
                        "need a valid filter\n",
-                       0, 0, 0 );
+                       fname, 0, 0 );
                return -1;
        }
 
@@ -747,13 +793,18 @@ monitor_back_register_entry_attrs(
 
                if ( BER_BVISNULL( &ndn ) ) {
                        if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) {
-                               /* entry does not exist */
-                               Debug( LDAP_DEBUG_ANY,
-                                       "monitor_back_register_entry_*(\"\"): "
+                               char            buf[ SLAP_TEXT_BUFLEN ];
+
+                               snprintf( buf, sizeof( buf ),
+                                       "monitor_back_register_entry_%s(\"\"): "
                                        "base=%s scope=%d filter=%s : "
                                        "unable to find entry\n",
+                                       fname,
                                        base->bv_val ? base->bv_val : "\"\"",
                                        scope, filter->bv_val );
+
+                               /* entry does not exist */
+                               Debug( LDAP_DEBUG_ANY, "%s\n", buf, 0, 0 );
                                return -1;
                        }
 
@@ -763,9 +814,9 @@ monitor_back_register_entry_attrs(
                if ( monitor_cache_get( mi, &ndn, &e ) != 0 ) {
                        /* entry does not exist */
                        Debug( LDAP_DEBUG_ANY,
-                               "monitor_back_register_entry_*(\"%s\"): "
+                               "monitor_back_register_entry_%s(\"%s\"): "
                                "entry does not exist\n",
-                               ndn.bv_val, 0, 0 );
+                               fname, ndn.bv_val, 0 );
                        rc = -1;
                        goto done;
                }
@@ -776,9 +827,9 @@ monitor_back_register_entry_attrs(
                if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
                        /* entry is volatile; cannot append callback */
                        Debug( LDAP_DEBUG_ANY,
-                               "monitor_back_register_entry_*(\"%s\"): "
+                               "monitor_back_register_entry_%s(\"%s\"): "
                                "entry is volatile\n",
-                               e->e_name.bv_val, 0, 0 );
+                               fname, e->e_name.bv_val, 0 );
                        rc = -1;
                        goto done;
                }
@@ -790,9 +841,9 @@ monitor_back_register_entry_attrs(
                        *atp = attrs_dup( a );
                        if ( *atp == NULL ) {
                                Debug( LDAP_DEBUG_ANY,
-                                       "monitor_back_register_entry_*(\"%s\"): "
+                                       "monitor_back_register_entry_%s(\"%s\"): "
                                        "attrs_dup() failed\n",
-                                       e->e_name.bv_val, 0, 0 );
+                                       fname, e->e_name.bv_val, 0 );
                                rc = -1;
                                goto done;
                        }
index 70007135bde55b51884259f3ba63081af0ffd7b5..a3bb542b70209e15bbc91753f5c6bc4060d046bf 100644 (file)
@@ -130,6 +130,8 @@ monitor_back_get_subsys_by_dn LDAP_P((
        struct berval           *ndn,
        int                     sub ));
 extern int
+monitor_back_is_configured LDAP_P(( void ));
+extern int
 monitor_back_register_entry LDAP_P((
        Entry                   *e,
        monitor_callback_t      *cb ));