⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slapi_ops.c

📁 ldap服务器源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $OpenLDAP: pkg/ldap/servers/slapd/slapi/slapi_ops.c,v 1.70.2.10 2007/01/02 21:44:10 kurt Exp $ *//* This work is part of OpenLDAP Software <http://www.openldap.org/>. * * Copyright 2002-2007 The OpenLDAP Foundation. * Portions Copyright 1997,2002-2003 IBM Corporation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted only as authorized by the OpenLDAP * Public License. * * A copy of this license is available in the file LICENSE in the * top-level directory of the distribution or, alternatively, at * <http://www.OpenLDAP.org/license.html>. *//* ACKNOWLEDGEMENTS: * This work was initially developed by IBM Corporation for use in * IBM products and subsequently ported to OpenLDAP Software by * Steve Omrani.  Additional significant contributors include: *   Luke Howard */#include "portable.h"#include <ac/string.h>#include <ac/stdarg.h>#include <ac/ctype.h>#include <ac/unistd.h>#include <slap.h>#include <lber_pvt.h>#include <slapi.h>#ifdef LDAP_SLAPIstatic struct slap_listener slapi_listener = {	BER_BVC("slapi://"),	BER_BVC("slapi://")};static LDAPControl **slapi_int_dup_controls( LDAPControl **controls ){	LDAPControl **c;	size_t i;	if ( controls == NULL )		return NULL;	for ( i = 0; controls[i] != NULL; i++ )		;	c = (LDAPControl **) slapi_ch_calloc( i + 1, sizeof(LDAPControl *) );	for ( i = 0; controls[i] != NULL; i++ ) {		c[i] = slapi_dup_control( controls[i] );	}	return c;}static intslapi_int_result(	Operation	*op, 	SlapReply	*rs ){	Slapi_PBlock		*pb = SLAPI_OPERATION_PBLOCK( op );	plugin_result_callback	prc = NULL;	void			*callback_data = NULL;	LDAPControl		**ctrls = NULL;	assert( pb != NULL );		slapi_pblock_get( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void **)&prc );	slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA,   &callback_data );	/* we need to duplicate controls because they might go out of scope */	ctrls = slapi_int_dup_controls( rs->sr_ctrls );	slapi_pblock_set( pb, SLAPI_RESCONTROLS, ctrls );	if ( prc != NULL ) {		(*prc)( rs->sr_err, callback_data );	}	return rs->sr_err;}static intslapi_int_search_entry(	Operation	*op,	SlapReply	*rs ){	Slapi_PBlock			*pb = SLAPI_OPERATION_PBLOCK( op );	plugin_search_entry_callback	psec = NULL;	void				*callback_data = NULL;	int				rc = LDAP_SUCCESS;	assert( pb != NULL );	slapi_pblock_get( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, (void **)&psec );	slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA,         &callback_data );	if ( psec != NULL ) {		rc = (*psec)( rs->sr_entry, callback_data );	}	return rc;}static intslapi_int_search_reference(	Operation	*op,		SlapReply	*rs ){	int				i, rc = LDAP_SUCCESS;	plugin_referral_entry_callback	prec = NULL;	void				*callback_data = NULL;	Slapi_PBlock			*pb = SLAPI_OPERATION_PBLOCK( op );	assert( pb != NULL );	slapi_pblock_get( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void **)&prec );	slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA,           &callback_data );	if ( prec != NULL ) {		for ( i = 0; rs->sr_ref[i].bv_val != NULL; i++ ) {			rc = (*prec)( rs->sr_ref[i].bv_val, callback_data );			if ( rc != LDAP_SUCCESS ) {				break;			}		}	}	return rc;}intslapi_int_response( Slapi_Operation *op, SlapReply *rs ){	int				rc;	switch ( rs->sr_type ) {	case REP_RESULT:		rc = slapi_int_result( op, rs );		break;	case REP_SEARCH:		rc = slapi_int_search_entry( op, rs );		break;	case REP_SEARCHREF:		rc = slapi_int_search_reference( op, rs );		break;	default:		rc = LDAP_OTHER;		break;	}	assert( rc != SLAP_CB_CONTINUE ); /* never try to send a wire response */	return rc;}static intslapi_int_get_ctrls( Slapi_PBlock *pb ){	LDAPControl		**c;	int			rc = LDAP_SUCCESS;	if ( pb->pb_op->o_ctrls != NULL ) {		for ( c = pb->pb_op->o_ctrls; *c != NULL; c++ ) {			rc = slap_parse_ctrl( pb->pb_op, pb->pb_rs, *c, &pb->pb_rs->sr_text );			if ( rc != LDAP_SUCCESS )				break;		}	}	return rc;}voidslapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag ){	Connection		*conn;	Operation		*op;	ber_len_t		max = sockbuf_max_incoming;	conn = (Connection *) slapi_ch_calloc( 1, sizeof(Connection) );	LDAP_STAILQ_INIT( &conn->c_pending_ops );	op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );	op->o_hdr = (Opheader *)(op + 1);	op->o_controls = (void **)(op->o_hdr + 1);	op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );	op->o_callback->sc_response = slapi_int_response;	op->o_callback->sc_cleanup = NULL;	op->o_callback->sc_private = pb;	op->o_callback->sc_next = NULL;	conn->c_pending_ops.stqh_first = op;	/* connection object authorization information */	conn->c_authtype = LDAP_AUTH_NONE;	BER_BVZERO( &conn->c_authmech );	BER_BVZERO( &conn->c_dn );	BER_BVZERO( &conn->c_ndn );	conn->c_listener = &slapi_listener;	ber_dupbv( &conn->c_peer_domain, (struct berval *)&slap_unknown_bv );	ber_dupbv( &conn->c_peer_name, (struct berval *)&slap_unknown_bv );	LDAP_STAILQ_INIT( &conn->c_ops );	BER_BVZERO( &conn->c_sasl_bind_mech );	conn->c_sasl_authctx = NULL;	conn->c_sasl_sockctx = NULL;	conn->c_sasl_extra = NULL;	conn->c_sb = ber_sockbuf_alloc();	ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );	conn->c_currentber = NULL;	/* should check status of thread calls */	ldap_pvt_thread_mutex_init( &conn->c_mutex );	ldap_pvt_thread_mutex_init( &conn->c_write_mutex );	ldap_pvt_thread_cond_init( &conn->c_write_cv );	ldap_pvt_thread_mutex_lock( &conn->c_mutex );	conn->c_n_ops_received = 0;	conn->c_n_ops_executing = 0;	conn->c_n_ops_pending = 0;	conn->c_n_ops_completed = 0;	conn->c_n_get = 0;	conn->c_n_read = 0;	conn->c_n_write = 0;	conn->c_protocol = LDAP_VERSION3; 	conn->c_activitytime = conn->c_starttime = slap_get_time();	/*	 * A real connection ID is required, because syncrepl associates	 * pending CSNs with unique ( connection, operation ) tuples.	 * Setting a fake connection ID will cause slap_get_commit_csn()	 * to return a stale value.	 */	connection_assign_nextid( conn );	conn->c_conn_state  = 0x01;	/* SLAP_C_ACTIVE */	conn->c_struct_state = 0x02;	/* SLAP_C_USED */	conn->c_ssf = conn->c_transport_ssf = local_ssf;	conn->c_tls_ssf = 0;	backend_connection_init( conn );	conn->c_send_ldap_result = slap_send_ldap_result;	conn->c_send_search_entry = slap_send_search_entry;	conn->c_send_ldap_extended = slap_send_ldap_extended;	conn->c_send_search_reference = slap_send_search_reference;	/* operation object */	op->o_tag = tag;	op->o_protocol = LDAP_VERSION3; 	BER_BVZERO( &op->o_authmech );	op->o_time = slap_get_time();	op->o_do_not_cache = 1;	op->o_threadctx = ldap_pvt_thread_pool_context();	op->o_tmpmemctx = NULL;	op->o_tmpmfuncs = &ch_mfuncs;	op->o_conn = conn;	op->o_connid = conn->c_connid;	op->o_bd = frontendDB;	/* extensions */	slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );	slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );	pb->pb_rs = (SlapReply *)slapi_ch_calloc( 1, sizeof(SlapReply) );	pb->pb_op = op;	pb->pb_conn = conn;	pb->pb_intop = 1;	ldap_pvt_thread_mutex_unlock( &conn->c_mutex );}static voidslapi_int_set_operation_dn( Slapi_PBlock *pb ){	Backend			*be;	Operation		*op = pb->pb_op;	if ( BER_BVISNULL( &op->o_ndn ) ) {		/* set to root DN */		be = select_backend( &op->o_req_ndn, get_manageDSAit( op ), 1 );		if ( be != NULL ) {			ber_dupbv( &op->o_dn, &be->be_rootdn );			ber_dupbv( &op->o_ndn, &be->be_rootndn );		}	}}voidslapi_int_connection_done_pb( Slapi_PBlock *pb ){	Connection		*conn;	Operation		*op;	PBLOCK_ASSERT_INTOP( pb, 0 );	conn = pb->pb_conn;	op = pb->pb_op;	/* free allocated DNs */	if ( !BER_BVISNULL( &op->o_dn ) )		op->o_tmpfree( op->o_dn.bv_val, op->o_tmpmemctx );	if ( !BER_BVISNULL( &op->o_ndn ) )		op->o_tmpfree( op->o_ndn.bv_val, op->o_tmpmemctx );	if ( !BER_BVISNULL( &op->o_req_dn ) )		op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );	if ( !BER_BVISNULL( &op->o_req_ndn ) )		op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );	switch ( op->o_tag ) {	case LDAP_REQ_MODRDN:		if ( !BER_BVISNULL( &op->orr_newrdn ))			op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );		if ( !BER_BVISNULL( &op->orr_nnewrdn ))			op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );		if ( op->orr_newSup != NULL ) {			assert( !BER_BVISNULL( op->orr_newSup ) );			op->o_tmpfree( op->orr_newSup->bv_val, op->o_tmpmemctx );			op->o_tmpfree( op->orr_newSup, op->o_tmpmemctx );		}		if ( op->orr_nnewSup != NULL ) {			assert( !BER_BVISNULL( op->orr_nnewSup ) );			op->o_tmpfree( op->orr_nnewSup->bv_val, op->o_tmpmemctx );			op->o_tmpfree( op->orr_nnewSup, op->o_tmpmemctx );		}		break;	case LDAP_REQ_ADD:		slap_mods_free( op->ora_modlist, 0 );		break;	case LDAP_REQ_MODIFY:		slap_mods_free( op->orm_modlist, 1 );		break;	case LDAP_REQ_SEARCH:		if ( op->ors_attrs != NULL ) {			op->o_tmpfree( op->ors_attrs, op->o_tmpmemctx );			op->ors_attrs = NULL;		}		break;	default:		break;	}	slapi_ch_free_string( &conn->c_authmech.bv_val );	slapi_ch_free_string( &conn->c_dn.bv_val );	slapi_ch_free_string( &conn->c_ndn.bv_val );	slapi_ch_free_string( &conn->c_peer_domain.bv_val );	slapi_ch_free_string( &conn->c_peer_name.bv_val );	if ( conn->c_sb != NULL ) {		ber_sockbuf_free( conn->c_sb );	}	slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, op );	slapi_int_free_object_extensions( SLAPI_X_EXT_CONNECTION, conn );	slapi_ch_free( (void **)&pb->pb_op->o_callback );	slapi_ch_free( (void **)&pb->pb_op );	slapi_ch_free( (void **)&pb->pb_conn );	slapi_ch_free( (void **)&pb->pb_rs );}static intslapi_int_func_internal_pb( Slapi_PBlock *pb, slap_operation_t which ){	BI_op_bind		**func;	SlapReply		*rs = pb->pb_rs;	int			rc;	PBLOCK_ASSERT_INTOP( pb, 0 );	rc = slapi_int_get_ctrls( pb );	if ( rc != LDAP_SUCCESS ) {		rs->sr_err = rc;		return rc;	}	pb->pb_op->o_bd = frontendDB;	func = &frontendDB->be_bind;	return func[which]( pb->pb_op, pb->pb_rs );}intslapi_delete_internal_pb( Slapi_PBlock *pb ){	if ( pb == NULL ) {		return -1;	}	PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_DELETE );	slapi_int_func_internal_pb( pb, op_delete );	return 0;}intslapi_add_internal_pb( Slapi_PBlock *pb ){	SlapReply		*rs;	Slapi_Entry		*entry_orig = NULL;	if ( pb == NULL ) {		return -1;	}	PBLOCK_ASSERT_INTOP( pb, LDAP_REQ_ADD );	rs = pb->pb_rs;	entry_orig = pb->pb_op->ora_e;	pb->pb_op->ora_e = NULL;	/*	 * The caller can specify a new entry, or a target DN and set	 * of modifications, but not both.	 */	if ( entry_orig != NULL ) {		if ( pb->pb_op->ora_modlist != NULL || !BER_BVISNULL( &pb->pb_op->o_req_ndn )) {			rs->sr_err = LDAP_PARAM_ERROR;			goto cleanup;		}		assert( BER_BVISNULL( &pb->pb_op->o_req_dn ) ); /* shouldn't get set */		ber_dupbv( &pb->pb_op->o_req_dn, &entry_orig->e_name );		ber_dupbv( &pb->pb_op->o_req_ndn, &entry_orig->e_nname );	} else if ( pb->pb_op->ora_modlist == NULL || BER_BVISNULL( &pb->pb_op->o_req_ndn )) {		rs->sr_err = LDAP_PARAM_ERROR;		goto cleanup;	}	pb->pb_op->ora_e = (Entry *)slapi_ch_calloc( 1, sizeof(Entry) );	ber_dupbv( &pb->pb_op->ora_e->e_name,  &pb->pb_op->o_req_dn );	ber_dupbv( &pb->pb_op->ora_e->e_nname, &pb->pb_op->o_req_ndn );	if ( entry_orig != NULL ) {		assert( pb->pb_op->ora_modlist == NULL );		rs->sr_err = slap_entry2mods( entry_orig, &pb->pb_op->ora_modlist,			&rs->sr_text, pb->pb_textbuf, sizeof( pb->pb_textbuf ) );		if ( rs->sr_err != LDAP_SUCCESS ) {			goto cleanup;		}	} else {		assert( pb->pb_op->ora_modlist != NULL );	}	rs->sr_err = slap_mods_check( pb->pb_op->ora_modlist, &rs->sr_text,		pb->pb_textbuf, sizeof( pb->pb_textbuf ), NULL );	if ( rs->sr_err != LDAP_SUCCESS ) {                goto cleanup;        }	/* Duplicate the values, because we may call slapi_entry_free() */	rs->sr_err = slap_mods2entry( pb->pb_op->ora_modlist, &pb->pb_op->ora_e,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -