diff --git a/checkin_notes b/checkin_notes index e56ff70b2e..4fe84ee7ce 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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 diff --git a/client/app_start.C b/client/app_start.C index 7ac196b1d2..1be03a571e 100644 --- a/client/app_start.C +++ b/client/app_start.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, diff --git a/clientgui/BOINCClientManager.cpp b/clientgui/BOINCClientManager.cpp index 74e39fee7f..d9e4cbd6d9 100644 --- a/clientgui/BOINCClientManager.cpp +++ b/clientgui/BOINCClientManager.cpp @@ -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; } diff --git a/lib/proc_control.C b/lib/proc_control.C index dfa90bffcf..4f5644e460 100644 --- a/lib/proc_control.C +++ b/lib/proc_control.C @@ -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 -#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, "", encoded_username_str)) continue; - if (parse_str(buf, "", 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, "", encoded_username_str)) continue; - if (parse_str(buf, "", 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 +#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, "", encoded_username_str)) continue; + if (parse_str(buf, "", 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, "", encoded_username_str)) continue; + if (parse_str(buf, "", 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