diff options
Diffstat (limited to 'src/dutil/srputil.cpp')
| -rw-r--r-- | src/dutil/srputil.cpp | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/dutil/srputil.cpp b/src/dutil/srputil.cpp index 9fc2f94a..e44536cc 100644 --- a/src/dutil/srputil.cpp +++ b/src/dutil/srputil.cpp | |||
| @@ -3,6 +3,21 @@ | |||
| 3 | #include "precomp.h" | 3 | #include "precomp.h" |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | // Exit macros | ||
| 7 | #define SrpExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
| 8 | #define SrpExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
| 9 | #define SrpExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
| 10 | #define SrpExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
| 11 | #define SrpExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
| 12 | #define SrpExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_SRPUTIL, x, s, __VA_ARGS__) | ||
| 13 | #define SrpExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_SRPUTIL, p, x, e, s, __VA_ARGS__) | ||
| 14 | #define SrpExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, p, x, s, __VA_ARGS__) | ||
| 15 | #define SrpExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_SRPUTIL, p, x, e, s, __VA_ARGS__) | ||
| 16 | #define SrpExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_SRPUTIL, p, x, s, __VA_ARGS__) | ||
| 17 | #define SrpExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_SRPUTIL, e, x, s, __VA_ARGS__) | ||
| 18 | #define SrpExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_SRPUTIL, g, x, s, __VA_ARGS__) | ||
| 19 | |||
| 20 | |||
| 6 | typedef BOOL (WINAPI *PFN_SETRESTOREPTW)( | 21 | typedef BOOL (WINAPI *PFN_SETRESTOREPTW)( |
| 7 | __in PRESTOREPOINTINFOW pRestorePtSpec, | 22 | __in PRESTOREPOINTINFOW pRestorePtSpec, |
| 8 | __out PSTATEMGRSTATUS pSMgrStatus | 23 | __out PSTATEMGRSTATUS pSMgrStatus |
| @@ -28,7 +43,7 @@ DAPI_(HRESULT) SrpInitialize( | |||
| 28 | } | 43 | } |
| 29 | 44 | ||
| 30 | vpfnSRSetRestorePointW = reinterpret_cast<PFN_SETRESTOREPTW>(::GetProcAddress(vhSrClientDll, "SRSetRestorePointW")); | 45 | vpfnSRSetRestorePointW = reinterpret_cast<PFN_SETRESTOREPTW>(::GetProcAddress(vhSrClientDll, "SRSetRestorePointW")); |
| 31 | ExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address."); | 46 | SrpExitOnNullWithLastError(vpfnSRSetRestorePointW, hr, "Failed to find set restore point proc address."); |
| 32 | 47 | ||
| 33 | // If allowed, initialize COM security to enable NetworkService, | 48 | // If allowed, initialize COM security to enable NetworkService, |
| 34 | // LocalService and System to make callbacks to the process | 49 | // LocalService and System to make callbacks to the process |
| @@ -37,7 +52,7 @@ DAPI_(HRESULT) SrpInitialize( | |||
| 37 | if (fInitializeComSecurity) | 52 | if (fInitializeComSecurity) |
| 38 | { | 53 | { |
| 39 | hr = InitializeComSecurity(); | 54 | hr = InitializeComSecurity(); |
| 40 | ExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore."); | 55 | SrpExitOnFailure(hr, "Failed to initialize security for COM to talk to system restore."); |
| 41 | } | 56 | } |
| 42 | 57 | ||
| 43 | LExit: | 58 | LExit: |
| @@ -79,7 +94,7 @@ DAPI_(HRESULT) SrpCreateRestorePoint( | |||
| 79 | 94 | ||
| 80 | if (!vpfnSRSetRestorePointW(&restorePoint, &status)) | 95 | if (!vpfnSRSetRestorePointW(&restorePoint, &status)) |
| 81 | { | 96 | { |
| 82 | ExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point."); | 97 | SrpExitOnWin32Error(status.nStatus, hr, "Failed to create system restore point."); |
| 83 | } | 98 | } |
| 84 | 99 | ||
| 85 | LExit: | 100 | LExit: |
| @@ -116,42 +131,42 @@ static HRESULT InitializeComSecurity() | |||
| 116 | // Initialize the security descriptor. | 131 | // Initialize the security descriptor. |
| 117 | if (!::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) | 132 | if (!::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) |
| 118 | { | 133 | { |
| 119 | ExitWithLastError(hr, "Failed to initialize security descriptor for system restore."); | 134 | SrpExitWithLastError(hr, "Failed to initialize security descriptor for system restore."); |
| 120 | } | 135 | } |
| 121 | 136 | ||
| 122 | // Create an administrator group security identifier (SID). | 137 | // Create an administrator group security identifier (SID). |
| 123 | cbSid = sizeof(rgSidBA); | 138 | cbSid = sizeof(rgSidBA); |
| 124 | if (!::CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, rgSidBA, &cbSid)) | 139 | if (!::CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, rgSidBA, &cbSid)) |
| 125 | { | 140 | { |
| 126 | ExitWithLastError(hr, "Failed to create administrator SID for system restore."); | 141 | SrpExitWithLastError(hr, "Failed to create administrator SID for system restore."); |
| 127 | } | 142 | } |
| 128 | 143 | ||
| 129 | // Create a local service security identifier (SID). | 144 | // Create a local service security identifier (SID). |
| 130 | cbSid = sizeof(rgSidLS); | 145 | cbSid = sizeof(rgSidLS); |
| 131 | if (!::CreateWellKnownSid(WinLocalServiceSid, NULL, rgSidLS, &cbSid)) | 146 | if (!::CreateWellKnownSid(WinLocalServiceSid, NULL, rgSidLS, &cbSid)) |
| 132 | { | 147 | { |
| 133 | ExitWithLastError(hr, "Failed to create local service SID for system restore."); | 148 | SrpExitWithLastError(hr, "Failed to create local service SID for system restore."); |
| 134 | } | 149 | } |
| 135 | 150 | ||
| 136 | // Create a network service security identifier (SID). | 151 | // Create a network service security identifier (SID). |
| 137 | cbSid = sizeof(rgSidNS); | 152 | cbSid = sizeof(rgSidNS); |
| 138 | if (!::CreateWellKnownSid(WinNetworkServiceSid, NULL, rgSidNS, &cbSid)) | 153 | if (!::CreateWellKnownSid(WinNetworkServiceSid, NULL, rgSidNS, &cbSid)) |
| 139 | { | 154 | { |
| 140 | ExitWithLastError(hr, "Failed to create network service SID for system restore."); | 155 | SrpExitWithLastError(hr, "Failed to create network service SID for system restore."); |
| 141 | } | 156 | } |
| 142 | 157 | ||
| 143 | // Create a personal account security identifier (SID). | 158 | // Create a personal account security identifier (SID). |
| 144 | cbSid = sizeof(rgSidPS); | 159 | cbSid = sizeof(rgSidPS); |
| 145 | if (!::CreateWellKnownSid(WinSelfSid, NULL, rgSidPS, &cbSid)) | 160 | if (!::CreateWellKnownSid(WinSelfSid, NULL, rgSidPS, &cbSid)) |
| 146 | { | 161 | { |
| 147 | ExitWithLastError(hr, "Failed to create self SID for system restore."); | 162 | SrpExitWithLastError(hr, "Failed to create self SID for system restore."); |
| 148 | } | 163 | } |
| 149 | 164 | ||
| 150 | // Create a local service security identifier (SID). | 165 | // Create a local service security identifier (SID). |
| 151 | cbSid = sizeof(rgSidSY); | 166 | cbSid = sizeof(rgSidSY); |
| 152 | if (!::CreateWellKnownSid(WinLocalSystemSid, NULL, rgSidSY, &cbSid)) | 167 | if (!::CreateWellKnownSid(WinLocalSystemSid, NULL, rgSidSY, &cbSid)) |
| 153 | { | 168 | { |
| 154 | ExitWithLastError(hr, "Failed to create local system SID for system restore."); | 169 | SrpExitWithLastError(hr, "Failed to create local system SID for system restore."); |
| 155 | } | 170 | } |
| 156 | 171 | ||
| 157 | // Setup the access control entries (ACE) for COM. COM_RIGHTS_EXECUTE and | 172 | // Setup the access control entries (ACE) for COM. COM_RIGHTS_EXECUTE and |
| @@ -203,29 +218,29 @@ static HRESULT InitializeComSecurity() | |||
| 203 | 218 | ||
| 204 | // Create an access control list (ACL) using this ACE list. | 219 | // Create an access control list (ACL) using this ACE list. |
| 205 | er = ::SetEntriesInAcl(countof(ea), ea, NULL, &pAcl); | 220 | er = ::SetEntriesInAcl(countof(ea), ea, NULL, &pAcl); |
| 206 | ExitOnWin32Error(er, hr, "Failed to create ACL for system restore."); | 221 | SrpExitOnWin32Error(er, hr, "Failed to create ACL for system restore."); |
| 207 | 222 | ||
| 208 | // Set the security descriptor owner to Administrators. | 223 | // Set the security descriptor owner to Administrators. |
| 209 | if (!::SetSecurityDescriptorOwner(&sd, rgSidBA, FALSE)) | 224 | if (!::SetSecurityDescriptorOwner(&sd, rgSidBA, FALSE)) |
| 210 | { | 225 | { |
| 211 | ExitWithLastError(hr, "Failed to set administrators owner for system restore."); | 226 | SrpExitWithLastError(hr, "Failed to set administrators owner for system restore."); |
| 212 | } | 227 | } |
| 213 | 228 | ||
| 214 | // Set the security descriptor group to Administrators. | 229 | // Set the security descriptor group to Administrators. |
| 215 | if (!::SetSecurityDescriptorGroup(&sd, rgSidBA, FALSE)) | 230 | if (!::SetSecurityDescriptorGroup(&sd, rgSidBA, FALSE)) |
| 216 | { | 231 | { |
| 217 | ExitWithLastError(hr, "Failed to set administrators group access for system restore."); | 232 | SrpExitWithLastError(hr, "Failed to set administrators group access for system restore."); |
| 218 | } | 233 | } |
| 219 | 234 | ||
| 220 | // Set the discretionary access control list (DACL) to the ACL. | 235 | // Set the discretionary access control list (DACL) to the ACL. |
| 221 | if (!::SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) | 236 | if (!::SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) |
| 222 | { | 237 | { |
| 223 | ExitWithLastError(hr, "Failed to set DACL for system restore."); | 238 | SrpExitWithLastError(hr, "Failed to set DACL for system restore."); |
| 224 | } | 239 | } |
| 225 | 240 | ||
| 226 | // Note that an explicit security descriptor is being passed in. | 241 | // Note that an explicit security descriptor is being passed in. |
| 227 | hr= ::CoInitializeSecurity(&sd, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_DISABLE_AAA | EOAC_NO_CUSTOM_MARSHAL, NULL); | 242 | hr= ::CoInitializeSecurity(&sd, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_DISABLE_AAA | EOAC_NO_CUSTOM_MARSHAL, NULL); |
| 228 | ExitOnFailure(hr, "Failed to initialize COM security for system restore."); | 243 | SrpExitOnFailure(hr, "Failed to initialize COM security for system restore."); |
| 229 | 244 | ||
| 230 | LExit: | 245 | LExit: |
| 231 | if (pAcl) | 246 | if (pAcl) |
