Mercurial > hg > waaad
view extensions/sec_nosec/sec_nosec.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 | 98806d0e175f |
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_nosec.h" static sec_module_t sns_mod; static sec_mod_hdl_t * sns_hdl; int sec_nosec_verbosity = 0; /* The main entry point of the extension, called when the extension is loaded, after API initialization */ static int sec_nosec_main(char * conffile) { int ret = 0; TRACE_ENTRY("%p", conffile); /* The configuration file is mandatory */ if (!conffile) { TRACE_DEBUG(INFO, "Missing configuration file"); return EINVAL; } /* Now initialize the extension */ ret = sns_init(); if (ret != 0) { TRACE_DEBUG(INFO, "sns_init failed: %s", strerror(ret)); return ret; } /* Parse the configuration file */ ret = sns_parse(conffile); if (ret != 0) { TRACE_DEBUG(INFO, "sns_parse failed: %s", strerror(ret)); (void)sns_fini(); return ret; } /* Finaly, register the security module */ memset(&sns_mod, 0, sizeof(sec_module_t) ); sns_mod.sec_insecid = SEC_NOSEC_INBAND_SECURITY_ID; sns_mod.sec_is_supported_peer = sns_is_supported_peer; sns_mod.sec_state_change = sns_state_change; sns_mod.sec_send_protect = sns_send_protect; sns_mod.sec_recv_unprotect = sns_recv_unprotect; ret = sec_register( &sns_mod, &sns_hdl ); if (ret != 0) { TRACE_DEBUG(INFO, "sec_register failed: %s", strerror(ret)); (void)sns_fini(); return ret; } /* For debug purpose */ TRACE_DEBUG(INFO, "Extension SEC/No Sec initialized with configuration: '%s'", conffile); sns_dump(); /* Done! */ return 0; } EXTENSION_API_INIT(API_MODULE_LOG | API_MODULE_CONF | API_MODULE_SECURITY, sec_nosec_main, "sec_nosec", 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( sns_hdl ); if (ret != 0) { TRACE_DEBUG(INFO, "sec_unregister failed: %s", strerror(ret)); } /* Destroy the data of the extension */ ret = sns_fini(); if (ret != 0) { TRACE_DEBUG(INFO, "sns_fini failed: %s", strerror(ret)); } /* Done! */ return ; }