annotate cinst/main.c @ 963:62b832d0b839

(issue89) Package help for windows
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 28 Aug 2014 12:54:28 +0200
parents 76c410aff382
children 78798d3af8f0
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 382
diff changeset
7 */
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
8 /**
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
9 * @file main.c
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
10 * @brief Main entry point for the cinst process.
25
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 *
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 * The cinst process may or may not be run with elevated
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 * privileges. When run with elevated privileges this
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 * process will modify system wide certificate stores.
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 * Otherwise only the users certificate stores are modified.
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
17 * The first parameter to this process should be list=<file_name>
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
18 * of the certificate list to work on. The second parameter should
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
19 * be choices=<choices_file_name>|uninstall
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
20 *
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
21 * choices_file_name should be the absolute path to an
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
22 * choices file formatted as:
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
23 *
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
24 * I:<certificate>
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
25 * R:<certificate>
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
26 *
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
27 * Line breaks can be system dependent in the Choices file.
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
28 *
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
29 * It will only execute the choices if the
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
30 * I and R choices are also part of the signed
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
31 * certificate list. The signature is validated with the
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
32 * built in key.
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
33 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
34 * The special instruction "uninstall" will cause the installer
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
35 * to remove all certificates (Even those marked with I) that
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
36 * are part of the list.
25
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 *
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 **/
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39 #include <stdio.h>
64
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
40 #include <stdlib.h>
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
41 #include <string.h>
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
42 #include <assert.h>
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
43 #include <stdbool.h>
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
44
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
45 #include "strhelp.h"
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
46 #include "listutil.h"
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
47 #include "logging.h"
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
48 #include "errorcodes.h"
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
49 #include "windowsstore.h"
302
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
50 #include "nssstore.h"
125
24fb90ef8f6a Fix install_certificates_win.
Andre Heinecke <aheinecke@intevation.de>
parents: 116
diff changeset
51
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
52 /* The certificate list + choices may only be so long as
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
53 * twice the accepted certificatelist size */
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
54 #define MAX_INPUT_SIZE MAX_LINE_LENGTH * MAX_LINES * 2
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
55
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
56 /* @brief Read stdin into data structures.
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
57 *
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
58 * Reads choices from an input file into the to_install
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
59 * and to_remove buffers.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
60 *
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
61 * Lines starting with I: are treated as install choices.
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
62 * Lines starting with R: are treated as remove choices.
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
63 * Other lines are ignored.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
64 *
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
65 * Terminates in OOM conditions.
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
66 *
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
67 * The caller needs to free the memory allocated by this function
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
68 * even when an error is returned.
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
69 *
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
70 * @param[in] file_name absolute path to the choices file.
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
71 * @param[out] to_install strv of installation choices or NULL
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
72 * @param[out] to_remove strv of remove choices or NULL
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
73 *
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
74 * @returns: 0 on success. An error code otherwise.
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
75 */
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
76 static int
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
77 read_choices_file (char *file_name, char ***to_install,
905
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
78 char ***to_remove)
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
79 {
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
80 int lines_read = 0;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
81 char buf[MAX_LINE_LENGTH + 2];
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
82 FILE *f = NULL;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
83 long file_size;
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
84
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
85 if (*to_install || *to_remove)
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
86 {
626
f595fcbe3e76 Replace "normal printfs" with DEBUG / ERROR printf macros
Andre Heinecke <andre.heinecke@intevation.de>
parents: 501
diff changeset
87 ERRORPRINTF ("Error invalid parameters.\n");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
88 return -1;
90
899fcddb92d0 Check parameters in readInput
Andre Heinecke <aheinecke@intevation.de>
parents: 68
diff changeset
89 }
899fcddb92d0 Check parameters in readInput
Andre Heinecke <aheinecke@intevation.de>
parents: 68
diff changeset
90
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
91 f = fopen (file_name, "rb");
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
92 if (f == NULL)
667
fb69aef056ea Be more verbose in error logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
93 {
fb69aef056ea Be more verbose in error logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
94 ERRORPRINTF ("Failed to open file: %s\n", file_name);
fb69aef056ea Be more verbose in error logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
95 return ERR_NO_INSTRUCTIONS;
fb69aef056ea Be more verbose in error logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
96 }
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
97
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
98 fseek (f, 0, SEEK_END);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
99 file_size = ftell (f);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
100 if (file_size <= 0)
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
101 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
102 fclose (f);
667
fb69aef056ea Be more verbose in error logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
103 ERRORPRINTF ("File size error: %s\n", file_name);
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
104 return ERR_NO_INSTRUCTIONS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
105 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
106
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
107 fseek (f, 0, SEEK_SET);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
108
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
109 if (file_size + 1 == 0)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
110 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
111 fclose (f);
667
fb69aef056ea Be more verbose in error logging
Andre Heinecke <andre.heinecke@intevation.de>
parents: 626
diff changeset
112 ERRORPRINTF ("File seek error: %s\n", file_name);
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
113 return ERR_INVALID_INSTRUCTIONS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
114 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
115
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
116 while (fgets (buf, MAX_LINE_LENGTH + 1, f) )
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
117 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
118 size_t len = strlen (buf); /* fgets ensures buf is terminated */
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
119 if (len <= 3)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
120 {
626
f595fcbe3e76 Replace "normal printfs" with DEBUG / ERROR printf macros
Andre Heinecke <andre.heinecke@intevation.de>
parents: 501
diff changeset
121 ERRORPRINTF ("Line too short.\n");
339
5fa58979cb3a Fix ressource leak found by cppcheck
Andre Heinecke <aheinecke@intevation.de>
parents: 325
diff changeset
122 fclose (f);
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
123 return ERR_INVALID_INPUT;
91
80ab2168760f Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents: 90
diff changeset
124 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
125 if (lines_read++ > MAX_LINES)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
126 {
626
f595fcbe3e76 Replace "normal printfs" with DEBUG / ERROR printf macros
Andre Heinecke <andre.heinecke@intevation.de>
parents: 501
diff changeset
127 ERRORPRINTF ("Too many lines\n");
339
5fa58979cb3a Fix ressource leak found by cppcheck
Andre Heinecke <aheinecke@intevation.de>
parents: 325
diff changeset
128 fclose (f);
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
129 return ERR_TOO_MUCH_INPUT;
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
130 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
131 if (*buf == 'I')
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
132 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
133 char *trimmed = buf+2;
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
134 /* Remove leading I: and trailing whitespace */
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
135 str_trim(&trimmed);
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
136 strv_append (to_install, trimmed, strlen(trimmed));
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
137 continue;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
138 }
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
139 if (*buf == 'R')
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
140 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
141 char *trimmed = buf+2;
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
142 /* Remove leading R: and trailing whitespace */
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
143 str_trim(&trimmed);
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
144 strv_append (to_remove, trimmed, strlen(trimmed));
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
145 continue;
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
146 }
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
147 }
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
148
339
5fa58979cb3a Fix ressource leak found by cppcheck
Andre Heinecke <aheinecke@intevation.de>
parents: 325
diff changeset
149 fclose (f);
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
150 return 0;
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
151 }
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
152
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
153 /** @brief Check that the insturctions match to the list
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
154 *
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
155 * Only certificates part of the certificate_list are allowed
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
156 * for installation.
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
157 *
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
158 * @param[in] all_certs strv of all valid certificates in a list
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
159 * @param[in] to_validate strv of choices
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
160 *
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
161 * @returns 0 on success, an error otherwise
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
162 */
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
163 int
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
164 validate_choices (char **all_certs, char **to_validate)
64
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
165 {
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
166 int i = 0, j = 0;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
167
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
168 if (!all_certs || strv_length (all_certs) < 1)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
169 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
170 /* Invalid parameters */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
171 return -1;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
172 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
173
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
174 if (to_validate == NULL)
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 /* Nothing is valid */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
177 return 0;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
178 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
179
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
180 for (i = 0; to_validate[i]; i++)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
181 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
182 bool found = false;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
183 for (j = 0; all_certs[j]; j++)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
184 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
185 if (strncmp (to_validate[i], all_certs[j], MAX_LINE_LENGTH) ==
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
186 0)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
187 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
188 found = true;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
189 break;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
190 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
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 (!found)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
193 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
194 DEBUGPRINTF ("Failed to find certificate; \n%s\n", to_validate[i]);
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
195 return ERR_INVALID_INSTRUCTIONS;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
196 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
197 }
65
e4088afd5281 Comment out validate instructions for now to avoid unused warnings
Andre Heinecke <aheinecke@intevation.de>
parents: 64
diff changeset
198
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
199 return 0;
64
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
200 }
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
201
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
202
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
203 int
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
204 main (int argc, char **argv)
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
205 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
206 /* TODO handle wchar arguments on Windows or do conversion dance */
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
207 char **to_install = NULL,
905
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
208 **to_remove = NULL,
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
209 **all_valid_certs = NULL;
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
210 int ret = -1;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
211
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
212 char *certificate_list = NULL,
905
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
213 *certificate_file_name = NULL,
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
214 *choices_file_name = NULL;
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
215 size_t list_len = 0;
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
216 list_status_t list_status;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
217 bool do_uninstall = false;
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
218
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
219 /* Some very static argument parsing. list= and choices= is only
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
220 added to make it more transparent how this programm is called if
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
221 a user looks at the detailed uac dialog. */
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
222 if (argc != 3 || strncmp(argv[1], "list=", 5) != 0 ||
905
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
223 strncmp(argv[2], "choices=", 8) != 0)
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
224 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
225 ERRORPRINTF ("Invalid arguments.\n"
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
226 "Expected arguments: list=<certificate_list> \n"
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
227 " choices=<choices_file>|uninstall\n");
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
228 return ERR_INVALID_PARAMS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
229 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
230
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
231 certificate_file_name = strchr(argv[1], '=') + 1;
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
232 choices_file_name = strchr(argv[2], '=') + 1;
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
233
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
234 if (!certificate_file_name || !choices_file_name)
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
235 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
236 ERRORPRINTF ("Invalid arguments.\n"
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
237 "Expected arguments: list=<certificate_list> \n"
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
238 " choices=<choices_file>|uninstall\n");
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
239 return ERR_INVALID_PARAMS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
240 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
241
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
242 if (strncmp(choices_file_name, "uninstall", 9) == 0)
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
243 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
244 do_uninstall = true;
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
245 choices_file_name = NULL;
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
246 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
247
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
248 list_status = read_and_verify_list (certificate_file_name, &certificate_list,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
249 &list_len);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
250
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
251 if (list_status != Valid)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
252 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
253 if (list_status == InvalidSignature)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
254 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
255 ERRORPRINTF ("Failed to verify signature.\n");
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
256 return ERR_INVALID_SIGNATURE;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
257 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
258
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
259 ERRORPRINTF ("Failed to read certificate list.\n");
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
260 return ERR_INVALID_INPUT_NO_LIST;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
261 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
262
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
263 all_valid_certs = get_certs_from_list (certificate_list, list_len);
944
76c410aff382 Fix two "memory leaks"
Andre Heinecke <andre.heinecke@intevation.de>
parents: 905
diff changeset
264 free (certificate_list);
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
265
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
266 if (!all_valid_certs)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
267 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
268 /* Impossible */
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
269 return -1;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
270 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
271
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
272
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
273 /* For uninstall we are done now */
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
274 if (do_uninstall)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
275 {
290
b460d2cf088d Move ifdef for write_stores_win call lower so that do_uninstall is no longer unused on linux
Andre Heinecke <aheinecke@intevation.de>
parents: 289
diff changeset
276 #ifdef WIN32
302
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
277 ret = write_stores_win (NULL, all_valid_certs);
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
278 if (ret != 0)
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
279 {
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
280 ERRORPRINTF ("Failed to write windows stores retval: %i\n", ret);
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
281 }
299
ccb00bf48b75 Fix misplaced endif
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
282 #endif
302
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
283 ret = write_stores_nss (NULL, all_valid_certs);
944
76c410aff382 Fix two "memory leaks"
Andre Heinecke <andre.heinecke@intevation.de>
parents: 905
diff changeset
284 strv_free (all_valid_certs);
302
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
285 return ret;
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
286 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
287
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
288 ret = read_choices_file (choices_file_name, &to_install,
905
698b6a9bd75e Fix coding style for C code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 667
diff changeset
289 &to_remove);
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
290
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
291 if (ret)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
292 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
293 ERRORPRINTF ("Failed to read choices file\n");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
294 return ret;
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
295 }
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
296
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
297 if (!strv_length (to_install) && !strv_length (to_remove) )
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
298 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
299 ERRORPRINTF ("Failed to read choices file\n");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
300 return ERR_NO_INSTRUCTIONS;
64
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
301 }
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
302
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
303 /* Check that the choices are ok to execute */
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
304 if (to_install)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
305 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
306 ret = validate_choices (all_valid_certs, to_install);
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
307 if (ret)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
308 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
309 ERRORPRINTF ("Failed to validate choices\n");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
310 return ret;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
311 }
64
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
312 }
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
313
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
314 if (to_remove)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
315 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
316 ret = validate_choices (all_valid_certs, to_remove);
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
317 if (ret)
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
318 {
382
124f08a85532 Rename instructions to choices
Andre Heinecke <andre.heinecke@intevation.de>
parents: 339
diff changeset
319 ERRORPRINTF ("Failed to validate removal choices\n");
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
320 return ret;
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
321 }
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
322 }
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
323
944
76c410aff382 Fix two "memory leaks"
Andre Heinecke <andre.heinecke@intevation.de>
parents: 905
diff changeset
324 strv_free (all_valid_certs);
76c410aff382 Fix two "memory leaks"
Andre Heinecke <andre.heinecke@intevation.de>
parents: 905
diff changeset
325
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
326 #ifdef WIN32
302
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
327 ret = write_stores_win (to_install, to_remove);
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
328 if (ret != 0)
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
329 {
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
330 ERRORPRINTF ("Failed to write windows stores retval: %i\n", ret);
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
331 }
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
332 #endif
302
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
333 ret = write_stores_nss (to_install, to_remove);
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
334 if (ret != 0)
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
335 {
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
336 ERRORPRINTF ("Failed to write nss stores");
fac7e1b0e558 Add nss store calling function and use it in cinst
Andre Heinecke <andre.heinecke@intevation.de>
parents: 299
diff changeset
337 }
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
338
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
339 /* Make valgrind happy */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
340 strv_free (to_install);
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
341 strv_free (to_remove);
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
342
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
343 return 0;
25
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
344 }

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