1 /*
2  * Copyright (c) 2012 Stefan Walter
3  * Copyright (c) 2019 Red Hat, Inc.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  *     * Redistributions of source code must retain the above
10  *       copyright notice, this list of conditions and the
11  *       following disclaimer.
12  *     * Redistributions in binary form must reproduce the
13  *       above copyright notice, this list of conditions and
14  *       the following disclaimer in the documentation and/or
15  *       other materials provided with the distribution.
16  *     * The names of contributors to this software may not be
17  *       used to endorse or promote products derived from this
18  *       software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31  * DAMAGE.
32  *
33  * Author: Stef Walter <stef@thewalter.net>, Daiki Ueno
34  */
35 
36 #include "config.h"
37 
38 #define CRYPTOKI_EXPORTS 1
39 #include "pkcs11.h"
40 
41 #include "mock.h"
42 #include "test.h"
43 
44 static CK_RV
override_wait_for_slot_event(CK_FLAGS flags,CK_SLOT_ID_PTR slot,CK_VOID_PTR reserved)45 override_wait_for_slot_event (CK_FLAGS flags,
46 			      CK_SLOT_ID_PTR slot,
47 			      CK_VOID_PTR reserved)
48 {
49 	if (flags & CKF_DONT_BLOCK) {
50 		*slot = MOCK_SLOT_ONE_ID;
51 		return CKR_OK;
52 	}
53 
54 	return mock_C_WaitForSlotEvent(flags, slot, reserved);
55 }
56 
57 #ifdef OS_WIN32
58 __declspec(dllexport)
59 #endif
60 CK_RV
C_GetFunctionList(CK_FUNCTION_LIST_PTR_PTR list)61 C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR list)
62 {
63 	mock_module_init ();
64 	mock_module.C_GetFunctionList = C_GetFunctionList;
65 	if (list == NULL)
66 		return CKR_ARGUMENTS_BAD;
67 	mock_module.C_WaitForSlotEvent = override_wait_for_slot_event;
68 	*list = &mock_module;
69 	return CKR_OK;
70 }
71