[Pcsclite-cvs-commit] PKCS11/src crackcert.c,1.1,1.1.2.1 p11_crypt.c,1.10,1.10.2.1 p11_digest.c,1.4,1.4.4.1 p11_dual.c,1.4,1.4.4.1 p11_ext.c,1.4,1.4.4.1 p11_general.c,1.11,1.11.2.1 p11_key.c,1.10,1.10.2.1 p11_object.c,1.23,1.23.2.1 p11_parallel.c,1.4,1.4.4.1 p11_random.c,1.5,1.5.4.1 p11_session.c,1.12,1.12.2.1 p11_sign.c,1.13,1.13.2.1 p11_token.c,1.14,1.14.2.1 p11_verify.c,1.5,1.5.4.1 p11x_async.c,1.12,1.12.4.1 p11x_bio.c,1.1,1.1.4.1 p11x_error.c,1.5,1.5.4.1 p11x_log.c,1.8,1.8.4.1 p11x_msc.c,1.9,1.9.2.1 p11x_object.c,1.42,1.42.2.1 p11x_prefs.c,1.10,1.10.2.1 p11x_session.c,1.6,1.6.2.1 p11x_slot.c,1.30,1.30.2.1 p11x_state.c,1.16,1.16.2.1 p11x_thread.c,1.8,1.8.2.1 p11x_unixdll.c,1.3,1.3.4.1 p11x_util.c,1.11,1.11.2.1 p11x_win32dll.c,1.4,1.4.4.1

corcoran-guest@quantz.debian.org corcoran-guest@quantz.debian.org
Sat, 31 Jan 2004 01:21:25 +0100


Update of /cvsroot/muscleapps/PKCS11/src
In directory quantz:/tmp/cvs-serv13260/src

Modified Files:
      Tag: corcoran-013004
	crackcert.c p11_crypt.c p11_digest.c p11_dual.c p11_ext.c 
	p11_general.c p11_key.c p11_object.c p11_parallel.c 
	p11_random.c p11_session.c p11_sign.c p11_token.c p11_verify.c 
	p11x_async.c p11x_bio.c p11x_error.c p11x_log.c p11x_msc.c 
	p11x_object.c p11x_prefs.c p11x_session.c p11x_slot.c 
	p11x_state.c p11x_thread.c p11x_unixdll.c p11x_util.c 
	p11x_win32dll.c 
Log Message:
Some bug fixes and changes placed on branch.  Passes test suite.




Index: crackcert.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/crackcert.c,v
retrieving revision 1.1
retrieving revision 1.1.2.1
diff -u -d -r1.1 -r1.1.2.1

Index: p11_crypt.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_crypt.c,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -d -r1.10 -r1.10.2.1

Index: p11_digest.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_digest.c,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -d -r1.4 -r1.4.4.1

Index: p11_dual.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_dual.c,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -d -r1.4 -r1.4.4.1

Index: p11_ext.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_ext.c,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -d -r1.4 -r1.4.4.1

Index: p11_general.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_general.c,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -d -r1.11 -r1.11.2.1

Index: p11_key.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_key.c,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -d -r1.10 -r1.10.2.1

Index: p11_object.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_object.c,v
retrieving revision 1.23
retrieving revision 1.23.2.1
diff -u -d -r1.23 -r1.23.2.1

Index: p11_parallel.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_parallel.c,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -d -r1.4 -r1.4.4.1

Index: p11_random.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_random.c,v
retrieving revision 1.5
retrieving revision 1.5.4.1
diff -u -d -r1.5 -r1.5.4.1

Index: p11_session.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_session.c,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -d -r1.12 -r1.12.2.1

Index: p11_sign.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_sign.c,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -d -r1.13 -r1.13.2.1
--- p11_sign.c	4 Oct 2003 08:30:18 -0000	1.13
+++ p11_sign.c	31 Jan 2004 00:21:23 -0000	1.13.2.1
@@ -107,8 +107,15 @@
 
     if (CKR_ERROR(rv = slot_TokenChanged()))
         rv = CKR_SESSION_HANDLE_INVALID;
-    else if (!pData || !pSignature)
+    else if (!pData)
         rv = CKR_ARGUMENTS_BAD;
