annotate cinst/main.c @ 298:56507c3d5f1e

Adapt remaining cinstprocesstest to new arg pattern
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 02 Apr 2014 16:13:37 +0000
parents f733f4aa2a90
children ccb00bf48b75
rev   line source
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
1 /**
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
2 * @file main.c
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
3 * @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
4 *
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 * 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
6 * privileges. When run with elevated privileges this
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 * process will modify system wide certificate stores.
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 * Otherwise only the users certificate stores are modified.
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
10 * 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
11 * of the certificate list to work on. The second parameter should
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
12 * be instruction=<instruction_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
13 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
14 * instruction_file_name should be the absolute path to an
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
15 * instructions file formatted as:
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
16 *
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
17 * I:<certificate>
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
18 * R:<certificate>
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
19 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
20 * Line breaks can be system dependent in the Instructions file.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
21 *
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
22 * It will only execute the instructions if the
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
23 * I and R instructions are also part of the signed
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
24 * 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
25 * 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
26 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
27 * 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
28 * 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
29 * are part of the list.
25
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 *
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 **/
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 #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
33 #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
34 #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
35 #include <assert.h>
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
36 #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
37
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
38 #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
39 #include "listutil.h"
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
40 #include "logging.h"
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
41 #include "errorcodes.h"
137
4904fe01055d Factor out windows specific parts
Andre Heinecke <aheinecke@intevation.de>
parents: 126
diff changeset
42 #include "windowsstore.h"
125
24fb90ef8f6a Fix install_certificates_win.
Andre Heinecke <aheinecke@intevation.de>
parents: 116
diff changeset
43
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
44 /* The certificate list + instructions may only be so long as
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
45 * twice the accepted certificatelist size */
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
46 #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
47
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
48 /* @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
49 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
50 * Reads instructions from an input file into the to_install
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
51 * and to_remove buffers.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
52 *
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
53 * Lines starting with I: are treated as install instructions.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
54 * Lines starting with R: are treated as remove instructions.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
55 * Other lines are ignored.
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
56 *
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
57 * 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
58 *
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
59 * 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
60 * even when an error is returned.
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
61 *
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
62 * @param[in] file_name absolute path to the instructions file.
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
63 * @param[out] to_install strv of installation instructions or NULL
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
64 * @param[out] to_remove strv of remove instructions or NULL
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
65 *
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
66 * @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
67 */
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
68 static int
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
69 read_instructions_file (char *file_name, char ***to_install,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
70 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
71 {
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
72 int lines_read = 0;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
73 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
74 FILE *f = NULL;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
75 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
76
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
77 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
78 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
79 printf ("Error invalid parameters.\n");
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
80 return -1;
90
899fcddb92d0 Check parameters in readInput
Andre Heinecke <aheinecke@intevation.de>
parents: 68
diff changeset
81 }
899fcddb92d0 Check parameters in readInput
Andre Heinecke <aheinecke@intevation.de>
parents: 68
diff changeset
82
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
83 f = fopen (file_name, "rb");
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
84 if (f == NULL)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
85 return ERR_NO_INSTRUCTIONS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
86
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
87 fseek (f, 0, SEEK_END);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
88 file_size = ftell (f);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
89 if (file_size <= 0)
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
90 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
91 fclose (f);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
92 return ERR_NO_INSTRUCTIONS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
93 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
94
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
95 fseek (f, 0, SEEK_SET);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
96
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
97 if (file_size + 1 == 0)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
98 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
99 fclose (f);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
100 return ERR_INVALID_INSTRUCTIONS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
101 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
102
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
103 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
104 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
105 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
106 if (len <= 3)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
107 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
108 printf ("Line too short.\n");
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
109 return ERR_INVALID_INPUT;
91
80ab2168760f Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents: 90
diff changeset
110 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
111 if (lines_read++ > MAX_LINES)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
112 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
113 printf ("Too many lines\n");
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
114 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
115 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
116 if (*buf == 'I')
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
117 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
118 char *trimmed = buf+2;
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
119 /* Remove leading I: and trailing whitespace */
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
120 str_trim(&trimmed);
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
121 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
122 continue;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
123 }
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
124 if (*buf == 'R')
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
125 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
126 char *trimmed = buf+2;
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
127 /* Remove leading R: and trailing whitespace */
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
128 str_trim(&trimmed);
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
129 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
130 continue;
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
131 }
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
132 }
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
133
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
134 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
135 }
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
136
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
137 /** @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
138 *
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
139 * 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
140 * for installation.
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
141 *
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
142 * @param[in] all_certs strv of all valid certificates in a list
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
143 * @param[in] to_validate strv of instructions
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
144 *
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
145 * @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
146 */
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
147 int
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
148 validate_instructions (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
149 {
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
150 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
151
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
152 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
153 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
154 /* Invalid parameters */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
155 return -1;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
156 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
157
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
158 if (to_validate == NULL)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
159 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
160 /* Nothing is valid */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
161 return 0;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
162 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
163
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
164 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
165 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
166 bool found = false;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
167 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
168 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
169 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
170 0)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
171 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
172 found = true;
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
173 break;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
174 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
175 }
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
176 if (!found)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
177 {
291
5ab445e6a4da Trim instruction lines to avoid line ending trouble
Andre Heinecke <aheinecke@intevation.de>
parents: 290
diff changeset
178 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
179 return ERR_INVALID_INSTRUCTIONS;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
180 }
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
181 }
65
e4088afd5281 Comment out validate instructions for now to avoid unused warnings
Andre Heinecke <aheinecke@intevation.de>
parents: 64
diff changeset
182
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
183 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
184 }
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
185
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
186
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
187 int
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
188 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
189 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
190 /* 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
191 char **to_install = NULL,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
192 **to_remove = NULL,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
193 **all_valid_certs = NULL;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
194 int ret = -1;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
195
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
196 char *certificate_list = NULL,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
197 *certificate_file_name = NULL,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
198 *instruction_file_name = NULL;
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
199 size_t list_len = 0;
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
200 list_status_t list_status;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
201 bool do_uninstall = false;
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
202
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
203 /* Some very static argument parsing. list= and instructions= is only
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
204 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
205 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
206 if (argc != 3 || strncmp(argv[1], "list=", 5) != 0 ||
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
207 strncmp(argv[2], "instructions=", 13) != 0)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
208 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
209 ERRORPRINTF ("Invalid arguments.\n"
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
210 "Expected arguments: list=<certificate_list> \n"
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
211 " instructions=<instructions_file>|uninstall\n");
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
212 return ERR_INVALID_PARAMS;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
213 }
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
214
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
215 certificate_file_name = strchr(argv[1], '=') + 1;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
216 instruction_file_name = strchr(argv[2], '=') + 1;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
217
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
218 if (!certificate_file_name || !instruction_file_name)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
219 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
220 ERRORPRINTF ("Invalid arguments.\n"
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
221 "Expected arguments: list=<certificate_list> \n"
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
222 " instructions=<instructions_file>|uninstall\n");
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
223 return ERR_INVALID_PARAMS;
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
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
226 if (strncmp(instruction_file_name, "uninstall", 9) == 0)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
227 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
228 do_uninstall = true;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
229 instruction_file_name = NULL;
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
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
232 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
233 &list_len);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
234
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
235 if (list_status != Valid)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
236 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
237 if (list_status == InvalidSignature)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
238 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
239 return ERR_INVALID_SIGNATURE;
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
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
242 return ERR_INVALID_INPUT_NO_LIST;
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
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
245 all_valid_certs = get_certs_from_list (certificate_list, list_len);
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 if (!all_valid_certs)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
248 {
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
249 /* Impossible */
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
250 return -1;
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
251 }
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
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
254 /* For uninstall we are done now */
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
255 if (do_uninstall)
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
256 {
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
257 #ifdef WIN32
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
258 return write_stores_win (NULL, all_valid_certs);
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
259 #else
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
260 /*TODO*/
297
f733f4aa2a90 Return 0 for linux uninstall for now even if it does nothing
Andre Heinecke <aheinecke@intevation.de>
parents: 291
diff changeset
261 return 0;
289
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 #endif
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
264
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
265 ret = read_instructions_file (instruction_file_name, &to_install,
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
266 &to_remove);
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
267
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
268 if (ret)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
269 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
270 return ret;
60
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
271 }
6acb1dae6185 Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents: 59
diff changeset
272
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
273 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
274 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
275 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
276 }
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
277
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
278 /* Check that the instructions are ok to execute */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
279 if (to_install)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
280 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
281 ret = validate_instructions (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
282 if (ret)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
283 {
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
284 return ret;
148
095d0e7f8ed4 Add instruction verification and handle uninstall command in input
Andre Heinecke <aheinecke@intevation.de>
parents: 137
diff changeset
285 }
64
fb9f78f7ab2f Improve error handling free memory before exiting. Include line endings in Marker lines
Andre Heinecke <aheinecke@intevation.de>
parents: 60
diff changeset
286 }
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
287
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
288 if (to_remove)
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
289 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
290 ret = validate_instructions (all_valid_certs, to_remove);
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
291 if (ret)
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
292 {
289
9ad00a3255f4 Change cinst from stdin input to use arguments.
Andre Heinecke <aheinecke@intevation.de>
parents: 247
diff changeset
293 return ret;
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
294 }
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
295 }
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
296
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
297 #ifdef WIN32
247
4de97f74d038 Check for process elevation and write into system store accordingly
Andre Heinecke <aheinecke@intevation.de>
parents: 216
diff changeset
298 return write_stores_win (to_install, to_remove);
68
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
299 #endif
8ffbb48528ae Add certificate installation for windows
Andre Heinecke <aheinecke@intevation.de>
parents: 65
diff changeset
300
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
301 /* Make valgrind happy */
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
302 strv_free (to_install);
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
303 strv_free (to_remove);
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
304 free (certificate_list);
59
3f6378647371 Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents: 26
diff changeset
305
163
8cfcd38a9bb3 Change coding style for cinst main / windowsstore to GNU
Andre Heinecke <aheinecke@intevation.de>
parents: 161
diff changeset
306 return 0;
25
92108a2120f1 Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
307 }

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