Skip to content

Commit

Permalink
HADOOP-11639. Clean up Windows native code compilation warnings relat…
Browse files Browse the repository at this point in the history
…ed to Windows Secure Container Executor. Contributed by Remus Rusanu.
  • Loading branch information
cnauroth committed Mar 27, 2015
1 parent 05499b1 commit 3836ad6
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 55 deletions.
3 changes: 3 additions & 0 deletions hadoop-common-project/hadoop-common/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
17 changes: 7 additions & 10 deletions hadoop-common-project/hadoop-common/src/main/winutils/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -375,7 +372,7 @@ DWORD RpcCall_WinutilsCreateFile(
RpcEndExcept;

if (ERROR_SUCCESS == dwError) {
*hFile = response->hFile;
*hFile = (HANDLE) response->hFile;
}

done:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) { \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -2619,7 +2619,7 @@ LPCWSTR GetSystemTimeString() {
// Native debugger: windbg, ntsd, cdb, visual studio
//
VOID LogDebugMessage(LPCWSTR format, ...) {
LPWSTR buffer[8192];
wchar_t buffer[8192];
va_list args;
HRESULT hr;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
34 changes: 17 additions & 17 deletions hadoop-common-project/hadoop-common/src/main/winutils/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,14 @@ 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};
ACL_SIZE_INFORMATION aclInfo;
DWORD cbSid = SECURITY_MAX_SID_SIZE;
PSID* allowedSids = NULL;
int cAllowedSids = 0;
BOOL isSidDefaulted;
PSID sidOwner = NULL;
PSID sidGroup = NULL;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -382,7 +381,7 @@ DWORD InitLocalDirs() {
}

done:
if (value) LocalFree(value);
if (value) LocalFree((HLOCAL)value);

return dwError;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -500,7 +499,7 @@ DWORD RunService(__in int argc, __in_ecount(argc) wchar_t *argv[])
// Description:
// Service main entry point.
//
VOID WINAPI SvcMain() {
VOID WINAPI SvcMain(DWORD dwArg, LPTSTR* lpszArgv) {
DWORD dwError = ERROR_SUCCESS;

gSvcStatusHandle = RegisterServiceCtrlHandler(
Expand Down Expand Up @@ -693,15 +692,15 @@ RPC_STATUS CALLBACK RpcAuthorizeCallback (
//
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;


Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 3836ad6

Please sign in to comment.