1 /*
2  * COPYRIGHT (c) International Business Machines Corp. 2001-2017
3  *
4  * This program is provided under the terms of the Common Public License,
5  * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
6  * software constitutes recipient's acceptance of CPL-1.0 terms which can be
7  * found in the file LICENSE file or at
8  * https://opensource.org/licenses/cpl1.0.php
9  */
10 
11 /***********************************************************************
12  *
13  *  Slot Manager Daemon header file
14  *
15  ***********************************************************************/
16 
17 #ifndef _PKCSSLOTMGR_H
18 #define _PKCSSLOTMGR_H  1
19 
20 #include <sys/types.h>
21 #include <sys/ipc.h>
22 
23 /***********
24  * Defines *
25  ***********/
26 
27 #define UNUSED(var)            ((void)(var))
28 
29 #ifdef DEV
30 #ifndef BECOME_DAEMON
31 #define BECOME_DAEMON   FALSE
32 #endif                          /* BECOME_DAEMON */
33 
34 #ifndef DEFAULT_LOG_FILE
35 #define DEFAULT_LOG_FILE    (TOK_PATH ".log")
36 #endif                          /* DEFAULT_LOG_FILE */
37 
38 #ifndef DEFAULT_DEBUG_LEVEL
39 #define DEFAULT_DEBUG_LEVEL DEBUG_LEVEL0
40 #endif                          /* DEFAULT_DEBUG_LEVEL */
41 
42 #else                           /* DEV not defined */
43 #define BECOME_DAEMON          TRUE
44 #define DEFAULT_DEBUG_LEVEL    DEBUG_NONE
45 
46 #endif                          /* DEV */
47 
48 #define HASH_SHA1   1
49 #define HASH_MD5    2
50 #define compute_md5(a,b,c)      compute_hash(HASH_MD5,b,a,c)
51 
52 int compute_hash(int hash_type, int buf_size, char *buf, char *digest);
53 
54 /********************
55  * Global Variables *
56  ********************/
57 
58 extern Slot_Mgr_Shr_t *shmp;    // pointer to the shared memory region.
59 extern int shmid;
60 extern key_t tok;
61 
62 extern Slot_Info_t_64 sinfo[NUMBER_SLOTS_MANAGED];
63 
64 extern unsigned int NumberSlotsInDB;
65 
66 extern int socketfd;
67 extern Slot_Mgr_Socket_t socketData;
68 
69 
70 /***********************
71  * Function Prototypes *
72  ***********************/
73 
74 BOOL IsDaemon(void);
75 BOOL StopGCThread(void *Ptr);
76 BOOL StartGCThread(Slot_Mgr_Shr_t *MemPtr);
77 BOOL CheckForGarbage(Slot_Mgr_Shr_t *MemPtr);
78 int InitializeMutexes(void);
79 int DestroyMutexes(void);
80 int CreateSharedMemory(void);
81 int AttachToSharedMemory(void);
82 int InitSharedMemory(Slot_Mgr_Shr_t *sp);
83 void DetachFromSharedMemory(void);
84 void DestroySharedMemory(void);
85 int SetupSignalHandlers(void);
86 void slotdGenericSignalHandler(int Signal);
87 void PopulateCKInfo(CK_INFO_PTR_64 ckinf);
88 void PopulateSlotInfo(Slot_Info_t_64 *slot_info, unsigned int *processed);
89 
90 int XProcLock(void);
91 int XProcUnLock(void);
92 int CreateXProcLock(void);
93 
94 int CreateListenerSocket(void);
95 int InitSocketData(Slot_Mgr_Socket_t *sp);
96 int SocketConnectionHandler(int socketfd, int timeout_secs);
97 void DetachSocketListener(int socketfd);
98 
99 int load_and_parse(const char *configfile);
100 
101 #endif                          /* _SLOTMGR_H */
102