[pkg-opensc-commit] [pkcs11-helper] 13/17: Added new slot event mode (poll vs fetch)

Eric Dorland eric at moszumanska.debian.org
Fri Jan 6 23:40:01 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to tag pkcs11-helper-1.04
in repository pkcs11-helper.

commit 995eb139fa2d62400b917490f36af7231c5e6564
Author: alonbl <alonbl at 485eb718-1723-0410-b8a9-88cf21a28c35>
Date:   Fri Aug 31 00:37:28 2007 +0000

    Added new slot event mode (poll vs fetch)
---
 ChangeLog                                |  2 +
 include/pkcs11-helper-1.0/pkcs11h-core.h |  2 +
 lib/pkcs11h-slotevent.c                  | 97 ++++++++++++++++++++++----------
 tests/test-slotevent/test-slotevent.c    | 58 +++++++++++++++++++
 4 files changed, 128 insertions(+), 31 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b9e64af..00c7164 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@ $Id$
 
 * Added NSS crypto enigne.
 
+* Added new slotevent mode (poll vs fetch).
+
 2007-06-13 - Version 1.03
 
 * Autoconf fixups.
diff --git a/include/pkcs11-helper-1.0/pkcs11h-core.h b/include/pkcs11-helper-1.0/pkcs11h-core.h
index 7a4b9e5..270f7f3 100644
--- a/include/pkcs11-helper-1.0/pkcs11h-core.h
+++ b/include/pkcs11-helper-1.0/pkcs11h-core.h
@@ -158,6 +158,8 @@ extern "C" {
 #define PKCS11H_SLOTEVENT_METHOD_TRIGGER	1
 /** Force poll. */
 #define PKCS11H_SLOTEVENT_METHOD_POLL		2
+/** Force fetch. */
+#define PKCS11H_SLOTEVENT_METHOD_FETCH		3
 /** @} */
 
 /**
diff --git a/lib/pkcs11h-slotevent.c b/lib/pkcs11h-slotevent.c
index c533521..f49f007 100644
--- a/lib/pkcs11h-slotevent.c
+++ b/lib/pkcs11h-slotevent.c
@@ -131,59 +131,94 @@ __pkcs11h_slotevent_provider (
 		provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_AUTO ||
 		provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_TRIGGER
 	) { 
-		if (
-			provider->f->C_WaitForSlotEvent (
-				CKF_DONT_BLOCK,
+		_PKCS11H_DEBUG (
+			PKCS11H_LOG_DEBUG1,
+			"PKCS#11: Setup slotevent provider='%s' checking trigger",
+			provider->manufacturerID
+		);
+
+		while (
+			!_g_pkcs11h_data->slotevent.should_terminate &&
+			provider->enabled &&
+			(rv = provider->f->C_WaitForSlotEvent (
+				0,
 				&slot,
 				NULL_PTR
-			) == CKR_FUNCTION_NOT_SUPPORTED
+			)) == CKR_OK
 		) {
 			_PKCS11H_DEBUG (
 				PKCS11H_LOG_DEBUG1,
-				"PKCS#11: Setup slotevent provider='%s' mode is poll",
+				"PKCS#11: Slotevent provider='%s' event",
 				provider->manufacturerID
 			);
 
-			provider->slot_event_method = PKCS11H_SLOTEVENT_METHOD_POLL;
+			_pkcs11h_threading_condSignal (&_g_pkcs11h_data->slotevent.cond_event);
 		}
-		else {
-			_PKCS11H_DEBUG (
-				PKCS11H_LOG_DEBUG1,
-				"PKCS#11: Setup slotevent provider='%s' mode is trigger",
-				provider->manufacturerID
-			);
 
-			provider->slot_event_method = PKCS11H_SLOTEVENT_METHOD_TRIGGER;
+		if (rv != CKR_FUNCTION_NOT_SUPPORTED) {
+			goto cleanup;
 		}
 	}
 
-	if (provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_TRIGGER) {
+	if (
+		provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_AUTO ||
+		provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_POLL
+	) { 
+		_PKCS11H_DEBUG (
+			PKCS11H_LOG_DEBUG1,
+			"PKCS#11: Setup slotevent provider='%s' checking poll",
+			provider->manufacturerID
+		);
+		PKCS11H_BOOL had_sleep = TRUE;
+
 		while (
 			!_g_pkcs11h_data->slotevent.should_terminate &&
 			provider->enabled &&
-			(rv = provider->f->C_WaitForSlotEvent (
-				0,
-				&slot,
-				NULL_PTR
-			)) == CKR_OK
+			(
+				(rv = provider->f->C_WaitForSlotEvent (
+					CKF_DONT_BLOCK,
+					&slot,
+					NULL_PTR
+				)) == CKR_OK ||
+				rv == CKR_NO_EVENT
+			)
 		) {
-			_PKCS11H_DEBUG (
-				PKCS11H_LOG_DEBUG1,
-				"PKCS#11: Slotevent provider='%s' event",
-				provider->manufacturerID
-			);
+			if (rv == CKR_OK) {
+				if (had_sleep) {
+					_PKCS11H_DEBUG (
+						PKCS11H_LOG_DEBUG1,
+						"PKCS#11: Slotevent provider='%s' event",
+						provider->manufacturerID
+					);
 
-			_pkcs11h_threading_condSignal (&_g_pkcs11h_data->slotevent.cond_event);
+					had_sleep = FALSE; /* Mask out seq events */
+					_pkcs11h_threading_condSignal (&_g_pkcs11h_data->slotevent.cond_event);
+				}
+			}
+			else {
+				_pkcs11h_threading_sleep (provider->slot_poll_interval);
+				had_sleep = TRUE;
+			}
 		}
 