+   /* Fix if NULL is passed it should return key length */
+   else if (!pSignature)
+   {
+        *pulSignatureLen = key->msc_key->keySize / 8;
+        rv = CKR_OK;
+   }
+
 /*
 	else if (INVALID_SESSION)
         rv = CKR_SESSION_HANDLE_INVALID;
@@ -147,6 +154,16 @@
             log_Log(LOG_LOW, "Pad and Sign object keyNum: %lu tlen: %lu", 
                     key->msc_key->keyNum, tlen);
 
+#ifdef PKCS11_DEBUG_SIGNATURE
+           { 
+              CK_BYTE *buf;
+              buf = (CK_BYTE *)malloc((ulDataLen * 3) + 1);
+              object_BinToHex(pData, ulDataLen, buf);
+              log_Log(LOG_LOW, "Data to Sign: %s", buf);
+              free(buf); 
+           }
+#endif
+
             if (!to)
                 rv = CKR_HOST_MEMORY;
             else if (!padRSAType1(to, tlen, pData, ulDataLen))
@@ -168,6 +185,17 @@
                                            pSignature,
                                            pulSignatureLen)))
             rv = CKR_FUNCTION_FAILED;
+
+#ifdef PKCS11_DEBUG_SIGNATURE
+            { 
+	      CK_BYTE *buf;
+              buf = (CK_BYTE *)malloc((*pulSignatureLen * 3) + 1);
+              object_BinToHex(pSignature, *pulSignatureLen, buf);
+              log_Log(LOG_LOW, "Returned Signature: %s", buf);
+              free(buf); 
+            }
+#endif
+
         }
         else if (ulValue & MSC_CAPABLE_RSA_PKCS1)
         {
@@ -180,6 +208,16 @@
             log_Log(LOG_LOW, "Sign object keyNum: %lu DataLen: %lu", 
                     key->msc_key->keyNum, ulDataLen);
 
+#ifdef PKCS11_DEBUG_SIGNATURE
+            { 
+	      CK_BYTE *buf;
+              buf = (CK_BYTE *)malloc((ulDataLen * 3) + 1);
+              object_BinToHex(pData, ulDataLen, buf);
+              log_Log(LOG_LOW, "Data to Sign: %s", buf);
+              free(buf); 
+            }
+#endif
+
             if (MSC_ERROR(msc_ComputeCrypt(
                             slot,
                             slotID,
@@ -190,18 +228,68 @@
                             pSignature,
                             pulSignatureLen)))
                 rv = CKR_FUNCTION_FAILED;
-        } else
+
+#ifdef PKCS11_DEBUG_SIGNATURE
+            { 
+              CK_BYTE *buf;
+              buf = (CK_BYTE *)malloc((*pulSignatureLen * 3) + 1);
+              object_BinToHex(pSignature, *pulSignatureLen, buf);
+              log_Log(LOG_LOW, "Returned Signature: %s", buf);
+              free(buf); 
+            }
+#endif
+
+        }
+        else
             rv = CKR_MECHANISM_PARAM_INVALID;
 
         (void)CKR_ERROR(slot_EndTransaction(session->session.slotID, MSC_LEAVE_TOKEN));
     }
+    else if (session->sign_mech.mechanism == CKM_RSA_X_509)
+    {
+        cryptInit.keyNum = key->msc_key->keyNum;
+        cryptInit.cipherMode = MSC_MODE_RSA_NOPAD;
+        cryptInit.cipherDirection = MSC_DIR_SIGN;
+        cryptInit.optParams = 0;
+        cryptInit.optParamsSize = 0;
+
+        tlen = key->msc_key->keySize / 8;
+        to = (CK_BYTE *)malloc(tlen);
+
+        log_Log(LOG_LOW, "Sign object keyNum: %lu tlen: %lu", key->msc_key->keyNum, tlen);
+
+        if (!to)
+            rv = CKR_HOST_MEMORY;
+        else if (ulDataLen > tlen)
+            rv = CKR_DATA_LEN_RANGE;
+        else
+        {
+            memcpy(to, pData, ulDataLen);
+
+            if (tlen > ulDataLen)
+               memset(&to[ulDataLen], 0x00, tlen - ulDataLen);
+        }
+
+        if (!CKR_ERROR_NOLOG(rv) && MSC_ERROR(msc_ComputeCrypt(
+                                              slot, slotID, &slot->conn,
+                                              &cryptInit,
+                                              to,
+                                              tlen,
+                                              pSignature,
+                                              pulSignatureLen)))
+            rv = CKR_FUNCTION_FAILED;
+
+        (void)CKR_ERROR(slot_EndTransaction(session->session.slotID, MSC_LEAVE_TOKEN));
+    }
     else
     {
         (void)CKR_ERROR(slot_EndTransaction(session->session.slotID, MSC_LEAVE_TOKEN));
         rv = CKR_MECHANISM_INVALID;
     }
 
-    session->sign_key = 0;
+    /* Fix - if function is queried for signature length */
+    if (pSignature)
+        session->sign_key = 0;
 
     if (to)
         free(to);

