From b37bf079d8ddfc7989d8e7da0b3e7eb7b9d8c856 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 5 Dec 2008 04:21:29 +0000 Subject: Add ability to run NSS libsoftokn3 using the lazy flag. --- src/module.c | 73 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'src/module.c') diff --git a/src/module.c b/src/module.c index b1b82b0..9e018e7 100644 --- a/src/module.c +++ b/src/module.c @@ -166,14 +166,17 @@ p11t_module_load(const char *filename) if(rv != CKR_OK) p11t_msg_fatal("C_GetFunctiontList: couldn't get function list: %s", p11t_msg_rv(rv)); - /** C_GetFunctionList */ - rv = (p11t_module_funcs->C_GetFunctionList)(&list); - if(rv != CKR_OK) - p11t_msg_print("C_GetFunctionList: call through function list failed: %s", p11t_msg_rv(rv)); - - /** - See if returns same data as library entry point */ - if(!memcmp(list, p11t_module_funcs, sizeof(*list)) != 0) - p11t_msg_print("C_GetFunctionList: function lists returned directly and recursively differ"); + if(p11t_test_unexpected) + { + /** C_GetFunctionList */ + rv = (p11t_module_funcs->C_GetFunctionList)(&list); + if(rv != CKR_OK) + p11t_msg_print("C_GetFunctionList: call through function list failed: %s", p11t_msg_rv(rv)); + + /** - See if returns same data as library entry point */ + if(!memcmp(list, p11t_module_funcs, sizeof(*list)) != 0) + p11t_msg_print("C_GetFunctionList: function lists returned directly and recursively differ"); + } } static int @@ -259,15 +262,18 @@ p11t_module_initialize(void) assert(p11t_module_funcs); - /** - Calls without initializing */ - rv = (p11t_module_funcs->C_GetInfo)(&info); - p11t_check_returns("C_GetInfo: shouldn't run without initialize", rv, CKR_CRYPTOKI_NOT_INITIALIZED); + if(p11t_test_unexpected) + { + /** - Calls without initializing */ + rv = (p11t_module_funcs->C_GetInfo)(&info); + p11t_check_returns("C_GetInfo: shouldn't run without initialize", rv, CKR_CRYPTOKI_NOT_INITIALIZED); - /** - NULL argument */ - rv = (p11t_module_funcs->C_Initialize) (NULL); - p11t_check_returns("C_Initialize: should succeed with null argument", rv, CKR_OK); - is_initialized = 1; - p11t_module_finalize(); + /** - NULL argument */ + rv = (p11t_module_funcs->C_Initialize) (NULL); + p11t_check_returns("C_Initialize: should succeed with null argument", rv, CKR_OK); + is_initialized = 1; + p11t_module_finalize(); + } /** - Multiple initialize with C_Finalize between */ initialize_locking_1(); @@ -286,16 +292,17 @@ p11t_module_initialize(void) if(!is_initialized) p11t_msg_fatal("C_Initialize: couldn't initialize pkcs11 module"); - /** - Double initialize in a row */ - rv = (p11t_module_funcs->C_Initialize) (&init_args); - if (rv != CKR_CRYPTOKI_ALREADY_INITIALIZED) + if(p11t_test_unexpected) { - p11t_msg_print("C_Initialize: double initialize should return CKR_CRYPTOKI_ALREADY_INITIALIZED: %s", p11t_msg_rv(rv)); - } - else - { - is_initialized = 1; + /** - Double initialize in a row */ + rv = (p11t_module_funcs->C_Initialize) (&init_args); + if(rv != CKR_CRYPTOKI_ALREADY_INITIALIZED) + { + p11t_msg_print("C_Initialize: double initialize should return CKR_CRYPTOKI_ALREADY_INITIALIZED: %s", p11t_msg_rv(rv)); + } } + + is_initialized = 1; } void @@ -306,9 +313,12 @@ p11t_module_finalize(void) /** C_Finalize */ if(is_initialized) { - /** - With invalid argument */ - rv = p11t_module_funcs->C_Finalize(&rv); - p11t_check_returns("C_Finalize: bad argument", rv, CKR_ARGUMENTS_BAD); + if(p11t_test_unexpected) + { + /** - With invalid argument */ + rv = p11t_module_funcs->C_Finalize(&rv); + p11t_check_returns("C_Finalize: bad argument", rv, CKR_ARGUMENTS_BAD); + } /** - Normal call */ assert(p11t_module_funcs); @@ -317,9 +327,12 @@ p11t_module_finalize(void) is_initialized = 0; } - /** - Double finalize in a row */ - rv = p11t_module_funcs->C_Finalize(NULL); - p11t_check_returns("C_Finalize: double finalize", rv, CKR_CRYPTOKI_NOT_INITIALIZED); + if(p11t_test_unexpected) + { + /** - Double finalize in a row */ + rv = p11t_module_funcs->C_Finalize(NULL); + p11t_check_returns("C_Finalize: double finalize", rv, CKR_CRYPTOKI_NOT_INITIALIZED); + } } void -- cgit v1.2.3