diff cinst/nssstore_win.c @ 825:24e1e47e2d1a

Start NSS process only from the current installation directory
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 21 Jul 2014 18:52:41 +0200
parents a511c1f45c70
children 4aa33c408776
line wrap: on
line diff
--- a/cinst/nssstore_win.c	Mon Jul 21 18:51:34 2014 +0200
+++ b/cinst/nssstore_win.c	Mon Jul 21 18:52:41 2014 +0200
@@ -664,14 +664,15 @@
 static bool
 start_procces_for_user (wchar_t *selection_file)
 {
-  HANDLE hToken = NULL;/*,
-         hChildToken = NULL;*/
-  /* TODO get this as absolute path based on current module location */
-  LPWSTR lpApplicationName = L"mozilla.exe",
-         lpCommandLine;
+  HANDLE hToken = NULL;
+  LPWSTR lpApplicationPath = NULL,
+         lpCommandLine = NULL;
   PROCESS_INFORMATION piProcInfo = {0};
   STARTUPINFOW siStartInfo = {0};
   BOOL success = FALSE;
+  char *install_dir = get_install_dir();
+  wchar_t *w_inst_dir;
+  size_t w_path_len = 0;
 
   if (!selection_file)
     {
@@ -679,6 +680,24 @@
       return false;
     }
 
+  /* Set up the application path. It's installdir + NSS_APP_NAME */
+  if (install_dir == NULL)
+    {
+      ERRORPRINTF ("Failed to get installation directory");
+      return FALSE;
+    }
+
+  w_inst_dir = utf8_to_wchar (install_dir, strlen(install_dir));
+  xfree (install_dir);
+  install_dir = NULL;
+
+  w_path_len = wcslen(w_inst_dir) + wcslen(L"\\" NSS_APP_NAME) + 1;
+  lpApplicationPath = xmalloc(w_path_len * sizeof (wchar_t));
+  wcscpy_s (lpApplicationPath, w_path_len, w_inst_dir);
+  xfree (w_inst_dir);
+  w_inst_dir = NULL;
+  wcscat_s (lpApplicationPath, w_path_len, L"\\" NSS_APP_NAME);
+
   /* set up handles. stdin and stdout go to the same stdout*/
   siStartInfo.cb = sizeof (STARTUPINFO);
 
@@ -695,6 +714,7 @@
   else if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken))
     {
       PRINTLASTERROR("Failed to get current handle.");
+      xfree (lpApplicationPath);
       return false;
     }
 
@@ -703,13 +723,14 @@
   if (lpCommandLine == NULL)
     {
       ERRORPRINTF ("Failed to build command line.");
+      xfree (lpApplicationPath);
       return false;
     }
 
-  DEBUGPRINTF ("Starting %S with command line %S\n", lpApplicationName, lpCommandLine);
+  DEBUGPRINTF ("Starting %S with command line %S\n", lpApplicationPath, lpCommandLine);
 
   success = CreateProcessAsUserW (hToken,
-                                  lpApplicationName,
+                                  lpApplicationPath,
                                   lpCommandLine, /* Commandline */
                                   NULL, /* Process attributes. Take hToken */
                                   NULL, /* Thread attribues. Take hToken */
@@ -719,6 +740,7 @@
                                   NULL, /* Current working directory */
                                   &siStartInfo,
                                   &piProcInfo);
+  xfree (lpApplicationPath);
   xfree (lpCommandLine);
   if (!success)
     {

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