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

📄 init.c

📁 OpenLdap是LDAP的开源项目
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $OpenLDAP: pkg/ldap/servers/slapd/back-sql/init.c,v 1.47.2.14 2007/08/22 21:37:58 ando Exp $ *//* This work is part of OpenLDAP Software <http://www.openldap.org/>. * * Copyright 1999-2007 The OpenLDAP Foundation. * Portions Copyright 1999 Dmitry Kovalev. * Portions Copyright 2002 Pierangelo Masarati. * 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 Dmitry Kovalev for inclusion * by OpenLDAP Software.  Additional significant contributors include * Pierangelo Masarati. */#include "portable.h"#include <stdio.h>#include <sys/types.h>#include "ac/string.h"#include "slap.h"#include "proto-sql.h"intsql_back_initialize(	BackendInfo	*bi ){ 	static char *controls[] = {		LDAP_CONTROL_ASSERT,		LDAP_CONTROL_MANAGEDSAIT,		LDAP_CONTROL_NOOP,#if 0 /* SLAP_CONTROL_X_TREE_DELETE */		SLAP_CONTROL_X_TREE_DELETE,#endif /* SLAP_CONTROL_X_TREE_DELETE */		NULL	};	bi->bi_controls = controls;	bi->bi_flags |=#if 0		SLAP_BFLAG_INCREMENT |#endif		SLAP_BFLAG_REFERRALS;	Debug( LDAP_DEBUG_TRACE,"==>sql_back_initialize()\n", 0, 0, 0 );		bi->bi_db_init = backsql_db_init;	bi->bi_db_config = backsql_db_config;	bi->bi_db_open = backsql_db_open;	bi->bi_db_close = backsql_db_close;	bi->bi_db_destroy = backsql_db_destroy;	bi->bi_op_abandon = 0;	bi->bi_op_compare = backsql_compare;	bi->bi_op_bind = backsql_bind;	bi->bi_op_unbind = 0;	bi->bi_op_search = backsql_search;	bi->bi_op_modify = backsql_modify;	bi->bi_op_modrdn = backsql_modrdn;	bi->bi_op_add = backsql_add;	bi->bi_op_delete = backsql_delete;		bi->bi_chk_referrals = 0;	bi->bi_operational = backsql_operational;	bi->bi_entry_get_rw = backsql_entry_get;	bi->bi_entry_release_rw = backsql_entry_release; 	bi->bi_connection_init = 0;	bi->bi_connection_destroy = backsql_connection_destroy;	Debug( LDAP_DEBUG_TRACE,"<==sql_back_initialize()\n", 0, 0, 0 );	return 0;}intbacksql_destroy( 	BackendInfo 	*bi ){	Debug( LDAP_DEBUG_TRACE, "==>backsql_destroy()\n", 0, 0, 0 );	Debug( LDAP_DEBUG_TRACE, "<==backsql_destroy()\n", 0, 0, 0 );	return 0;}intbacksql_db_init(	BackendDB 	*bd ){	backsql_info	*bi;	int		rc = 0; 	Debug( LDAP_DEBUG_TRACE, "==>backsql_db_init()\n", 0, 0, 0 );	bi = (backsql_info *)ch_calloc( 1, sizeof( backsql_info ) );	ldap_pvt_thread_mutex_init( &bi->sql_dbconn_mutex );	ldap_pvt_thread_mutex_init( &bi->sql_schema_mutex );	if ( backsql_init_db_env( bi ) != SQL_SUCCESS ) {		rc = -1;	}	bd->be_private = bi;	Debug( LDAP_DEBUG_TRACE, "<==backsql_db_init()\n", 0, 0, 0 );	return rc;}intbacksql_db_destroy(	BackendDB 	*bd ){	backsql_info	*bi = (backsql_info*)bd->be_private; 	Debug( LDAP_DEBUG_TRACE, "==>backsql_db_destroy()\n", 0, 0, 0 );	ldap_pvt_thread_mutex_lock( &bi->sql_dbconn_mutex );	backsql_free_db_env( bi );	ldap_pvt_thread_mutex_unlock( &bi->sql_dbconn_mutex );	ldap_pvt_thread_mutex_destroy( &bi->sql_dbconn_mutex );	ldap_pvt_thread_mutex_lock( &bi->sql_schema_mutex );	backsql_destroy_schema_map( bi );	ldap_pvt_thread_mutex_unlock( &bi->sql_schema_mutex );	ldap_pvt_thread_mutex_destroy( &bi->sql_schema_mutex );	if ( bi->sql_dbname ) {		ch_free( bi->sql_dbname );	}	if ( bi->sql_dbuser ) {		ch_free( bi->sql_dbuser );	}	if ( bi->sql_dbpasswd ) {		ch_free( bi->sql_dbpasswd );	}	if ( bi->sql_dbhost ) {		ch_free( bi->sql_dbhost );	}	if ( bi->sql_upper_func.bv_val ) {		ch_free( bi->sql_upper_func.bv_val );		ch_free( bi->sql_upper_func_open.bv_val );		ch_free( bi->sql_upper_func_close.bv_val );	}	if ( bi->sql_concat_func ) {		ber_bvarray_free( bi->sql_concat_func );	}	if ( !BER_BVISNULL( &bi->sql_strcast_func ) ) {		ch_free( bi->sql_strcast_func.bv_val );	}	if ( !BER_BVISNULL( &bi->sql_children_cond ) ) {		ch_free( bi->sql_children_cond.bv_val );	}	if ( !BER_BVISNULL( &bi->sql_subtree_cond ) ) {		ch_free( bi->sql_subtree_cond.bv_val );	}	if ( !BER_BVISNULL( &bi->sql_dn_oc_aliasing ) ) {		ch_free( bi->sql_dn_oc_aliasing.bv_val );	}	if ( bi->sql_oc_query ) {		ch_free( bi->sql_oc_query );	}	if ( bi->sql_at_query ) {		ch_free( bi->sql_at_query );	}	if ( bi->sql_id_query ) {		ch_free( bi->sql_id_query );	}	if ( bi->sql_has_children_query ) {		ch_free( bi->sql_has_children_query );	}	if ( bi->sql_insentry_stmt ) {		ch_free( bi->sql_insentry_stmt );	}	if ( bi->sql_delentry_stmt ) {		ch_free( bi->sql_delentry_stmt );	}	if ( bi->sql_renentry_stmt ) {		ch_free( bi->sql_renentry_stmt );	}	if ( bi->sql_delobjclasses_stmt ) {		ch_free( bi->sql_delobjclasses_stmt );	}	if ( !BER_BVISNULL( &bi->sql_aliasing ) ) {		ch_free( bi->sql_aliasing.bv_val );	}	if ( !BER_BVISNULL( &bi->sql_aliasing_quote ) ) {		ch_free( bi->sql_aliasing_quote.bv_val );	}	if ( bi->sql_anlist ) {		int	i;		for ( i = 0; !BER_BVISNULL( &bi->sql_anlist[ i ].an_name ); i++ )		{			ch_free( bi->sql_anlist[ i ].an_name.bv_val );		}		ch_free( bi->sql_anlist );	}	if ( bi->sql_baseObject ) {		entry_free( bi->sql_baseObject );	}		ch_free( bi );		Debug( LDAP_DEBUG_TRACE, "<==backsql_db_destroy()\n", 0, 0, 0 );	return 0;}intbacksql_db_open(	BackendDB 	*bd ){	backsql_info 	*bi = (backsql_info*)bd->be_private;	SQLHDBC 	dbh = SQL_NULL_HDBC;	struct berbuf	bb = BB_NULL;	OperationBuffer	opbuf;	Operation*	op = (Operation *) &opbuf;		Debug( LDAP_DEBUG_TRACE, "==>backsql_db_open(): "		"testing RDBMS connection\n", 0, 0, 0 );	if ( bi->sql_dbname == NULL ) {		Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "			"datasource name not specified "			"(use \"dbname\" directive in slapd.conf)\n", 0, 0, 0 );		return 1;	}	if ( bi->sql_concat_func == NULL ) {		Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "			"concat func not specified (use \"concat_pattern\" "			"directive in slapd.conf)\n", 0, 0, 0 );		if ( backsql_split_pattern( backsql_def_concat_func, 				&bi->sql_concat_func, 2 ) ) {			Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "				"unable to parse pattern \"%s\"",				backsql_def_concat_func, 0, 0 );			return 1;		}	}	/*	 * see back-sql.h for default values	 */	if ( BER_BVISNULL( &bi->sql_aliasing ) ) {		ber_str2bv( BACKSQL_ALIASING,			STRLENOF( BACKSQL_ALIASING ),			1, &bi->sql_aliasing );	}	if ( BER_BVISNULL( &bi->sql_aliasing_quote ) ) {		ber_str2bv( BACKSQL_ALIASING_QUOTE,			STRLENOF( BACKSQL_ALIASING_QUOTE ),			1, &bi->sql_aliasing_quote );	}	/*	 * Prepare cast string as required	 */	if ( bi->sql_upper_func.bv_val ) {		char buf[1024];		if ( BACKSQL_UPPER_NEEDS_CAST( bi ) ) {			snprintf( buf, sizeof( buf ), 				"%s(cast (" /* ? as varchar(%d))) */ , 				bi->sql_upper_func.bv_val );			ber_str2bv( buf, 0, 1, &bi->sql_upper_func_open );			snprintf( buf, sizeof( buf ),				/* (cast(? */ " as varchar(%d)))",				BACKSQL_MAX_DN_LEN );			ber_str2bv( buf, 0, 1, &bi->sql_upper_func_close );		} else {			snprintf( buf, sizeof( buf ), "%s(" /* ?) */ ,					bi->sql_upper_func.bv_val );			ber_str2bv( buf, 0, 1, &bi->sql_upper_func_open );			ber_str2bv( /* (? */ ")", 0, 1, &bi->sql_upper_func_close );		}	}	/* normalize filter values only if necessary */	bi->sql_caseIgnoreMatch = mr_find( "caseIgnoreMatch" );	assert( bi->sql_caseIgnoreMatch != NULL );	bi->sql_telephoneNumberMatch = mr_find( "telephoneNumberMatch" );	assert( bi->sql_telephoneNumberMatch != NULL );	if ( bi->sql_dbuser == NULL ) {		Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "			"user name not specified "			"(use \"dbuser\" directive in slapd.conf)\n", 0, 0, 0 );		return 1;	}

⌨️ 快捷键说明

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