mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
use direct access instead of string comparison to check supported controls
This commit is contained in:
parent
25b15e0014
commit
d0b804c439
@ -21,6 +21,7 @@
|
|||||||
#include "portable.h"
|
#include "portable.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <ac/string.h>
|
||||||
|
|
||||||
#include "slap.h"
|
#include "slap.h"
|
||||||
#include "back-relay.h"
|
#include "back-relay.h"
|
||||||
@ -102,15 +103,11 @@ relay_back_db_open( Backend *be )
|
|||||||
assert( ri->ri_bd );
|
assert( ri->ri_bd );
|
||||||
|
|
||||||
/* inherit controls */
|
/* inherit controls */
|
||||||
if ( ri->ri_bd->be_controls ) {
|
AC_MEMCPY( be->be_ctrls, ri->ri_bd->be_ctrls, sizeof( be->be_ctrls ) );
|
||||||
be->be_controls = ldap_charray_dup( ri->ri_bd->be_controls );
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* inherit all? */
|
/* inherit all? */
|
||||||
if ( frontendDB->be_controls ) {
|
AC_MEMCPY( be->be_ctrls, frontendDB->be_ctrls, sizeof( be->be_ctrls ) );
|
||||||
be->be_controls = ldap_charray_dup( frontendDB->be_controls );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -65,6 +65,32 @@ BackendDB *backendDB = NULL;
|
|||||||
ldap_pvt_thread_pool_t syncrepl_pool;
|
ldap_pvt_thread_pool_t syncrepl_pool;
|
||||||
int syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
|
int syncrepl_pool_max = SLAP_MAX_SYNCREPL_THREADS;
|
||||||
|
|
||||||
|
static int
|
||||||
|
backend_init_controls( BackendInfo *bi )
|
||||||
|
{
|
||||||
|
if ( bi->bi_controls ) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for ( i = 0; bi->bi_controls[ i ]; i++ ) {
|
||||||
|
int cid;
|
||||||
|
|
||||||
|
if ( slap_find_control_id( bi->bi_controls[ i ], &cid )
|
||||||
|
== LDAP_CONTROL_NOT_FOUND )
|
||||||
|
{
|
||||||
|
if ( !( slapMode & SLAP_TOOL_MODE ) ) {
|
||||||
|
assert( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bi->bi_ctrls[ cid ] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int backend_init(void)
|
int backend_init(void)
|
||||||
{
|
{
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
@ -132,13 +158,16 @@ int backend_add(BackendInfo *aBackendInfo)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rc = aBackendInfo->bi_init(aBackendInfo)) != 0) {
|
rc = aBackendInfo->bi_init(aBackendInfo);
|
||||||
|
if ( rc != 0) {
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"backend_add: initialization for type \"%s\" failed\n",
|
"backend_add: initialization for type \"%s\" failed\n",
|
||||||
aBackendInfo->bi_type, 0, 0 );
|
aBackendInfo->bi_type, 0, 0 );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void)backend_init_controls( aBackendInfo );
|
||||||
|
|
||||||
/* now add the backend type to the Backend Info List */
|
/* now add the backend type to the Backend Info List */
|
||||||
{
|
{
|
||||||
BackendInfo *newBackendInfo = 0;
|
BackendInfo *newBackendInfo = 0;
|
||||||
@ -175,25 +204,27 @@ int backend_startup_one(Backend *be)
|
|||||||
LDAP_TAILQ_INIT( be->be_pending_csn_list );
|
LDAP_TAILQ_INIT( be->be_pending_csn_list );
|
||||||
|
|
||||||
/* back-relay takes care of itself; so may do other */
|
/* back-relay takes care of itself; so may do other */
|
||||||
if ( be->be_controls == NULL ) {
|
if ( be->be_ctrls[ SLAP_MAX_CIDS ] == 0 ) {
|
||||||
if ( overlay_is_over( be ) ) {
|
if ( overlay_is_over( be ) ) {
|
||||||
bi = ((slap_overinfo *)be->bd_info->bi_private)->oi_orig;
|
bi = ((slap_overinfo *)be->bd_info->bi_private)->oi_orig;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( bi->bi_controls ) {
|
if ( bi->bi_controls ) {
|
||||||
be->be_controls = ldap_charray_dup( bi->bi_controls );
|
AC_MEMCPY( be->be_ctrls, bi->bi_ctrls, sizeof( be->be_ctrls ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
be->be_ctrls[ SLAP_MAX_CIDS ] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug( LDAP_DEBUG_TRACE,
|
Debug( LDAP_DEBUG_TRACE,
|
||||||
"backend_startup: starting \"%s\"\n",
|
"backend_startup_one: starting \"%s\"\n",
|
||||||
be->be_suffix ? be->be_suffix[0].bv_val : "(unknown)",
|
be->be_suffix ? be->be_suffix[0].bv_val : "(unknown)",
|
||||||
0, 0 );
|
0, 0 );
|
||||||
if ( be->bd_info->bi_db_open ) {
|
if ( be->bd_info->bi_db_open ) {
|
||||||
rc = be->bd_info->bi_db_open( be );
|
rc = be->bd_info->bi_db_open( be );
|
||||||
if ( rc != 0 ) {
|
if ( rc != 0 ) {
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"backend_startup: bi_db_open failed! (%d)\n",
|
"backend_startup_one: bi_db_open failed! (%d)\n",
|
||||||
rc, 0, 0 );
|
rc, 0, 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,19 +236,16 @@ int backend_startup_one(Backend *be)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( bi->bi_controls ) {
|
if ( bi->bi_controls ) {
|
||||||
if ( be->be_controls == NULL ) {
|
if ( be->be_ctrls[ SLAP_MAX_CIDS ] == 0 ) {
|
||||||
be->be_controls = ldap_charray_dup( bi->bi_controls );
|
AC_MEMCPY( be->be_ctrls, bi->bi_ctrls, sizeof( be->be_ctrls ) );
|
||||||
|
be->be_ctrls[ SLAP_MAX_CIDS ] = 1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* maybe not efficient, but it's startup and few dozens of controls... */
|
for ( i = 0; i < SLAP_MAX_CIDS; i++ ) {
|
||||||
for ( i = 0; bi->bi_controls[ i ]; i++ ) {
|
if ( bi->bi_ctrls[ i ] ) {
|
||||||
if ( !ldap_charray_inlist( be->be_controls, bi->bi_controls[ i ] ) ) {
|
be->be_ctrls[ i ] = 1;
|
||||||
rc = ldap_charray_add( &be->be_controls, bi->bi_controls[ i ] );
|
|
||||||
if ( rc != 0 ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,8 +301,7 @@ int backend_startup(Backend *be)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( backendInfo[i].bi_open ) {
|
if( backendInfo[i].bi_open ) {
|
||||||
rc = backendInfo[i].bi_open(
|
rc = backendInfo[i].bi_open( &backendInfo[i] );
|
||||||
&backendInfo[i] );
|
|
||||||
if ( rc != 0 ) {
|
if ( rc != 0 ) {
|
||||||
Debug( LDAP_DEBUG_ANY,
|
Debug( LDAP_DEBUG_ANY,
|
||||||
"backend_startup: bi_open %d failed!\n",
|
"backend_startup: bi_open %d failed!\n",
|
||||||
@ -282,6 +309,8 @@ int backend_startup(Backend *be)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void)backend_init_controls( &backendInfo[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex );
|
ldap_pvt_thread_mutex_init( &slapd_rq.rq_mutex );
|
||||||
@ -448,9 +477,6 @@ int backend_destroy(void)
|
|||||||
free( bd->be_rootpw.bv_val );
|
free( bd->be_rootpw.bv_val );
|
||||||
}
|
}
|
||||||
acl_destroy( bd->be_acl, frontendDB->be_acl );
|
acl_destroy( bd->be_acl, frontendDB->be_acl );
|
||||||
if ( bd->be_controls ) {
|
|
||||||
ldap_charray_free( bd->be_controls );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
free( backendDB );
|
free( backendDB );
|
||||||
|
|
||||||
@ -860,8 +886,7 @@ backend_check_controls(
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if ( !slap_global_control( op, (*ctrls)->ldctl_oid ) &&
|
} else if ( !slap_global_control( op, (*ctrls)->ldctl_oid ) &&
|
||||||
!ldap_charray_inlist( op->o_bd->be_controls,
|
!op->o_bd->be_ctrls[ cid ] )
|
||||||
(*ctrls)->ldctl_oid ) )
|
|
||||||
{
|
{
|
||||||
/* Per RFC 2251 (and LDAPBIS discussions), if the control
|
/* Per RFC 2251 (and LDAPBIS discussions), if the control
|
||||||
* is recognized and appropriate for the operation (which
|
* is recognized and appropriate for the operation (which
|
||||||
|
@ -472,6 +472,11 @@ overlay_register_control( BackendDB *be, const char *oid )
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int gotit = 0;
|
int gotit = 0;
|
||||||
|
int cid;
|
||||||
|
|
||||||
|
if ( slap_find_control_id( oid, &cid ) == LDAP_CONTROL_NOT_FOUND ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_GLOBAL_OVERLAY ) {
|
if ( SLAP_DBFLAGS( be ) & SLAP_DBFLAG_GLOBAL_OVERLAY ) {
|
||||||
int i;
|
int i;
|
||||||
@ -484,23 +489,13 @@ overlay_register_control( BackendDB *be, const char *oid )
|
|||||||
gotit = 1;
|
gotit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( bd->be_controls == NULL ||
|
bd->be_ctrls[ cid ] = 1;
|
||||||
!ldap_charray_inlist( bd->be_controls, oid ) )
|
|
||||||
{
|
|
||||||
rc = ldap_charray_add( &bd->be_controls, oid );
|
|
||||||
if ( rc ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( rc == 0 && !gotit && !ldap_charray_inlist( be->be_controls, oid ) ) {
|
if ( rc == 0 && !gotit ) {
|
||||||
rc = ldap_charray_add( &be->be_controls, oid );
|
be->be_ctrls[ cid ] = 1;
|
||||||
if ( rc ) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -86,8 +86,25 @@ frontend_init( void )
|
|||||||
frontendDB->bd_info->bi_type = "frontend";
|
frontendDB->bd_info->bi_type = "frontend";
|
||||||
|
|
||||||
/* known controls */
|
/* known controls */
|
||||||
|
if ( slap_known_controls ) {
|
||||||
|
int i;
|
||||||
|
|
||||||
frontendDB->bd_info->bi_controls = slap_known_controls;
|
frontendDB->bd_info->bi_controls = slap_known_controls;
|
||||||
frontendDB->be_controls = ldap_charray_dup( slap_known_controls );
|
|
||||||
|
for ( i = 0; slap_known_controls[ i ]; i++ ) {
|
||||||
|
int cid;
|
||||||
|
|
||||||
|
if ( slap_find_control_id( slap_known_controls[ i ], &cid )
|
||||||
|
== LDAP_CONTROL_NOT_FOUND )
|
||||||
|
{
|
||||||
|
assert( 0 );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
frontendDB->bd_info->bi_ctrls[ cid ] = 1;
|
||||||
|
frontendDB->be_ctrls[ cid ] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* calls */
|
/* calls */
|
||||||
frontendDB->bd_info->bi_op_abandon = fe_op_abandon;
|
frontendDB->bd_info->bi_op_abandon = fe_op_abandon;
|
||||||
|
@ -1527,6 +1527,10 @@ typedef struct syncinfo_s {
|
|||||||
|
|
||||||
LDAP_TAILQ_HEAD( be_pcl, slap_csn_entry );
|
LDAP_TAILQ_HEAD( be_pcl, slap_csn_entry );
|
||||||
|
|
||||||
|
#ifndef SLAP_MAX_CIDS
|
||||||
|
#define SLAP_MAX_CIDS 32 /* Maximum number of supported controls */
|
||||||
|
#endif
|
||||||
|
|
||||||
struct slap_backend_db {
|
struct slap_backend_db {
|
||||||
BackendInfo *bd_info; /* pointer to shared backend info */
|
BackendInfo *bd_info; /* pointer to shared backend info */
|
||||||
|
|
||||||
@ -1568,7 +1572,12 @@ struct slap_backend_db {
|
|||||||
/* NOTE: this stores a duplicate of the control OIDs as listed
|
/* NOTE: this stores a duplicate of the control OIDs as listed
|
||||||
* in bd_info->bi_controls at database startup; later on,
|
* in bd_info->bi_controls at database startup; later on,
|
||||||
* controls may be added run-time, e.g. by overlays */
|
* controls may be added run-time, e.g. by overlays */
|
||||||
|
#if 0
|
||||||
char **be_controls;
|
char **be_controls;
|
||||||
|
#endif
|
||||||
|
/* note: set to 0 if the database does not support the control;
|
||||||
|
* be_ctrls[SLAP_MAX_CIDS] is set to 1 if initialized */
|
||||||
|
char be_ctrls[SLAP_MAX_CIDS + 1];
|
||||||
|
|
||||||
#define be_connection_init bd_info->bi_connection_init
|
#define be_connection_init bd_info->bi_connection_init
|
||||||
#define be_connection_destroy bd_info->bi_connection_destroy
|
#define be_connection_destroy bd_info->bi_connection_destroy
|
||||||
@ -2018,6 +2027,7 @@ struct slap_backend_info {
|
|||||||
#define SLAP_LASTMODCMD(be) (!SLAP_NOLASTMODCMD(be))
|
#define SLAP_LASTMODCMD(be) (!SLAP_NOLASTMODCMD(be))
|
||||||
|
|
||||||
char **bi_controls; /* supported controls */
|
char **bi_controls; /* supported controls */
|
||||||
|
char bi_ctrls[SLAP_MAX_CIDS + 1];
|
||||||
|
|
||||||
unsigned int bi_nDB; /* number of databases of this type */
|
unsigned int bi_nDB; /* number of databases of this type */
|
||||||
void *bi_private; /* anything the backend type needs */
|
void *bi_private; /* anything the backend type needs */
|
||||||
@ -2103,10 +2113,6 @@ typedef struct slap_gacl {
|
|||||||
char ga_ndn[1];
|
char ga_ndn[1];
|
||||||
} GroupAssertion;
|
} GroupAssertion;
|
||||||
|
|
||||||
#ifndef SLAP_MAX_CIDS
|
|
||||||
#define SLAP_MAX_CIDS 32 /* Maximum number of supported controls */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct slap_control_ids {
|
struct slap_control_ids {
|
||||||
int sc_assert;
|
int sc_assert;
|
||||||
int sc_preRead;
|
int sc_preRead;
|
||||||
|
Loading…
Reference in New Issue
Block a user