diff options
Diffstat (limited to '')
-rw-r--r-- | src/dutil/metautil.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/dutil/metautil.cpp b/src/dutil/metautil.cpp index 612b1127..109cd31e 100644 --- a/src/dutil/metautil.cpp +++ b/src/dutil/metautil.cpp | |||
@@ -9,6 +9,21 @@ | |||
9 | #include "metautil.h" | 9 | #include "metautil.h" |
10 | 10 | ||
11 | 11 | ||
12 | // Exit macros | ||
13 | #define MetaExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
14 | #define MetaExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
15 | #define MetaExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
16 | #define MetaExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
17 | #define MetaExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
18 | #define MetaExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_METAUTIL, x, s, __VA_ARGS__) | ||
19 | #define MetaExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_METAUTIL, p, x, e, s, __VA_ARGS__) | ||
20 | #define MetaExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_METAUTIL, p, x, s, __VA_ARGS__) | ||
21 | #define MetaExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_METAUTIL, p, x, e, s, __VA_ARGS__) | ||
22 | #define MetaExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_METAUTIL, p, x, s, __VA_ARGS__) | ||
23 | #define MetaExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_METAUTIL, e, x, s, __VA_ARGS__) | ||
24 | #define MetaExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_METAUTIL, g, x, s, __VA_ARGS__) | ||
25 | |||
26 | |||
12 | // prototypes | 27 | // prototypes |
13 | static void Sort( | 28 | static void Sort( |
14 | __in_ecount(cArray) DWORD dwArray[], | 29 | __in_ecount(cArray) DWORD dwArray[], |
@@ -75,7 +90,7 @@ extern "C" HRESULT DAPI MetaFindWebBase( | |||
75 | hr = S_FALSE; // didn't find anything, try next one | 90 | hr = S_FALSE; // didn't find anything, try next one |
76 | continue; | 91 | continue; |
77 | } | 92 | } |
78 | ExitOnFailure(hr, "failed to get key from metabase while searching for web servers"); | 93 | MetaExitOnFailure(hr, "failed to get key from metabase while searching for web servers"); |
79 | 94 | ||
80 | // if we have an IIsWebServer store the key | 95 | // if we have an IIsWebServer store the key |
81 | if (0 == lstrcmpW(L"IIsWebServer", (LPCWSTR)mr.pbMDData)) | 96 | if (0 == lstrcmpW(L"IIsWebServer", (LPCWSTR)mr.pbMDData)) |
@@ -83,7 +98,7 @@ extern "C" HRESULT DAPI MetaFindWebBase( | |||
83 | hr = MetaGetValue(piMetabase, METADATA_MASTER_ROOT_HANDLE, wzKey, &mrAddress); | 98 | hr = MetaGetValue(piMetabase, METADATA_MASTER_ROOT_HANDLE, wzKey, &mrAddress); |
84 | if (MD_ERROR_DATA_NOT_FOUND == hr) | 99 | if (MD_ERROR_DATA_NOT_FOUND == hr) |
85 | hr = S_FALSE; | 100 | hr = S_FALSE; |
86 | ExitOnFailure(hr, "failed to get address from metabase while searching for web servers"); | 101 | MetaExitOnFailure(hr, "failed to get address from metabase while searching for web servers"); |
87 | 102 | ||
88 | // break down the first address into parts | 103 | // break down the first address into parts |
89 | pwzIPExists = reinterpret_cast<LPWSTR>(mrAddress.pbMDData); | 104 | pwzIPExists = reinterpret_cast<LPWSTR>(mrAddress.pbMDData); |
@@ -111,7 +126,7 @@ extern "C" HRESULT DAPI MetaFindWebBase( | |||
111 | { | 126 | { |
112 | // if the passed in buffer wasn't big enough | 127 | // if the passed in buffer wasn't big enough |
113 | hr = ::StringCchCopyW(wzWebBase, cchWebBase, wzKey); | 128 | hr = ::StringCchCopyW(wzWebBase, cchWebBase, wzKey); |
114 | ExitOnFailure(hr, "failed to copy in web base: %ls", wzKey); | 129 | MetaExitOnFailure(hr, "failed to copy in web base: %ls", wzKey); |
115 | 130 | ||
116 | fFound = TRUE; | 131 | fFound = TRUE; |
117 | break; | 132 | break; |
@@ -182,7 +197,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase( | |||
182 | hr = S_FALSE; // didn't find anything, try next one | 197 | hr = S_FALSE; // didn't find anything, try next one |
183 | continue; | 198 | continue; |
184 | } | 199 | } |
185 | ExitOnFailure(hr, "failed to get key from metabase while searching for free web root"); | 200 | MetaExitOnFailure(hr, "failed to get key from metabase while searching for free web root"); |
186 | 201 | ||
187 | // if we have a IIsWebServer get the address information | 202 | // if we have a IIsWebServer get the address information |
188 | if (0 == lstrcmpW(L"IIsWebServer", reinterpret_cast<LPCWSTR>(mr.pbMDData))) | 203 | if (0 == lstrcmpW(L"IIsWebServer", reinterpret_cast<LPCWSTR>(mr.pbMDData))) |
@@ -190,7 +205,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase( | |||
190 | if (cSubKeys >= countof(dwSubKeys)) | 205 | if (cSubKeys >= countof(dwSubKeys)) |
191 | { | 206 | { |
192 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); | 207 | hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); |
193 | ExitOnFailure(hr, "Insufficient buffer to track all sub-WebSites"); | 208 | MetaExitOnFailure(hr, "Insufficient buffer to track all sub-WebSites"); |
194 | } | 209 | } |
195 | 210 | ||
196 | dwSubKeys[cSubKeys] = wcstol(wzSubkey, NULL, 10); | 211 | dwSubKeys[cSubKeys] = wcstol(wzSubkey, NULL, 10); |
@@ -201,7 +216,7 @@ extern "C" HRESULT DAPI MetaFindFreeWebBase( | |||
201 | 216 | ||
202 | if (E_NOMOREITEMS == hr) | 217 | if (E_NOMOREITEMS == hr) |
203 | hr = S_OK; | 218 | hr = S_OK; |
204 | ExitOnFailure(hr, "failed to find free web root"); | 219 | MetaExitOnFailure(hr, "failed to find free web root"); |
205 | 220 | ||
206 | // find the lowest free web root | 221 | // find the lowest free web root |
207 | dwKey = 1; | 222 | dwKey = 1; |
@@ -270,18 +285,18 @@ extern "C" HRESULT DAPI MetaGetValue( | |||
270 | if (!piMetabase) | 285 | if (!piMetabase) |
271 | { | 286 | { |
272 | hr = ::CoInitialize(NULL); | 287 | hr = ::CoInitialize(NULL); |
273 | ExitOnFailure(hr, "failed to initialize COM"); | 288 | MetaExitOnFailure(hr, "failed to initialize COM"); |
274 | fInitialized = TRUE; | 289 | fInitialized = TRUE; |
275 | 290 | ||
276 | hr = ::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, reinterpret_cast<LPVOID*>(&piMetabase)); | 291 | hr = ::CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, reinterpret_cast<LPVOID*>(&piMetabase)); |
277 | ExitOnFailure(hr, "failed to get IID_IMSAdminBaseW object"); | 292 | MetaExitOnFailure(hr, "failed to get IID_IMSAdminBaseW object"); |
278 | } | 293 | } |
279 | 294 | ||
280 | if (!pmr->pbMDData) | 295 | if (!pmr->pbMDData) |
281 | { | 296 | { |
282 | pmr->dwMDDataLen = 256; | 297 | pmr->dwMDDataLen = 256; |
283 | pmr->pbMDData = static_cast<BYTE*>(MemAlloc(pmr->dwMDDataLen, TRUE)); | 298 | pmr->pbMDData = static_cast<BYTE*>(MemAlloc(pmr->dwMDDataLen, TRUE)); |
284 | ExitOnNull(pmr->pbMDData, hr, E_OUTOFMEMORY, "failed to allocate memory for metabase value"); | 299 | MetaExitOnNull(pmr->pbMDData, hr, E_OUTOFMEMORY, "failed to allocate memory for metabase value"); |
285 | } | 300 | } |
286 | else // set the size of the data to the actual size of the memory | 301 | else // set the size of the data to the actual size of the memory |
287 | pmr->dwMDDataLen = (DWORD)MemSize(pmr->pbMDData); | 302 | pmr->dwMDDataLen = (DWORD)MemSize(pmr->pbMDData); |
@@ -291,12 +306,12 @@ extern "C" HRESULT DAPI MetaGetValue( | |||
291 | { | 306 | { |
292 | pmr->dwMDDataLen = cbRequired; | 307 | pmr->dwMDDataLen = cbRequired; |
293 | BYTE* pb = static_cast<BYTE*>(MemReAlloc(pmr->pbMDData, pmr->dwMDDataLen, TRUE)); | 308 | BYTE* pb = static_cast<BYTE*>(MemReAlloc(pmr->pbMDData, pmr->dwMDDataLen, TRUE)); |
294 | ExitOnNull(pb, hr, E_OUTOFMEMORY, "failed to reallocate memory for metabase value"); | 309 | MetaExitOnNull(pb, hr, E_OUTOFMEMORY, "failed to reallocate memory for metabase value"); |
295 | 310 | ||
296 | pmr->pbMDData = pb; | 311 | pmr->pbMDData = pb; |
297 | hr = piMetabase->GetData(mhKey, wzKey, pmr, &cbRequired); | 312 | hr = piMetabase->GetData(mhKey, wzKey, pmr, &cbRequired); |
298 | } | 313 | } |
299 | ExitOnFailure(hr, "failed to get metabase data"); | 314 | MetaExitOnFailure(hr, "failed to get metabase data"); |
300 | 315 | ||
301 | LExit: | 316 | LExit: |
302 | if (fInitialized) | 317 | if (fInitialized) |