Back to index

openldap  2.4.31
Functions
candidates.c File Reference
#include "portable.h"
#include <stdio.h>
#include "ac/string.h"
#include "slap.h"
#include "../back-ldap/back-ldap.h"
#include "back-meta.h"

Go to the source code of this file.

Functions

static metasubtree_tmeta_subtree_match (metatarget_t *mt, struct berval *ndn, int scope)
int meta_back_is_candidate (metatarget_t *mt, struct berval *ndn, int scope)
int meta_back_select_unique_candidate (metainfo_t *mi, struct berval *ndn)
int meta_clear_unused_candidates (Operation *op, int candidate)
int meta_clear_one_candidate (Operation *op, metaconn_t *mc, int candidate)

Function Documentation

int meta_back_is_candidate ( metatarget_t mt,
struct berval ndn,
int  scope 
)

Definition at line 94 of file candidates.c.

{
       struct berval rdn;
       int d = ndn->bv_len - mt->mt_nsuffix.bv_len;

       if ( d >= 0 ) {
              if ( !dnIsSuffix( ndn, &mt->mt_nsuffix ) ) {
                     return META_NOT_CANDIDATE;
              }

              /*
               * |  match  | exclude |
               * +---------+---------+-------------------+
               * |    T    |    T    | not candidate     |
               * |    F    |    T    | continue checking |
               * +---------+---------+-------------------+
               * |    T    |    F    | candidate         |
               * |    F    |    F    | not candidate     |
               * +---------+---------+-------------------+
               */
                     
              if ( mt->mt_subtree ) {
                     int match = ( meta_subtree_match( mt, ndn, scope ) != NULL );

                     if ( !mt->mt_subtree_exclude ) {
                            return match ? META_CANDIDATE : META_NOT_CANDIDATE;
                     }

                     if ( match /* && mt->mt_subtree_exclude */ ) {
                            return META_NOT_CANDIDATE;
                     }
              }

              switch ( mt->mt_scope ) {
              case LDAP_SCOPE_SUBTREE:
              default:
                     return META_CANDIDATE;

              case LDAP_SCOPE_SUBORDINATE:
                     if ( d > 0 ) {
                            return META_CANDIDATE;
                     }
                     break;

              /* nearly useless; not allowed by config */
              case LDAP_SCOPE_ONELEVEL:
                     if ( d > 0 ) {
                            rdn.bv_val = ndn->bv_val;
                            rdn.bv_len = (ber_len_t)d - STRLENOF( "," );
                            if ( dnIsOneLevelRDN( &rdn ) ) {
                                   return META_CANDIDATE;
                            }
                     }
                     break;

              /* nearly useless; not allowed by config */
              case LDAP_SCOPE_BASE:
                     if ( d == 0 ) {
                            return META_CANDIDATE;
                     }
                     break;
              }

       } else /* if ( d < 0 ) */ {
              if ( !dnIsSuffix( &mt->mt_nsuffix, ndn ) ) {
                     return META_NOT_CANDIDATE;
              }

              switch ( scope ) {
              case LDAP_SCOPE_SUBTREE:
              case LDAP_SCOPE_SUBORDINATE:
                     /*
                      * suffix longer than dn, but common part matches
                      */
                     return META_CANDIDATE;

              case LDAP_SCOPE_ONELEVEL:
                     rdn.bv_val = mt->mt_nsuffix.bv_val;
                     rdn.bv_len = (ber_len_t)(-d) - STRLENOF( "," );
                     if ( dnIsOneLevelRDN( &rdn ) ) {
                            return META_CANDIDATE;
                     }
                     break;
              }
       }

       return META_NOT_CANDIDATE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 195 of file candidates.c.

{
       int    i, candidate = META_TARGET_NONE;

       for ( i = 0; i < mi->mi_ntargets; i++ ) {
              metatarget_t  *mt = mi->mi_targets[ i ];

              if ( meta_back_is_candidate( mt, ndn, LDAP_SCOPE_BASE ) ) {
                     if ( candidate == META_TARGET_NONE ) {
                            candidate = i;

                     } else {
                            return META_TARGET_MULTIPLE;
                     }
              }
       }

       return candidate;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int meta_clear_one_candidate ( Operation op,
metaconn_t mc,
int  candidate 
)

Definition at line 247 of file candidates.c.

{
       metasingleconn_t     *msc = &mc->mc_conns[ candidate ];

       if ( msc->msc_ld != NULL ) {

#ifdef DEBUG_205
              char   buf[ BUFSIZ ];

              snprintf( buf, sizeof( buf ), "meta_clear_one_candidate ldap_unbind_ext[%d] mc=%p ld=%p",
                     candidate, (void *)mc, (void *)msc->msc_ld );
              Debug( LDAP_DEBUG_ANY, "### %s %s\n",
                     op ? op->o_log_prefix : "", buf, 0 );
#endif /* DEBUG_205 */

              ldap_unbind_ext( msc->msc_ld, NULL, NULL );
              msc->msc_ld = NULL;
       }

       if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
              ber_memfree_x( msc->msc_bound_ndn.bv_val, NULL );
              BER_BVZERO( &msc->msc_bound_ndn );
       }

       if ( !BER_BVISNULL( &msc->msc_cred ) ) {
              memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
              ber_memfree_x( msc->msc_cred.bv_val, NULL );
              BER_BVZERO( &msc->msc_cred );
       }

       msc->msc_mscflags = 0;

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int meta_clear_unused_candidates ( Operation op,
int  candidate 
)

Definition at line 223 of file candidates.c.

{
       metainfo_t    *mi = ( metainfo_t * )op->o_bd->be_private;
       int           i;
       SlapReply     *candidates = meta_back_candidates_get( op );
       
       for ( i = 0; i < mi->mi_ntargets; ++i ) {
              if ( i == candidate ) {
                     continue;
              }
              META_CANDIDATE_RESET( &candidates[ i ] );
       }

       return 0;
}

Here is the call graph for this function:

static metasubtree_t* meta_subtree_match ( metatarget_t mt,
struct berval ndn,
int  scope 
) [static]

Definition at line 56 of file candidates.c.

{
       metasubtree_t *ms = mt->mt_subtree;

       for ( ms = mt->mt_subtree; ms; ms = ms->ms_next ) {
              switch ( ms->ms_type ) {
              case META_ST_SUBTREE:
                     if ( dnIsSuffix( ndn, &ms->ms_dn ) ) {
                            return ms;
                     }
                     break;

              case META_ST_SUBORDINATE:
                     if ( dnIsSuffix( ndn, &ms->ms_dn ) &&
                            ( ndn->bv_len > ms->ms_dn.bv_len || scope != LDAP_SCOPE_BASE ) )
                     {
                            return ms;
                     }
                     break;

              case META_ST_REGEX:
                     /* NOTE: cannot handle scope */
                     if ( regexec( &ms->ms_regex, ndn->bv_val, 0, NULL, 0 ) == 0 ) {
                            return ms;
                     }
                     break;
              }
       }

       return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function: