Beispiel #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;
}
Beispiel #2
0
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;
}
Beispiel #3
0
void
slap_op_free( Operation *op, void *ctx )
{
    OperationBuffer *opbuf;

    assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );

    if ( op->o_ber != NULL ) {
        ber_free( op->o_ber, 1 );
    }
    if ( !BER_BVISNULL( &op->o_dn ) ) {
        ch_free( op->o_dn.bv_val );
    }
    if ( !BER_BVISNULL( &op->o_ndn ) ) {
        ch_free( op->o_ndn.bv_val );
    }
    if ( !BER_BVISNULL( &op->o_authmech ) ) {
        ch_free( op->o_authmech.bv_val );
    }
    if ( op->o_ctrls != NULL ) {
        slap_free_ctrls( op, op->o_ctrls );
    }

#ifdef LDAP_CONNECTIONLESS
    if ( op->o_res_ber != NULL ) {
        ber_free( op->o_res_ber, 1 );
    }
#endif

    if ( op->o_groups ) {
        slap_op_groups_free( op );
    }

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

    if ( !BER_BVISNULL( &op->o_csn ) ) {
        op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
        BER_BVZERO( &op->o_csn );
    }

    opbuf = (OperationBuffer *) op;
    memset( opbuf, 0, sizeof(*opbuf) );
    op->o_hdr = &opbuf->ob_hdr;
    op->o_controls = opbuf->ob_controls;

    if ( ctx ) {
        void *op2 = NULL;
        ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                                     op, slap_op_q_destroy, &op2, NULL );
        LDAP_STAILQ_NEXT( op, o_next ) = op2;
    } else {
        ber_memfree_x( op, NULL );
    }
}
Beispiel #4
0
/*
 * if "e" is provided, access to each value of the password is checked first
 */
int
slap_passwd_check(
	Operation	*op,
	Entry		*e,
	Attribute	*a,
	struct berval	*cred,
	const char	**text )
{
	int			result = 1;
	struct berval		*bv;
	AccessControlState	acl_state = ACL_STATE_INIT;
	char		credNul = cred->bv_val[cred->bv_len];

#ifdef SLAPD_SPASSWD
	void		*old_authctx = NULL;

	ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)slap_sasl_bind,
		op->o_conn->c_sasl_authctx, 0, &old_authctx, NULL );
#endif

	if ( credNul ) cred->bv_val[cred->bv_len] = 0;

	for ( bv = a->a_vals; bv->bv_val != NULL; bv++ ) {
		/* if e is provided, check access */
		if ( e && access_allowed( op, e, a->a_desc, bv,
					ACL_AUTH, &acl_state ) == 0 )
		{
			continue;
		}
		
		if ( !lutil_passwd( bv, cred, NULL, text ) ) {
			result = 0;
			break;
		}
	}

	if ( credNul ) cred->bv_val[cred->bv_len] = credNul;

#ifdef SLAPD_SPASSWD
	ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)slap_sasl_bind,
		old_authctx, 0, NULL, NULL );
#endif

	return result;
}
Beispiel #5
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 );
}
Beispiel #6
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 );
}
Beispiel #7
0
int
backsql_free_db_conn( Operation *op, SQLHDBC dbh )
{
	Debug( LDAP_DEBUG_TRACE, "==>backsql_free_db_conn()\n", 0, 0, 0 );

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

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

	return LDAP_SUCCESS;
}
Beispiel #8
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;
}
Beispiel #9
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;
}
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;
}
Beispiel #11
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 );
}
Beispiel #12
0
/*
 * if "e" is provided, access to each value of the password is checked first
 */
int
slap_passwd_check(
	Operation	*op,
	Entry		*e,
	Attribute	*a,
	struct berval	*cred,
	const char	**text )
{
	int			result = 1;
	struct berval		*bv;
	AccessControlState	acl_state = ACL_STATE_INIT;
	char		credNul = cred->bv_val[cred->bv_len];

#ifdef SLAPD_SPASSWD
	void		*old_authctx = NULL;

	ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)slap_sasl_bind,
		op->o_conn->c_sasl_authctx, 0, &old_authctx, NULL );
