]> granicus.if.org Git - p11-kit/commitdiff
Don't complain when applications call C_Logout or C_Login
authorStef Walter <stefw@gnome.org>
Thu, 28 Mar 2013 16:54:39 +0000 (17:54 +0100)
committerStef Walter <stefw@gnome.org>
Thu, 28 Mar 2013 16:54:39 +0000 (17:54 +0100)
Some callers erroneously call our C_Logout function, like NSS.
So return appropriate error codes in these cases.

https://bugs.freedesktop.org/show_bug.cgi?id=62874

trust/module.c
trust/tests/test-module.c

index 6be28470afa45e63f52953919bd35709720d1229..51a75e02969e989fa923ead663be8779cb6d9f6d 100644 (file)
@@ -855,13 +855,41 @@ sys_C_Login (CK_SESSION_HANDLE handle,
              CK_UTF8CHAR_PTR pin,
              CK_ULONG pin_len)
 {
-       return_val_if_reached (CKR_FUNCTION_NOT_SUPPORTED);
+       CK_RV rv;
+
+       p11_debug ("in");
+
+       p11_lock ();
+
+               rv = lookup_session (handle, NULL);
+               if (rv == CKR_OK)
+                       rv = CKR_USER_TYPE_INVALID;
+
+       p11_unlock ();
+
+       p11_debug ("out: 0x%lx", rv);
+
+       return rv;
 }
 
 static CK_RV
 sys_C_Logout (CK_SESSION_HANDLE handle)
 {
-       return_val_if_reached (CKR_FUNCTION_NOT_SUPPORTED);
+       CK_RV rv;
+
+       p11_debug ("in");
+
+       p11_lock ();
+
+               rv = lookup_session (handle, NULL);
+               if (rv == CKR_OK)
+                       rv = CKR_USER_NOT_LOGGED_IN;
+
+       p11_unlock ();
+
+       p11_debug ("out: 0x%lx", rv);
+
+       return rv;
 }
 
 static CK_RV
index 1033b054bae858724a07bef7e4faa4a343ff0c91..c92e1c3cea45736620e6973fa10c461e3efb265c 100644 (file)
@@ -867,6 +867,28 @@ test_find_serial_der_decoded (CuTest *cu)
        teardown (cu);
 }
 
+static void
+test_login_logout (CuTest *cu)
+{
+       CK_SESSION_HANDLE session;
+       CK_RV rv;
+
+       setup (cu);
+
+       rv = test.module->C_OpenSession (test.slots[0], CKF_SERIAL_SESSION, NULL, NULL, &session);
+       CuAssertTrue (cu, rv == CKR_OK);
+
+       /* Just testing our stubs for now */
+
+       rv = test.module->C_Login (session, CKU_USER, NULL, 0);
+       CuAssertTrue (cu, rv == CKR_USER_TYPE_INVALID);
+
+       rv = test.module->C_Logout (session);
+       CuAssertTrue (cu, rv == CKR_USER_NOT_LOGGED_IN);
+
+       teardown (cu);
+}
+
 int
 main (void)
 {
@@ -894,6 +916,7 @@ main (void)
        SUITE_ADD_TEST (suite, test_session_remove);
        SUITE_ADD_TEST (suite, test_session_setattr);
        SUITE_ADD_TEST (suite, test_find_serial_der_decoded);
+       SUITE_ADD_TEST (suite, test_login_logout);
 
        CuSuiteRun (suite);
        CuSuiteSummary (suite, output);