[PATCH 3 of 3] (issue86) Install into default profile folders on windows

Wald Commits scm-commit at wald.intevation.org
Fri Aug 29 17:13:51 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1409325210 -7200
# Node ID 1743895b39b820c07419f9ded32708f04551352b
# Parent  faf58e9f518bb19186104f8a753650d6eb414aa4
(issue86) Install into default profile folders on windows.

diff -r faf58e9f518b -r 1743895b39b8 cinst/mozilla.c
--- 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;
 }
 
diff -r faf58e9f518b -r 1743895b39b8 cinst/nssstore_win.c
--- 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);


More information about the Trustbridge-commits mailing list