Index: p11_token.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_token.c,v
retrieving revision 1.14
retrieving revision 1.14.2.1
diff -u -d -r1.14 -r1.14.2.1

Index: p11_verify.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11_verify.c,v
retrieving revision 1.5
retrieving revision 1.5.4.1
diff -u -d -r1.5 -r1.5.4.1

Index: p11x_async.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_async.c,v
retrieving revision 1.12
retrieving revision 1.12.4.1
diff -u -d -r1.12 -r1.12.4.1

Index: p11x_bio.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_bio.c,v
retrieving revision 1.1
retrieving revision 1.1.4.1
diff -u -d -r1.1 -r1.1.4.1

Index: p11x_error.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_error.c,v
retrieving revision 1.5
retrieving revision 1.5.4.1
diff -u -d -r1.5 -r1.5.4.1

Index: p11x_log.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_log.c,v
retrieving revision 1.8
retrieving revision 1.8.4.1
diff -u -d -r1.8 -r1.8.4.1
--- p11x_log.c	11 Jun 2002 02:26:46 -0000	1.8
+++ p11x_log.c	31 Jan 2004 00:21:23 -0000	1.8.4.1
@@ -3,7 +3,7 @@
 **  $Id$
 **
 **  Package: PKCS-11
-**  Author : Chris Osgood <oznet@mac.com>
+**  Author : Chris Osgood <cosgood@functionalfuture.com>
 **  License: Copyright (C) 2002 Schlumberger Network Solutions
 **           <http://www.slb.com/sns>
 **  Purpose: Logging functions
@@ -97,11 +97,18 @@
     FILE *fp;
     time_t t;
     struct tm *time_s;
-    char format[256];
+    char *format;
 
     if (st.prefs.log_level > level)
         return;
 
+    format = malloc(strlen(msg) + 32);
+    if (!format)
+    {
+        fprintf(stderr, "memory alloc failed in log_Log()\n");
+        return;
+    }
+
     thread_MutexLock(st.log_lock);
 
     fp = fopen((char *)st.prefs.log_filename, "ab");