-		if (rv != CKR_OK) {
+		if (rv != CKR_FUNCTION_NOT_SUPPORTED) {
 			goto cleanup;
 		}
 	}
-	else {
+
+	if (
+		provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_AUTO ||
+		provider->slot_event_method == PKCS11H_SLOTEVENT_METHOD_FETCH
+	) { 
 		unsigned long last_checksum = 0;
 		PKCS11H_BOOL is_first_time = TRUE;
 
+		_PKCS11H_DEBUG (
+			PKCS11H_LOG_DEBUG1,
+			"PKCS#11: Setup slotevent provider='%s' checking fetch",
+			provider->manufacturerID
+		);
+
 		while (
 			!_g_pkcs11h_data->slotevent.should_terminate &&
 			provider->enabled
@@ -260,13 +295,13 @@ __pkcs11h_slotevent_provider (
 				_pkcs11h_mem_free ((void *)&slots);
 			}
 			
-			if (!_g_pkcs11h_data->slotevent.should_terminate) {
-				_pkcs11h_threading_sleep (provider->slot_poll_interval);
-			}
-
 			if (rv != CKR_OK) {
 				goto cleanup;
 			}
+
+			if (!_g_pkcs11h_data->slotevent.should_terminate) {
+				_pkcs11h_threading_sleep (provider->slot_poll_interval);
+			}
 		}
 	}
 
diff --git a/tests/test-slotevent/test-slotevent.c b/tests/test-slotevent/test-slotevent.c
index 7dfccc2..b2b929a 100644
--- a/tests/test-slotevent/test-slotevent.c
+++ b/tests/test-slotevent/test-slotevent.c
@@ -76,6 +76,34 @@ int main () {
 		fatal ("pkcs11h_setSlotEventHook failed", rv);
 	}
 
+	printf ("Adding provider '%s' as auto\n", TEST_PROVIDER);
+
+	if (
+		(rv = pkcs11h_addProvider (
+			TEST_PROVIDER,
+			TEST_PROVIDER,
+			FALSE,
+			PKCS11H_PRIVATEMODE_MASK_AUTO,
+			PKCS11H_SLOTEVENT_METHOD_AUTO,
+			0,
+			FALSE
+		)) != CKR_OK
+	) {
+		fatal ("pkcs11h_terminate failed", rv);
+	}
+
+	printf ("Please remove and insert tokens (pause for 30 seconds)\n");
+
+#if defined(_WIN32)
+	Sleep (30*1024);
+#else
+	sleep (30);
+#endif
+
+	if ((rv = pkcs11h_removeProvider (TEST_PROVIDER)) != CKR_OK) {
+		fatal ("pkcs11h_removeProvider failed", rv);
+	}
+
 	printf ("Adding provider '%s' as trigger\n", TEST_PROVIDER);
 
 	if (
@@ -128,6 +156,36 @@ int main () {
 	sleep (30);
 #endif
 
+	printf ("Adding provider '%s' as fetch\n", TEST_PROVIDER);
+
+	if (
+		(rv = pkcs11h_addProvider (
+			TEST_PROVIDER,
+			TEST_PROVIDER,
+			FALSE,
+			PKCS11H_PRIVATEMODE_MASK_AUTO,
+			PKCS11H_SLOTEVENT_METHOD_FETCH,
+			0,
+			FALSE
+		)) != CKR_OK
+	) {
+		fatal ("pkcs11h_terminate failed", rv);
+	}
+
+	printf ("Please remove and insert tokens (pause for 30 seconds)\n");
+
+#if defined(_WIN32)
+	Sleep (30*1024);
+#else
+	sleep (30);
+#endif
+
+	printf ("Terminating pkcs11-helper\n");
+
+	if ((rv = pkcs11h_terminate ()) != CKR_OK) {
+		fatal ("pkcs11h_terminate failed", rv);
+	}
+
 	printf ("Terminating pkcs11-helper\n");
 
 	if ((rv = pkcs11h_terminate ()) != CKR_OK) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/pkcs11-helper.git



More information about the pkg-opensc-commit mailing list