1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
#include "precomp.h"
HRESULT HashPublicKeyInfo(
__in PCERT_CONTEXT pCertContext,
__in_ecount(*pcbSubjectKeyIndentifier) BYTE* rgbSubjectKeyIdentifier,
__inout DWORD* pcbSubjectKeyIndentifier
)
{
HRESULT hr = S_OK;
if (!::CryptHashPublicKeyInfo(NULL, CALG_SHA1, 0, X509_ASN_ENCODING, &pCertContext->pCertInfo->SubjectPublicKeyInfo, rgbSubjectKeyIdentifier, pcbSubjectKeyIndentifier))
{
ExitWithLastError(hr, "Failed to hash public key information.");
}
LExit:
return hr;
}
HRESULT ResetAcls(
__in LPCWSTR pwzFiles[],
__in DWORD cFiles
)
{
HRESULT hr = S_OK;
ACL* pacl = NULL;
DWORD cbAcl = sizeof(ACL);
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!::GetVersionExA(&osvi))
{
ExitOnLastError(hr, "failed to get OS version");
}
// If we're running on NT 4 or earlier, or ME or earlier, don't reset ACLs.
if (4 >= osvi.dwMajorVersion)
{
ExitFunction1(hr = S_FALSE);
}
// create an empty (not NULL!) ACL to use on all the files
pacl = static_cast<ACL*>(MemAlloc(cbAcl, FALSE));
ExitOnNull(pacl, hr, E_OUTOFMEMORY, "failed to allocate ACL");
#pragma prefast(push)
#pragma prefast(disable:25029)
if (!::InitializeAcl(pacl, cbAcl, ACL_REVISION))
#pragma prefast(op)
{
ExitOnLastError(hr, "failed to initialize ACL");
}
// reset the existing security permissions on each file
for (DWORD i = 0; i < cFiles; ++i)
{
hr = ::SetNamedSecurityInfoW(const_cast<LPWSTR>(pwzFiles[i]), SE_FILE_OBJECT, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, NULL, NULL, pacl, NULL);
if (ERROR_FILE_NOT_FOUND != hr && ERROR_PATH_NOT_FOUND != hr)
{
ExitOnFailure(hr = HRESULT_FROM_WIN32(hr), "failed to set security descriptor for file: %S", pwzFiles[i]);
}
}
// Setting to S_OK because we could end with ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND as valid return values.
hr = S_OK;
AssertSz(::IsValidAcl(pacl), "ResetAcls() - created invalid ACL");
LExit:
if (pacl)
{
MemFree(pacl);
}
return hr;
}
HRESULT CreateCabBegin(
__in LPCWSTR wzCab,
__in LPCWSTR wzCabDir,
__in DWORD dwMaxFiles,
__in DWORD dwMaxSize,
__in DWORD dwMaxThresh,
__in COMPRESSION_TYPE ct,
__out HANDLE *phContext
)
{
return CabCBegin(wzCab, wzCabDir, dwMaxFiles, dwMaxSize, dwMaxThresh, ct, phContext);
}
HRESULT CreateCabAddFile(
__in LPCWSTR wzFile,
__in_opt LPCWSTR wzToken,
__in_opt PMSIFILEHASHINFO pmfHash,
__in HANDLE hContext
)
{
return CabCAddFile(wzFile, wzToken, pmfHash, hContext);
}
HRESULT CreateCabAddFiles(
__in LPCWSTR pwzFiles[],
__in LPCWSTR pwzTokens[],
__in PMSIFILEHASHINFO pmfHash[],
__in DWORD cFiles,
__in HANDLE hContext
)
{
HRESULT hr = S_OK;
DWORD i;
Assert(pwzFiles);
Assert(hContext);
for (i = 0; i < cFiles; i++)
{
hr = CreateCabAddFile(
pwzFiles[i],
pwzTokens ? pwzTokens[i] : NULL,
pmfHash[i],
hContext
);
ExitOnFailure(hr, "Failed to add file %S to cab", pwzFiles[i]);
}
LExit:
return hr;
}
HRESULT CreateCabFinish(
__in HANDLE hContext,
__in_opt FileSplitCabNamesCallback newCabNamesCallBackAddress
)
{
// Convert address into Binder callback function
return CabCFinish(hContext, newCabNamesCallBackAddress);
}
void CreateCabCancel(
__in HANDLE hContext
)
{
CabCCancel(hContext);
}
HRESULT ExtractCabBegin()
{
return CabInitialize(FALSE);
}
HRESULT ExtractCab(
__in LPCWSTR wzCabinet,
__in LPCWSTR wzExtractDir
)
{
return CabExtract(wzCabinet, L"*", wzExtractDir, NULL, NULL, 0);
}
void ExtractCabFinish()
{
CabUninitialize();
return;
}
HRESULT EnumerateCabBegin()
{
return CabInitialize(FALSE);
}
HRESULT EnumerateCab(
__in LPCWSTR wzCabinet,
__in STDCALL_PFNFDINOTIFY pfnNotify
)
{
return CabEnumerate(wzCabinet, L"*", pfnNotify, 0);
}
void EnumerateCabFinish()
{
CabUninitialize();
return;
}
BOOL WINAPI DllMain(
__in HINSTANCE /*hInstance*/,
__in DWORD dwReason,
__in LPVOID /*lpvReserved*/
)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
case DLL_PROCESS_DETACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
|