diff 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
line wrap: on
line diff
--- a/cinst/main.c	Tue Mar 18 10:03:34 2014 +0000
+++ b/cinst/main.c	Tue Mar 18 10:04:30 2014 +0000
@@ -5,12 +5,95 @@
  *  process will modify system wide certificate stores.
  *  Otherwise only the users certificate stores are modified.
  *
- * TODO
+ *  It expects a certificatelist on stdin enclosed in a
+ *  -----BEGIN CERTIFICATE LIST-----
+ *  ...
+ *  -----END CERTIFICATE LIST-----
+ *
+ *  Followed by additional instruction lines of:
+ *  I:<certificate>
+ *  R:<certificate>
+ *
+ *  It will only execute the instructions if the
+ *  I and R instructions are also part of the signed
+ *  certificate list. The signature is validated with the
+ *  built in key.
+ *
+ *  The special instruction "UNINSTALL" will cause the installer
+ *  to remove all certificates (Even those marked with I) that
+ *  are part of the list to be removed.
  *
  **/
+#define MAX_LINE_LENGTH 1000
+#define MAX_LINES 1000
+#define MAX_INPUT_SIZE 2000000 /* MAX_LINE_LENGTH * (MAX_LINES *2) */
 
 #include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include "strhelp.h"
+#include "listutil.h"
+
+/* @brief Read stdin into data structures.
+ *
+ * Reads from stdin and sorts the input into the respective
+ * variables. The pointers returned need to be freed by the caller.
+ * Terminates in OOM conditions.
+ *
+ * @returns: 0 on success. -1 otherwise.
+ */
+void readInput(char **certificateList, char ***to_install,
+              char ***to_remove)
+{
+    int lines_read = 0;
+    int readingList = 0;
+    char buf[MAX_LINE_LENGTH + 1];
+
+    while (fgets(buf, MAX_LINE_LENGTH + 1, stdin)) {
+        if (lines_read ++ > MAX_LINES) {
+            printf("Too many lines\n");
+        }
+        if (strcmp("-----BEGIN CERTIFICATE LIST-----", buf) == 0){
+            readingList = 1;
+            continue;
+        }
+        if (strcmp("-----END CERTIFICATE LIST-----", buf) == 0){
+            readingList = 0;
+            continue;
+        }
+        if (readingList) {
+            str_append_str(certificateList, buf);
+            continue;
+        }
+        if (*buf == 'I') {
+            array_append_str(to_install, buf+2);
+            continue;
+        }
+        if (*buf == 'R') {
+            array_append_str(to_remove, buf+2);
+            continue;
+        }
+        if (strcmp("UNINSTALL", buf) == 0) {
+            array_append_str(to_remove, buf);
+        }
+    }
+
+    return;
+}
 
 int main() {
+
+    char **to_install = NULL;
+    char **to_remove = NULL;
+    char *certificateList = NULL;
+    int ret = -1;
+
+    readInput(&certificateList, &to_install, &to_remove);
+
+    ret = verify_list(certificateList, strlen(certificateList));
+
+    printf ("Verify List returned %i\n", ret);
+
     return 0;
 }

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