xref: /titanic_41/usr/src/lib/pkcs11/libpkcs11/common/pkcs11Session.h (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_PKCS11_SESSION_H
28 #define	_PKCS11_SESSION_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	PKCS11_SESSION_MAGIC	0xECF00001
37 
38 typedef struct pkcs11_session {
39 
40 	ulong_t			se_magic; /* ensure this is a valid session */
41 	CK_SESSION_HANDLE	se_handle; /* from slot's C_OpenSession() */
42 	CK_SLOT_ID		se_slotid; /* slotID in framework */
43 	struct pkcs11_session	*se_prev;	/* Chain of sessions  */
44 	struct pkcs11_session	*se_next; 	/* in this slot */
45 
46 } pkcs11_session_t;
47 
48 
49 /*
50  * This macro is used to typecast a session handle to a pointer
51  * to a session structure.  It also checks to see if the session
52  * is tagged with a session magic number.  This is to detect when an
53  * application passes a bogus session pointer.
54  */
55 #define	HANDLE2SESSION(hSession, sessionp, rv)\
56 		sessionp = (pkcs11_session_t *)(hSession);	\
57 		rv = CKR_OK;					\
58 		if ((sessionp == NULL) || 			\
59 		    (sessionp->se_magic != PKCS11_SESSION_MAGIC)) \
60 			rv = CKR_SESSION_HANDLE_INVALID;	\
61 
62 
63 struct pkcs11_slot;
64 
65 extern CK_RV pkcs11_session_add(struct pkcs11_slot *pslot, CK_SLOT_ID slot_id,
66 	CK_SESSION_HANDLE_PTR pfwhandle, CK_SESSION_HANDLE prov_sess);
67 
68 extern void pkcs11_session_delete(struct pkcs11_slot *pslot,
69 	pkcs11_session_t *psess);
70 
71 extern void pkcs11_sessionlist_delete(struct pkcs11_slot *pslot);
72 
73 #ifdef	__cplusplus
74 }
75 #endif
76 
77 #endif /* _PKCS11_SESSION_H */
78