diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2018-12-16 13:53:48 -0600 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2018-12-16 13:54:52 -0600 |
commit | 7d813eaad8eaca04a687d1bb942316232d1c54fd (patch) | |
tree | 8f5adb9da22b1f9fb79892fb6cf2de23fac32c71 /src/ca/scauser.cpp | |
parent | 1b7a9d3734119e658c91ebd9742ab5a3ce94cce4 (diff) | |
download | wix-7d813eaad8eaca04a687d1bb942316232d1c54fd.tar.gz wix-7d813eaad8eaca04a687d1bb942316232d1c54fd.tar.bz2 wix-7d813eaad8eaca04a687d1bb942316232d1c54fd.zip |
Import implementation of SqlCA from old repo's scasched/scaexec.
Diffstat (limited to 'src/ca/scauser.cpp')
-rw-r--r-- | src/ca/scauser.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/ca/scauser.cpp b/src/ca/scauser.cpp new file mode 100644 index 00000000..4d74e4d4 --- /dev/null +++ b/src/ca/scauser.cpp | |||
@@ -0,0 +1,82 @@ | |||
1 | // 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. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | LPCWSTR vcsUserQuery = L"SELECT `User`, `Component_`, `Name`, `Domain`, `Password` FROM `User` WHERE `User`=?"; | ||
6 | enum eUserQuery { vuqUser = 1, vuqComponent, vuqName, vuqDomain, vuqPassword }; | ||
7 | |||
8 | |||
9 | HRESULT __stdcall ScaGetUser( | ||
10 | __in LPCWSTR wzUser, | ||
11 | __out SCA_USER* pscau | ||
12 | ) | ||
13 | { | ||
14 | if (!wzUser || !pscau) | ||
15 | { | ||
16 | return E_INVALIDARG; | ||
17 | } | ||
18 | |||
19 | HRESULT hr = S_OK; | ||
20 | PMSIHANDLE hView, hRec; | ||
21 | |||
22 | LPWSTR pwzData = NULL; | ||
23 | |||
24 | // clear struct and bail right away if no user key was passed to search for | ||
25 | ::ZeroMemory(pscau, sizeof(*pscau)); | ||
26 | if (!*wzUser) | ||
27 | { | ||
28 | ExitFunction1(hr = S_OK); | ||
29 | } | ||
30 | |||
31 | hRec = ::MsiCreateRecord(1); | ||
32 | hr = WcaSetRecordString(hRec, 1, wzUser); | ||
33 | ExitOnFailure(hr, "Failed to look up User"); | ||
34 | |||
35 | hr = WcaOpenView(vcsUserQuery, &hView); | ||
36 | ExitOnFailure(hr, "Failed to open view on User table"); | ||
37 | hr = WcaExecuteView(hView, hRec); | ||
38 | ExitOnFailure(hr, "Failed to execute view on User table"); | ||
39 | |||
40 | hr = WcaFetchSingleRecord(hView, &hRec); | ||
41 | if (S_OK == hr) | ||
42 | { | ||
43 | hr = WcaGetRecordString(hRec, vuqUser, &pwzData); | ||
44 | ExitOnFailure(hr, "Failed to get User.User"); | ||
45 | hr = ::StringCchCopyW(pscau->wzKey, countof(pscau->wzKey), pwzData); | ||
46 | ExitOnFailure(hr, "Failed to copy key string to user object"); | ||
47 | |||
48 | hr = WcaGetRecordString(hRec, vuqComponent, &pwzData); | ||
49 | ExitOnFailure(hr, "Failed to get User.Component_"); | ||
50 | hr = ::StringCchCopyW(pscau->wzComponent, countof(pscau->wzComponent), pwzData); | ||
51 | ExitOnFailure(hr, "Failed to copy component string to user object"); | ||
52 | |||
53 | hr = WcaGetRecordFormattedString(hRec, vuqName, &pwzData); | ||
54 | ExitOnFailure(hr, "Failed to get User.Name"); | ||
55 | hr = ::StringCchCopyW(pscau->wzName, countof(pscau->wzName), pwzData); | ||
56 | ExitOnFailure(hr, "Failed to copy name string to user object"); | ||
57 | |||
58 | hr = WcaGetRecordFormattedString(hRec, vuqDomain, &pwzData); | ||
59 | ExitOnFailure(hr, "Failed to get User.Domain"); | ||
60 | hr = ::StringCchCopyW(pscau->wzDomain, countof(pscau->wzDomain), pwzData); | ||
61 | ExitOnFailure(hr, "Failed to copy domain string to user object"); | ||
62 | |||
63 | hr = WcaGetRecordFormattedString(hRec, vuqPassword, &pwzData); | ||
64 | ExitOnFailure(hr, "Failed to get User.Password"); | ||
65 | hr = ::StringCchCopyW(pscau->wzPassword, countof(pscau->wzPassword), pwzData); | ||
66 | ExitOnFailure(hr, "Failed to copy password string to user object"); | ||
67 | } | ||
68 | else if (E_NOMOREITEMS == hr) | ||
69 | { | ||
70 | WcaLog(LOGMSG_STANDARD, "Error: Cannot locate User.User='%ls'", wzUser); | ||
71 | hr = E_FAIL; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | ExitOnFailure(hr, "Error or found multiple matching User rows"); | ||
76 | } | ||
77 | |||
78 | LExit: | ||
79 | ReleaseStr(pwzData); | ||
80 | |||
81 | return hr; | ||
82 | } | ||