4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <strings.h>
27 #include <errno.h>
28 #include <cryptoutil.h>
29 #include <unistd.h> /* for pid_t */
30 #include <pthread.h>
31 #include <security/cryptoki.h>
32 #include "softGlobal.h"
33 #include "softSession.h"
34 #include "softObject.h"
35 #include "softKeystore.h"
36 #include "softKeystoreUtil.h"
37
38 #pragma init(softtoken_init)
39 #pragma fini(softtoken_fini)
40
41 extern soft_session_t token_session; /* for fork handler */
42
43 static struct CK_FUNCTION_LIST functionList = {
337
338 (void) pthread_mutex_lock(&soft_sessionlist_mutex);
339 /*
340 * Set all_sessions_closing flag so any access to any
341 * existing sessions will be rejected.
342 */
343 all_sessions_closing = 1;
344 (void) pthread_mutex_unlock(&soft_sessionlist_mutex);
345
346 /* Delete all the sessions and release the allocated resources */
347 rv = soft_delete_all_sessions(force);
348
349 (void) pthread_mutex_lock(&soft_sessionlist_mutex);
350 /* Reset all_sessions_closing flag. */
351 all_sessions_closing = 0;
352 (void) pthread_mutex_unlock(&soft_sessionlist_mutex);
353
354 softtoken_initialized = B_FALSE;
355 softtoken_pid = 0;
356
357 pkcs11_close_urandom();
358 pkcs11_close_urandom_seed();
359 pkcs11_close_random();
360
361 /* Destroy the session list lock here */
362 (void) pthread_mutex_destroy(&soft_sessionlist_mutex);
363
364 /*
365 * Destroy token object related stuffs
366 * 1. Clean up the token object list
367 * 2. Destroy slot mutex
368 * 3. Destroy mutex in token_session
369 */
370 soft_delete_all_in_core_token_objects(ALL_TOKEN);
371 (void) pthread_mutex_destroy(&soft_slot.slot_mutex);
372 (void) pthread_mutex_destroy(&soft_slot.keystore_mutex);
373 (void) soft_destroy_token_session();
374
375 /*
376 * free all entries in the delay_freed list
377 */
378 delay_free_obj = obj_delay_freed.first;
379 while (delay_free_obj != NULL) {
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
26 */
27
28 #include <strings.h>
29 #include <errno.h>
30 #include <cryptoutil.h>
31 #include <unistd.h> /* for pid_t */
32 #include <pthread.h>
33 #include <security/cryptoki.h>
34 #include "softGlobal.h"
35 #include "softSession.h"
36 #include "softObject.h"
37 #include "softKeystore.h"
38 #include "softKeystoreUtil.h"
39
40 #pragma init(softtoken_init)
41 #pragma fini(softtoken_fini)
42
43 extern soft_session_t token_session; /* for fork handler */
44
45 static struct CK_FUNCTION_LIST functionList = {
339
340 (void) pthread_mutex_lock(&soft_sessionlist_mutex);
341 /*
342 * Set all_sessions_closing flag so any access to any
343 * existing sessions will be rejected.
344 */
345 all_sessions_closing = 1;
346 (void) pthread_mutex_unlock(&soft_sessionlist_mutex);
347
348 /* Delete all the sessions and release the allocated resources */
349 rv = soft_delete_all_sessions(force);
350
351 (void) pthread_mutex_lock(&soft_sessionlist_mutex);
352 /* Reset all_sessions_closing flag. */
353 all_sessions_closing = 0;
354 (void) pthread_mutex_unlock(&soft_sessionlist_mutex);
355
356 softtoken_initialized = B_FALSE;
357 softtoken_pid = 0;
358
359 /*
360 * There used to be calls to cleanup libcryptoutil here. Given that
361 * libcryptoutil can be linked and invoked independently of PKCS#11,
362 * cleaning up libcryptoutil here makes no sense. Decoupling these
363 * two also prevent deadlocks and other artificial dependencies.
364 */
365
366 /* Destroy the session list lock here */
367 (void) pthread_mutex_destroy(&soft_sessionlist_mutex);
368
369 /*
370 * Destroy token object related stuffs
371 * 1. Clean up the token object list
372 * 2. Destroy slot mutex
373 * 3. Destroy mutex in token_session
374 */
375 soft_delete_all_in_core_token_objects(ALL_TOKEN);
376 (void) pthread_mutex_destroy(&soft_slot.slot_mutex);
377 (void) pthread_mutex_destroy(&soft_slot.keystore_mutex);
378 (void) soft_destroy_token_session();
379
380 /*
381 * free all entries in the delay_freed list
382 */
383 delay_free_obj = obj_delay_freed.first;
384 while (delay_free_obj != NULL) {
|