[PATCH] Improve debug output and fix cert context leak on removal
Wald Commits
scm-commit at wald.intevation.org
Mon Oct 13 13:29:22 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1413199759 -7200
# Node ID 32a44cfb78c0a2eec142b4393bef49799b8b5fbc
# Parent fce8c122cbc4cffc3baa95b43263cec2392ab80b
Improve debug output and fix cert context leak on removal
diff -r fce8c122cbc4 -r 32a44cfb78c0 cinst/windowsstore.c
--- a/cinst/windowsstore.c Mon Oct 13 13:25:36 2014 +0200
+++ b/cinst/windowsstore.c Mon Oct 13 13:29:19 2014 +0200
@@ -18,6 +18,26 @@
#include "certhelp.h"
void
+debug_print_subject(PCCERT_CONTEXT pCert)
+{
+ char pszNameString[256];
+ if (!pCert || !g_debug)
+ {
+ return;
+ }
+
+ if(CertGetNameString(pCert,
+ CERT_NAME_SIMPLE_DISPLAY_TYPE,
+ 0,
+ NULL,
+ pszNameString,
+ 128))
+ {
+ DEBUGPRINTF("Certificate Subject: %s", pszNameString);
+ }
+}
+
+void
do_remove(HCERTSTORE hStore, char **to_remove)
{
PCCERT_CONTEXT pCert = NULL;
@@ -54,14 +74,16 @@
pc_to_remove,
NULL);
- CertFreeCertificateContext (pc_to_remove);
-
if (pCert == NULL)
{
- ERRORPRINTF ("Did not find certificate\n");
+ DEBUGPRINTF ("Did not find certificate\n");
+ debug_print_subject (pc_to_remove);
+ CertFreeCertificateContext (pc_to_remove);
continue;
}
+ CertFreeCertificateContext (pc_to_remove);
+
if (!CertDeleteCertificateFromStore (pCert))
{
/* From MSDN:
@@ -70,11 +92,14 @@
function, even if an error is encountered. */
char *error = getLastErrorMsg();
ERRORPRINTF ("Error deleting certificate. %s", error);
+ debug_print_subject (pCert);
+ CertFreeCertificateContext (pCert);
free (error);
continue;
}
log_certificate (elevated ? "Local Machine" : "Current User",
to_remove[i], false);
+ CertFreeCertificateContext (pCert);
}
return;
}
@@ -112,7 +137,7 @@
NULL);
if (found_cert != NULL)
{
- DEBUGPRINTF ("Certificate already in store\n");
+ /* DEBUGPRINTF ("Certificate already in store\n"); */
CertFreeCertificateContext (found_cert);
CertFreeCertificateContext (pc_to_add);
continue;
@@ -122,16 +147,17 @@
pc_to_add,
CERT_STORE_ADD_ALWAYS,
NULL);
- CertFreeCertificateContext (pc_to_add);
if (!ret)
{
char *error = getLastErrorMsg();
if (error)
{
ERRORPRINTF ("Failed to add certificate: %s \n", error);
+ debug_print_subject (pc_to_add);
free (error);
}
}
+ CertFreeCertificateContext (pc_to_add);
log_certificate (elevated ? "Local Machine" : "Current User",
to_install[i], true);
}
More information about the Trustbridge-commits
mailing list