diff cinst/mozilla.c @ 235:0c4d65a7cd14

Started to write input parser. Strange problems with b64 decode seemingly to accept invalid input?
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 13:04:59 +0100
parents 774e944c395b
children dd417a2ff9cd 74d6e33c7d38
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Mar 28 10:50:14 2014 +0100
+++ b/cinst/mozilla.c	Fri Mar 28 13:04:59 2014 +0100
@@ -31,6 +31,14 @@
  *
  */
 
+/**
+ * @brief Needs to eb defined to get strnlen()
+ */
+#define _POSIX_C_SOURCE 200809L
+
+/* REMOVEME: */
+#include <unistd.h>
+
 #include <dirent.h>
 #include <cert.h>
 #include <certt.h>
@@ -324,11 +332,61 @@
 int
 main ()
 {
+  char inpl[LINEBUFLEN];
+  size_t inpllen;
+  char *dercert;
+  size_t dercertlen;
   char **pdirs;
+  bool parserr = true;
   pdirs =
     get_all_profile_dirs();
+
   if (pdirs != NULL)
     {
+      while ( fgets(inpl, LINEBUFLEN, stdin) != NULL )
+        {
+          inpllen = strnlen(inpl, LINEBUFLEN);
+          /* Validate input line:
+           * - must be (much) longer than 3 characters
+           * - must start with "*:"
+           */
+          if ((inpllen > 3) && (inpl[1] == ':'))
+            /* Now parse Input */
+            switch(inpl[0])
+              {
+              case 'R':
+                parserr = true;
+                DEBUGPRINTF("Removing Certificate: %s", &inpl[2]);
+                if ( str_base64_decode(&dercert, &dercertlen,
+                                       &inpl[2], inpllen-2) == 0 )
+                  {
+                    DEBUGPRINTF("Successfully b64 decoded cert: '");
+                    write(2, dercert, dercertlen);
+                    fprintf(stderr,"'\n");
+                    parserr = false;
+                  }
+                else
+                  DEBUGPRINTF("Base64 decoded failed!\n'");
+                break;
+              case 'I':
+                DEBUGPRINTF("Installing Certificate: %s", &inpl[2]);
+                parserr = false;
+                break;
+              default:
+                parserr = true;
+              }
+          else
+            {
+              parserr = true;
+            }
+
+          if (parserr)
+            {
+              DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl);
+              exit(ERR_MOZ_INVALID_INPUT);
+            }
+        }
+
       for (int i=0; pdirs[i] != NULL; i++)
         {
           puts(pdirs[i]);

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