Mercurial > hg > waaad
changeset 110:2fb02c5fdf16
Add call to find a security module by its id
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 29 Jul 2008 16:11:07 +0900 |
parents | 7fe2dff0424e |
children | f5d811b6e2e2 |
files | waaad/security.c waaad/security.h waaad/tests/testsec.c |
diffstat | 3 files changed, 82 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/waaad/security.c Tue Jul 29 13:54:08 2008 +0900 +++ b/waaad/security.c Tue Jul 29 16:11:07 2008 +0900 @@ -157,7 +157,6 @@ return 0; } - /* Decrement a refcount of a module */ int sec_modunlink(sec_mod_hdl_t * module) { @@ -184,7 +183,54 @@ return 0; } + +/* Find a module by its insecid */ +int sec_module(uint32_t insecid, _sec_item_t *module) +{ + int ret = 0; + _sm_t * mod; + TRACE_ENTRY( "%d %p", insecid, module ); + + if (!module) { + TRACE_DEBUG(INFO, "Invalid parameter"); + return EINVAL; + } + + memset(module, 0, sizeof(_sec_item_t)); + + /* Get the mutex */ + ret = pthread_mutex_lock(&sm_lock); + if (ret != 0) { + TRACE_DEBUG(INFO, "pthread_mutex_lock failed: %s", strerror(ret)); + return ret; + } + + /* Seach a corresponding module */ + for (mod = sm_senti.next; mod != &sm_senti; mod = mod->next) { + if (mod->sm->sec_insecid < insecid) + continue; + + if (mod->sm->sec_insecid > insecid) + break; + + /* We found it */ + module->sm = mod->sm; + module->hdl= (sec_mod_hdl_t *) mod; + /* increment the refcount of this module */ + mod->peers ++; + } + + /* Release the mutex */ + ret = pthread_mutex_unlock(&sm_lock); + if (ret != 0) { + TRACE_DEBUG(INFO, "pthread_mutex_unlock failed: %s", strerror(ret)); + return ret; + } + + return (module->sm == NULL) ? ENOENT : 0; +} + /* Destroy a list of _sec_item_t */ int sec_freemodules(_sec_item_t * modules) {
--- a/waaad/security.h Tue Jul 29 13:54:08 2008 +0900 +++ b/waaad/security.h Tue Jul 29 16:11:07 2008 +0900 @@ -88,6 +88,24 @@ int sec_fini ( void ); /* + * FUNCTION: sec_module + * + * PARAMETERS: + * insecid: A value of Inband-Security-Id. + * module : upon success, the security module corresponding. The next field is always NULL. + * + * DESCRIPTION: + * Get a reference to a security module from its ID. + * An implicit call to sec_modlink is made on successful return. + * The sec_freemodules must not be called on returned module list. + * + * RETURN VALUE: + * 0 : Module found + * !0 : No such module + */ +int sec_module(uint32_t insecid, _sec_item_t *module); + +/* * FUNCTION: sec_getmodules * * PARAMETERS:
--- a/waaad/tests/testsec.c Tue Jul 29 13:54:08 2008 +0900 +++ b/waaad/tests/testsec.c Tue Jul 29 16:11:07 2008 +0900 @@ -150,6 +150,23 @@ CHECK( 0, sec_register( &mod_b, &modhdl_b) ); } + /* Test finding a module by its id */ + { + _sec_item_t modinfo; + + CHECK( 0, sec_module( 0, &modinfo) ); + CHECK( 0, modinfo.sm->sec_insecid ); + CHECK( modhdl_a, modinfo.hdl ); + CHECK( 0, sec_modunlink( modinfo.hdl ) ); + + CHECK( 0, sec_module( 1, &modinfo) ); + CHECK( 1, modinfo.sm->sec_insecid ); + CHECK( modhdl_b, modinfo.hdl ); + CHECK( 0, sec_modunlink( modinfo.hdl ) ); + + CHECK( ENOENT, sec_module( 2, &modinfo) ); + } + /* Test the module election process (daemon internals) */ { _sec_item_t * list;