HADOOP-11639. Clean up Windows native code compilation warnings related to Windows Secure Container Executor. Contributed by Remus Rusanu.

(cherry picked from commit 3836ad6c0b)
This commit is contained in:
cnauroth 2015-03-27 15:03:41 -07:00
parent 853cc04668
commit eb7068c2c9
9 changed files with 76 additions and 55 deletions

View File

@ -756,6 +756,9 @@ Release 2.7.0 - UNRELEASED
HADOOP-11691. X86 build of libwinutils is broken.
(Kiran Kumar M R via cnauroth)
HADOOP-11639. Clean up Windows native code compilation warnings related to
Windows Secure Container Executor. (Remus Rusanu via cnauroth)
Release 2.6.1 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -409,7 +409,7 @@ Java_org_apache_hadoop_yarn_server_nodemanager_WindowsSecureContainerExecutor_00
done:
if (path) (*env)->ReleaseStringChars(env, jpath, path);
return hFile;
return (jlong) hFile;
#endif
}

View File

@ -28,8 +28,6 @@ static ACCESS_MASK CLIENT_MASK = 1;
VOID ReportClientError(LPWSTR lpszLocation, DWORD dwError) {
LPWSTR debugMsg = NULL;
int len;
WCHAR hexError[32];
HRESULT hr;
if (IsDebuggerPresent()) {
len = FormatMessageW(
@ -49,7 +47,6 @@ DWORD PrepareRpcBindingHandle(
DWORD dwError = EXIT_FAILURE;
RPC_STATUS status;
LPWSTR lpszStringBinding = NULL;
ULONG ulCode;
RPC_SECURITY_QOS_V3 qos;
SID_IDENTIFIER_AUTHORITY authNT = SECURITY_NT_AUTHORITY;
BOOL rpcBindingInit = FALSE;
@ -104,7 +101,7 @@ DWORD PrepareRpcBindingHandle(
RPC_C_AUTHN_WINNT, // AuthnSvc
NULL, // AuthnIdentity (self)
RPC_C_AUTHZ_NONE, // AuthzSvc
&qos);
(RPC_SECURITY_QOS*) &qos);
if (RPC_S_OK != status) {
ReportClientError(L"RpcBindingSetAuthInfoEx", status);
dwError = status;
@ -375,7 +372,7 @@ DWORD RpcCall_WinutilsCreateFile(
RpcEndExcept;
if (ERROR_SUCCESS == dwError) {
*hFile = response->hFile;
*hFile = (HANDLE) response->hFile;
}
done:
@ -479,11 +476,11 @@ DWORD RpcCall_TaskCreateAsUser(
RpcEndExcept;
if (ERROR_SUCCESS == dwError) {
*phProcess = response->hProcess;
*phThread = response->hThread;
*phStdIn = response->hStdIn;
*phStdOut = response->hStdOut;
*phStdErr = response->hStdErr;
*phProcess = (HANDLE) response->hProcess;
*phThread = (HANDLE) response->hThread;
*phStdIn = (HANDLE) response->hStdIn;
*phStdOut = (HANDLE) response->hStdOut;
*phStdErr = (HANDLE) response->hStdErr;
}
done:

View File

@ -18,7 +18,7 @@
#include "winutils.h"
#include <string.h>
#include <stdlib.h>
#import "msxml6.dll"
#import "msxml6.dll" exclude("ISequentialStream", "_FILETIME")
#define ERROR_CHECK_HRESULT_DONE(hr, message) \
if (FAILED(hr)) { \

View File

@ -248,8 +248,8 @@ DWORD BuildServiceSecurityDescriptor(
__out PSECURITY_DESCRIPTOR* pSD);
DWORD AddNodeManagerAndUserACEsToObject(
__in HANDLE hObject,
__in LPWSTR user,
__in HANDLE hProcess,
__in LPCWSTR user,
__in ACCESS_MASK accessMask);
@ -283,15 +283,29 @@ DWORD RpcCall_WinutilsCreateFile(
__out HANDLE* hFile);
DWORD RpcCall_WinutilsMoveFile(
__in LPCWSTR sourcePath,
__in LPCWSTR destinationPath,
__in BOOL replaceExisting);
__in int operation,
__in LPCWSTR sourcePath,
__in LPCWSTR destinationPath,
__in BOOL replaceExisting);
DWORD RpcCall_WinutilsDeletePath(
__in LPCWSTR path,
__in BOOL isDir,
__out BOOL* pDeleted);
DWORD RpcCall_WinutilsChown(
__in LPCWSTR filePath,
__in_opt LPCWSTR ownerName,
__in_opt LPCWSTR groupName);
DWORD RpcCall_WinutilsMkDir(
__in LPCWSTR filePath);
DWORD RpcCall_WinutilsChmod(
__in LPCWSTR filePath,
__in int mode);
#ifdef __cplusplus
}
#endif

View File

@ -2596,7 +2596,7 @@ LPCWSTR GetSystemTimeString() {
QueryPerformanceFrequency(&frequency);
qpc = (double) counter.QuadPart / (double) frequency.QuadPart;
subSec = ((qpc - (long)qpc) * 1000000);
subSec = (int)((qpc - (long)qpc) * 1000000);
hr = StringCbPrintf(buffer, sizeof(buffer), L"%02d:%02d:%02d.%06d",
(int)systime.wHour, (int)systime.wMinute, (int)systime.wSecond, (int)subSec);
@ -2619,7 +2619,7 @@ done:
// Native debugger: windbg, ntsd, cdb, visual studio
//
VOID LogDebugMessage(LPCWSTR format, ...) {
LPWSTR buffer[8192];
wchar_t buffer[8192];
va_list args;
HRESULT hr;
@ -2657,8 +2657,8 @@ DWORD SplitStringIgnoreSpaceW(
size_t tokenCount = 0;
size_t crtSource;
size_t crtToken = 0;
WCHAR* lpwszTokenStart = NULL;
WCHAR* lpwszTokenEnd = NULL;
const WCHAR* lpwszTokenStart = NULL;
const WCHAR* lpwszTokenEnd = NULL;
WCHAR* lpwszBuffer = NULL;
size_t tokenLength = 0;
size_t cchBufferLength = 0;
@ -2849,7 +2849,7 @@ DWORD BuildServiceSecurityDescriptor(
}
}
pTokenGroup = (PTOKEN_USER) LocalAlloc(LPTR, dwBufferSize);
pTokenGroup = (PTOKEN_PRIMARY_GROUP) LocalAlloc(LPTR, dwBufferSize);
if (NULL == pTokenGroup) {
dwError = GetLastError();
LogDebugMessage(L"LocalAlloc:pTokenGroup: %d\n", dwError);
@ -2870,11 +2870,11 @@ DWORD BuildServiceSecurityDescriptor(
owner.TrusteeForm = TRUSTEE_IS_SID;
owner.TrusteeType = TRUSTEE_IS_UNKNOWN;
owner.ptstrName = (LPCWSTR) pOwner;
owner.ptstrName = (LPWSTR) pOwner;
group.TrusteeForm = TRUSTEE_IS_SID;
group.TrusteeType = TRUSTEE_IS_UNKNOWN;
group.ptstrName = (LPCWSTR) pTokenGroup->PrimaryGroup;
group.ptstrName = (LPWSTR) pTokenGroup->PrimaryGroup;
eas = (EXPLICIT_ACCESS*) LocalAlloc(LPTR, sizeof(EXPLICIT_ACCESS) * (grantSidCount + denySidCount));
if (NULL == eas) {
@ -2890,7 +2890,7 @@ DWORD BuildServiceSecurityDescriptor(
eas[crt].grfInheritance = NO_INHERITANCE;
eas[crt].Trustee.TrusteeForm = TRUSTEE_IS_SID;
eas[crt].Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
eas[crt].Trustee.ptstrName = (LPCWSTR) pGrantSids[crt];
eas[crt].Trustee.ptstrName = (LPWSTR) pGrantSids[crt];
eas[crt].Trustee.pMultipleTrustee = NULL;
eas[crt].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
}
@ -2902,7 +2902,7 @@ DWORD BuildServiceSecurityDescriptor(
eas[crt].grfInheritance = NO_INHERITANCE;
eas[crt].Trustee.TrusteeForm = TRUSTEE_IS_SID;
eas[crt].Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
eas[crt].Trustee.ptstrName = (LPCWSTR) pDenySids[crt - grantSidCount];
eas[crt].Trustee.ptstrName = (LPWSTR) pDenySids[crt - grantSidCount];
eas[crt].Trustee.pMultipleTrustee = NULL;
eas[crt].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
}

View File

@ -206,7 +206,7 @@ DWORD ValidateConfigurationFile() {
BOOL daclPresent = FALSE;
BOOL daclDefaulted = FALSE;
PACL pDacl = NULL;
unsigned int crt = 0, crtSid = 0;
DWORD crt = 0;
WELL_KNOWN_SID_TYPE allowedSidTypes[] = {
WinLocalSystemSid,
WinBuiltinAdministratorsSid};
@ -214,7 +214,6 @@ DWORD ValidateConfigurationFile() {
DWORD cbSid = SECURITY_MAX_SID_SIZE;
PSID* allowedSids = NULL;
int cAllowedSids = 0;
BOOL isSidDefaulted;
PSID sidOwner = NULL;
PSID sidGroup = NULL;
@ -324,7 +323,7 @@ DWORD InitJobName() {
int crt = 0;
// Services can be restarted
if (gJobName) LocalFree(gJobName);
if (gJobName) LocalFree((HLOCAL)gJobName);
gJobName = NULL;
dwError = GetConfigValue(
@ -382,7 +381,7 @@ DWORD InitLocalDirs() {
}
done:
if (value) LocalFree(value);
if (value) LocalFree((HLOCAL)value);
return dwError;
}
@ -437,7 +436,7 @@ DWORD ValidateLocalPath(LPCWSTR lpszPath) {
gLocalDirs[crt], gCchLocalDir[crt],
NULL, // lpVersionInformation
NULL, // lpReserved
NULL); // lParam
(LPARAM) NULL); // lParam
if (0 == compareResult) {
dwError = GetLastError();
@ -500,7 +499,7 @@ done:
// Description:
// Service main entry point.
//
VOID WINAPI SvcMain() {
VOID WINAPI SvcMain(DWORD dwArg, LPTSTR* lpszArgv) {
DWORD dwError = ERROR_SUCCESS;
gSvcStatusHandle = RegisterServiceCtrlHandler(
@ -693,15 +692,15 @@ done:
//
DWORD AuthInit() {
DWORD dwError = ERROR_SUCCESS;
int count = 0;
int crt = 0;
size_t count = 0;
size_t crt = 0;
size_t len = 0;
LPCWSTR value = NULL;
WCHAR** tokens = NULL;
LPWSTR lpszSD = NULL;
ULONG cchSD = 0;
DWORD dwBufferSize = 0;
int allowedCount = 0;
size_t allowedCount = 0;
PSID* allowedSids = NULL;
@ -737,7 +736,7 @@ DWORD AuthInit() {
done:
if (lpszSD) LocalFree(lpszSD);
if (value) LocalFree(value);
if (value) LocalFree((HLOCAL)value);
if (tokens) LocalFree(tokens);
return dwError;
}
@ -1167,11 +1166,12 @@ error_status_t WinutilsCreateProcessAsUser(
// Note that there are no more API calls, only assignments. A failure could occur only if
// foced (process kill) or hardware error (faulty memory, processort bit flip etc).
(*response)->hProcess = hDuplicateProcess;
(*response)->hThread = hDuplicateThread;
(*response)->hStdIn = hDuplicateStdIn;
(*response)->hStdOut = hDuplicateStdOut;
(*response)->hStdErr = hDuplicateStdErr;
// as MIDL has no 'HANDLE' type, the (LONG_PTR) is used instead
(*response)->hProcess = (LONG_PTR)hDuplicateProcess;
(*response)->hThread = (LONG_PTR)hDuplicateThread;
(*response)->hStdIn = (LONG_PTR)hDuplicateStdIn;
(*response)->hStdOut = (LONG_PTR)hDuplicateStdOut;
(*response)->hStdErr = (LONG_PTR)hDuplicateStdErr;
fMustCleanupProcess = FALSE;
@ -1276,7 +1276,8 @@ error_status_t WinutilsCreateFile(
goto done;
}
(*response)->hFile = hDuplicateFile;
// As MIDL has no 'HANDLE' type, (LONG_PTR) is used instead
(*response)->hFile = (LONG_PTR)hDuplicateFile;
hDuplicateFile = INVALID_HANDLE_VALUE;
done:
@ -1302,7 +1303,6 @@ error_status_t WinutilsKillTask(
/* [in] */ handle_t IDL_handle,
/* [in] */ KILLTASK_REQUEST *request) {
DWORD dwError = ERROR_SUCCESS;
HRESULT hr;
WCHAR bufferName[MAX_PATH];
dwError = GetSecureJobObjectName(request->taskName, MAX_PATH, bufferName);

View File

@ -19,6 +19,9 @@
#include <psapi.h>
#include <PowrProf.h>
#ifdef PSAPI_VERSION
#undef PSAPI_VERSION
#endif
#define PSAPI_VERSION 1
#pragma comment(lib, "psapi.lib")
#pragma comment(lib, "Powrprof.lib")

View File

@ -22,6 +22,9 @@
#include <authz.h>
#include <sddl.h>
#ifdef PSAPI_VERSION
#undef PSAPI_VERSION
#endif
#define PSAPI_VERSION 1
#pragma comment(lib, "psapi.lib")
@ -231,7 +234,7 @@ DWORD BuildImpersonateSecurityDescriptor(__out PSECURITY_DESCRIPTOR* ppSD) {
LocalFree(tokens);
tokens = NULL;
LocalFree(value);
LocalFree((HLOCAL)value);
value = NULL;
dwError = GetConfigValue(wsceConfigRelativePath, NM_WSCE_IMPERSONATE_DENIED, &len, &value);
@ -298,18 +301,18 @@ done:
//
DWORD AddNodeManagerAndUserACEsToObject(
__in HANDLE hObject,
__in LPWSTR user,
__in LPCWSTR user,
__in ACCESS_MASK accessMask) {
DWORD dwError = ERROR_SUCCESS;
int countTokens = 0;
size_t countTokens = 0;
size_t len = 0;
LPCWSTR value = NULL;
WCHAR** tokens = NULL;
int crt = 0;
DWORD crt = 0;
PACL pDacl = NULL;
PSECURITY_DESCRIPTOR psdProcess = NULL;
LPSTR lpszOldDacl = NULL, lpszNewDacl = NULL;
LPWSTR lpszOldDacl = NULL, lpszNewDacl = NULL;
ULONG daclLen = 0;
PACL pNewDacl = NULL;
ACL_SIZE_INFORMATION si;
@ -381,8 +384,8 @@ DWORD AddNodeManagerAndUserACEsToObject(
// ACCESS_ALLOWED_ACE struct contains the first DWORD of the SID
//
dwNewAclSize = si.AclBytesInUse +
(countTokens + 1 + sizeof(forcesSidTypes)/sizeof(forcesSidTypes[0])) *
(sizeof(ACCESS_ALLOWED_ACE) + SECURITY_MAX_SID_SIZE - sizeof(DWORD));
(DWORD)(countTokens + 1 + sizeof(forcesSidTypes)/sizeof(forcesSidTypes[0])) *
(sizeof(ACCESS_ALLOWED_ACE) + SECURITY_MAX_SID_SIZE - sizeof(DWORD));
pNewDacl = (PSID) LocalAlloc(LPTR, dwNewAclSize);
if (!pNewDacl) {
@ -511,7 +514,7 @@ DWORD AddNodeManagerAndUserACEsToObject(
goto done;
}
LogDebugMessage(L"Old DACL: %s\nNew DACL: %s\n", lpszOldDacl, lpszNewDacl);
LogDebugMessage(L"Old DACL: %ls\nNew DACL: %ls\n", lpszOldDacl, lpszNewDacl);
}
done:
@ -634,7 +637,7 @@ done:
// Returns:
// ERROR_SUCCESS: On success
// GetLastError: otherwise
DWORD CreateTaskImpl(__in_opt HANDLE logonHandle, __in PCWSTR jobObjName,__in PCWSTR cmdLine,
DWORD CreateTaskImpl(__in_opt HANDLE logonHandle, __in PCWSTR jobObjName,__in PWSTR cmdLine,
__in LPCWSTR userName, __in long memory, __in long cpuRate)
{
DWORD dwErrorCode = ERROR_SUCCESS;
@ -912,7 +915,7 @@ DWORD CreateTask(__in PCWSTR jobObjName,__in PWSTR cmdLine, __in long memory, __
// ERROR_SUCCESS: On success
// GetLastError: otherwise
DWORD CreateTaskAsUser(__in PCWSTR jobObjName,
__in PCWSTR user, __in PCWSTR pidFilePath, __in PCWSTR cmdLine)
__in PCWSTR user, __in PCWSTR pidFilePath, __in PWSTR cmdLine)
{
DWORD err = ERROR_SUCCESS;
DWORD exitCode = EXIT_FAILURE;
@ -923,6 +926,7 @@ DWORD CreateTaskAsUser(__in PCWSTR jobObjName,
FILE* pidFile = NULL;
DWORD retLen = 0;
HANDLE logonHandle = NULL;
errno_t pidErrNo = 0;
err = EnableImpersonatePrivileges();
if( err != ERROR_SUCCESS ) {
@ -961,8 +965,8 @@ DWORD CreateTaskAsUser(__in PCWSTR jobObjName,
profileIsLoaded = TRUE;
// Create the PID file
if (!(pidFile = _wfopen(pidFilePath, "w"))) {
pidErrNo = _wfopen_s(&pidFile, pidFilePath, L"w");
if (pidErrNo) {
err = GetLastError();
ReportErrorCode(L"_wfopen:pidFilePath", err);
goto done;