mirror of https://github.com/BOINC/boinc.git
- MGR/CLI: remove direct references to CreateEnvironmentBlock and
DestroyEnvironmentBlock since Win98 doesn't support them. This functionality is only required for the Windows sandbox implementation anyway. - LIB: Remove direct reference to OpenThread in win_util.C since it isn't supported on Win98. - MGR: Another fix for CC execution on a Linux machine. client/ app_start.C clientgui/ BOINCClientManager.cpp lib/ proc_control.C win_util.C svn path=/trunk/boinc/; revision=15117
This commit is contained in:
parent
d9645557a5
commit
3dc77154e5
|
@ -3511,3 +3511,20 @@ David May 1 2008
|
|||
coproc.C
|
||||
sched/
|
||||
sched_send.C
|
||||
|
||||
Rom May 2 2008
|
||||
- MGR/CLI: remove direct references to CreateEnvironmentBlock and
|
||||
DestroyEnvironmentBlock since Win98 doesn't support them. This
|
||||
functionality is only required for the Windows sandbox implementation
|
||||
anyway.
|
||||
- LIB: Remove direct reference to OpenThread in win_util.C since it
|
||||
isn't supported on Win98.
|
||||
- MGR: Another fix for CC execution on a Linux machine.
|
||||
|
||||
client/
|
||||
app_start.C
|
||||
clientgui/
|
||||
BOINCClientManager.cpp
|
||||
lib/
|
||||
proc_control.C
|
||||
win_util.C
|
||||
|
|
|
@ -77,6 +77,18 @@ using std::vector;
|
|||
|
||||
#include "app.h"
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
// Dynamically link to these functions at runtime, otherwise BOINC
|
||||
// cannot run on Win98
|
||||
|
||||
// CreateEnvironmentBlock
|
||||
typedef BOOL (WINAPI *tCEB)(LPVOID *lpEnvironment, HANDLE hToken, BOOL bInherit);
|
||||
// DestroyEnvironmentBlock
|
||||
typedef BOOL (WINAPI *tDEB)(LPVOID lpEnvironment);
|
||||
|
||||
#endif
|
||||
|
||||
// Goes through an array of strings, and prints each string
|
||||
//
|
||||
#ifndef _WIN32
|
||||
|
@ -514,8 +526,18 @@ int ACTIVE_TASK::start(bool first_time) {
|
|||
|
||||
for (i=0; i<5; i++) {
|
||||
if (sandbox_account_service_token != NULL) {
|
||||
// Find CreateEnvironmentBlock/DestroyEnvironmentBlock pointers
|
||||
tCEB pCEB = NULL;
|
||||
tDEB pDEB = NULL;
|
||||
HMODULE hUserEnvLib = NULL;
|
||||
|
||||
if (!CreateEnvironmentBlock(&environment_block, sandbox_account_service_token, FALSE)) {
|
||||
hUserEnvLib = LoadLibrary("userenv.dll");
|
||||
if (hUserEnvLib) {
|
||||
pCEB = (tCEB) GetProcAddress(hUserEnvLib, "CreateEnvironmentBlock");
|
||||
pDEB = (tDEB) GetProcAddress(hUserEnvLib, "DestroyEnvironmentBlock");
|
||||
}
|
||||
|
||||
if (!pCEB(&environment_block, sandbox_account_service_token, FALSE)) {
|
||||
if (log_flags.task) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
msg_printf(result->project, MSG_INFO,
|
||||
|
@ -546,7 +568,7 @@ int ACTIVE_TASK::start(bool first_time) {
|
|||
);
|
||||
}
|
||||
|
||||
if (!DestroyEnvironmentBlock(environment_block)) {
|
||||
if (!pDEB(environment_block)) {
|
||||
if (log_flags.task) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
msg_printf(result->project, MSG_INFO,
|
||||
|
@ -555,6 +577,12 @@ int ACTIVE_TASK::start(bool first_time) {
|
|||
}
|
||||
}
|
||||
|
||||
if (hUserEnvLib) {
|
||||
pCEB = NULL;
|
||||
pDEB = NULL;
|
||||
FreeLibrary(hUserEnvLib);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (CreateProcess(
|
||||
exec_path,
|
||||
|
|
|
@ -144,6 +144,8 @@ bool CBOINCClientManager::IsBOINCCoreRunning() {
|
|||
|
||||
|
||||
bool CBOINCClientManager::StartupBOINCCore() {
|
||||
wxLogTrace(wxT("Function Start/End"), wxT("CMainDocument::CachedStateUpdate - Function Begin"));
|
||||
|
||||
bool bReturnValue = false;
|
||||
wxString strExecute = wxEmptyString;
|
||||
|
||||
|
@ -182,6 +184,9 @@ bool CBOINCClientManager::StartupBOINCCore() {
|
|||
szDataDirectory = (LPTSTR)wxGetApp().GetDataDirectory().c_str();
|
||||
}
|
||||
|
||||
fprintf(stderr, "CMainDocument::CachedStateUpdate - szExecute '%s'\n", szExecute);
|
||||
fprintf(stderr, "CMainDocument::CachedStateUpdate - szDataDirectory '%s'\n", szDataDirectory);
|
||||
|
||||
bProcessStarted = CreateProcess(
|
||||
NULL,
|
||||
szExecute,
|
||||
|
@ -257,7 +262,7 @@ bool CBOINCClientManager::StartupBOINCCore() {
|
|||
#else // Unix based systems
|
||||
|
||||
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
||||
strExecute = wxT("boinc -redirectio -launched_by_manager");
|
||||
strExecute = wxT("./boinc -redirectio -launched_by_manager");
|
||||
if (!g_use_sandbox) {
|
||||
strExecute += wxT(" -insecure");
|
||||
}
|
||||
|
@ -271,6 +276,7 @@ bool CBOINCClientManager::StartupBOINCCore() {
|
|||
bReturnValue = true;
|
||||
}
|
||||
|
||||
wxLogTrace(wxT("Function Start/End"), wxT("CMainDocument::CachedStateUpdate - Function End"));
|
||||
return bReturnValue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,286 +1,311 @@
|
|||
// Berkeley Open Infrastructure for Network Computing
|
||||
// http://boinc.berkeley.edu
|
||||
// Copyright (C) 2008 University of California
|
||||
//
|
||||
// This is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This software is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// To view the GNU Lesser General Public License visit
|
||||
// http://www.gnu.org/copyleft/lesser.html
|
||||
// or write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// Code to run a BOINC application (main or graphics) under Windows
|
||||
// Don't include this in applications
|
||||
|
||||
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
||||
#include "boinc_win.h"
|
||||
#endif
|
||||
#include <string>
|
||||
#include "win_util.h"
|
||||
|
||||
#include "filesys.h"
|
||||
#include "error_numbers.h"
|
||||
#include "common_defs.h"
|
||||
#include "util.h"
|
||||
#include "parse.h"
|
||||
#include "base64.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
HANDLE sandbox_account_interactive_token = NULL;
|
||||
HANDLE sandbox_account_service_token = NULL;
|
||||
|
||||
void get_sandbox_account_interactive_token() {
|
||||
FILE* f;
|
||||
char buf[256];
|
||||
std::string encoded_username_str;
|
||||
std::string encoded_password_str;
|
||||
std::string username_str;
|
||||
std::string domainname_str;
|
||||
std::string password_str;
|
||||
int retval = 0;
|
||||
static bool first=true;
|
||||
PSID sandbox_account_sid = NULL;
|
||||
|
||||
if (!first) return;
|
||||
first = false;
|
||||
|
||||
f = fopen(CLIENT_AUTH_FILENAME, "r");
|
||||
if (!f) return;
|
||||
while (fgets(buf, 256, f)) {
|
||||
if (parse_str(buf, "<username>", encoded_username_str)) continue;
|
||||
if (parse_str(buf, "<password>", encoded_password_str)) continue;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
password_str = r_base64_decode(encoded_password_str);
|
||||
|
||||
if (string::npos != encoded_username_str.find('\\')) {
|
||||
domainname_str = encoded_username_str.substr(
|
||||
0, encoded_username_str.find('\\')
|
||||
);
|
||||
username_str = encoded_username_str.substr(
|
||||
encoded_username_str.rfind(_T('\\')) + 1,
|
||||
encoded_username_str.length() - encoded_username_str.rfind(_T('\\')) - 1
|
||||
);
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
(char*) domainname_str.c_str(),
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_INTERACTIVE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_interactive_token
|
||||
);
|
||||
if (retval) {
|
||||
GetAccountSid(domainname_str.c_str(), username_str.c_str(), &sandbox_account_sid);
|
||||
}
|
||||
} else {
|
||||
username_str = encoded_username_str;
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
NULL,
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_INTERACTIVE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_interactive_token
|
||||
);
|
||||
if (retval) {
|
||||
GetAccountSid(NULL, username_str.c_str(), &sandbox_account_sid);
|
||||
}
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
sandbox_account_interactive_token = NULL;
|
||||
sandbox_account_sid = NULL;
|
||||
} else {
|
||||
// Adjust the permissions on the current desktop and window station
|
||||
// to allow the sandbox user account to create windows and such.
|
||||
//
|
||||
if (!AddAceToWindowStation(GetProcessWindowStation(), sandbox_account_sid)) {
|
||||
fprintf(stderr, "Failed to add ACE to current WindowStation\n");
|
||||
}
|
||||
if (!AddAceToDesktop(GetThreadDesktop(GetCurrentThreadId()), sandbox_account_sid)) {
|
||||
fprintf(stderr, "Failed to add ACE to current Desktop\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_sandbox_account_service_token() {
|
||||
FILE* f;
|
||||
char buf[256];
|
||||
std::string encoded_username_str;
|
||||
std::string encoded_password_str;
|
||||
std::string username_str;
|
||||
std::string domainname_str;
|
||||
std::string password_str;
|
||||
int retval = 0;
|
||||
static bool first=true;
|
||||
|
||||
if (!first) return;
|
||||
first = false;
|
||||
|
||||
f = fopen(CLIENT_AUTH_FILENAME, "r");
|
||||
if (!f) return;
|
||||
while (fgets(buf, 256, f)) {
|
||||
if (parse_str(buf, "<username>", encoded_username_str)) continue;
|
||||
if (parse_str(buf, "<password>", encoded_password_str)) continue;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
password_str = r_base64_decode(encoded_password_str);
|
||||
|
||||
if (string::npos != encoded_username_str.find('\\')) {
|
||||
domainname_str = encoded_username_str.substr(
|
||||
0, encoded_username_str.find('\\')
|
||||
);
|
||||
username_str = encoded_username_str.substr(
|
||||
encoded_username_str.rfind(_T('\\')) + 1,
|
||||
encoded_username_str.length() - encoded_username_str.rfind(_T('\\')) - 1
|
||||
);
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
(char*) domainname_str.c_str(),
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_SERVICE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_service_token
|
||||
);
|
||||
} else {
|
||||
username_str = encoded_username_str;
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
NULL,
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_SERVICE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_service_token
|
||||
);
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
sandbox_account_service_token = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Run application, Windows.
|
||||
// chdir into the given directory, and run a program there.
|
||||
// argv is set up Unix-style, i.e. argv[0] is the program name
|
||||
//
|
||||
int run_app_windows(
|
||||
const char* dir, const char* file, int argc, char *const argv[], HANDLE& id
|
||||
) {
|
||||
int retval;
|
||||
PROCESS_INFORMATION process_info;
|
||||
STARTUPINFO startup_info;
|
||||
LPVOID environment_block = NULL;
|
||||
char cmdline[1024];
|
||||
char error_msg[1024];
|
||||
|
||||
memset(&process_info, 0, sizeof(process_info));
|
||||
memset(&startup_info, 0, sizeof(startup_info));
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
|
||||
strcpy(cmdline, "");
|
||||
for (int i=0; i<argc; i++) {
|
||||
strcat(cmdline, argv[i]);
|
||||
if (i<argc-1) {
|
||||
strcat(cmdline, " ");
|
||||
}
|
||||
}
|
||||
|
||||
get_sandbox_account_interactive_token();
|
||||
if (sandbox_account_interactive_token != NULL) {
|
||||
|
||||
// Retrieve the current window station and desktop names
|
||||
char szWindowStation[256];
|
||||
memset(szWindowStation, 0, sizeof(szWindowStation));
|
||||
char szDesktop[256];
|
||||
memset(szDesktop, 0, sizeof(szDesktop));
|
||||
char szDesktopName[512];
|
||||
memset(szDesktopName, 0, sizeof(szDesktopName));
|
||||
|
||||
if (!GetUserObjectInformation(
|
||||
GetProcessWindowStation(),
|
||||
UOI_NAME,
|
||||
&szWindowStation,
|
||||
sizeof(szWindowStation),
|
||||
NULL)
|
||||
) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "GetUserObjectInformation failed: %s\n", error_msg);
|
||||
}
|
||||
if (!GetUserObjectInformation(
|
||||
GetThreadDesktop(GetCurrentThreadId()),
|
||||
UOI_NAME,
|
||||
&szDesktop,
|
||||
sizeof(szDesktop),
|
||||
NULL)
|
||||
) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "GetUserObjectInformation failed: %s\n", error_msg);
|
||||
}
|
||||
|
||||
// Construct the destination desktop name
|
||||
strncat(szDesktopName, szWindowStation, sizeof(szDesktopName) - strlen(szDesktopName));
|
||||
strncat(szDesktopName, "\\", sizeof(szDesktopName) - strlen(szDesktopName));
|
||||
strncat(szDesktopName, szDesktop, sizeof(szDesktopName) - strlen(szDesktopName));
|
||||
|
||||
// Tell CreateProcessAsUser which desktop to use explicitly.
|
||||
startup_info.lpDesktop = szDesktopName;
|
||||
|
||||
// Construct an environment block that contains environment variables that don't
|
||||
// describe the current user.
|
||||
if (!CreateEnvironmentBlock(&environment_block, sandbox_account_interactive_token, FALSE)) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "CreateEnvironmentBlock failed: %s\n", error_msg);
|
||||
}
|
||||
|
||||
retval = CreateProcessAsUser(
|
||||
sandbox_account_interactive_token,
|
||||
file,
|
||||
cmdline,
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE,
|
||||
CREATE_NEW_PROCESS_GROUP|CREATE_UNICODE_ENVIRONMENT,
|
||||
environment_block,
|
||||
dir,
|
||||
&startup_info,
|
||||
&process_info
|
||||
);
|
||||
|
||||
if (!DestroyEnvironmentBlock(environment_block)) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "DestroyEnvironmentBlock failed: %s\n", error_msg);
|
||||
}
|
||||
} else {
|
||||
retval = CreateProcess(
|
||||
file,
|
||||
cmdline,
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE,
|
||||
0,
|
||||
NULL,
|
||||
dir,
|
||||
&startup_info,
|
||||
&process_info
|
||||
);
|
||||
}
|
||||
if (!retval) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "CreateProcess failed: '%s'\n", error_msg);
|
||||
return -1; // CreateProcess returns 1 if successful, false if it failed.
|
||||
}
|
||||
|
||||
id = process_info.hProcess;
|
||||
return 0;
|
||||
}
|
||||
// Berkeley Open Infrastructure for Network Computing
|
||||
// http://boinc.berkeley.edu
|
||||
// Copyright (C) 2008 University of California
|
||||
//
|
||||
// This is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// either version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This software is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Lesser General Public License for more details.
|
||||
//
|
||||
// To view the GNU Lesser General Public License visit
|
||||
// http://www.gnu.org/copyleft/lesser.html
|
||||
// or write to the Free Software Foundation, Inc.,
|
||||
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
// Code to run a BOINC application (main or graphics) under Windows
|
||||
// Don't include this in applications
|
||||
|
||||
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
||||
#include "boinc_win.h"
|
||||
#endif
|
||||
#include <string>
|
||||
#include "win_util.h"
|
||||
|
||||
#include "filesys.h"
|
||||
#include "error_numbers.h"
|
||||
#include "common_defs.h"
|
||||
#include "util.h"
|
||||
#include "parse.h"
|
||||
#include "base64.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
HANDLE sandbox_account_interactive_token = NULL;
|
||||
HANDLE sandbox_account_service_token = NULL;
|
||||
|
||||
void get_sandbox_account_interactive_token() {
|
||||
FILE* f;
|
||||
char buf[256];
|
||||
std::string encoded_username_str;
|
||||
std::string encoded_password_str;
|
||||
std::string username_str;
|
||||
std::string domainname_str;
|
||||
std::string password_str;
|
||||
int retval = 0;
|
||||
static bool first=true;
|
||||
PSID sandbox_account_sid = NULL;
|
||||
|
||||
if (!first) return;
|
||||
first = false;
|
||||
|
||||
f = fopen(CLIENT_AUTH_FILENAME, "r");
|
||||
if (!f) return;
|
||||
while (fgets(buf, 256, f)) {
|
||||
if (parse_str(buf, "<username>", encoded_username_str)) continue;
|
||||
if (parse_str(buf, "<password>", encoded_password_str)) continue;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
password_str = r_base64_decode(encoded_password_str);
|
||||
|
||||
if (string::npos != encoded_username_str.find('\\')) {
|
||||
domainname_str = encoded_username_str.substr(
|
||||
0, encoded_username_str.find('\\')
|
||||
);
|
||||
username_str = encoded_username_str.substr(
|
||||
encoded_username_str.rfind(_T('\\')) + 1,
|
||||
encoded_username_str.length() - encoded_username_str.rfind(_T('\\')) - 1
|
||||
);
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
(char*) domainname_str.c_str(),
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_INTERACTIVE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_interactive_token
|
||||
);
|
||||
if (retval) {
|
||||
GetAccountSid(domainname_str.c_str(), username_str.c_str(), &sandbox_account_sid);
|
||||
}
|
||||
} else {
|
||||
username_str = encoded_username_str;
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
NULL,
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_INTERACTIVE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_interactive_token
|
||||
);
|
||||
if (retval) {
|
||||
GetAccountSid(NULL, username_str.c_str(), &sandbox_account_sid);
|
||||
}
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
sandbox_account_interactive_token = NULL;
|
||||
sandbox_account_sid = NULL;
|
||||
} else {
|
||||
// Adjust the permissions on the current desktop and window station
|
||||
// to allow the sandbox user account to create windows and such.
|
||||
//
|
||||
if (!AddAceToWindowStation(GetProcessWindowStation(), sandbox_account_sid)) {
|
||||
fprintf(stderr, "Failed to add ACE to current WindowStation\n");
|
||||
}
|
||||
if (!AddAceToDesktop(GetThreadDesktop(GetCurrentThreadId()), sandbox_account_sid)) {
|
||||
fprintf(stderr, "Failed to add ACE to current Desktop\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_sandbox_account_service_token() {
|
||||
FILE* f;
|
||||
char buf[256];
|
||||
std::string encoded_username_str;
|
||||
std::string encoded_password_str;
|
||||
std::string username_str;
|
||||
std::string domainname_str;
|
||||
std::string password_str;
|
||||
int retval = 0;
|
||||
static bool first=true;
|
||||
|
||||
if (!first) return;
|
||||
first = false;
|
||||
|
||||
f = fopen(CLIENT_AUTH_FILENAME, "r");
|
||||
if (!f) return;
|
||||
while (fgets(buf, 256, f)) {
|
||||
if (parse_str(buf, "<username>", encoded_username_str)) continue;
|
||||
if (parse_str(buf, "<password>", encoded_password_str)) continue;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
password_str = r_base64_decode(encoded_password_str);
|
||||
|
||||
if (string::npos != encoded_username_str.find('\\')) {
|
||||
domainname_str = encoded_username_str.substr(
|
||||
0, encoded_username_str.find('\\')
|
||||
);
|
||||
username_str = encoded_username_str.substr(
|
||||
encoded_username_str.rfind(_T('\\')) + 1,
|
||||
encoded_username_str.length() - encoded_username_str.rfind(_T('\\')) - 1
|
||||
);
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
(char*) domainname_str.c_str(),
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_SERVICE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_service_token
|
||||
);
|
||||
} else {
|
||||
username_str = encoded_username_str;
|
||||
retval = LogonUser(
|
||||
(char*) username_str.c_str(),
|
||||
NULL,
|
||||
(char*) password_str.c_str(),
|
||||
LOGON32_LOGON_SERVICE,
|
||||
LOGON32_PROVIDER_DEFAULT,
|
||||
&sandbox_account_service_token
|
||||
);
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
sandbox_account_service_token = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Run application, Windows.
|
||||
// chdir into the given directory, and run a program there.
|
||||
// argv is set up Unix-style, i.e. argv[0] is the program name
|
||||
//
|
||||
|
||||
// CreateEnvironmentBlock
|
||||
typedef BOOL (WINAPI *tCEB)(LPVOID *lpEnvironment, HANDLE hToken, BOOL bInherit);
|
||||
// DestroyEnvironmentBlock
|
||||
typedef BOOL (WINAPI *tDEB)(LPVOID lpEnvironment);
|
||||
|
||||
|
||||
int run_app_windows(
|
||||
const char* dir, const char* file, int argc, char *const argv[], HANDLE& id
|
||||
) {
|
||||
int retval;
|
||||
PROCESS_INFORMATION process_info;
|
||||
STARTUPINFO startup_info;
|
||||
LPVOID environment_block = NULL;
|
||||
char cmdline[1024];
|
||||
char error_msg[1024];
|
||||
|
||||
memset(&process_info, 0, sizeof(process_info));
|
||||
memset(&startup_info, 0, sizeof(startup_info));
|
||||
startup_info.cb = sizeof(startup_info);
|
||||
|
||||
strcpy(cmdline, "");
|
||||
for (int i=0; i<argc; i++) {
|
||||
strcat(cmdline, argv[i]);
|
||||
if (i<argc-1) {
|
||||
strcat(cmdline, " ");
|
||||
}
|
||||
}
|
||||
|
||||
get_sandbox_account_interactive_token();
|
||||
if (sandbox_account_interactive_token != NULL) {
|
||||
|
||||
// Find CreateEnvironmentBlock/DestroyEnvironmentBlock pointers
|
||||
tCEB pCEB = NULL;
|
||||
tDEB pDEB = NULL;
|
||||
HMODULE hUserEnvLib = NULL;
|
||||
|
||||
hUserEnvLib = LoadLibrary("userenv.dll");
|
||||
if (hUserEnvLib) {
|
||||
pCEB = (tCEB) GetProcAddress(hUserEnvLib, "CreateEnvironmentBlock");
|
||||
pDEB = (tDEB) GetProcAddress(hUserEnvLib, "DestroyEnvironmentBlock");
|
||||
}
|
||||
|
||||
|
||||
// Retrieve the current window station and desktop names
|
||||
char szWindowStation[256];
|
||||
memset(szWindowStation, 0, sizeof(szWindowStation));
|
||||
char szDesktop[256];
|
||||
memset(szDesktop, 0, sizeof(szDesktop));
|
||||
char szDesktopName[512];
|
||||
memset(szDesktopName, 0, sizeof(szDesktopName));
|
||||
|
||||
if (!GetUserObjectInformation(
|
||||
GetProcessWindowStation(),
|
||||
UOI_NAME,
|
||||
&szWindowStation,
|
||||
sizeof(szWindowStation),
|
||||
NULL)
|
||||
) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "GetUserObjectInformation failed: %s\n", error_msg);
|
||||
}
|
||||
if (!GetUserObjectInformation(
|
||||
GetThreadDesktop(GetCurrentThreadId()),
|
||||
UOI_NAME,
|
||||
&szDesktop,
|
||||
sizeof(szDesktop),
|
||||
NULL)
|
||||
) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "GetUserObjectInformation failed: %s\n", error_msg);
|
||||
}
|
||||
|
||||
// Construct the destination desktop name
|
||||
strncat(szDesktopName, szWindowStation, sizeof(szDesktopName) - strlen(szDesktopName));
|
||||
strncat(szDesktopName, "\\", sizeof(szDesktopName) - strlen(szDesktopName));
|
||||
strncat(szDesktopName, szDesktop, sizeof(szDesktopName) - strlen(szDesktopName));
|
||||
|
||||
// Tell CreateProcessAsUser which desktop to use explicitly.
|
||||
startup_info.lpDesktop = szDesktopName;
|
||||
|
||||
// Construct an environment block that contains environment variables that don't
|
||||
// describe the current user.
|
||||
if (!pCEB(&environment_block, sandbox_account_interactive_token, FALSE)) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "CreateEnvironmentBlock failed: %s\n", error_msg);
|
||||
}
|
||||
|
||||
retval = CreateProcessAsUser(
|
||||
sandbox_account_interactive_token,
|
||||
file,
|
||||
cmdline,
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE,
|
||||
CREATE_NEW_PROCESS_GROUP|CREATE_UNICODE_ENVIRONMENT,
|
||||
environment_block,
|
||||
dir,
|
||||
&startup_info,
|
||||
&process_info
|
||||
);
|
||||
|
||||
if (!pDEB(environment_block)) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "DestroyEnvironmentBlock failed: %s\n", error_msg);
|
||||
}
|
||||
|
||||
if (hUserEnvLib) {
|
||||
pCEB = NULL;
|
||||
pDEB = NULL;
|
||||
FreeLibrary(hUserEnvLib);
|
||||
}
|
||||
} else {
|
||||
retval = CreateProcess(
|
||||
file,
|
||||
cmdline,
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE,
|
||||
0,
|
||||
NULL,
|
||||
dir,
|
||||
&startup_info,
|
||||
&process_info
|
||||
);
|
||||
}
|
||||
if (!retval) {
|
||||
windows_error_string(error_msg, sizeof(error_msg));
|
||||
fprintf(stderr, "CreateProcess failed: '%s'\n", error_msg);
|
||||
return -1; // CreateProcess returns 1 if successful, false if it failed.
|
||||
}
|
||||
|
||||
id = process_info.hProcess;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -745,10 +745,24 @@ GetAccountSid(
|
|||
// all the threads in the entire system,
|
||||
// and find those belonging to the process (ugh!!)
|
||||
//
|
||||
|
||||
// OpenThread
|
||||
typedef HANDLE (WINAPI *tOT)(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId);
|
||||
|
||||
int suspend_or_resume_threads(DWORD pid, bool resume) {
|
||||
HANDLE threads, thread;
|
||||
HMODULE hKernel32Lib = NULL;
|
||||
THREADENTRY32 te = {0};
|
||||
tOT pOT = NULL;
|
||||
|
||||
// Dynamically link to the proper function pointers.
|
||||
hKernel32Lib = GetModuleHandle("kernel32.dll");
|
||||
pOT = (tOT) GetProcAddress( hKernel32Lib, "OpenThread" );
|
||||
|
||||
if (!pOT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
threads = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
|
||||
if (threads == INVALID_HANDLE_VALUE) return -1;
|
||||
|
||||
|
@ -757,13 +771,16 @@ int suspend_or_resume_threads(DWORD pid, bool resume) {
|
|||
CloseHandle(threads);
|
||||
return -1;
|
||||
}
|
||||
|
||||
do {
|
||||
if (te.th32OwnerProcessID == pid) {
|
||||
thread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, te.th32ThreadID);
|
||||
thread = pOT(THREAD_SUSPEND_RESUME, FALSE, te.th32ThreadID);
|
||||
resume ? ResumeThread(thread) : SuspendThread(thread);
|
||||
CloseHandle(thread);
|
||||
}
|
||||
} while (Thread32Next(threads, &te));
|
||||
|
||||
CloseHandle (threads);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="zlib1d.lib ssleay32.lib libeay32.lib libcurld_imp.lib MSVCRTD.LIB MSVCPRTD.LIB wsock32.lib wininet.lib winmm.lib libboincd.lib sensapi.lib userenv.lib"
|
||||
AdditionalDependencies="zlib1d.lib ssleay32.lib libeay32.lib libcurld_imp.lib MSVCRTD.LIB MSVCPRTD.LIB wsock32.lib wininet.lib winmm.lib libboincd.lib sensapi.lib"
|
||||
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\boinc.exe"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
|
@ -302,7 +302,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="zlib1.lib ssleay32.lib libeay32.lib libcurl_imp.lib MSVCRT.LIB MSVCPRT.LIB wsock32.lib wininet.lib winmm.lib libboinc.lib sensapi.lib userenv.lib"
|
||||
AdditionalDependencies="zlib1.lib ssleay32.lib libeay32.lib libcurl_imp.lib MSVCRT.LIB MSVCPRT.LIB wsock32.lib wininet.lib winmm.lib libboinc.lib sensapi.lib"
|
||||
ShowProgress="0"
|
||||
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\boinc.exe"
|
||||
LinkIncremental="1"
|
||||
|
@ -523,7 +523,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="zlib1.lib ssleay32.lib libeay32.lib libcurl_imp.lib MSVCRT.LIB MSVCPRT.LIB wsock32.lib wininet.lib winmm.lib libboinc.lib sensapi.lib userenv.lib"
|
||||
AdditionalDependencies="zlib1.lib ssleay32.lib libeay32.lib libcurl_imp.lib MSVCRT.LIB MSVCPRT.LIB wsock32.lib wininet.lib winmm.lib libboinc.lib sensapi.lib"
|
||||
ShowProgress="0"
|
||||
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\boinc.exe"
|
||||
LinkIncremental="1"
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="MSVCRT.LIB MSVCPRT.LIB kernel32.lib user32.lib gdi32.lib ole32.lib oleacc.lib shell32.lib comdlg32.lib advapi32.lib oldnames.lib uuid.lib rpcrt4.lib comctl32.lib wsock32.lib wininet.lib userenv.lib wxbase28.lib wxbase28_net.lib wxbase28_xml.lib wxmsw28_adv.lib wxmsw28_core.lib wxmsw28_html.lib wxregex.lib wxexpat.lib wxpng.lib wxzlib.lib boinc_dll.lib"
|
||||
AdditionalDependencies="MSVCRT.LIB MSVCPRT.LIB kernel32.lib user32.lib gdi32.lib ole32.lib oleacc.lib shell32.lib comdlg32.lib advapi32.lib oldnames.lib uuid.lib rpcrt4.lib comctl32.lib wsock32.lib wininet.lib wxbase28.lib wxbase28_net.lib wxbase28_xml.lib wxmsw28_adv.lib wxmsw28_core.lib wxmsw28_html.lib wxregex.lib wxexpat.lib wxpng.lib wxzlib.lib boinc_dll.lib"
|
||||
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""$(OutDir)";"$(WXWIN)\lib\vc_lib";"$(WXWIN)\contrib\lib""
|
||||
|
@ -268,7 +268,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="MSVCRTD.LIB MSVCPRTD.LIB kernel32.lib user32.lib gdi32.lib ole32.lib oleacc.lib shell32.lib comdlg32.lib advapi32.lib oldnames.lib uuid.lib rpcrt4.lib comctl32.lib wsock32.lib wininet.lib userenv.lib wxbase28d.lib wxbase28d_net.lib wxbase28d_xml.lib wxmsw28d_adv.lib wxmsw28d_core.lib wxmsw28d_html.lib wxregexd.lib wxexpatd.lib wxpngd.lib wxzlibd.lib boinc_dll.lib"
|
||||
AdditionalDependencies="MSVCRTD.LIB MSVCPRTD.LIB kernel32.lib user32.lib gdi32.lib ole32.lib oleacc.lib shell32.lib comdlg32.lib advapi32.lib oldnames.lib uuid.lib rpcrt4.lib comctl32.lib wsock32.lib wininet.lib wxbase28d.lib wxbase28d_net.lib wxbase28d_xml.lib wxmsw28d_adv.lib wxmsw28d_core.lib wxmsw28d_html.lib wxregexd.lib wxexpatd.lib wxpngd.lib wxzlibd.lib boinc_dll.lib"
|
||||
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe"
|
||||
LinkIncremental="0"
|
||||
AdditionalLibraryDirectories=""$(OutDir)";"$(WXWIN)\lib\vc_lib";"$(WXWIN)\contrib\lib""
|
||||
|
@ -457,7 +457,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="MSVCRT.LIB MSVCPRT.LIB kernel32.lib user32.lib gdi32.lib ole32.lib oleacc.lib shell32.lib comdlg32.lib advapi32.lib oldnames.lib uuid.lib rpcrt4.lib comctl32.lib wsock32.lib wininet.lib userenv.lib wxbase26.lib wxbase26_net.lib wxbase26_xml.lib wxmsw26_adv.lib wxmsw26_core.lib wxmsw26_html.lib wxregex.lib wxexpat.lib wxpng.lib wxzlib.lib boinc_dll.lib"
|
||||
AdditionalDependencies="MSVCRT.LIB MSVCPRT.LIB kernel32.lib user32.lib gdi32.lib ole32.lib oleacc.lib shell32.lib comdlg32.lib advapi32.lib oldnames.lib uuid.lib rpcrt4.lib comctl32.lib wsock32.lib wininet.lib wxbase26.lib wxbase26_net.lib wxbase26_xml.lib wxmsw26_adv.lib wxmsw26_core.lib wxmsw26_html.lib wxregex.lib wxexpat.lib wxpng.lib wxzlib.lib boinc_dll.lib"
|
||||
OutputFile=".\Build\$(PlatformName)\$(ConfigurationName)\$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories=""$(OutDir)";"$(WXWINPROD)\lib\vc_lib";"$(WXWINPROD)\contrib\lib""
|
||||
|
|
Loading…
Reference in New Issue