comparison 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
comparison
equal deleted inserted replaced
824:a511c1f45c70 825:24e1e47e2d1a
662 * @returns true on success, false on error. 662 * @returns true on success, false on error.
663 */ 663 */
664 static bool 664 static bool
665 start_procces_for_user (wchar_t *selection_file) 665 start_procces_for_user (wchar_t *selection_file)
666 { 666 {
667 HANDLE hToken = NULL;/*, 667 HANDLE hToken = NULL;
668 hChildToken = NULL;*/ 668 LPWSTR lpApplicationPath = NULL,
669 /* TODO get this as absolute path based on current module location */ 669 lpCommandLine = NULL;
670 LPWSTR lpApplicationName = L"mozilla.exe",
671 lpCommandLine;
672 PROCESS_INFORMATION piProcInfo = {0}; 670 PROCESS_INFORMATION piProcInfo = {0};
673 STARTUPINFOW siStartInfo = {0}; 671 STARTUPINFOW siStartInfo = {0};
674 BOOL success = FALSE; 672 BOOL success = FALSE;
673 char *install_dir = get_install_dir();
674 wchar_t *w_inst_dir;
675 size_t w_path_len = 0;
675 676
676 if (!selection_file) 677 if (!selection_file)
677 { 678 {
678 ERRORPRINTF ("Invalid call\n"); 679 ERRORPRINTF ("Invalid call\n");
679 return false; 680 return false;
680 } 681 }
682
683 /* Set up the application path. It's installdir + NSS_APP_NAME */
684 if (install_dir == NULL)
685 {
686 ERRORPRINTF ("Failed to get installation directory");
687 return FALSE;
688 }
689
690 w_inst_dir = utf8_to_wchar (install_dir, strlen(install_dir));
691 xfree (install_dir);
692 install_dir = NULL;
693
694 w_path_len = wcslen(w_inst_dir) + wcslen(L"\\" NSS_APP_NAME) + 1;
695 lpApplicationPath = xmalloc(w_path_len * sizeof (wchar_t));
696 wcscpy_s (lpApplicationPath, w_path_len, w_inst_dir);
697 xfree (w_inst_dir);
698 w_inst_dir = NULL;
699 wcscat_s (lpApplicationPath, w_path_len, L"\\" NSS_APP_NAME);
681 700
682 /* set up handles. stdin and stdout go to the same stdout*/ 701 /* set up handles. stdin and stdout go to the same stdout*/
683 siStartInfo.cb = sizeof (STARTUPINFO); 702 siStartInfo.cb = sizeof (STARTUPINFO);
684 703
685 if (is_elevated()) 704 if (is_elevated())
693 } 712 }
694 } 713 }
695 else if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken)) 714 else if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken))
696 { 715 {
697 PRINTLASTERROR("Failed to get current handle."); 716 PRINTLASTERROR("Failed to get current handle.");
717 xfree (lpApplicationPath);
698 return false; 718 return false;
699 } 719 }
700 720
701 lpCommandLine = get_command_line (selection_file); 721 lpCommandLine = get_command_line (selection_file);
702 722
703 if (lpCommandLine == NULL) 723 if (lpCommandLine == NULL)
704 { 724 {
705 ERRORPRINTF ("Failed to build command line."); 725 ERRORPRINTF ("Failed to build command line.");
726 xfree (lpApplicationPath);
706 return false; 727 return false;
707 } 728 }
708 729
709 DEBUGPRINTF ("Starting %S with command line %S\n", lpApplicationName, lpCommandLine); 730 DEBUGPRINTF ("Starting %S with command line %S\n", lpApplicationPath, lpCommandLine);
710 731
711 success = CreateProcessAsUserW (hToken, 732 success = CreateProcessAsUserW (hToken,
712 lpApplicationName, 733 lpApplicationPath,
713 lpCommandLine, /* Commandline */ 734 lpCommandLine, /* Commandline */
714 NULL, /* Process attributes. Take hToken */ 735 NULL, /* Process attributes. Take hToken */
715 NULL, /* Thread attribues. Take hToken */ 736 NULL, /* Thread attribues. Take hToken */
716 FALSE, /* Inherit Handles */ 737 FALSE, /* Inherit Handles */
717 0, /* Creation flags. */ 738 0, /* Creation flags. */
718 NULL, /* Inherit environment */ 739 NULL, /* Inherit environment */
719 NULL, /* Current working directory */ 740 NULL, /* Current working directory */
720 &siStartInfo, 741 &siStartInfo,
721 &piProcInfo); 742 &piProcInfo);
743 xfree (lpApplicationPath);
722 xfree (lpCommandLine); 744 xfree (lpCommandLine);
723 if (!success) 745 if (!success)
724 { 746 {
725 PRINTLASTERROR ("Failed to create process.\n"); 747 PRINTLASTERROR ("Failed to create process.\n");
726 return false; 748 return false;

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