@@ -116,8 +123,8 @@
     time_s = localtime(&t);
 
     sprintf(format, "%.2d/%.2d %.2d:%.2d:%.2d %s", 
-                    time_s->tm_mday, 
                     time_s->tm_mon+1, 
+                    time_s->tm_mday, 
                     time_s->tm_hour, 
                     time_s->tm_min, 
                     time_s->tm_sec, 
@@ -126,6 +133,8 @@
     va_start(args, msg);
     vfprintf(fp, format, args);
     va_end(args);
+
+    free(format);
     
 #ifdef WIN32
     fputs("\r\n", fp);

Index: p11x_msc.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_msc.c,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -d -r1.9 -r1.9.2.1

Index: p11x_object.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_object.c,v
retrieving revision 1.42
retrieving revision 1.42.2.1
diff -u -d -r1.42 -r1.42.2.1
--- p11x_object.c	28 Nov 2003 09:47:13 -0000	1.42
+++ p11x_object.c	31 Jan 2004 00:21:23 -0000	1.42.2.1
@@ -3,7 +3,7 @@
 **  $Id$
 **
 **  Package: PKCS-11
-**  Author : Chris Osgood <oznet@mac.com>
+**  Author : Chris Osgood <cosgood@functionalfuture.com>
 **  License: Copyright (C) 2002 Schlumberger Network Solutions
 **           <http://www.slb.com/sns>
 **  Purpose: Session & object management functions
@@ -710,30 +710,20 @@
         }
         else
         {
-            {
-              CK_BYTE *buf; 
-              int len = attrib->ulValueLen;
-
-              /* be sure object_GetAttrib() worked before dereferencing
-               * obj_attrib */
-              if ((rv == CKR_OK) && (obj_attrib->attrib.ulValueLen > len))
-                  len = obj_attrib->attrib.ulValueLen;
- 
-              buf = (CK_BYTE *)malloc((len * 3) + 1);
-              if (buf == NULL)
-                  return CKR_HOST_MEMORY;
+            { CK_BYTE* buf = malloc(attrib->ulValueLen * 4);
               object_BinToHex((CK_BYTE *)forward, attrib->ulValueLen, buf); 
               log_Log(LOG_LOW, "Orig:%s", buf);
               object_BinToHex((CK_BYTE *)reverse, attrib->ulValueLen, buf); 
               log_Log(LOG_LOW, " Rev:%s", buf);
+              free(buf);
     
               if (rv == CKR_OK)
-              {
+              { 
+                  CK_BYTE* buf = malloc(obj_attrib->attrib.ulValueLen * 4);
                   object_BinToHex((CK_BYTE *)obj_attrib->attrib.pValue, obj_attrib->attrib.ulValueLen, buf); 
-                  log_Log(LOG_LOW, " Obj:%s", buf);
-              }
-
-              free(buf);
+                  log_Log(LOG_LOW, " Obj:%s", buf); 
+                  free(buf);
+              } 
             }
     
             rv = 0;
@@ -2155,6 +2145,8 @@
             rv = CKR_HOST_MEMORY;
         else
         {
+
+#ifndef USE_PRIVATE_EXPONENT
             object->msc_key->keyNum = keyNum;
             object->msc_key->keyType = MSC_KEY_RSA_PRIVATE_CRT;
             object->msc_key->keySize = (MSCUShort16)keySize;
@@ -2189,6 +2181,34 @@
             keyBlob[keyBlobSize++] = (CK_BYTE)exponent_2->attrib.ulValueLen;
             memcpy(&keyBlob[keyBlobSize], exponent_2->attrib.pValue, exponent_2->attrib.ulValueLen);
             keyBlobSize += exponent_2->attrib.ulValueLen;
+
+#else
+
+            object->msc_key->keyNum = keyNum;
+            object->msc_key->keyType = MSC_KEY_RSA_PRIVATE;
+            object->msc_key->keySize = (MSCUShort16)keySize;
+            object->msc_key->keyPolicy.cipherDirection = MSC_KEYPOLICY_DIR_SIGN | MSC_KEYPOLICY_DIR_DECRYPT;
+            object->msc_key->keyPolicy.cipherMode = MSC_KEYPOLICY_MODE_RSA_PAD_PKCS1;
+            object->msc_key->keyACL.readPermission = MSC_AUT_NONE;
+            object->msc_key->keyACL.writePermission = (MSCUShort16)object_MapPIN(st.prefs.user_pin_num);
+            object->msc_key->keyACL.usePermission = (MSCUShort16)object_MapPIN(st.prefs.user_pin_num);
+    
+            keyBlobSize = 0;
+            keyBlob[keyBlobSize++] = MSC_BLOB_ENC_PLAIN;
+            keyBlob[keyBlobSize++] = object->msc_key->keyType;
+            keyBlob[keyBlobSize++] = (CK_BYTE)(object->msc_key->keySize >> 8);
+            keyBlob[keyBlobSize++] = (CK_BYTE)object->msc_key->keySize;
+            keyBlob[keyBlobSize++] = (CK_BYTE)(modulus->attrib.ulValueLen >> 8);
+            keyBlob[keyBlobSize++] = (CK_BYTE)modulus->attrib.ulValueLen;
+            memcpy(&keyBlob[keyBlobSize], modulus->attrib.pValue, 
+				   modulus->attrib.ulValueLen);
+            keyBlobSize += modulus->attrib.ulValueLen;
+            keyBlob[keyBlobSize++] = (CK_BYTE)(private_exponent->attrib.ulValueLen >> 8);
+            keyBlob[keyBlobSize++] = (CK_BYTE)private_exponent->attrib.ulValueLen;
+            memcpy(&keyBlob[keyBlobSize], private_exponent->attrib.pValue, 
+				   private_exponent->attrib.ulValueLen);
+            keyBlobSize += private_exponent->attrib.ulValueLen;
+#endif
 
             { CK_BYTE *buf;
               buf = (CK_BYTE *)malloc((keyBlobSize * 3) + 1);

Index: p11x_prefs.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_prefs.c,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -d -r1.10 -r1.10.2.1
--- p11x_prefs.c	4 Oct 2003 08:28:02 -0000	1.10
+++ p11x_prefs.c	31 Jan 2004 00:21:23 -0000	1.10.2.1
@@ -265,10 +265,10 @@
  * the trailing slash or backslash.
  * It is the caller's responsibility to free() the buffer that is returned.
  */
-#ifdef WIN32
 static char*
 getDLLDirectory()
 {
+#ifdef WIN32
     char *buf=NULL;
     const DWORD INCREMENT = 5;
     DWORD avail = INCREMENT;
@@ -314,8 +314,10 @@
 loser:
     free(buf);
     return NULL;
-}
+#else
+    return NULL;
 #endif
+}
 
 /******************************************************************************
 ** Function: util_ReadPreferences
@@ -341,7 +343,12 @@
     char rcfilename[] = "/.pkcs11rc";
     char buf[1024];
 
-    strncpy(rcfilepath, getenv("HOME"), sizeof(rcfilepath) - sizeof(rcfilename) - 1);
+   if (getenv("HOME")) {
+        strncpy(rcfilepath, getenv("HOME"), sizeof(rcfilepath) - sizeof(rcfilename) - 1);
+    } else {
+        strncpy(rcfilepath, "/etc", sizeof(rcfilepath) - sizeof(rcfilename) - 1);
+    }
+
     strcat(rcfilepath, rcfilename);
 
     fp = fopen(rcfilepath, "rb");

Index: p11x_session.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_session.c,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -d -r1.6 -r1.6.2.1
--- p11x_session.c	4 Oct 2003 08:30:18 -0000	1.6
+++ p11x_session.c	31 Jan 2004 00:21:23 -0000	1.6.2.1
@@ -12,31 +12,31 @@
 
 #include "cryptoki.h"
 
-/******************************************************************************
-** Function: session_LookupSession
-**
-** Looks up the session in the hash table, given its handle.
-**
-** Parameters:
-**  handle - handle of the session
-**
-** Returns:
-**  Pointer to the session with the given handle, if found.
-**  NULL if no session is found with the given handle.
-*******************************************************************************/
-P11_Session*
-session_LookupSession(CK_SESSION_HANDLE handle)
-{
-    P11_Session *cur;
-
-    cur = st.session_hash[handle % NUM_SESSION_HASH_SLOTS];
-    for( ; cur ; cur = cur->hnext) {
-        if( cur->handle == handle ) {
-            return cur;
-        }
-    }
-    return NULL;
-}
+/******************************************************************************
+** Function: session_LookupSession
+**
+** Looks up the session in the hash table, given its handle.
+**
+** Parameters:
+**  handle - handle of the session
+**
+** Returns:
+**  Pointer to the session with the given handle, if found.
+**  NULL if no session is found with the given handle.
+*******************************************************************************/
+P11_Session*
+session_LookupSession(CK_SESSION_HANDLE handle)
+{
+    P11_Session *cur;
+
+    cur = st.session_hash[handle % NUM_SESSION_HASH_SLOTS];
+    for( ; cur ; cur = cur->hnext) {
+        if( cur->handle == handle ) {
+            return cur;
+        }
+    }
+    return NULL;
+}
 
 /******************************************************************************
 ** Function: session_AddSession
@@ -44,7 +44,7 @@
 ** Adds a new session 
 **
 ** Parameters:
-**  phandle - Returns the handle for the new session
+**  phandle - Returns the handle for the new session
 **  psession - Returns a pointer to the new session
 **
 ** Returns:
@@ -54,7 +54,7 @@
 CK_RV session_AddSession(CK_SESSION_HANDLE *phandle, P11_Session **psession)
 {
     CK_RV rv = CKR_OK;
-    unsigned int idx;
+    unsigned int idx;
 
     if (st.sessions)
     {
@@ -64,9 +64,9 @@
 			goto finish;
         }
 
-		st.sessions->prev->next = st.sessions;
-        st.sessions = st.sessions->prev;
-        st.sessions->check = st.sessions;
+		st.sessions->prev->next = st.sessions;
+        st.sessions = st.sessions->prev;
+        st.sessions->check = st.sessions;
 
     }
     else
@@ -76,30 +76,30 @@
             rv = CKR_HOST_MEMORY;
 			goto finish;    
 		}
-
-		st.sessions->check = st.sessions;
+
+		st.sessions->check = st.sessions;
 
     }
 
-	*psession = st.sessions;
-
-    /*
-     * Find an unused session handle
-     */
-    do {
-        st.last_session_handle++;
-    } while( (st.last_session_handle == CK_INVALID_HANDLE) ||
-             session_LookupSession(st.last_session_handle)    );
-    *phandle = st.last_session_handle;
-    (*psession)->handle = st.last_session_handle;
-
-    /*
-     * Put this session in the session hashtable
-     */
-    idx = (*psession)->handle % NUM_SESSION_HASH_SLOTS;
-    (*psession)->hnext = st.session_hash[idx];
-    st.session_hash[idx] = *psession;
+	*psession = st.sessions;
 
+    /*
+     * Find an unused session handle
+     */
+    do {
+        st.last_session_handle++;
+    } while( (st.last_session_handle == CK_INVALID_HANDLE) ||
+             session_LookupSession(st.last_session_handle)    );
+    *phandle = st.last_session_handle;
+    (*psession)->handle = st.last_session_handle;
+
+    /*
+     * Put this session in the session hashtable
+     */
+    idx = (*psession)->handle % NUM_SESSION_HASH_SLOTS;
+    (*psession)->hnext = st.session_hash[idx];
+    st.session_hash[idx] = *psession;
+
 finish:
     return rv;
 }
@@ -122,47 +122,47 @@
 	unsigned int idx;
 
 
-      log_Log(LOG_LOW, "Removing session: %lX", session->handle);
-
-	  /*
-	  * take the session out of the session hashtable
-      */
-    idx = session->handle % NUM_SESSION_HASH_SLOTS;
-    if( st.session_hash[idx] == session ) {
-        /* first session in the list */
-        st.session_hash[idx] = session->hnext;
-    } else {
-        P11_Session *prev = st.session_hash[idx];
-        while( prev->hnext != session ) {
+      log_Log(LOG_LOW, "Removing session: %lX", session->handle);
+
+	  /*
+	  * take the session out of the session hashtable
+      */
+    idx = session->handle % NUM_SESSION_HASH_SLOTS;
+    if( st.session_hash[idx] == session ) {
+        /* first session in the list */
+        st.session_hash[idx] = session->hnext;
+    } else {
+        P11_Session *prev = st.session_hash[idx];
+        while( prev->hnext != session ) {
             prev = prev->hnext;
         }
-        prev->hnext = prev->hnext->hnext;
-    }
+        prev->hnext = prev->hnext->hnext;
+    }
 
-    /*
-     * Take the session out of the session list
-     */
+    /*
+     * Take the session out of the session list
+     */
 
-    if (session->prev) /* Fixme: check for head of list? st.sessions */
-    {
+    if (session->prev) /* Fixme: check for head of list? st.sessions */
+    {
         session->prev->next = session->next;
-        if (session == st.sessions) /* Fixme: Is this needed? */
-            st.sessions = session->prev;
-    }
-
-    if (session->next)
-    {
-        session->next->prev = session->prev;
-
-        if (session == st.sessions)
-            st.sessions = session->next;
-    }
-
-    if (!session->prev && !session->next)
-        st.sessions = 0x00;
+        if (session == st.sessions) /* Fixme: Is this needed? */
+            st.sessions = session->prev;
+    }
+
+    if (session->next)
+    {
+        session->next->prev = session->prev;
 
-    if (session->search_attrib)
-        free(session->search_attrib);
+        if (session == st.sessions)
+            st.sessions = session->next;
+    }
+
+    if (!session->prev && !session->next)
+        st.sessions = 0x00;
+
+    if (session->search_attrib)
+        free(session->search_attrib);
 
         
     /* Clear memory, just to be safe */

Index: p11x_slot.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_slot.c,v
retrieving revision 1.30
retrieving revision 1.30.2.1
diff -u -d -r1.30 -r1.30.2.1
--- p11x_slot.c	4 Oct 2003 08:30:18 -0000	1.30
+++ p11x_slot.c	31 Jan 2004 00:21:23 -0000	1.30.2.1
@@ -1224,4 +1224,3 @@
  
      return rv;
 }
-

Index: p11x_state.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_state.c,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -d -r1.16 -r1.16.2.1

Index: p11x_thread.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_thread.c,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1

Index: p11x_unixdll.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_unixdll.c,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -d -r1.3 -r1.3.4.1

Index: p11x_util.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_util.c,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -d -r1.11 -r1.11.2.1

Index: p11x_win32dll.c
===================================================================
RCS file: /cvsroot/muscleapps/PKCS11/src/p11x_win32dll.c,v
retrieving revision 1.4
retrieving revision 1.4.4.1
diff -u -d -r1.4 -r1.4.4.1