view cinst/mozilla.c @ 122:65941f3d5db8

Added missing stuff from last commit.
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Mar 2014 10:06:43 +0100
parents 4bb5f295987b
children ffb20e76e7d0
line wrap: on
line source
/**
 * @file
 * @brief Mozilla installation process
 *
 * Reads from stdin a list of instructions in the form:
 *
 * I:<base64 DER econded certificate>\r\n
 * R:<base64 DER econded certificate>\r\n
 * ...
 *
 * The maximum size of an input line is 1000 characters
 * (including the \r\n) at the end of the line.
 *
 * Certificates marked with I: will be installed and the ones
 * marked with R: will be searched and if available removed from
 * the databases.
 *
 * This tool tries to find all NSS databases the user has
 * access to and to execute the instructions on all of them.
 *
 * If there are other processes accessing the databases the caller
 * has to ensure that those are terminated before this process is
 * executed.
 *
 * Returns 0 on success (Even when no stores where found) an error value
 * as defined in errorcodes.h otherwise.
 *
 * Success messages are written to stdout. Errors to stderr. For logging
 * purposes each installation / removal of a certificate will be reported
 * with the profile name that it modified.
 *
 */

/* @brief IniParser for mozilla profiles.ini
 *
 * Parse data to find values formed in
 *
 * [Profile99]
 * IsRelative=1
 * Path=Profiles/fooo.bar
 *
 * or
 * [Profile0]
 * IsRelative=0
 * Path=c:\foo\bar\baz
 *
 * Mozilla also accepts the ini file on Windows even if it is UTF-16
 * encoded.
 * */

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <errorcodes.h>
#include <strhelp.h>

#ifndef _WIN32
#define UNIX 1
#else
#define UNIX 0
#endif

/**
 * @brief Global Return Code
 *
 * This will be retuned by the programm and might be set to an
 * error code on fatal errors and to and warning code on non-fatal
 * errors.  In case of mor than one warning the warning codes will be
 * ORed together.
 */
int return_code = 0;

/**
 * @brief Get a list of all mozilla profile directories
 *
 * Read the profiles.ini and extract all profile paths from that.
 *
 * @param[in] inifile_name path of the profile.ini to read.
 * @return NULL terminated array of strings containing containing the
 * absolute path of the profile directories. The array needs to
 * be freed by the caller.
 */
static char **
get_profile_dirs (char *inifile_name)
{
  char **dirs = NULL;
  FILE *inifile;
  char line[1000];
  bool inprofile = false;

  if ((inifile = fopen(inifile_name, "r")) != NULL)
    {
      while (fgets(line, 1000, inifile) != NULL)
        {
          if (strncmp(line, "[Profile", 8) == 0)
            inprofile = true;
          else if (line[0] == '[')
            inprofile = false;
          if (inprofile &&
              (strncmp(line, "Path=", 5) == 0))
            strv_append(&dirs, line, strlen(line));
        }
    }
  else
    {
      return_code |= WARN_MOZ_FAILED_TO_OPEN_INI;
    }

  return dirs;
}

int
main ()
{
  int x = 0;
  char **pdirs =
    get_profile_dirs("/home/wilde/.mozilla/firefox/profiles.ini");
  while (pdirs[x] != NULL)
    puts(pdirs[x++]);
  strv_free(pdirs);
  exit(return_code);
}

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