changeset 236:bd83b038829d

Merged
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 13:05:21 +0100
parents 0c4d65a7cd14 (diff) a7317252a27c (current diff)
children 6435e28ae753 74d6e33c7d38
files
diffstat 2 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Mar 28 11:34:48 2014 +0000
+++ b/cinst/mozilla.c	Fri Mar 28 13:05:21 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]);
--- a/common/errorcodes.h	Fri Mar 28 11:34:48 2014 +0000
+++ b/common/errorcodes.h	Fri Mar 28 13:05:21 2014 +0100
@@ -29,6 +29,7 @@
 
 /* Error: could not determine current users HOME */
 #define ERR_MOZ_HOMELESS 0x0081
+#define ERR_MOZ_INVALID_INPUT 0x0082
 
 /* Warning: Failed to read profile.ini */
 #define WARN_MOZ_FAILED_TO_OPEN_INI 0x0091

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