changeset 219:57bef180d560

Add debug output and make windowsstore linkable from C++ code
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 26 Mar 2014 20:16:50 +0100
parents 8fb12af98960
children e6c5c70a67b0
files cinst/windowsstore.c cinst/windowsstore.h
diffstat 2 files changed, 55 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/windowsstore.c	Wed Mar 26 20:15:56 2014 +0100
+++ b/cinst/windowsstore.c	Wed Mar 26 20:16:50 2014 +0100
@@ -32,7 +32,7 @@
   return bufPtr;
 }
 
-static void
+void
 do_remove(HCERTSTORE hStore, char **to_remove)
 {
   PCCERT_CONTEXT pCert = NULL;
@@ -48,6 +48,7 @@
       char *asn1_data = NULL;
       size_t asn1_size = 0;
       int ret = -1;
+      DWORD j;
       PCCERT_CONTEXT pc_to_remove = NULL;
 
       ret = str_base64_decode (&asn1_data, &asn1_size, to_remove[i],
@@ -61,6 +62,7 @@
           continue;
         }
 
+      printf ("Deleting cert %s\n", to_remove[i]);
       pc_to_remove = CertCreateContext (CERT_STORE_CERTIFICATE_CONTEXT,
                                         X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
                                         (const PBYTE) asn1_data,
@@ -86,6 +88,31 @@
                                           pc_to_remove,
                                           NULL);
 
+
+        {
+          char pszNameString[256];
+          if(CertGetNameString(   
+             pc_to_remove,   
+             CERT_NAME_SIMPLE_DISPLAY_TYPE,   
+             0,
+             NULL,   
+             pszNameString,   
+             128))
+          {
+            printf("wanted: %s \n",pszNameString);
+          }
+          if(CertGetNameString(   
+             pCert,   
+             CERT_NAME_SIMPLE_DISPLAY_TYPE,   
+             0,
+             NULL,   
+             pszNameString,   
+             128))
+          {
+             printf("got: %s \n",pszNameString);
+          }
+        }
+
       CertFreeCertificateContext (pc_to_remove);
 
       if (pCert == NULL)
@@ -93,6 +120,18 @@
           printf ("Did not find certificate\n");
           continue;
         }
+      for (j = 0; j < pCert->cbCertEncoded; j++) {
+          if (asn1_data[j] != pCert->pbCertEncoded[j]) {
+              printf("%1x", (unsigned)(unsigned char)pCert->pbCertEncoded[j]);
+          }
+      }
+      printf("\nWanted: \n");
+      for (j = 0; j < pCert->cbCertEncoded; j++) {
+          if (asn1_data[j] != pCert->pbCertEncoded[j]) {
+              printf("%1x", (unsigned)(unsigned char)asn1_data[j]);
+          }
+      }
+      printf("\n");
 
       if (!CertDeleteCertificateFromStore (pCert))
         {
@@ -109,7 +148,7 @@
   return;
 }
 
-static void
+void
 do_install(HCERTSTORE hStore, char **to_install)
 {
   int i = 0,
--- a/cinst/windowsstore.h	Wed Mar 26 20:15:56 2014 +0100
+++ b/cinst/windowsstore.h	Wed Mar 26 20:16:50 2014 +0100
@@ -2,6 +2,10 @@
 #ifndef WINDOWSSTORE_H
 #define WINDOWSSTORE_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <windows.h>
 #include <wincrypt.h>
 
@@ -18,5 +22,15 @@
 int write_stores_win (char **to_install, char **to_remove,
                       bool user_store);
 
+/* The do_ functions are private helper functions and should not be used
+ * from other code. They are not static to allow it to use them directly
+ * in unit tests */
+void do_remove(HCERTSTORE hStore, char **to_remove);
+void do_install(HCERTSTORE hStore, char **to_install);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif // WINDOWSSTORE_H
 #endif // WIN32

http://wald.intevation.org/projects/trustbridge/