changeset 985:1743895b39b8

(issue86) Install into default profile folders on windows.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 29 Aug 2014 17:13:30 +0200
parents faf58e9f518b
children 66f6361fba1b
files cinst/mozilla.c cinst/nssstore_win.c
diffstat 2 files changed, 42 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Aug 29 17:12:35 2014 +0200
+++ b/cinst/mozilla.c	Fri Aug 29 17:13:30 2014 +0200
@@ -84,11 +84,13 @@
 #define NSSSHARED ".pki/nssdb"
 #define NSSSHARED_GLOBAL "/etc/pki/nssdb"
 #define TARGET_LINUX 1
+#define DIRSEP "/"
 #else
-#define MOZILLA_DEFAULTS 0
+#define MOZILLA_DEFAULTS "Mozilla Firefox\\browser\\defaults", "Mozilla Thunderbird\\defaults"
 #define CONFDIRS "Mozilla", "Thunderbird"
 #define NSSSHARED ""
 #define TARGET_LINUX 0
+#define DIRSEP "\\"
 #endif
 
 /**
@@ -318,16 +320,36 @@
 
   const char *confdirs[] = { MOZILLA_DEFAULTS, NULL };
 
+#ifdef _WIN32
+  char *program_files = get_program_files_folder();
+  if (!program_files)
+    {
+      ERRORPRINTF ("Failed to look up program files folder.\n");
+      return NULL;
+    }
+#endif
+
   for (int i=0; confdirs[i] != NULL; i++)
     {
-      char * realpath = port_realpath(confdirs[i]);
-      char * profile_dir = NULL;
+      char *realpath = NULL,
+           *profile_dir = NULL;
+#ifndef _WIN32
+      realpath = port_realpath(confdirs[i]);
+#else
+      /* As on linux we only respect the default installation directory
+         mozilla firefox and thunderbird change their registry key with
+         each version as the key includes the version number. It would
+         be error prone to search the system for every instance. So we
+         only check the default installation directories. */
+      xasprintf(&realpath, "%s" DIRSEP "%s", program_files, confdirs[i]);
+#endif
       if (realpath == NULL)
         {
           DEBUGPRINTF ("Did not find directory: '%s'\n", confdirs[i]);
           continue;
         }
-      xasprintf(&profile_dir, "%s/profile", realpath);
+      xasprintf(&profile_dir, "%s" DIRSEP "profile", realpath);
+      xfree(realpath);
       if (port_isdir(profile_dir))
         {
           DEBUGPRINTF("Found default directory: '%s'\n", profile_dir);
@@ -351,7 +373,7 @@
           else
             {
               /* Lets create it */
-              if (!port_mkdir(profile_dir))
+              if (!port_mkdir_p(profile_dir))
                 {
                   ERRORPRINTF ("Failed to create directory: '%s'\n", profile_dir);
                   xfree(profile_dir);
@@ -364,6 +386,7 @@
             }
         }
     }
+  xfree (program_files);
   return retval;
 }
 
--- a/cinst/nssstore_win.c	Fri Aug 29 17:12:35 2014 +0200
+++ b/cinst/nssstore_win.c	Fri Aug 29 17:13:30 2014 +0200
@@ -628,10 +628,13 @@
 * @param [in] selection_file filename of the file containing
 *             the users install / remove selection.
 *
+* @param [in] drop_privileges weather or not elevated privileges
+*             should be dropped before starting the process.
+*
 * @returns true on success, false on error.
 */
 static bool
-start_procces_for_user (wchar_t *selection_file)
+start_procces_for_user (wchar_t *selection_file, bool drop_privileges)
 {
   HANDLE hToken = NULL;
   LPWSTR lpApplicationPath = NULL,
@@ -670,7 +673,7 @@
   /* set up handles. stdin and stdout go to the same stdout*/
   siStartInfo.cb = sizeof (STARTUPINFO);
 
-  if (is_elevated())
+  if (is_elevated() && drop_privileges)
     {
       /* Start the child process as normal user */
       hToken = get_restricted_token ();
@@ -884,9 +887,17 @@
   if (is_elevated())
     {
       register_proccesses_for_others (selection_file_name);
+      /* Start the NSS process once with elevated rights to
+         install into the default profile directories. */
+      if (!start_procces_for_user (selection_file_name, false))
+        {
+          ERRORPRINTF ("Failed to run NSS installation process for default folders.\n");
+          xfree(selection_file_name);
+          return -1;
+        }
     }
 
-  if (!start_procces_for_user (selection_file_name))
+  if (!start_procces_for_user (selection_file_name, true))
     {
       ERRORPRINTF ("Failed to run NSS installation process.\n");
       xfree(selection_file_name);

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