aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/userutil.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-03-02 14:19:14 -0600
committerSean Hall <r.sean.hall@gmail.com>2021-03-02 15:40:02 -0600
commit10ebf674da5df9224e4eddd3545518434c5b455b (patch)
treeea1f4063edd46e9942eab94dd7adb2f75c6c589e /src/dutil/userutil.cpp
parent3bbf1347b900ec115a12faf8f46965c9b7649696 (diff)
downloadwix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.gz
wix-10ebf674da5df9224e4eddd3545518434c5b455b.tar.bz2
wix-10ebf674da5df9224e4eddd3545518434c5b455b.zip
Update rest of dutil to use their own source with the Exit* macros.
Fix some CA warnings.
Diffstat (limited to 'src/dutil/userutil.cpp')
-rw-r--r--src/dutil/userutil.cpp61
1 files changed, 38 insertions, 23 deletions
diff --git a/src/dutil/userutil.cpp b/src/dutil/userutil.cpp
index 2e77f1df..ca6d5480 100644
--- a/src/dutil/userutil.cpp
+++ b/src/dutil/userutil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5
6// UserExit macros
7#define UserExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
8#define UserExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
9#define UserExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
10#define UserExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
11#define UserExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
12#define UserExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_USERUTIL, x, s, __VA_ARGS__)
13#define UserExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_USERUTIL, p, x, e, s, __VA_ARGS__)
14#define UserExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_USERUTIL, p, x, s, __VA_ARGS__)
15#define UserExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_USERUTIL, p, x, e, s, __VA_ARGS__)
16#define UserExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_USERUTIL, p, x, s, __VA_ARGS__)
17#define UserExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_USERUTIL, e, x, s, __VA_ARGS__)
18#define UserExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_USERUTIL, g, x, s, __VA_ARGS__)
19
5static BOOL CheckIsMemberHelper( 20static BOOL CheckIsMemberHelper(
6 __in_z LPCWSTR pwzGroupUserDomain, 21 __in_z LPCWSTR pwzGroupUserDomain,
7 __in_ecount(cguiGroupData) const GROUP_USERS_INFO_0 *pguiGroupData, 22 __in_ecount(cguiGroupData) const GROUP_USERS_INFO_0 *pguiGroupData,
@@ -29,14 +44,14 @@ extern "C" HRESULT DAPI UserBuildDomainUserName(
29 if (cch >= cchLeft) 44 if (cch >= cchLeft)
30 { 45 {
31 hr = ERROR_MORE_DATA; 46 hr = ERROR_MORE_DATA;
32 ExitOnFailure(hr, "Buffer size is not big enough to hold domain name: %ls", pwzDomain); 47 UserExitOnFailure(hr, "Buffer size is not big enough to hold domain name: %ls", pwzDomain);
33 } 48 }
34 else if (cch > 0) 49 else if (cch > 0)
35 { 50 {
36 // handle the domain case 51 // handle the domain case
37 52
38 hr = ::StringCchCopyNW(pwz, cchWz, pwzDomain, cchLeft - 1); // last parameter does not include '\0' 53 hr = ::StringCchCopyNW(pwz, cchWz, pwzDomain, cchLeft - 1); // last parameter does not include '\0'
39 ExitOnFailure(hr, "Failed to copy Domain onto string."); 54 UserExitOnFailure(hr, "Failed to copy Domain onto string.");
40 55
41 cchLeft -= cch; 56 cchLeft -= cch;
42 pwz += cch; 57 pwz += cch;
@@ -45,11 +60,11 @@ extern "C" HRESULT DAPI UserBuildDomainUserName(
45 if (1 >= cchLeft) 60 if (1 >= cchLeft)
46 { 61 {
47 hr = ERROR_MORE_DATA; 62 hr = ERROR_MORE_DATA;
48 ExitOnFailure(hr, "Insufficient buffer size while building domain user name"); 63 UserExitOnFailure(hr, "Insufficient buffer size while building domain user name");
49 } 64 }
50 65
51 hr = ::StringCchCopyNW(pwz, cchWz, L"\\", cchLeft - 1); // last parameter does not include '\0' 66 hr = ::StringCchCopyNW(pwz, cchWz, L"\\", cchLeft - 1); // last parameter does not include '\0'
52 ExitOnFailure(hr, "Failed to copy backslash onto string."); 67 UserExitOnFailure(hr, "Failed to copy backslash onto string.");
53 68
54 --cchLeft; 69 --cchLeft;
55 ++pwz; 70 ++pwz;
@@ -60,11 +75,11 @@ extern "C" HRESULT DAPI UserBuildDomainUserName(
60 if (cch >= cchLeft) 75 if (cch >= cchLeft)
61 { 76 {
62 hr = ERROR_MORE_DATA; 77 hr = ERROR_MORE_DATA;
63 ExitOnFailure(hr, "Buffer size is not big enough to hold user name: %ls", pwzName); 78 UserExitOnFailure(hr, "Buffer size is not big enough to hold user name: %ls", pwzName);
64 } 79 }
65 80
66 hr = ::StringCchCopyNW(pwz, cchWz, pwzName, cchLeft - 1); // last parameter does not include '\0' 81 hr = ::StringCchCopyNW(pwz, cchWz, pwzName, cchLeft - 1); // last parameter does not include '\0'
67 ExitOnFailure(hr, "Failed to copy User name onto string."); 82 UserExitOnFailure(hr, "Failed to copy User name onto string.");
68 83
69LExit: 84LExit:
70 return hr; 85 return hr;
@@ -98,10 +113,10 @@ extern "C" HRESULT DAPI UserCheckIsMember(
98 VARIANT_BOOL vtBoolResult = VARIANT_FALSE; 113 VARIANT_BOOL vtBoolResult = VARIANT_FALSE;
99 114
100 hr = UserBuildDomainUserName(wzGroupUserDomain, countof(wzGroupUserDomain), pwzGroupName, pwzGroupDomain); 115 hr = UserBuildDomainUserName(wzGroupUserDomain, countof(wzGroupUserDomain), pwzGroupName, pwzGroupDomain);
101 ExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName); 116 UserExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName);
102 117
103 hr = UserBuildDomainUserName(wzUserDomain, countof(wzUserDomain), pwzName, pwzDomain); 118 hr = UserBuildDomainUserName(wzUserDomain, countof(wzUserDomain), pwzName, pwzDomain);
104 ExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName); 119 UserExitOnFailure(hr, "Failed to build group name from group domain %ls, group name %ls", pwzGroupDomain, pwzGroupName);
105 120
106 if (pwzDomain && *pwzDomain) 121 if (pwzDomain && *pwzDomain)
107 { 122 {
@@ -115,12 +130,12 @@ extern "C" HRESULT DAPI UserCheckIsMember(
115 Trace(REPORT_VERBOSE, "failed to get groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er)); 130 Trace(REPORT_VERBOSE, "failed to get groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er));
116 er = ERROR_SUCCESS; 131 er = ERROR_SUCCESS;
117 } 132 }
118 ExitOnWin32Error(er, hr, "Failed to get list of global groups for user while checking group membership information for user: %ls", pwzName); 133 UserExitOnWin32Error(er, hr, "Failed to get list of global groups for user while checking group membership information for user: %ls", pwzName);
119 134
120 if (dwRead != dwTotal) 135 if (dwRead != dwTotal)
121 { 136 {
122 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA); 137 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
123 ExitOnRootFailure(hr, "Failed to get entire list of groups (global) for user while checking group membership information for user: %ls", pwzName); 138 UserExitOnRootFailure(hr, "Failed to get entire list of groups (global) for user while checking group membership information for user: %ls", pwzName);
124 } 139 }
125 140
126 if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead)) 141 if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead))
@@ -143,12 +158,12 @@ extern "C" HRESULT DAPI UserCheckIsMember(
143 Trace(REPORT_VERBOSE, "failed to get local groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er)); 158 Trace(REPORT_VERBOSE, "failed to get local groups for user %ls from domain %ls with error code 0x%x - continuing", pwzName, (wz != NULL) ? wz : L"", HRESULT_FROM_WIN32(er));
144 er = ERROR_SUCCESS; 159 er = ERROR_SUCCESS;
145 } 160 }
146 ExitOnWin32Error(er, hr, "Failed to get list of groups for user while checking group membership information for user: %ls", pwzName); 161 UserExitOnWin32Error(er, hr, "Failed to get list of groups for user while checking group membership information for user: %ls", pwzName);
147 162
148 if (dwRead != dwTotal) 163 if (dwRead != dwTotal)
149 { 164 {
150 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA); 165 hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
151 ExitOnRootFailure(hr, "Failed to get entire list of groups (local) for user while checking group membership information for user: %ls", pwzName); 166 UserExitOnRootFailure(hr, "Failed to get entire list of groups (local) for user while checking group membership information for user: %ls", pwzName);
152 } 167 }
153 168
154 if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead)) 169 if (CheckIsMemberHelper(wzGroupUserDomain, pguiGroupData, dwRead))
@@ -159,18 +174,18 @@ extern "C" HRESULT DAPI UserCheckIsMember(
159 174
160 // If the above methods failed, let's try active directory 175 // If the above methods failed, let's try active directory
161 hr = UserCreateADsPath(pwzDomain, pwzName, &bstrUser); 176 hr = UserCreateADsPath(pwzDomain, pwzName, &bstrUser);
162 ExitOnFailure(hr, "failed to create user ADsPath in order to check group membership for group: %ls domain: %ls", pwzName, pwzDomain); 177 UserExitOnFailure(hr, "failed to create user ADsPath in order to check group membership for group: %ls domain: %ls", pwzName, pwzDomain);
163 178
164 hr = UserCreateADsPath(pwzGroupDomain, pwzGroupName, &bstrGroup); 179 hr = UserCreateADsPath(pwzGroupDomain, pwzGroupName, &bstrGroup);
165 ExitOnFailure(hr, "failed to create group ADsPath in order to check group membership for group: %ls domain: %ls", pwzGroupName, pwzGroupDomain); 180 UserExitOnFailure(hr, "failed to create group ADsPath in order to check group membership for group: %ls domain: %ls", pwzGroupName, pwzGroupDomain);
166 181
167 if (lstrlenW(pwzGroupDomain) > 0) 182 if (lstrlenW(pwzGroupDomain) > 0)
168 { 183 {
169 hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup)); 184 hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup));
170 ExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) ); 185 UserExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) );
171 186
172 hr = pGroup->IsMember(bstrUser, &vtBoolResult); 187 hr = pGroup->IsMember(bstrUser, &vtBoolResult);
173 ExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) ); 188 UserExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) );
174 } 189 }
175 190
176 if (vtBoolResult) 191 if (vtBoolResult)
@@ -180,10 +195,10 @@ extern "C" HRESULT DAPI UserCheckIsMember(
180 } 195 }
181 196
182 hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup)); 197 hr = ::ADsGetObject(bstrGroup, IID_IADsGroup, reinterpret_cast<void**>(&pGroup));
183 ExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) ); 198 UserExitOnFailure(hr, "Failed to get group '%ls' from active directory.", reinterpret_cast<WCHAR*>(bstrGroup) );
184 199
185 hr = pGroup->IsMember(bstrUser, &vtBoolResult); 200 hr = pGroup->IsMember(bstrUser, &vtBoolResult);
186 ExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) ); 201 UserExitOnFailure(hr, "Failed to check if user %ls is a member of group '%ls' using active directory.", reinterpret_cast<WCHAR*>(bstrUser), reinterpret_cast<WCHAR*>(bstrGroup) );
187 202
188 if (vtBoolResult) 203 if (vtBoolResult)
189 { 204 {
@@ -222,25 +237,25 @@ extern "C" HRESULT DAPI UserCreateADsPath(
222 LPWSTR pwzAdsPath = NULL; 237 LPWSTR pwzAdsPath = NULL;
223 238
224 hr = StrAllocString(&pwzAdsPath, L"WinNT://", 0); 239 hr = StrAllocString(&pwzAdsPath, L"WinNT://", 0);
225 ExitOnFailure(hr, "failed to allocate AdsPath string"); 240 UserExitOnFailure(hr, "failed to allocate AdsPath string");
226 241
227 if (*wzObjectDomain) 242 if (*wzObjectDomain)
228 { 243 {
229 hr = StrAllocFormatted(&pwzAdsPath, L"%s/%s", wzObjectDomain, wzObjectName); 244 hr = StrAllocFormatted(&pwzAdsPath, L"%s/%s", wzObjectDomain, wzObjectName);
230 ExitOnFailure(hr, "failed to allocate AdsPath string"); 245 UserExitOnFailure(hr, "failed to allocate AdsPath string");
231 } 246 }
232 else if (NULL != wcsstr(wzObjectName, L"\\") || NULL != wcsstr(wzObjectName, L"/")) 247 else if (NULL != wcsstr(wzObjectName, L"\\") || NULL != wcsstr(wzObjectName, L"/"))
233 { 248 {
234 hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0); 249 hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0);
235 ExitOnFailure(hr, "failed to concat objectname: %ls", wzObjectName); 250 UserExitOnFailure(hr, "failed to concat objectname: %ls", wzObjectName);
236 } 251 }
237 else 252 else
238 { 253 {
239 hr = StrAllocConcat(&pwzAdsPath, L"Localhost/", 0); 254 hr = StrAllocConcat(&pwzAdsPath, L"Localhost/", 0);
240 ExitOnFailure(hr, "failed to concat LocalHost/"); 255 UserExitOnFailure(hr, "failed to concat LocalHost/");
241 256
242 hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0); 257 hr = StrAllocConcat(&pwzAdsPath, wzObjectName, 0);
243 ExitOnFailure(hr, "failed to concat object name: %ls", wzObjectName); 258 UserExitOnFailure(hr, "failed to concat object name: %ls", wzObjectName);
244 } 259 }
245 260
246 *pbstrAdsPath = ::SysAllocString(pwzAdsPath); 261 *pbstrAdsPath = ::SysAllocString(pwzAdsPath);