annotate cinst/windowsstore.c @ 218:8fb12af98960

According to MSDN you Must also provide message encoding flag. I would not be surprised if both those values are defined 0 :)
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 26 Mar 2014 20:15:56 +0100
parents 83a015f2e078
children 57bef180d560
rev   line source
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 #ifdef WIN32
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2
161
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
3 #include <stdio.h>
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
4
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 #include "windowsstore.h"
161
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
6 #include "errorcodes.h"
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
7 #include "listutil.h"
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
8 #include "strhelp.h"
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
10 static LPWSTR getLastErrorMsg()
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
11 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
12 LPWSTR bufPtr = NULL;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
13 DWORD err = GetLastError();
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
14 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
15 FORMAT_MESSAGE_FROM_SYSTEM |
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
16 FORMAT_MESSAGE_IGNORE_INSERTS,
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
17 NULL, err, 0, (LPWSTR) &bufPtr, 0, NULL);
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
18 if (!bufPtr)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
19 {
185
ee37c085b9f7 Try to handle crypt32 errors. Print the error code as fallback
Andre Heinecke <aheinecke@intevation.de>
parents: 163
diff changeset
20 HMODULE hWinhttp = GetModuleHandleW (L"crypt32");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
21 if (hWinhttp)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
22 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
23 FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER |
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
24 FORMAT_MESSAGE_FROM_HMODULE |
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
25 FORMAT_MESSAGE_IGNORE_INSERTS,
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
26 hWinhttp, HRESULT_CODE (err), 0,
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
27 (LPWSTR) &bufPtr, 0, NULL);
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
28 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
30 if (!bufPtr)
185
ee37c085b9f7 Try to handle crypt32 errors. Print the error code as fallback
Andre Heinecke <aheinecke@intevation.de>
parents: 163
diff changeset
31 printf ("Error getting last error for code: %lx \n", err);
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
32 return bufPtr;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
35 static void
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
36 do_remove(HCERTSTORE hStore, char **to_remove)
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 {
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
38 PCCERT_CONTEXT pCert = NULL;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
39 unsigned int i = 0;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
40
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
41 if (!to_remove)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
42 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
43 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
44 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
45
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
46 for (i=0; to_remove[i]; i++)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
47 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
48 char *asn1_data = NULL;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
49 size_t asn1_size = 0;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
50 int ret = -1;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
51 PCCERT_CONTEXT pc_to_remove = NULL;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
52
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
53 ret = str_base64_decode (&asn1_data, &asn1_size, to_remove[i],
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
54 strnlen(to_remove[i], MAX_LINE_LENGTH));
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
55 /* Decoding / parsing errors in here should not happen at all.
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
56 The only errors which are not a bug would be out of memory or
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
57 if the signed certificate list contained an invalid certificate. */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
58 if (ret != 0)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
59 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
60 printf ("Error base64 certificate.\n");
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
61 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
62 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
63
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
64 pc_to_remove = CertCreateContext (CERT_STORE_CERTIFICATE_CONTEXT,
218
8fb12af98960 According to MSDN you Must also provide message encoding flag.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 217
diff changeset
65 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
66 (const PBYTE) asn1_data,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
67 (DWORD) asn1_size,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
68 0,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
69 NULL);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
70 free (asn1_data); /* Windows has a copy */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
71 if (pc_to_remove == NULL)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
72 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
73 LPWSTR error = getLastErrorMsg();
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
74 if (error)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
75 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
76 printf ("Failed to add certificate: %S \n", error);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
77 LocalFree (error);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
78 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
79 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
80 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
81
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
82 pCert = CertFindCertificateInStore (hStore,
218
8fb12af98960 According to MSDN you Must also provide message encoding flag.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 217
diff changeset
83 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
84 0,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
85 CERT_FIND_EXISTING,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
86 pc_to_remove,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
87 NULL);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
88
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
89 CertFreeCertificateContext (pc_to_remove);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
90
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
91 if (pCert == NULL)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
92 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
93 printf ("Did not find certificate\n");
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
94 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
95 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
96
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
97 if (!CertDeleteCertificateFromStore (pCert))
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
98 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
99 /* From MSDN:
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
100 The CertDeleteCertificateFromStore function always frees
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
101 pCertContext by calling the CertFreeCertificateContext
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
102 function, even if an error is encountered. */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
103 LPWSTR error = getLastErrorMsg();
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
104 printf ("Error deleting certificate. %S", error);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
105 LocalFree (error);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
106 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
107 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
108 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
109 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
110 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
111
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
112 static void
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
113 do_install(HCERTSTORE hStore, char **to_install)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
114 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
115 int i = 0,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
116 ret = -1;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
117
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
118 if (!to_install)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
119 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
120 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
121 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
122
217
83a015f2e078 Remove leftover incrementation of i from former loop style. Fixes a crash when adding only one
Andre Heinecke <andre.heinecke@intevation.de>
parents: 215
diff changeset
123 for (i = 0; to_install[i]; i++)
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
124 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
125 size_t cert_len = strnlen (to_install[i], MAX_LINE_LENGTH),
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
126 buf_size = 0;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
127 char *buf = NULL;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
128
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
129 ret = str_base64_decode (&buf, &buf_size, to_install[i], cert_len);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
130
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
131 if (ret != 0)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
132 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
133 printf ("decoding certificate failed\n");
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
134 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
135 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
136
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
137 printf ("Adding cert %s\n", to_install[i]);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
138
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
139 ret = CertAddEncodedCertificateToStore (hStore,
218
8fb12af98960 According to MSDN you Must also provide message encoding flag.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 217
diff changeset
140 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
141 (PBYTE) buf,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
142 buf_size,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
143 CERT_STORE_ADD_ALWAYS,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
144 NULL);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
145
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
146 if (!ret)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
147 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
148 LPWSTR error = getLastErrorMsg();
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
149 if (error)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
150 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
151 printf ("Failed to add certificate: %S \n", error);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
152 LocalFree (error);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
153 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
154 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
155 free (buf);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
156 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
157 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
158 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
159
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
160 int
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
161 write_stores_win (char **to_install, char **to_remove, bool user_store)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
162 {
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
163 HCERTSTORE hStore = NULL;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
164
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
165 if (!to_install && !to_remove)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
166 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
167 /* Nothing to do */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
168 return 0;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
169 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
170
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
171 if (user_store)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
172 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
173 hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0,
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
174 0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
175 }
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
176 else
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
177 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
178 hStore = CertOpenStore (CERT_STORE_PROV_SYSTEM, 0,
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
179 0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root");
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
180 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
181
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
182 if (!hStore)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
183 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
184 return ERR_STORE_ACCESS_DENIED;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
185 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
186
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
187 /* Do the actual work */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
188 do_install (hStore, to_install);
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
189
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
190 do_remove (hStore, to_remove);
161
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
191
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
192 if (hStore)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
193 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
194 CertCloseStore (hStore, 0);
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
195 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
196 return 0;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
197 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
198 #endif // WIN32

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