Skip to content

Commit 72c3e62

Browse files
committed
Apply clang-format
1 parent f8e2eb5 commit 72c3e62

File tree

1 file changed

+76
-57
lines changed

1 file changed

+76
-57
lines changed

dpctl-capi/helper/source/dpctl_dynamic_lib_helper.cpp

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- dpctl_dynamic_lib_helper.cpp - Dynamic library helper -*-C++-*- ===//
1+
//===-- dpctl_dynamic_lib_helper.cpp - Dynamic library helper -*-C++-*- ===//
22
//
33
// Data Parallel Control (dpctl)
44
//
@@ -26,20 +26,20 @@
2626

2727
#if defined(_WIN32) || defined(_WIN64)
2828

29-
#include "Support/DllExport.h"
30-
#include <windows.h>
29+
#include "Support/DllExport.h"
30+
#include <windows.h>
3131

32-
#if !defined(DPCTL_CHECK_DLL_SIG)
33-
#define DPCTL_LOAD_DLL(name) LoadLibrary(name)
34-
#else
35-
#define DPCTL_LOAD_DLL(name) _DPCTLLoadLibrary(name)
32+
#if !defined(DPCTL_CHECK_DLL_SIG)
33+
#define DPCTL_LOAD_DLL(name) LoadLibrary(name)
34+
#else
35+
#define DPCTL_LOAD_DLL(name) _DPCTLLoadLibrary(name)
3636

37-
#include <stdio.h>
38-
#include <Softpub.h>
39-
#include <wincrypt.h>
40-
#include <wintrust.h>
37+
#include <Softpub.h>
38+
#include <stdio.h>
39+
#include <wincrypt.h>
40+
#include <wintrust.h>
4141

42-
#pragma comment(lib, "Wintrust.lib")
42+
#pragma comment(lib, "Wintrust.lib")
4343

