view extensions/sec_tls_gnutls/sec_tls_gnutls.c @ 400:22f29007b931

Detect when extensions are loaded several times (not allowed)
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 02 Jun 2009 14:49:37 +0900
parents e86dba02630a
children
line wrap: on
line source

/*********************************************************************************************************
* Software License Agreement (BSD License)                                                               *
* Author: Sebastien Decugis <sdecugis@nict.go.jp>							 *
*													 *
* Copyright (c) 2009, WIDE Project and NICT								 *
* All rights reserved.											 *
* 													 *
* Redistribution and use of this software in source and binary forms, with or without modification, are  *
* permitted provided that the following conditions are met:						 *
* 													 *
* * Redistributions of source code must retain the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer.										 *
*    													 *
* * Redistributions in binary form must reproduce the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer in the documentation and/or other						 *
*   materials provided with the distribution.								 *
* 													 *
* * Neither the name of the WIDE Project or NICT nor the 						 *
*   names of its contributors may be used to endorse or 						 *
*   promote products derived from this software without 						 *
*   specific prior written permission of WIDE Project and 						 *
*   NICT.												 *
* 													 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
*********************************************************************************************************/

/* 
 * Extension to implement the NO_SEC security mechanism (Inband-Security-Id 0)
 *
 * The peers to which no security is acceptable MUST be explicitely listed in the configuration file
 * of this extension.
 */

/* We need this to use the waaad API */
#define DECLARE_API_POINTERS

/* Include the extension definitions and daemon definitions */
#include "sec_tls_gnutls.h"

static sec_module_t 	tls_mod;
static sec_mod_hdl_t  * tls_hdl;
int sec_gnutls_verbosity = 0;

/* The main entry point of the extension, called when the extension is loaded, after API initialization */
static int tls_main(char * conffile)
{
	int ret = 0;
	
	TRACE_ENTRY("%p", conffile);

	/* Initialize the extension */
	ret = tls_init();
	if (ret != 0) {
		TRACE_DEBUG(INFO, "tls_init failed: %s", strerror(ret));
		return ret;
	}
	
	/* Register the security module */
	memset(&tls_mod, 0, sizeof(sec_module_t) );
	tls_mod.sec_insecid 		= SEC_TLS_INBAND_SECURITY_ID;
	tls_mod.sec_is_supported_peer	= tls_is_supported_peer;
	tls_mod.sec_state_change	= tls_state_change;
	tls_mod.sec_send_protect	= tls_send_protect;
	tls_mod.sec_recv_unprotect	= tls_recv_unprotect;
	
	ret = sec_register( &tls_mod, &tls_hdl );
	if (ret != 0) {
		TRACE_DEBUG(INFO, "sec_register failed: %s", strerror(ret));
		(void)tls_fini();
		return ret;
	}
	
	/* Done! */
	return 0;
}

EXTENSION_API_INIT(API_MODULE_LOG | API_MODULE_CONF | API_MODULE_SECURITY, tls_main, "sec_tls_gnutls", 1);

/* Code that is called after the extension terminates */
void waaad_ext_fini(void)
{
	int ret = 0;
	
	TRACE_ENTRY("");
	
	/* Unregister the security module */
	ret = sec_unregister( tls_hdl );
	if (ret != 0) {
		TRACE_DEBUG(INFO, "sec_unregister failed: %s", strerror(ret));
	}
	
	/* Destroy the data of the extension */
	ret = tls_fini();
	if (ret != 0) {
		TRACE_DEBUG(INFO, "tls_fini failed: %s", strerror(ret));
	}
	
	/* Done! */
	return ;
}


"Welcome to our mercurial repository"