changeset 316:43416dcbcc50

Merged
author Sascha Wilde <wilde@intevation.de>
date Fri, 04 Apr 2014 13:34:30 +0200
parents b832231640ab (diff) 5e4ae994a320 (current diff)
children 46fd11699646
files
diffstat 2 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Apr 04 11:05:44 2014 +0000
+++ b/cinst/mozilla.c	Fri Apr 04 13:34:30 2014 +0200
@@ -2,7 +2,8 @@
  * @file
  * @brief Mozilla installation process
  *
- * Reads from stdin a list of instructions in the form:
+ * Reads from a file given on command line or stdin a list of
+ * instructions in the form:
  *
  * I:<base64 DER econded certificate>
  * R:<base64 DER econded certificate>
@@ -555,14 +556,15 @@
  * @param[inout] remove_list list of SECItems with certifiactes to remove
  */
 static void
-parse_commands (seciteml_t **install_list, seciteml_t **remove_list)
+parse_commands (FILE *stream,
+                seciteml_t **install_list, seciteml_t **remove_list)
 {
   char inpl[LINEBUFLEN];
   size_t inpllen;
   bool parserr = true;
   SECItem secitem;
 
-  while ( fgets(inpl, LINEBUFLEN, stdin) != NULL )
+  while ( fgets(inpl, LINEBUFLEN, stream) != NULL )
     {
       inpllen = strnlen(inpl, LINEBUFLEN);
       /* Validate input line:
@@ -609,18 +611,41 @@
 
 
 int
-main ()
+main (int argc, char **argv)
 {
   char **dbdirs;
   seciteml_t *certs_to_remove = NULL;
   seciteml_t *certs_to_add = NULL;
+  FILE *input_stream;
+
+  switch (argc)
+    {
+    case 1:
+      DEBUGPRINTF("Opening STDIN for input..\n.");
+      input_stream = stdin;
+      break;
+    case 2:
+      DEBUGPRINTF("Opening %s for input...\n", argv[1]);
+      if ((input_stream = fopen(argv[1], "r")) == NULL)
+        {
+          DEBUGPRINTF("FATAL: Could not open %s for reading!\n",
+                      argv[1]);
+          return_code = ERR_MOZ_FAILED_TO_OPEN_INPUT;
+          goto exit;
+        }
+      break;
+    default:
+      DEBUGPRINTF("FATAL: Wrong number of arguments!\n");
+      return_code = ERR_MOZ_WRONG_ARGC;
+      goto exit;
+    }
 
   dbdirs =
     get_all_nssdb_dirs();
 
   if (dbdirs != NULL)
     {
-      parse_commands(&certs_to_add, &certs_to_remove);
+      parse_commands(input_stream, &certs_to_add, &certs_to_remove);
 
 #ifdef DEBUGOUTPUT
       DEBUGPRINTF("OLD List of installed certs:\n");
@@ -642,5 +667,9 @@
 
       strv_free(dbdirs);
     }
+
+ fclose(input_stream);
+
+ exit:
   exit(return_code);
 }
--- a/common/errorcodes.h	Fri Apr 04 11:05:44 2014 +0000
+++ b/common/errorcodes.h	Fri Apr 04 13:34:30 2014 +0200
@@ -34,6 +34,9 @@
 /* Error: could not determine current users HOME */
 #define ERR_MOZ_HOMELESS 0x0081
 #define ERR_MOZ_INVALID_INPUT 0x0082
+/* Error: Called with wrong number of arguments */
+#define ERR_MOZ_WRONG_ARGC 0x0083
+#define ERR_MOZ_FAILED_TO_OPEN_INPUT 0x0084
 
 /* Warning: Failed to read profile.ini */
 #define WARN_MOZ_FAILED_TO_OPEN_INI 0x0091

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