Skip to content
/ wix Public

Commit eac2aaa

Browse files
bevanweissrobmen
authored andcommitted
Fix ups for Domain Group creation / removal.
Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
1 parent e00595a commit eac2aaa

File tree

7 files changed

+45
-12
lines changed

7 files changed

+45
-12
lines changed

src/ext/Util/ca/precomp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@
5151
#include "scasmb.h"
5252
#include "scasmbexec.h"
5353
#include "utilca.h"
54+
#include "scanet.h"
5455

5556
#include "..\..\caDecor.h"

src/ext/Util/ca/scaexec.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ static HRESULT RemoveGroupInternal(
716716
//
717717
if (!(SCAG_DONT_CREATE_GROUP & iAttributes))
718718
{
719-
hr = GetDomainFromServerName(&pwzServerName, wzDomain, DS_WRITABLE_REQUIRED);
719+
hr = GetDomainServerName(wzDomain, &pwzServerName, DS_WRITABLE_REQUIRED);
720720

721721
NET_API_STATUS er = ::NetLocalGroupDel(pwzServerName, wzName);
722722
hr = HRESULT_FROM_WIN32(er);
@@ -1284,7 +1284,7 @@ extern "C" UINT __stdcall CreateGroup(
12841284

12851285
if (!(SCAG_DONT_CREATE_GROUP & iAttributes))
12861286
{
1287-
hr = GetDomainFromServerName(&pwzServerName, pwzDomain, DS_WRITABLE_REQUIRED);
1287+
hr = GetDomainServerName(pwzDomain, &pwzServerName, DS_WRITABLE_REQUIRED);
12881288
ExitOnFailure(hr, "failed to find writable server for domain %ls.", pwzDomain);
12891289

12901290
// Set the group's comment
@@ -1680,7 +1680,7 @@ HRESULT AlterGroupMembership(BOOL fRemove, BOOL fIsRollback)
16801680
}
16811681

16821682

1683-
hr = GetDomainFromServerName(&pwzServerName, pwzParentDomain, DS_WRITABLE_REQUIRED);
1683+
hr = GetDomainServerName(pwzParentDomain, &pwzServerName, DS_WRITABLE_REQUIRED);
16841684
ExitOnFailure(hr, "failed to obtain writable server for domain %ls", pwzParentDomain);
16851685

16861686
if (*pwzChildDomain)

src/ext/Util/ca/scagroup.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// 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.
22

33
#include "precomp.h"
4-
#include "scanet.h"
54

65
LPCWSTR vcsGroupQuery = L"SELECT `Group`, `Component_`, `Name`, `Domain` FROM `Wix4Group` WHERE `Group`=?";
76
enum eGroupQuery { vgqGroup = 1, vgqComponent, vgqName, vgqDomain };
@@ -458,7 +457,20 @@ HRESULT ScaGroupExecute(
458457
// and removing groups. Note: MSDN says that it is safe to call these APIs from any
459458
// user, so we should be safe calling it during immediate mode.
460459

461-
hr = GetDomainServerName(psg->wzDomain, &pwzServerName);
460+
hr = GetDomainServerName(psg->wzDomain, &pwzServerName, 0);
461+
if (HRESULT_FROM_WIN32(ERROR_NO_SUCH_DOMAIN) == hr)
462+
{
463+
if (SCAG_NON_VITAL & psg->iAttributes)
464+
{
465+
WcaLog(LOGMSG_VERBOSE, "Domain does not exist for non-vital group: %ls\\%ls - continuing", psg->wzDomain, psg->wzName);
466+
hr = S_OK;
467+
goto ExitCurrentGroup;
468+
}
469+
else
470+
{
471+
ExitOnFailure(hr, "Domain does not exist for vital group: %ls\\%ls - aborting", psg->wzDomain, psg->wzName);
472+
}
473+
}
462474

463475
er = ::NetLocalGroupGetInfo(pwzServerName, psg->wzName, 0, reinterpret_cast<LPBYTE*>(&pGroupInfo));
464476
if (NERR_Success == er)
@@ -597,6 +609,7 @@ HRESULT ScaGroupExecute(
597609
ExitOnFailure(hr, "failed to schedule RemoveGroup");
598610
}
599611

612+
ExitCurrentGroup:
600613
ReleaseNullStr(pwzScriptKey);
601614
ReleaseNullStr(pwzActionData);
602615
ReleaseNullStr(pwzRollbackData);

src/ext/Util/ca/scanet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG fla
88
DWORD er = ERROR_SUCCESS;
99
PDOMAIN_CONTROLLER_INFOW pDomainControllerInfo = NULL;
1010
HRESULT hr = S_OK;
11+
WCHAR pwzComputerName[MAX_COMPUTERNAME_LENGTH + 1];
12+
DWORD cchComputerName = countof(pwzComputerName);
1113

12-
if (pwzDomain && *pwzDomain)
14+
hr = ::GetComputerNameW(pwzComputerName, &cchComputerName);
15+
ExitOnFailure(hr, "failed to obtain computer name");
16+
17+
if (pwzDomain && *pwzDomain && 0!=lstrcmpiW(pwzComputerName, pwzDomain) && 0!=lstrcmpiW(L".", pwzDomain))
1318
{
1419
er = ::DsGetDcNameW(NULL, pwzDomain, NULL, NULL, flags, &pDomainControllerInfo);
1520
if (RPC_S_SERVER_UNAVAILABLE == er)
@@ -21,7 +26,7 @@ HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG fla
2126
if (ERROR_SUCCESS == er && pDomainControllerInfo->DomainControllerName)
2227
{
2328
// Skip the \\ prefix if present.
24-
if ('\\' == *pDomainControllerInfo->DomainControllerName && '\\' == *pDomainControllerInfo->DomainControllerName + 1)
29+
if ('\\' == *pDomainControllerInfo->DomainControllerName && '\\' == *(pDomainControllerInfo->DomainControllerName + 1) )
2530
{
2631
hr = StrAllocString(ppwzServerName, pDomainControllerInfo->DomainControllerName + 2, 0);
2732
}

src/ext/Util/ca/scanet.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
#pragma once
22
// 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.
33

4-
HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG flags = 0);
4+
5+
/**
6+
* Locates a domain controller (server name) for a given input domain.
7+
* Flags can be provided where required (as per those for DsGetDcName) for a specific server to be returned.
8+
* NOTE: Where the domain provided is identical to the local machine, this function will return NULL, such that the
9+
* result can be provided directly to NetUserAdd or similar functions.
10+
*
11+
* @param pwzDomain Pointer to the domain name to be queried
12+
* @param ppwzServerName Pointer to the server name to be returned
13+
* @param flags Flags to be used in the DsGetDcName call(s)
14+
* @return HRESULT to indicate if an error was encountered
15+
*/
16+
HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG flags);

src/test/burn/WixTestTools/RuntimeFactAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ static RuntimeFactAttribute()
4747

4848
var domainTestsEnabledString = Environment.GetEnvironmentVariable(RequiredDomainEnvironmentVariableName);
4949
RuntimeDomainTestsEnabled = Boolean.TryParse(domainTestsEnabledString, out var domainTestsEnabled) && domainTestsEnabled;
50+
51+
RunningOnWindowsServer = IsWindowsServer();
5052
}
5153

5254
public bool DomainRequired
@@ -63,8 +65,6 @@ public bool DomainRequired
6365
this.Skip = $"These tests require the test host to be running as a domain member ({(RunningInDomain ? "passed" : "failed")}). These tests affect both MACHINE AND DOMAIN state. To accept the consequences, set the {RequiredDomainEnvironmentVariableName} environment variable to true ({(RuntimeDomainTestsEnabled ? "passed" : "failed")}).";
6466
}
6567
}
66-
67-
RunningOnWindowsServer = IsWindowsServer();
6868
}
6969

7070
private bool _RequireWindowsServer;

src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionGroupTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ public void FailsIfNonDomainGroupExists()
151151
[RuntimeFact]
152152
public void FailsIfRestrictedDomain()
153153
{
154+
var testDomain = "DOESNOTEXIST";
155+
var testGroup = "testName1";
154156
var productRestrictedDomain = this.CreatePackageInstaller("ProductRestrictedDomain");
155157

156-
string logFile = productRestrictedDomain.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, "TESTDOMAIN=DOESNOTEXIST");
158+
string logFile = productRestrictedDomain.InstallProduct(MSIExec.MSIExecReturnCode.ERROR_INSTALL_FAILURE, $"TESTDOMAIN={testDomain}");
157159

158160
// Verify expected error message in the log file
159-
Assert.True(LogVerifier.MessageInLogFile(logFile, "CreateGroup: Error 0x8007054b: failed to find Domain DOESNOTEXIST."));
161+
Assert.True(LogVerifier.MessageInLogFile(logFile, $"ConfigureGroups: Error 0x8007054b: Domain does not exist for vital group: {testDomain}\\{testGroup} - aborting"));
160162
}
161163

162164
// Verify that a group can be created with a group comment

0 commit comments

Comments
 (0)