[PATCH 2 of 3] Start NSS process only from the current installation directory

Wald Commits scm-commit at wald.intevation.org
Mon Jul 21 18:53:19 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1405961561 -7200
# Node ID 24e1e47e2d1aa00a67d116793173038533798f92
# Parent  a511c1f45c707905df2bf0d210dba685873082e0
Start NSS process only from the current installation directory

diff -r a511c1f45c70 -r 24e1e47e2d1a cinst/nssstore_win.c
--- 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)
     {


More information about the Trustbridge-commits mailing list