diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 14:19:14 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-03-02 15:40:02 -0600 |
| commit | 10ebf674da5df9224e4eddd3545518434c5b455b (patch) | |
| tree | ea1f4063edd46e9942eab94dd7adb2f75c6c589e /src/dutil/acl2util.cpp | |
| parent | 3bbf1347b900ec115a12faf8f46965c9b7649696 (diff) | |
| download | wix-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/acl2util.cpp')
| -rw-r--r-- | src/dutil/acl2util.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/dutil/acl2util.cpp b/src/dutil/acl2util.cpp index 2261abe3..5aba60f0 100644 --- a/src/dutil/acl2util.cpp +++ b/src/dutil/acl2util.cpp | |||
| @@ -2,6 +2,20 @@ | |||
| 2 | 2 | ||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | // Exit macros | ||
| 6 | #define AclExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
| 7 | #define AclExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
| 8 | #define AclExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
| 9 | #define AclExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define AclExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define AclExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_ACLUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define AclExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__) | ||
| 13 | #define AclExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__) | ||
| 14 | #define AclExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_ACLUTIL, p, x, e, s, __VA_ARGS__) | ||
| 15 | #define AclExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_ACLUTIL, p, x, s, __VA_ARGS__) | ||
| 16 | #define AclExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_ACLUTIL, e, x, s, __VA_ARGS__) | ||
| 17 | #define AclExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_ACLUTIL, g, x, s, __VA_ARGS__) | ||
| 18 | |||
| 5 | /******************************************************************** | 19 | /******************************************************************** |
| 6 | AclCalculateServiceSidString - gets the SID string for the given service name | 20 | AclCalculateServiceSidString - gets the SID string for the given service name |
| 7 | 21 | ||
| @@ -26,17 +40,17 @@ extern "C" HRESULT DAPI AclCalculateServiceSidString( | |||
| 26 | if (0 == cchServiceName) | 40 | if (0 == cchServiceName) |
| 27 | { | 41 | { |
| 28 | hr = ::StringCchLengthW(wzServiceName, INT_MAX, reinterpret_cast<size_t*>(&cchServiceName)); | 42 | hr = ::StringCchLengthW(wzServiceName, INT_MAX, reinterpret_cast<size_t*>(&cchServiceName)); |
| 29 | ExitOnFailure(hr, "Failed to get the length of the service name."); | 43 | AclExitOnFailure(hr, "Failed to get the length of the service name."); |
| 30 | } | 44 | } |
| 31 | 45 | ||
| 32 | hr = StrAllocStringToUpperInvariant(&sczUpperServiceName, wzServiceName, cchServiceName); | 46 | hr = StrAllocStringToUpperInvariant(&sczUpperServiceName, wzServiceName, cchServiceName); |
| 33 | ExitOnFailure(hr, "Failed to upper case the service name."); | 47 | AclExitOnFailure(hr, "Failed to upper case the service name."); |
| 34 | 48 | ||
| 35 | pbHash = reinterpret_cast<BYTE*>(MemAlloc(cbHash, TRUE)); | 49 | pbHash = reinterpret_cast<BYTE*>(MemAlloc(cbHash, TRUE)); |
| 36 | ExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to allocate hash byte array."); | 50 | AclExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to allocate hash byte array."); |
| 37 | 51 | ||
| 38 | hr = CrypHashBuffer(reinterpret_cast<BYTE*>(sczUpperServiceName), cchServiceName * 2, PROV_RSA_FULL, CALG_SHA1, pbHash, cbHash); | 52 | hr = CrypHashBuffer(reinterpret_cast<BYTE*>(sczUpperServiceName), cchServiceName * 2, PROV_RSA_FULL, CALG_SHA1, pbHash, cbHash); |
| 39 | ExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to hash the service name."); | 53 | AclExitOnNull(pbHash, hr, E_OUTOFMEMORY, "Failed to hash the service name."); |
| 40 | 54 | ||
| 41 | hr = StrAllocFormatted(psczSid, L"S-1-5-80-%u-%u-%u-%u-%u", | 55 | hr = StrAllocFormatted(psczSid, L"S-1-5-80-%u-%u-%u-%u-%u", |
| 42 | MAKEDWORD(MAKEWORD(pbHash[0], pbHash[1]), MAKEWORD(pbHash[2], pbHash[3])), | 56 | MAKEDWORD(MAKEWORD(pbHash[0], pbHash[1]), MAKEWORD(pbHash[2], pbHash[3])), |
| @@ -80,7 +94,7 @@ extern "C" HRESULT DAPI AclGetAccountSidStringEx( | |||
| 80 | 94 | ||
| 81 | if (!::ConvertSidToStringSidW(psid, &pwz)) | 95 | if (!::ConvertSidToStringSidW(psid, &pwz)) |
| 82 | { | 96 | { |
| 83 | ExitWithLastError(hr, "Failed to convert SID to string for Account: %ls", wzAccount); | 97 | AclExitWithLastError(hr, "Failed to convert SID to string for Account: %ls", wzAccount); |
| 84 | } | 98 | } |
| 85 | 99 | ||
| 86 | hr = StrAllocString(psczSid, pwz, 0); | 100 | hr = StrAllocString(psczSid, pwz, 0); |
| @@ -90,20 +104,20 @@ extern "C" HRESULT DAPI AclGetAccountSidStringEx( | |||
| 90 | if (HRESULT_FROM_WIN32(ERROR_NONE_MAPPED) == hr) | 104 | if (HRESULT_FROM_WIN32(ERROR_NONE_MAPPED) == hr) |
| 91 | { | 105 | { |
| 92 | HRESULT hrLength = ::StringCchLengthW(wzAccount, INT_MAX, reinterpret_cast<size_t*>(&cchAccount)); | 106 | HRESULT hrLength = ::StringCchLengthW(wzAccount, INT_MAX, reinterpret_cast<size_t*>(&cchAccount)); |
| 93 | ExitOnFailure(hrLength, "Failed to get the length of the account name."); | 107 | AclExitOnFailure(hrLength, "Failed to get the length of the account name."); |
| 94 | 108 | ||
| 95 | if (11 < cchAccount && CSTR_EQUAL == CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, L"NT SERVICE\\", 11, wzAccount, 11)) | 109 | if (11 < cchAccount && CSTR_EQUAL == CompareStringW(LOCALE_NEUTRAL, NORM_IGNORECASE, L"NT SERVICE\\", 11, wzAccount, 11)) |
| 96 | { | 110 | { |
| 97 | // If the service is not installed then LookupAccountName doesn't resolve the SID, but we can calculate it. | 111 | // If the service is not installed then LookupAccountName doesn't resolve the SID, but we can calculate it. |
| 98 | LPCWSTR wzServiceName = &wzAccount[11]; | 112 | LPCWSTR wzServiceName = &wzAccount[11]; |
| 99 | hr = AclCalculateServiceSidString(wzServiceName, cchAccount - 11, &sczSid); | 113 | hr = AclCalculateServiceSidString(wzServiceName, cchAccount - 11, &sczSid); |
| 100 | ExitOnFailure(hr, "Failed to calculate the service SID for %ls", wzServiceName); | 114 | AclExitOnFailure(hr, "Failed to calculate the service SID for %ls", wzServiceName); |
| 101 | 115 | ||
| 102 | *psczSid = sczSid; | 116 | *psczSid = sczSid; |
| 103 | sczSid = NULL; | 117 | sczSid = NULL; |
| 104 | } | 118 | } |
| 105 | } | 119 | } |
| 106 | ExitOnFailure(hr, "Failed to get SID for account: %ls", wzAccount); | 120 | AclExitOnFailure(hr, "Failed to get SID for account: %ls", wzAccount); |
| 107 | } | 121 | } |
| 108 | 122 | ||
| 109 | LExit: | 123 | LExit: |
