Skip to content

Commit

Permalink
Fix ups for Domain Group creation / removal.
Browse files Browse the repository at this point in the history
Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
  • Loading branch information
bevanweiss committed Jan 3, 2025
1 parent 90c215a commit 1c29f42
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/ext/Util/ca/precomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
#include "scasmb.h"
#include "scasmbexec.h"
#include "utilca.h"
#include "scanet.h"

#include "..\..\caDecor.h"
6 changes: 3 additions & 3 deletions src/ext/Util/ca/scaexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ static HRESULT RemoveGroupInternal(
//
if (!(SCAG_DONT_CREATE_GROUP & iAttributes))
{
hr = GetDomainFromServerName(&pwzServerName, wzDomain, DS_WRITABLE_REQUIRED);
hr = GetDomainServerName(wzDomain, &pwzServerName, DS_WRITABLE_REQUIRED);

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

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

// Set the group's comment
Expand Down Expand Up @@ -1680,7 +1680,7 @@ HRESULT AlterGroupMembership(BOOL fRemove, BOOL fIsRollback)
}


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

if (*pwzChildDomain)
Expand Down
17 changes: 15 additions & 2 deletions src/ext/Util/ca/scagroup.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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.

#include "precomp.h"
#include "scanet.h"

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

hr = GetDomainServerName(psg->wzDomain, &pwzServerName);
hr = GetDomainServerName(psg->wzDomain, &pwzServerName, 0);
if (HRESULT_FROM_WIN32(ERROR_NO_SUCH_DOMAIN) == hr)
{
if (SCAG_NON_VITAL & psg->iAttributes)
{
WcaLog(LOGMSG_VERBOSE, "Domain does not exist for non-vital group: %ls\\%ls - continuing", psg->wzDomain, psg->wzName);
hr = S_OK;
goto ExitCurrentGroup;
}
else
{
ExitOnFailure(hr, "Domain does not exist for vital group: %ls\\%ls - aborting", psg->wzDomain, psg->wzName);
}
}

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

ExitCurrentGroup:
ReleaseNullStr(pwzScriptKey);
ReleaseNullStr(pwzActionData);
ReleaseNullStr(pwzRollbackData);
Expand Down
9 changes: 7 additions & 2 deletions src/ext/Util/ca/scanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG fla
DWORD er = ERROR_SUCCESS;
PDOMAIN_CONTROLLER_INFOW pDomainControllerInfo = NULL;
HRESULT hr = S_OK;
WCHAR pwzComputerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD cchComputerName = countof(pwzComputerName);

if (pwzDomain && *pwzDomain)
hr = ::GetComputerNameW(pwzComputerName, &cchComputerName);
ExitOnFailure(hr, "failed to obtain computer name");

if (pwzDomain && *pwzDomain && 0!=lstrcmpiW(pwzComputerName, pwzDomain) && 0!=lstrcmpiW(L".", pwzDomain))
{
er = ::DsGetDcNameW(NULL, pwzDomain, NULL, NULL, flags, &pDomainControllerInfo);
if (RPC_S_SERVER_UNAVAILABLE == er)
Expand All @@ -21,7 +26,7 @@ HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG fla
if (ERROR_SUCCESS == er && pDomainControllerInfo->DomainControllerName)
{
// Skip the \\ prefix if present.
if ('\\' == *pDomainControllerInfo->DomainControllerName && '\\' == *pDomainControllerInfo->DomainControllerName + 1)
if ('\\' == *pDomainControllerInfo->DomainControllerName && '\\' == *(pDomainControllerInfo->DomainControllerName + 1) )
{
hr = StrAllocString(ppwzServerName, pDomainControllerInfo->DomainControllerName + 2, 0);
}
Expand Down
14 changes: 13 additions & 1 deletion src/ext/Util/ca/scanet.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
#pragma once
// 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.

HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG flags = 0);

/**
* Locates a domain controller (server name) for a given input domain.
* Flags can be provided where required (as per those for DsGetDcName) for a specific server to be returned.
* NOTE: Where the domain provided is identical to the local machine, this function will return NULL, such that the
* result can be provided directly to NetUserAdd or similar functions.
*
* @param pwzDomain Pointer to the domain name to be queried
* @param ppwzServerName Pointer to the server name to be returned
* @param flags Flags to be used in the DsGetDcName call(s)
* @return HRESULT to indicate if an error was encountered
*/
HRESULT GetDomainServerName(LPCWSTR pwzDomain, LPWSTR* ppwzServerName, ULONG flags);
4 changes: 2 additions & 2 deletions src/test/burn/WixTestTools/RuntimeFactAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ static RuntimeFactAttribute()

var domainTestsEnabledString = Environment.GetEnvironmentVariable(RequiredDomainEnvironmentVariableName);
RuntimeDomainTestsEnabled = Boolean.TryParse(domainTestsEnabledString, out var domainTestsEnabled) && domainTestsEnabled;

RunningOnWindowsServer = IsWindowsServer();
}

public bool DomainRequired
Expand All @@ -63,8 +65,6 @@ public bool DomainRequired
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")}).";
}
}

RunningOnWindowsServer = IsWindowsServer();
}

private bool _RequireWindowsServer;
Expand Down
6 changes: 4 additions & 2 deletions src/test/msi/WixToolsetTest.MsiE2E/UtilExtensionGroupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ public void FailsIfNonDomainGroupExists()
[RuntimeFact]
public void FailsIfRestrictedDomain()
{
var testDomain = "DOESNOTEXIST";
var testGroup = "testName1";
var productRestrictedDomain = this.CreatePackageInstaller("ProductRestrictedDomain");

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

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

// Verify that a group can be created with a group comment
Expand Down

0 comments on commit 1c29f42

Please sign in to comment.