From e132a808e1aadfcb531c4f062ae6d20dc3bee45e Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Fri, 29 Feb 2008 15:20:19 +0000 Subject: [PATCH] - lib: remove references to LogonUserEx which does not exist on Win2k or older machines. - lib: comment out the CreateProcessAsUser code for graphics apps. (this is temporary) lib/ util.C win_util.C, .h svn path=/trunk/boinc/; revision=14823 --- checkin_notes | 10 +++++ lib/util.C | 27 +++++++------ lib/win_util.C | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/win_util.h | 11 ++++- 4 files changed, 140 insertions(+), 15 deletions(-) diff --git a/checkin_notes b/checkin_notes index 5db34b7ddf..06c450c9b0 100644 --- a/checkin_notes +++ b/checkin_notes @@ -1781,3 +1781,13 @@ David Feb 28 2008 main.h sched_send.C server_types.C + +Rom Feb 29 2008 + - lib: remove references to LogonUserEx which does not exist on Win2k or + older machines. + - lib: comment out the CreateProcessAsUser code for graphics apps. + (this is temporary) + + lib/ + util.C + win_util.C, .h diff --git a/lib/util.C b/lib/util.C index 9aa2cd5b3d..8a383c101d 100644 --- a/lib/util.C +++ b/lib/util.C @@ -319,32 +319,30 @@ void get_sandbox_account_token() { encoded_username_str.rfind(_T('\\')) + 1, encoded_username_str.length() - encoded_username_str.rfind(_T('\\')) - 1 ); - retval = LogonUserEx( + retval = LogonUser( username_str.c_str(), domainname_str.c_str(), password_str.c_str(), LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, - &sandbox_account_token, - &sandbox_account_sid, - &pProfileBuffer, - &dwProfileLength, - &ql + &sandbox_account_token ); + if (!retval) { + GetAccountSid(domainname_str.c_str(), username_str.c_str(), &sandbox_account_sid); + } } else { username_str = encoded_username_str; - retval = LogonUserEx( + retval = LogonUser( username_str.c_str(), NULL, password_str.c_str(), LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, - &sandbox_account_token, - &sandbox_account_sid, - &pProfileBuffer, - &dwProfileLength, - &ql + &sandbox_account_token ); + if (!retval) { + GetAccountSid(NULL, username_str.c_str(), &sandbox_account_sid); + } } if (!retval) { @@ -384,6 +382,7 @@ int run_program( } } +/* get_sandbox_account_token(); if (sandbox_account_token != NULL) { char szWindowStation[256]; @@ -447,6 +446,7 @@ int run_program( fprintf(stderr, "DestroyEnvironmentBlock failed: %s\n", error_msg); } } else { +*/ retval = CreateProcess( file, cmdline, @@ -459,8 +459,9 @@ int run_program( &startup_info, &process_info ); +/* } - +*/ if (!retval) { windows_error_string(error_msg, sizeof(error_msg)); fprintf(stderr, "CreateProcessAsUser failed: '%s'\n", error_msg); diff --git a/lib/win_util.C b/lib/win_util.C index 4eb30aac2b..5625af30a1 100644 --- a/lib/win_util.C +++ b/lib/win_util.C @@ -660,3 +660,110 @@ BOOL AddAceToDesktop(HDESK hdesk, PSID psid) return bSuccess; } + +/*++ +This function attempts to obtain a SID representing the supplied +account on the supplied system. + +If the function succeeds, the return value is TRUE. A buffer is +allocated which contains the SID representing the supplied account. +This buffer should be freed when it is no longer needed by calling +HeapFree(GetProcessHeap(), 0, buffer) + +If the function fails, the return value is FALSE. Call GetLastError() +to obtain extended error information. + +Scott Field (sfield) 12-Jul-95 +--*/ + +BOOL +GetAccountSid( + LPCTSTR SystemName, + LPCTSTR AccountName, + PSID *Sid + ) +{ + LPTSTR ReferencedDomain=NULL; + DWORD cbSid=128; // initial allocation attempt + DWORD cchReferencedDomain=16; // initial allocation size + SID_NAME_USE peUse; + BOOL bSuccess=FALSE; // assume this function will fail + + __try { + + // + // initial memory allocations + // + *Sid = (PSID)HeapAlloc(GetProcessHeap(), 0, cbSid); + + if(*Sid == NULL) __leave; + + ReferencedDomain = (LPTSTR)HeapAlloc( + GetProcessHeap(), + 0, + cchReferencedDomain * sizeof(TCHAR) + ); + + if(ReferencedDomain == NULL) __leave; + + // + // Obtain the SID of the specified account on the specified system. + // + while(!LookupAccountName( + SystemName, // machine to lookup account on + AccountName, // account to lookup + *Sid, // SID of interest + &cbSid, // size of SID + ReferencedDomain, // domain account was found on + &cchReferencedDomain, + &peUse + )) { + if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + // + // reallocate memory + // + *Sid = (PSID)HeapReAlloc( + GetProcessHeap(), + 0, + *Sid, + cbSid + ); + if(*Sid == NULL) __leave; + + ReferencedDomain = (LPTSTR)HeapReAlloc( + GetProcessHeap(), + 0, + ReferencedDomain, + cchReferencedDomain * sizeof(TCHAR) + ); + if(ReferencedDomain == NULL) __leave; + } + else __leave; + } + + // + // Indicate success. + // + bSuccess = TRUE; + + } // try + __finally { + + // + // Cleanup and indicate failure, if appropriate. + // + + HeapFree(GetProcessHeap(), 0, ReferencedDomain); + + if(!bSuccess) { + if(*Sid != NULL) { + HeapFree(GetProcessHeap(), 0, *Sid); + *Sid = NULL; + } + } + + } // finally + + return bSuccess; +} + diff --git a/lib/win_util.h b/lib/win_util.h index 1859280118..08cc746171 100644 --- a/lib/win_util.h +++ b/lib/win_util.h @@ -21,8 +21,15 @@ extern BOOL IsWindows2000Compatible(); extern BOOL IsTerminalServicesEnabled(); -extern BOOL ValidateProductSuite (LPSTR SuiteName); -extern BOOL TerminateProcessById (DWORD dwProcessId); +extern BOOL ValidateProductSuite(LPSTR SuiteName); +extern BOOL TerminateProcessById(DWORD dwProcessId); extern BOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid); extern BOOL AddAceToDesktop(HDESK hdesk, PSID psid); +extern BOOL +GetAccountSid( + LPCTSTR SystemName, // where to lookup account + LPCTSTR AccountName, // account of interest + PSID *Sid // resultant buffer containing SID + ); +