Mercurial > trustbridge
annotate cinst/main.c @ 59:3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
arrays and to have a terminating malloc / realloc
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 18 Mar 2014 10:04:30 +0000 |
parents | cbd57d767dfa |
children | 6acb1dae6185 |
rev | line source |
---|---|
25
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 /** @brief Main entry point for the cinst process. |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 * |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 * 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
|
4 * privileges. When run with elevated privileges this |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 * process will modify system wide certificate stores. |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 * Otherwise only the users certificate stores are modified. |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 * |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
8 * It expects a certificatelist on stdin enclosed in a |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
9 * -----BEGIN CERTIFICATE LIST----- |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
10 * ... |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
11 * -----END CERTIFICATE LIST----- |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
12 * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
13 * Followed by additional instruction lines of: |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
14 * I:<certificate> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
15 * R:<certificate> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
16 * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
17 * 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
|
18 * 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
|
19 * 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
|
20 * 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
|
21 * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
22 * The special instruction "UNINSTALL" will cause the installer |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
23 * to remove all certificates (Even those marked with I) that |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
24 * are part of the list to be removed. |
25
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 * |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 **/ |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
27 #define MAX_LINE_LENGTH 1000 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
28 #define MAX_LINES 1000 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
29 #define MAX_INPUT_SIZE 2000000 /* MAX_LINE_LENGTH * (MAX_LINES *2) */ |
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 #include <stdio.h> |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
32 #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
|
33 #include <assert.h> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
34 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
35 #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
|
36 #include "listutil.h" |
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 /* @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
|
39 * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
40 * Reads from stdin and sorts the input into the respective |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
41 * variables. The pointers returned need to be freed by the caller. |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
42 * 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
|
43 * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
44 * @returns: 0 on success. -1 otherwise. |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
45 */ |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
46 void readInput(char **certificateList, char ***to_install, |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
47 char ***to_remove) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
48 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
49 int lines_read = 0; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
50 int readingList = 0; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
51 char buf[MAX_LINE_LENGTH + 1]; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
52 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
53 while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
54 if (lines_read ++ > MAX_LINES) { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
55 printf("Too many lines\n"); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
56 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
57 if (strcmp("-----BEGIN CERTIFICATE LIST-----", buf) == 0){ |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
58 readingList = 1; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
59 continue; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
60 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
61 if (strcmp("-----END CERTIFICATE LIST-----", buf) == 0){ |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
62 readingList = 0; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
63 continue; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
64 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
65 if (readingList) { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
66 str_append_str(certificateList, buf); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
67 continue; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
68 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
69 if (*buf == 'I') { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
70 array_append_str(to_install, buf+2); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
71 continue; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
72 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
73 if (*buf == 'R') { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
74 array_append_str(to_remove, buf+2); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
75 continue; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
76 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
77 if (strcmp("UNINSTALL", buf) == 0) { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
78 array_append_str(to_remove, buf); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
79 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
80 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
81 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
82 return; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
83 } |
25
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 |
26
cbd57d767dfa
Move layout around. Restructure CMakeLists
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
85 int main() { |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
86 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
87 char **to_install = NULL; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
88 char **to_remove = NULL; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
89 char *certificateList = NULL; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
90 int ret = -1; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
91 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
92 readInput(&certificateList, &to_install, &to_remove); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
93 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
94 ret = verify_list(certificateList, strlen(certificateList)); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
95 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
96 printf ("Verify List returned %i\n", ret); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
26
diff
changeset
|
97 |
25
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
98 return 0; |
92108a2120f1
Move certificatelist to common. Add cinst directory
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
99 } |