4444
static HMODULE WINAPI _DPCTLLoadLibrary(LPCTSTR filename)
4545
{
@@ -49,40 +49,46 @@ static HMODULE WINAPI _DPCTLLoadLibrary(LPCTSTR filename)
4949
HMODULE rv2 = NULL;
5050

5151
// References:
52-
// "Dynamic-Link Library Security" - https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-security
53-
// "Dynamic-Link Library Search Order" - https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order?redirectedfrom=MSDN
54-
// "SearchPath function" - https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-searchpathw
55-
// "SetSearchPathMode function" - https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setsearchpathmode
56-
// "SetDllDirectory function" - https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectorya
57-
// "LoadLibraryExA function" - https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa
52+
// "Dynamic-Link Library Security" -
53+
// https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-security
54+
// "Dynamic-Link Library Search Order" -
55+
// https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order?redirectedfrom=MSDN
56+
// "SearchPath function" -
57+
// https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-searchpathw
58+
// "SetSearchPathMode function" -
59+
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setsearchpathmode
60+
// "SetDllDirectory function" -
61+
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setdlldirectorya
62+
// "LoadLibraryExA function" -
63+
// https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibraryexa
5864

5965
// Exclude current directory from the serch path
6066
rv1 = SetDllDirectoryA("");
61-
if (0 == rv1)
62-
{
63-
printf("Intel dpctl FATAL ERROR: Cannot exclude current directory from serch path.\n");
67+
if (0 == rv1) {
68+
printf("Intel dpctl FATAL ERROR: Cannot exclude current directory from "
69+
"serch path.\n");
6470
return NULL;
6571
}
6672

6773
rv2 = LoadLibraryExA(filename, NULL, DONT_RESOLVE_DLL_REFERENCES);
68-
if (NULL == rv2)
69-
{
70-
printf("Intel dpctl FATAL ERROR: Cannot find/load library %s.\n", filename);
74+
if (NULL == rv2) {
75+
printf("Intel dpctl FATAL ERROR: Cannot find/load library %s.\n",
76+
filename);
7177
return NULL;
7278
}
7379

7480
rv = GetModuleFileNameA(rv2, PathBuf, MAX_PATH);
75-
if (0 == rv)
76-
{
77-
printf("Intel dpctl FATAL ERROR: Cannot find module %s in memory.\n", filename);
81+
if (0 == rv) {
82+
printf("Intel dpctl FATAL ERROR: Cannot find module %s in memory.\n",
83+
filename);
7884
return NULL;
7985
}
8086

8187
FreeLibrary(rv2);
8288
rv2 = NULL;
8389

84-
size_t strLength = strnlen(PathBuf, MAX_PATH) + 1;
85-
wchar_t * wPathBuf = new wchar_t[strLength];
90+
size_t strLength = strnlen(PathBuf, MAX_PATH) + 1;
91+
wchar_t *wPathBuf = new wchar_t[strLength];
8692
size_t convertedChars = 0;
8793
mbstowcs_s(&convertedChars, wPathBuf, strLength, PathBuf, _TRUNCATE);
8894

@@ -92,64 +98,77 @@ static HMODULE WINAPI _DPCTLLoadLibrary(LPCTSTR filename)
9298
GUID pgActionID;
9399
WINTRUST_DATA pWVTData;
94100

95-
fdata.cbStruct = sizeof(WINTRUST_FILE_INFO);
96-
fdata.pcwszFilePath = wPathBuf;
97-
fdata.hFile = NULL;
101+
fdata.cbStruct = sizeof(WINTRUST_FILE_INFO);
102+
fdata.pcwszFilePath = wPathBuf;
103+
fdata.hFile = NULL;
98104
fdata.pgKnownSubject = NULL;
99105

100106
pgActionID = WINTRUST_ACTION_GENERIC_VERIFY_V2;
101107

102-
pWVTData.cbStruct = sizeof(WINTRUST_DATA);
108+
pWVTData.cbStruct = sizeof(WINTRUST_DATA);
103109
pWVTData.pPolicyCallbackData = NULL;
104-
pWVTData.pSIPClientData = NULL;
105-
pWVTData.dwUIChoice = WTD_UI_NONE;
110+
pWVTData.pSIPClientData = NULL;
111+
pWVTData.dwUIChoice = WTD_UI_NONE;
106112
pWVTData.fdwRevocationChecks = WTD_REVOKE_NONE;
107-
pWVTData.dwUnionChoice = WTD_CHOICE_FILE;
108-
pWVTData.pFile = &fdata;
109-
pWVTData.dwStateAction = WTD_STATEACTION_VERIFY;
110-
pWVTData.hWVTStateData = NULL;
111-
pWVTData.pwszURLReference = NULL;
112-
pWVTData.dwProvFlags = 0;
113-
pWVTData.dwUIContext = WTD_UICONTEXT_EXECUTE;
114-
pWVTData.pSignatureSettings = NULL;
113+
pWVTData.dwUnionChoice = WTD_CHOICE_FILE;
114+
pWVTData.pFile = &fdata;
115+
pWVTData.dwStateAction = WTD_STATEACTION_VERIFY;
116+
pWVTData.hWVTStateData = NULL;
117+
pWVTData.pwszURLReference = NULL;
118+
pWVTData.dwProvFlags = 0;
119+
pWVTData.dwUIContext = WTD_UICONTEXT_EXECUTE;
120+
pWVTData.pSignatureSettings = NULL;
115121

116122
sverif = WinVerifyTrust((HWND)INVALID_HANDLE_VALUE, &pgActionID, &pWVTData);
117123

118-
switch (sverif)
119-
{
124+
switch (sverif) {
120125
case TRUST_E_NOSIGNATURE:
121126
lerr = GetLastError();
122-
if (TRUST_E_NOSIGNATURE == lerr || TRUST_E_SUBJECT_FORM_UNKNOWN == lerr || TRUST_E_PROVIDER_UNKNOWN == lerr)
127+
if (TRUST_E_NOSIGNATURE == lerr ||
128+
TRUST_E_SUBJECT_FORM_UNKNOWN == lerr ||
129+
TRUST_E_PROVIDER_UNKNOWN == lerr)
123130
{
124131
printf("Intel dpctl FATAL ERROR: %s is not signed.\n", filename);
125132
}
126-
else
127-
{
128-
printf("Intel dpctl FATAL ERROR: An unknown error occurred trying to verify the signature of the %s.\n", filename);
133+
else {
134+
printf("Intel dpctl FATAL ERROR: An unknown error occurred trying "
135+
"to verify the signature of the %s.\n",
136+
filename);
129137
}
130138
break;
131139

132-
case TRUST_E_EXPLICIT_DISTRUST: printf("Intel dpctl FATAL ERROR: The signature/publisher of %s is disallowed.\n", filename); break;
140+
case TRUST_E_EXPLICIT_DISTRUST:
141+
printf("Intel dpctl FATAL ERROR: The signature/publisher of %s is "
142+
"disallowed.\n",
143+
filename);
144+
break;
133145

134-
case ERROR_SUCCESS: break;
146+
case ERROR_SUCCESS:
147+
break;
135148

136-
case TRUST_E_SUBJECT_NOT_TRUSTED: printf("Intel dpctl FATAL ERROR: The signature of %s in not trusted.\n", filename); break;
149+
case TRUST_E_SUBJECT_NOT_TRUSTED:
150+
printf("Intel dpctl FATAL ERROR: The signature of %s in not trusted.\n",
151+
filename);
152+
break;
137153

138154
case CRYPT_E_SECURITY_SETTINGS:
139-
printf("Intel dpctl FATAL ERROR: %s. The subject hash or publisher was not explicitly trusted and user trust was not allowed "
155+
printf("Intel dpctl FATAL ERROR: %s. The subject hash or publisher was "
156+
"not explicitly trusted and user trust was not allowed "
140157
"(CRYPT_E_SECURITY_SETTINGS).\n",
141158
filename);
142159
break;
143160

144-
default: printf("Intel dpctl FATAL ERROR: %s. Error code is 0x%x.\n", filename, (unsigned int)sverif); break;
161+
default:
162+
printf("Intel dpctl FATAL ERROR: %s. Error code is 0x%x.\n", filename,
163+
(unsigned int)sverif);
164+
break;
145165
}
146166

147167
pWVTData.dwStateAction = WTD_STATEACTION_CLOSE;
148168
WinVerifyTrust(NULL, &pgActionID, &pWVTData);
149169
delete[] wPathBuf;
150170

151-
if (ERROR_SUCCESS != sverif)
152-
{
171+
if (ERROR_SUCCESS != sverif) {
153172
return NULL;
154173
}
155174

@@ -160,7 +179,7 @@ static HMODULE WINAPI _DPCTLLoadLibrary(LPCTSTR filename)
160179

161180
return rv2;
162181
}
163-
#endif
182+
#endif
164183

165184
DPCTL_API HMODULE _dpctl_load_win_dynamic_lib(LPCTSTR filename)
166185
{

0 commit comments

Comments
 (0)