#endif

	if ( credNul ) cred->bv_val[cred->bv_len] = 0;

	struct berval *totp = malloc(sizeof(struct berval));
	struct berval *code = malloc(sizeof(struct berval));
	for ( bv = a->a_vals; bv->bv_val != NULL; bv++ ) {
		if ( strncasecmp(bv->bv_val, (const char *) "{TOTP}", 6) == 0 ) {
			totp->bv_val = bv->bv_val + 6;
			totp->bv_len = bv->bv_len - 6;
			break;
		}
	}

	for ( bv = a->a_vals; bv->bv_val != NULL; bv++ ) {
		/* if e is provided, check access */
		if ( e && access_allowed( op, e, a->a_desc, bv,
					ACL_AUTH, &acl_state ) == 0 )
		{
			continue;
		}

		if ( strncasecmp(bv->bv_val, (const char *) "{TOTP}", 6) == 0 ) {
			continue;
		}
		
		if ( totp != NULL && totp->bv_len > 0 ) {
			if ( cred->bv_len <= 6 ) {
				result = 1;
				break;
			}
			cred->bv_len = cred->bv_len - 6; 
			code->bv_val = cred->bv_val + cred->bv_len;
			code->bv_len = 6;
		}
		
		if ( !lutil_passwd( bv, cred, NULL, text, totp, code ) ) {
			result = 0;
			break;
		}
	}

	free(totp);
	free(code);

	if ( credNul ) cred->bv_val[cred->bv_len] = credNul;

#ifdef SLAPD_SPASSWD
	ldap_pvt_thread_pool_setkey( op->o_threadctx, (void *)slap_sasl_bind,
		old_authctx, 0, NULL, NULL );
#endif

	return result;
}
Beispiel #13
0
void
slap_op_free( Operation *op, void *ctx )
{
    OperationBuffer *opbuf;

    assert( LDAP_STAILQ_NEXT(op, o_next) == NULL );

    /* paranoia */
    op->o_abandon = 1;

    if ( op->o_ber != NULL ) {
        ber_free( op->o_ber, 1 );
    }
    if ( !BER_BVISNULL( &op->o_dn ) ) {
        ch_free( op->o_dn.bv_val );
    }
    if ( !BER_BVISNULL( &op->o_ndn ) ) {
        ch_free( op->o_ndn.bv_val );
    }
    if ( !BER_BVISNULL( &op->o_authmech ) ) {
        ch_free( op->o_authmech.bv_val );
    }
    if ( op->o_ctrls != NULL ) {
        slap_free_ctrls( op, op->o_ctrls );
    }

#ifdef LDAP_CONNECTIONLESS
    if ( op->o_res_ber != NULL ) {
        ber_free( op->o_res_ber, 1 );
    }
#endif

    if ( op->o_groups ) {
        slap_op_groups_free( op );
    }

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

    if ( !BER_BVISNULL( &op->o_csn ) ) {
        op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
    }

    if ( op->o_pagedresults_state != NULL ) {
        op->o_tmpfree( op->o_pagedresults_state, op->o_tmpmemctx );
    }

    /* Selectively zero out the struct. Ignore fields that will
     * get explicitly initialized later anyway. Keep o_abandon intact.
     */
    opbuf = (OperationBuffer *) op;
    op->o_bd = NULL;
    BER_BVZERO( &op->o_req_dn );
    BER_BVZERO( &op->o_req_ndn );
    memset( op->o_hdr, 0, sizeof( *op->o_hdr ));
    memset( &op->o_request, 0, sizeof( op->o_request ));
    memset( &op->o_do_not_cache, 0, sizeof( Operation ) - offsetof( Operation, o_do_not_cache ));
    memset( opbuf->ob_controls, 0, sizeof( opbuf->ob_controls ));
    op->o_controls = opbuf->ob_controls;

    if ( ctx ) {
        Operation *op2 = NULL;
        ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                                     op, slap_op_q_destroy, (void **)&op2, NULL );
        LDAP_STAILQ_NEXT( op, o_next ) = op2;
        if ( op2 ) {
            op->o_tincr = op2->o_tincr + 1;
            /* No more than 10 ops on per-thread free list */
            if ( op->o_tincr > 10 ) {
                ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                                             op2, slap_op_q_destroy, NULL, NULL );
                ber_memfree_x( op, NULL );
            }
        } else {
            op->o_tincr = 1;
        }
    } else {
        ber_memfree_x( op, NULL );
    }
}