Mercurial > trustbridge
comparison 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 |
comparison
equal
deleted
inserted
replaced
58:ad61489ce593 | 59:3f6378647371 |
---|---|
3 * The cinst process may or may not be run with elevated | 3 * The cinst process may or may not be run with elevated |
4 * privileges. When run with elevated privileges this | 4 * privileges. When run with elevated privileges this |
5 * process will modify system wide certificate stores. | 5 * process will modify system wide certificate stores. |
6 * Otherwise only the users certificate stores are modified. | 6 * Otherwise only the users certificate stores are modified. |
7 * | 7 * |
8 * TODO | 8 * It expects a certificatelist on stdin enclosed in a |
9 * -----BEGIN CERTIFICATE LIST----- | |
10 * ... | |
11 * -----END CERTIFICATE LIST----- | |
12 * | |
13 * Followed by additional instruction lines of: | |
14 * I:<certificate> | |
15 * R:<certificate> | |
16 * | |
17 * It will only execute the instructions if the | |
18 * I and R instructions are also part of the signed | |
19 * certificate list. The signature is validated with the | |
20 * built in key. | |
21 * | |
22 * The special instruction "UNINSTALL" will cause the installer | |
23 * to remove all certificates (Even those marked with I) that | |
24 * are part of the list to be removed. | |
9 * | 25 * |
10 **/ | 26 **/ |
27 #define MAX_LINE_LENGTH 1000 | |
28 #define MAX_LINES 1000 | |
29 #define MAX_INPUT_SIZE 2000000 /* MAX_LINE_LENGTH * (MAX_LINES *2) */ | |
11 | 30 |
12 #include <stdio.h> | 31 #include <stdio.h> |
32 #include <string.h> | |
33 #include <assert.h> | |
34 | |
35 #include "strhelp.h" | |
36 #include "listutil.h" | |
37 | |
38 /* @brief Read stdin into data structures. | |
39 * | |
40 * Reads from stdin and sorts the input into the respective | |
41 * variables. The pointers returned need to be freed by the caller. | |
42 * Terminates in OOM conditions. | |
43 * | |
44 * @returns: 0 on success. -1 otherwise. | |
45 */ | |
46 void readInput(char **certificateList, char ***to_install, | |
47 char ***to_remove) | |
48 { | |
49 int lines_read = 0; | |
50 int readingList = 0; | |
51 char buf[MAX_LINE_LENGTH + 1]; | |
52 | |
53 while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) { | |
54 if (lines_read ++ > MAX_LINES) { | |
55 printf("Too many lines\n"); | |
56 } | |
57 if (strcmp("-----BEGIN CERTIFICATE LIST-----", buf) == 0){ | |
58 readingList = 1; | |
59 continue; | |
60 } | |
61 if (strcmp("-----END CERTIFICATE LIST-----", buf) == 0){ | |
62 readingList = 0; | |
63 continue; | |
64 } | |
65 if (readingList) { | |
66 str_append_str(certificateList, buf); | |
67 continue; | |
68 } | |
69 if (*buf == 'I') { | |
70 array_append_str(to_install, buf+2); | |
71 continue; | |
72 } | |
73 if (*buf == 'R') { | |
74 array_append_str(to_remove, buf+2); | |
75 continue; | |
76 } | |
77 if (strcmp("UNINSTALL", buf) == 0) { | |
78 array_append_str(to_remove, buf); | |
79 } | |
80 } | |
81 | |
82 return; | |
83 } | |
13 | 84 |
14 int main() { | 85 int main() { |
86 | |
87 char **to_install = NULL; | |
88 char **to_remove = NULL; | |
89 char *certificateList = NULL; | |
90 int ret = -1; | |
91 | |
92 readInput(&certificateList, &to_install, &to_remove); | |
93 | |
94 ret = verify_list(certificateList, strlen(certificateList)); | |
95 | |
96 printf ("Verify List returned %i\n", ret); | |
97 | |
15 return 0; | 98 return 0; |
16 } | 99 } |