[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r5304 - in trunk/softHSM: . src/bin

Rickard Bellgrim rickard at opendnssec.org
Fri Jul 8 13:07:07 CEST 2011


Author: rb
Date: 2011-07-08 13:07:06 +0200 (Fri, 08 Jul 2011)
New Revision: 5304

Modified:
   trunk/softHSM/NEWS
   trunk/softHSM/src/bin/softhsm.cpp
Log:
Load library correctly and compatibility function for getpass


Modified: trunk/softHSM/NEWS
===================================================================
--- trunk/softHSM/NEWS	2011-07-08 10:49:21 UTC (rev 5303)
+++ trunk/softHSM/NEWS	2011-07-08 11:07:06 UTC (rev 5304)
@@ -26,6 +26,8 @@
   if an incorrect PIN has been entered at least once.
 * Windows: Detect LoadLibrary.
 * Windows: Set CRYPTOKI_EXPORTS.
+* Windows: Load library correctly softhsm.
+* Windows: Compatibility function for getpass.
 
 
 SoftHSM 1.2.1 - 2011-05-03 

Modified: trunk/softHSM/src/bin/softhsm.cpp
===================================================================
--- trunk/softHSM/src/bin/softhsm.cpp	2011-07-08 10:49:21 UTC (rev 5303)
+++ trunk/softHSM/src/bin/softhsm.cpp	2011-07-08 11:07:06 UTC (rev 5304)
@@ -48,10 +48,15 @@
 #include <iostream>
 #include <fstream>
 #include <sched.h>
-#if defined(HAVE_DLOPEN)
+
+#ifdef HAVE_DLOPEN
 #include <dlfcn.h>
 #endif
 
+#ifdef HAVE_LOADLIBRARY
+#include <windows.h>
+#endif
+
 // Includes for the crypto library
 #include <botan/auto_rng.h>
 #include <botan/rsa.h>
@@ -159,6 +164,25 @@
   { NULL,              0, NULL, 0 }
 };
 
+#ifdef WIN32
+#include <conio.h>
+char *getpass(const char *prompt) {
+  static char buf[MAX_PIN_LEN+1];
+  size_t i;
+
+  fputs(prompt, stderr);
+  fflush(stderr);
+  for(i = 0; i < sizeof(buf) - 1; i++) {
+    buf[i] = _getch();
+    if(buf[i] == '\r')
+      break;
+  }
+  buf[i] = 0;
+  fputs("\n", stderr);
+  return buf;
+}
+#endif
+
 int main(int argc, char *argv[]) {
   int option_index = 0;
   int opt;
@@ -341,7 +365,7 @@
     p11->C_Finalize(NULL_PTR);
     if(moduleHandle) {
 #if defined(HAVE_LOADLIBRARY)
-      // no idea
+      FreeLibrary((HMODULE)moduleHandle);
 #elif defined(HAVE_DLOPEN)
       dlclose(moduleHandle);
 #endif
@@ -357,20 +381,24 @@
 
 #if defined(HAVE_LOADLIBRARY)
   // Load PKCS #11 library
+  HMODULE pDynLib = NULL;
   if(module) {
-    HINSTANCE hDLL = LoadLibrary(_T(module));
+    pDynLib = LoadLibrary(module);
   } else {
-    HINSTANCE hDLL = LoadLibrary(_T(DEFAULT_PKCS11_LIB));
+    pDynLib = LoadLibrary(DEFAULT_PKCS11_LIB);
   }
 
-  if(hDLL == NULL) {
+  if(pDynLib == NULL) {
     // Failed to load the PKCS #11 library
     return NULL;
   }
 
   // Retrieve the entry point for C_GetFunctionList
-  pGetFunctionList = (CK_C_GetFunctionList) GetProcAddress(hDLL, _T("C_GetFunctionList"));
-            
+  pGetFunctionList = (CK_C_GetFunctionList) GetProcAddress(pDynLib, "C_GetFunctionList");
+
+  // Store the handle so we can close it later
+  moduleHandle = pDynLib;
+
 #elif defined(HAVE_DLOPEN)
   // Load PKCS #11 library
   void* pDynLib;




More information about the Opendnssec-commits mailing list