annotate cinst/windowsstore.c @ 1310:60e481aa75ca

(issue152) Do not return CryptUIDlgViewContext's return value The return value is false if the user cancels the dialog. But as the certificate has been shown this is not really an error.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 13 Oct 2014 14:13:05 +0200
parents 32a44cfb78c0
children 18211dce3106
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
7 */
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 #ifdef WIN32
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9
161
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
10 #include <stdio.h>
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
11
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 #include "windowsstore.h"
161
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
13 #include "errorcodes.h"
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
14 #include "listutil.h"
a4b1c77f3e6a Change install_certificates_win to generic write_stores_win
Andre Heinecke <aheinecke@intevation.de>
parents: 149
diff changeset
15 #include "strhelp.h"
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
16 #include "logging.h"
321
824ef90a6721 Move is_elevated into common/util.c file for better reuse
Andre Heinecke <aheinecke@intevation.de>
parents: 262
diff changeset
17 #include "util.h"
1288
265583011f24 (issue123) Add possibility to open native certificate dialog
Andre Heinecke <andre.heinecke@intevation.de>
parents: 905
diff changeset
18 #include "certhelp.h"
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
19
219
57bef180d560 Add debug output and make windowsstore linkable from C++ code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 218
diff changeset
20 void
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
21 debug_print_subject(PCCERT_CONTEXT pCert)
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
22 {
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
23 char pszNameString[256];
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
24 if (!pCert || !g_debug)
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
25 {
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
26 return;
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
27 }
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
28
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
29 if(CertGetNameString(pCert,
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
30 CERT_NAME_SIMPLE_DISPLAY_TYPE,
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
31 0,
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
32 NULL,
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
33 pszNameString,
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
34 128))
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
35 {
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
36 DEBUGPRINTF("Certificate Subject: %s", pszNameString);
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
37 }
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
38 }
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
39
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
40 void
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
41 do_remove(HCERTSTORE hStore, char **to_remove)
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42 {
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
43 PCCERT_CONTEXT pCert = NULL;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
44 unsigned int i = 0;
624
736e95c63b86 Log access to windows stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 504
diff changeset
45 bool elevated = is_elevated();
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
46
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
47 if (!to_remove)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
48 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
49 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
50 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
51
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
52 for (i=0; to_remove[i]; i++)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
53 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
54 PCCERT_CONTEXT pc_to_remove = NULL;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
55
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
56 pc_to_remove = b64_to_cert_context(to_remove[i],
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
57 strnlen(to_remove[i], MAX_LINE_LENGTH));
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
58
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
59 if (pc_to_remove == NULL)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
60 {
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
61 char *error = getLastErrorMsg();
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
62 if (error)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
63 {
626
f595fcbe3e76 Replace "normal printfs" with DEBUG / ERROR printf macros
Andre Heinecke <andre.heinecke@intevation.de>
parents: 624
diff changeset
64 ERRORPRINTF ("Failed to create cert context: %s \n", error);
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
65 free (error);
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
66 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
67 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
68 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
69
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
70 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
71 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
72 0,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
73 CERT_FIND_EXISTING,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
74 pc_to_remove,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
75 NULL);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
76
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
77 if (pCert == NULL)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
78 {
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
79 DEBUGPRINTF ("Did not find certificate\n");
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
80 debug_print_subject (pc_to_remove);
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
81 CertFreeCertificateContext (pc_to_remove);
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
82 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
83 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
84
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
85 CertFreeCertificateContext (pc_to_remove);
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
86
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
87 if (!CertDeleteCertificateFromStore (pCert))
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 /* From MSDN:
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
90 The CertDeleteCertificateFromStore function always frees
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
91 pCertContext by calling the CertFreeCertificateContext
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
92 function, even if an error is encountered. */
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
93 char *error = getLastErrorMsg();
626
f595fcbe3e76 Replace "normal printfs" with DEBUG / ERROR printf macros
Andre Heinecke <andre.heinecke@intevation.de>
parents: 624
diff changeset
94 ERRORPRINTF ("Error deleting certificate. %s", error);
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
95 debug_print_subject (pCert);
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
96 CertFreeCertificateContext (pCert);
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
97 free (error);
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
98 continue;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
99 }
624
736e95c63b86 Log access to windows stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 504
diff changeset
100 log_certificate (elevated ? "Local Machine" : "Current User",
736e95c63b86 Log access to windows stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 504
diff changeset
101 to_remove[i], false);
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
102 CertFreeCertificateContext (pCert);
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
103 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
104 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
105 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
106
219
57bef180d560 Add debug output and make windowsstore linkable from C++ code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 218
diff changeset
107 void
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
108 do_install(HCERTSTORE hStore, char **to_install)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
109 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
110 int i = 0,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
111 ret = -1;
624
736e95c63b86 Log access to windows stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 504
diff changeset
112 bool elevated = is_elevated();
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
113
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
114 if (!to_install)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
115 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
116 return;
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
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
119 for (i = 0; to_install[i]; i++)
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
120 {
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
121 PCCERT_CONTEXT pc_to_add = NULL;
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
122 PCCERT_CONTEXT found_cert = NULL;
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
123
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
124 pc_to_add = b64_to_cert_context(to_install[i],
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
125 strnlen(to_install[i], MAX_LINE_LENGTH));
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
126
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
127 if (pc_to_add == NULL)
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
128 {
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
129 continue;
215
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
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
132 found_cert = CertFindCertificateInStore (hStore,
905
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
133 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
134 0,
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
135 CERT_FIND_EXISTING,
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
136 pc_to_add,
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
137 NULL);
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
138 if (found_cert != NULL)
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
139 {
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
140 /* DEBUGPRINTF ("Certificate already in store\n"); */
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
141 CertFreeCertificateContext (found_cert);
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
142 CertFreeCertificateContext (pc_to_add);
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
143 continue;
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
144 }
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
145
222
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
146 ret = CertAddCertificateContextToStore (hStore,
53ea9b975d1c Cleanup windowsstore.c
Andre Heinecke <aheinecke@intevation.de>
parents: 219
diff changeset
147 pc_to_add,
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
148 CERT_STORE_ADD_ALWAYS,
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
149 NULL);
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
150 if (!ret)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
151 {
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
152 char *error = getLastErrorMsg();
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
153 if (error)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
154 {
626
f595fcbe3e76 Replace "normal printfs" with DEBUG / ERROR printf macros
Andre Heinecke <andre.heinecke@intevation.de>
parents: 624
diff changeset
155 ERRORPRINTF ("Failed to add certificate: %s \n", error);
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
156 debug_print_subject (pc_to_add);
253
3595ea4fd3fb Use getLastErrorMsg from logging
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
157 free (error);
215
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 }
1309
32a44cfb78c0 Improve debug output and fix cert context leak on removal
Andre Heinecke <andre.heinecke@intevation.de>
parents: 1288
diff changeset
160 CertFreeCertificateContext (pc_to_add);
624
736e95c63b86 Log access to windows stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 504
diff changeset
161 log_certificate (elevated ? "Local Machine" : "Current User",
736e95c63b86 Log access to windows stores
Andre Heinecke <andre.heinecke@intevation.de>
parents: 504
diff changeset
162 to_install[i], true);
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
163 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
164 return;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
165 }
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 int
247
4de97f74d038 Check for process elevation and write into system store accordingly
Andre Heinecke <aheinecke@intevation.de>
parents: 222
diff changeset
168 write_stores_win (char **to_install, char **to_remove)
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
169 {
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
170 HCERTSTORE hStore = NULL;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
171
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
172 if (!to_install && !to_remove)
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
173 {
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
174 /* Nothing to do */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
175 return 0;
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
176 }
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
177
247
4de97f74d038 Check for process elevation and write into system store accordingly
Andre Heinecke <aheinecke@intevation.de>
parents: 222
diff changeset
178 if (!is_elevated())
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
179 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
180 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
181 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
182 }
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
183 else
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
184 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
185 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
186 0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root");
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
187 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
188
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
189 if (!hStore)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
190 {
504
3cf72c5282e8 Redirect errorprintf to output debug string on windows
Andre Heinecke <aheinecke@intevation.de>
parents: 404
diff changeset
191 ERRORPRINTF ("Failed to access store.\n");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
192 return ERR_STORE_ACCESS_DENIED;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
193 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
194
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
195 /* Do the actual work */
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
196 do_install (hStore, to_install);
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
197
215
292e2cb60ef0 Add removal of certificates
Andre Heinecke <andre.heinecke@intevation.de>
parents: 185
diff changeset
198 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
199
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
200 if (hStore)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
201 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
202 CertCloseStore (hStore, 0);
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
203 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
204 return 0;
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
205 }
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
206 #endif // WIN32

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