Do not try to log in if we already have a user session
authorMartin Willi <martin@revosec.ch>
Mon, 19 Jul 2010 13:53:31 +0000 (15:53 +0200)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Aug 2010 07:26:21 +0000 (09:26 +0200)
src/libstrongswan/plugins/pkcs11/pkcs11_private_key.c

index fa96c7f..0f3c4b7 100644 (file)
@@ -340,8 +340,21 @@ static bool login(private_pkcs11_private_key_t *this, chunk_t keyid, int slot)
        shared_key_t *shared;
        chunk_t pin;
        CK_RV rv;
+       CK_SESSION_INFO info;
        bool found = FALSE, success = FALSE;
 
+       rv = this->lib->f->C_GetSessionInfo(this->session, &info);
+       if (rv != CKR_OK)
+       {
+               DBG1(DBG_CFG, "C_GetSessionInfo failed: %N", ck_rv_names, rv);
+               return FALSE;
+       }
+       if (info.state != CKS_RO_PUBLIC_SESSION &&
+               info.state != CKS_RW_PUBLIC_SESSION)
+       {       /* already logged in with another session, skip */
+               return TRUE;
+       }
+
        id = identification_create_from_encoding(ID_KEY_ID, keyid);
        enumerator = lib->credmgr->create_shared_enumerator(lib->credmgr,
                                                                                                                SHARED_PIN, id, NULL);