예제 #1
0
static void *search_stack( Operation *op )
{
	struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
	void *ret = NULL;

	if ( op->o_threadctx ) {
		ldap_pvt_thread_pool_getkey( op->o_threadctx, (void *)search_stack,
			&ret, NULL );
	} else {
		ret = mdb->mi_search_stack;
	}

	if ( !ret ) {
		size_t case_stack = mdb->mi_search_stack_depth * MDB_IDL_UM_SIZE * sizeof( ID );
		size_t case_sctmp = MDB_IDL_UM_SIZE * sizeof( ID2 );
		size_t size = (case_stack > case_sctmp) ? case_stack : case_sctmp;
		ret = ch_malloc( size );
		if ( op->o_threadctx ) {
			ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)search_stack,
				ret, search_stack_free, NULL, NULL );
		} else {
			mdb->mi_search_stack = ret;
		}
	}
	return ret;
}
예제 #2
0
파일: ctx.c 프로젝트: cptaffe/openldap
wt_ctx *
wt_ctx_get(Operation *op, struct wt_info *wi){
	int rc;
	void *data;
	wt_ctx *wc = NULL;

	rc = ldap_pvt_thread_pool_getkey(op->o_threadctx,
									 wt_ctx_get, &data, NULL );
	if( rc ){
		wc = wt_ctx_init(wi);
		if( !wc ) {
			Debug( LDAP_DEBUG_ANY,
				   LDAP_XSTRING(wt_ctx)
				   ": wt_ctx_init failed\n",
				   0, 0, 0 );
			return NULL;
		}
		rc = ldap_pvt_thread_pool_setkey( op->o_threadctx,
										  wt_ctx_get, wc, wt_ctx_free,
										  NULL, NULL );
		if( rc ) {
			Debug( LDAP_DEBUG_ANY, "wt_ctx: setkey error(%d)\n",
				   rc, 0, 0 );
			return NULL;
		}
		return wc;
	}
	return (wt_ctx *)data;
}
예제 #3
0
static void scope_chunk_ret( Operation *op, ID2 *scopes )
{
	void *ret = NULL;

	ldap_pvt_thread_pool_getkey( op->o_threadctx, (void *)scope_chunk_get,
			&ret, NULL );
	scopes[0].mval.mv_data = ret;
	ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)scope_chunk_get,
			(void *)scopes, scope_chunk_free, NULL, NULL );
}
예제 #4
0
static void scope_chunk_ret( Operation *op, ID2 *scopes )
{
	struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
	void *ret = NULL;

	ldap_pvt_thread_pool_getkey( op->o_threadctx, (void *)scope_chunk_get,
			&ret, NULL );
	scopes[0].mval.mv_data = ret;
	ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)scope_chunk_get,
			(void *)scopes, scope_chunk_free, NULL, NULL );
}
예제 #5
0
int
bdb_locker_id( Operation *op, DB_ENV *env, int *locker )
{
	int i, rc, lockid;
	void *data;
	void *ctx;

	if ( !env || !locker ) return -1;

	/* If no op was provided, try to find the ctx anyway... */
	if ( op ) {
		ctx = op->o_threadctx;
	} else {
		ctx = ldap_pvt_thread_pool_context( &connection_pool );
	}

	/* Shouldn't happen unless we're single-threaded */
	if ( !ctx ) {
		*locker = 0;
		return 0;
	}

	if ( ldap_pvt_thread_pool_getkey( ctx, env, &data, NULL ) ) {
		for ( i=0, rc=1; rc != 0 && i<4; i++ ) {
			rc = XLOCK_ID( env, &lockid );
			if (rc) ldap_pvt_thread_yield();
		}
		if ( rc != 0) {
			return rc;
		}
		data = (void *)lockid;
		if ( ( rc = ldap_pvt_thread_pool_setkey( ctx, env,
			data, bdb_locker_id_free ) ) ) {
			XLOCK_ID_FREE( env, lockid );
#ifdef NEW_LOGGING
			LDAP_LOG( BACK_BDB, ERR, "bdb_locker_id: err %s(%d)\n",
				db_strerror(rc), rc, 0 );
#else
			Debug( LDAP_DEBUG_ANY, "bdb_locker_id: err %s(%d)\n",
				db_strerror(rc), rc, 0 );
#endif

			return rc;
		}
	} else {
		lockid = (int)data;
	}
	*locker = lockid;
	return 0;
}
예제 #6
0
static ID2 *scope_chunk_get( Operation *op )
{
	ID2 *ret = NULL;

	ldap_pvt_thread_pool_getkey( op->o_threadctx, (void *)scope_chunk_get,
			(void *)&ret, NULL );
	if ( !ret ) {
		ret = ch_malloc( MDB_IDL_UM_SIZE * sizeof( ID2 ));
	} else {
		void *r2 = ret[0].mval.mv_data;
		ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)scope_chunk_get,
			r2, scope_chunk_free, NULL, NULL );
	}
	return ret;
}
예제 #7
0
int
backsql_get_db_conn( Operation *op, SQLHDBC *dbhp )
{
	backsql_info	*bi = (backsql_info *)op->o_bd->be_private;
	int		rc = LDAP_SUCCESS;
	SQLHDBC		dbh = SQL_NULL_HDBC;

	Debug( LDAP_DEBUG_TRACE, "==>backsql_get_db_conn()\n", 0, 0, 0 );

	assert( dbhp != NULL );
	*dbhp = SQL_NULL_HDBC;

	if ( op->o_threadctx ) {
		void		*data = NULL;

		ldap_pvt_thread_pool_getkey( op->o_threadctx,
				&backsql_db_conn_dummy, &data, NULL );
		dbh = (SQLHDBC)data;

	} else {
		dbh = bi->sql_dbh;
	}

	if ( dbh == SQL_NULL_HDBC ) {
		rc = backsql_open_db_handle( bi, &dbh );
		if ( rc != LDAP_SUCCESS ) {
			return rc;
		}

		if ( op->o_threadctx ) {
			void		*data = NULL;

			data = (void *)dbh;
			ldap_pvt_thread_pool_setkey( op->o_threadctx,
					&backsql_db_conn_dummy, data,
					backsql_db_conn_keyfree, NULL, NULL );

		} else {
			bi->sql_dbh = dbh;
		}
	}

	*dbhp = dbh;

	Debug( LDAP_DEBUG_TRACE, "<==backsql_get_db_conn()\n", 0, 0, 0 );

	return LDAP_SUCCESS;
}
예제 #8
0
파일: sasl.c 프로젝트: MPlatform/mdb
static int chk_sasl(
	const struct berval *sc,
	const struct berval * passwd,
	const struct berval * cred,
	const char **text )
{
	unsigned int i;
	int rtn;
	void *ctx, *sconn = NULL;

	for( i=0; i<cred->bv_len; i++) {
		if(cred->bv_val[i] == '\0') {
			return LUTIL_PASSWD_ERR;	/* NUL character in password */
		}
	}

	if( cred->bv_val[i] != '\0' ) {
		return LUTIL_PASSWD_ERR;	/* cred must behave like a string */
	}

	for( i=0; i<passwd->bv_len; i++) {
		if(passwd->bv_val[i] == '\0') {
			return LUTIL_PASSWD_ERR;	/* NUL character in password */
		}
	}

	if( passwd->bv_val[i] != '\0' ) {
		return LUTIL_PASSWD_ERR;	/* passwd must behave like a string */
	}

	rtn = LUTIL_PASSWD_ERR;

	ctx = ldap_pvt_thread_pool_context();
	ldap_pvt_thread_pool_getkey( ctx, (void *)slap_sasl_bind, &sconn, NULL );

	if( sconn != NULL ) {
		int sc;
		sc = sasl_checkpass( sconn,
			passwd->bv_val, passwd->bv_len,
			cred->bv_val, cred->bv_len );
		rtn = ( sc != SASL_OK ) ? LUTIL_PASSWD_ERR : LUTIL_PASSWD_OK;
	}

	return rtn;
}
예제 #9
0
Operation *
slap_op_alloc(
    BerElement		*ber,
    ber_int_t	msgid,
    ber_tag_t	tag,
    ber_int_t	id,
    void *ctx )
{
    Operation	*op = NULL;

    if ( ctx ) {
        void *otmp = NULL;
        ldap_pvt_thread_pool_getkey( ctx, (void *)slap_op_free, &otmp, NULL );
        if ( otmp ) {
            op = otmp;
            otmp = LDAP_STAILQ_NEXT( op, o_next );
            ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                                         otmp, slap_op_q_destroy, NULL, NULL );
            op->o_abandon = 0;
            op->o_cancel = 0;
        }
    }
    if (!op) {
        op = (Operation *) ch_calloc( 1, sizeof(OperationBuffer) );
        op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
        op->o_controls = ((OperationBuffer *) op)->ob_controls;
    }

    op->o_ber = ber;
    op->o_msgid = msgid;
    op->o_tag = tag;

    slap_op_time( &op->o_time, &op->o_tincr );
    op->o_opid = id;

#if defined( LDAP_SLAPI )
    if ( slapi_plugins_used ) {
        slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
    }
#endif /* defined( LDAP_SLAPI ) */

    return( op );
}