Skip to content

Commit 22c0c62

Browse files
Resolved #127: Added Windows Server 2022 compatibility
1 parent f277c7b commit 22c0c62

File tree

14 files changed

+276
-82
lines changed

14 files changed

+276
-82
lines changed

.github/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](../LICENSE.md)
66
[![PowerShell 3 | 4 | 5](https://img.shields.io/badge/PowerShell-3%20|%204%20|%205-0000FF.svg?logo=PowerShell)](#)
7-
[![Windows Server 2008 R2 | 2012 R2 | 2016 | 2019](https://img.shields.io/badge/Windows%20Server-2008%20R2%20|%202012%20R2%20|%202016%20|%202019-007bb8.svg?logo=Windows)](#)
7+
[![Windows Server 2008 R2 | 2012 R2 | 2016 | 2019 | 2022](https://img.shields.io/badge/Windows%20Server-2008%20R2%20|%202012%20R2%20|%202016%20|%202019%20|%202022-007bb8.svg?logo=Windows)](#)
88
[![.NET Framework 4.7.2+](https://img.shields.io/badge/.NET%20Framework-4.7.2%2B-007FFF.svg)](#)
99

1010
## Introduction

Documentation/CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ All notable changes to this project will be documented in this file. The format
99

1010
- The PowerShell module now advertizes `Desktop` as the required edition. Note that *PowerShell Core* is not supported because of heavy dependency on Win32 API.
1111

12+
## [4.6] - 2021-10-19
13+
14+
### Added
15+
16+
- Windows Server 2022 ntds.dit file modification is now supported.
17+
18+
### Changed
19+
20+
- Updated ManagedEsent to 1.9.4.1 and extracted customizations to partial classes.
21+
22+
### Fixed
23+
24+
- ESE parameter set now better mimics the one used in AD.
25+
1226
## [4.5] - 2021-10-14
1327

1428
### Fixed
@@ -410,7 +424,8 @@ This is a [Chocolatey](https://chocolatey.org/packages/dsinternals-psmodule)-onl
410424
## 1.0 - 2015-01-20
411425
Initial release!
412426

413-
[Unreleased]: https://github.com/MichaelGrafnetter/DSInternals/compare/v4.5...HEAD
427+
[Unreleased]: https://github.com/MichaelGrafnetter/DSInternals/compare/v4.6...HEAD
428+
[4.6]: https://github.com/MichaelGrafnetter/DSInternals/compare/v4.5...v4.6
414429
[4.5]: https://github.com/MichaelGrafnetter/DSInternals/compare/v4.4.1...v4.5
415430
[4.4.1]: https://github.com/MichaelGrafnetter/DSInternals/compare/v4.4...v4.4.1
416431
[4.4]: https://github.com/MichaelGrafnetter/DSInternals/compare/v4.3...v4.4

Src/DSInternals.DataStore/ADConstants.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
using System.Globalization;
3+
using Microsoft.Isam.Esent.Interop.Vista;
4+
25
namespace DSInternals.DataStore
36
{
47
internal static class ADConstants
@@ -9,8 +12,13 @@ internal static class ADConstants
912
public const string SecurityDescriptorTableName = "sd_table";
1013
public const int GeneralizedTimeCoefficient = 10000000;
1114
public const string EseBaseName = "edb";
15+
public const string EseTempDatabaseName = "temp.edb";
1216
public const int PageSize = 8192; // 8k
1317
public const int EseLogFileSize = 10240; // 10M
18+
public const int EseIndexDefaultLocale = 1033; // = DS_DEFAULT_LOCALE = EN-US | SORT_DEFAULT
19+
public const int EseIndexDefaultCompareOptions = 0x00000001 | 0x00000002 | 0x00010000 | 0x00020000 | 0x00001000; // = DS_DEFAULT_LOCALE_COMPARE_FLAGS | LCMAP_SORTKEY = NORM_IGNORECASE | NORM_IGNOREKANATYPE | NORM_IGNORENONSPACE | NORM_IGNOREWIDTH | SORT_STRINGSORT
20+
public const LegacyFileNames EseLegacyFileNames = LegacyFileNames.EightDotThreeSoftCompat | LegacyFileNames.ESE98FileNames;
21+
public const int EseMaxOpenTables = 1000;
1422
public const int NotAnObjectDNTag = 1;
1523
public const int RootDNTag = 2;
1624
public const int RootSecurityDescriptorId = 1;

Src/DSInternals.DataStore/DSInternals.DataStore.nuspec

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
<description>DSInternals DataStore is an advanced framework for offline ntds.dit file manipulation. It can be used to extract password hashes from Active Directory backups or to modify the sIDHistory and primaryGroupId attributes.</description>
1515
<summary>DSInternals DataStore is an advanced framework for offline ntds.dit file manipulation.</summary>
1616
<releaseNotes>
17-
- Added support for ntds.dit files with conflicting defunct attributes.
18-
- Improved parsing of roaming CNG private keys.
19-
- Updated the target .NET Framework to 4.7.2.
17+
- Added Windows Server 2022 support.
2018
</releaseNotes>
2119
<copyright>Copyright (c) 2015-2021 Michael Grafnetter. All rights reserved.</copyright>
2220
<tags>ActiveDirectory Security NTDS AD Identity Active Directory</tags>

Src/DSInternals.DataStore/DirectoryContext.cs

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,60 @@ public DirectoryContext(string dbFilePath, bool readOnly, string logDirectoryPat
2323
{
2424
if (!File.Exists(dbFilePath))
2525
{
26-
// TODO: Extract as resource
27-
throw new FileNotFoundException("The specified database file does not exist.", dbFilePath);
26+
throw new FileNotFoundException("The specified database file does not exist.", dbFilePath);
2827
}
2928

3029
this.DSADatabaseFile = dbFilePath;
3130
ValidateDatabaseState(this.DSADatabaseFile);
3231

3332
this.DSAWorkingDirectory = Path.GetDirectoryName(this.DSADatabaseFile);
3433
string checkpointDirectoryPath = this.DSAWorkingDirectory;
35-
string tempDirectoryPath = this.DSAWorkingDirectory;
34+
string tempDatabasePath = Path.Combine(this.DSAWorkingDirectory, ADConstants.EseTempDatabaseName);
3635

3736
this.DatabaseLogFilesPath = logDirectoryPath;
3837
if (this.DatabaseLogFilesPath != null)
3938
{
4039
if (!Directory.Exists(this.DatabaseLogFilesPath))
4140
{
42-
// TODO: Extract as resource
4341
throw new FileNotFoundException("The specified log directory does not exist.", this.DatabaseLogFilesPath);
4442
}
4543
}
4644
else
4745
{
46+
// Use the default location if an alternate log directory is not provided.
4847
this.DatabaseLogFilesPath = this.DSAWorkingDirectory;
4948
}
5049

5150
// TODO: Exception handling?
52-
// HACK: IsamInstance constructor throws AccessDenied Exception when the path does not end with a backslash.
53-
this.instance = new IsamInstance(AddPathSeparator(checkpointDirectoryPath), AddPathSeparator(this.DatabaseLogFilesPath), AddPathSeparator(tempDirectoryPath), ADConstants.EseBaseName, JetInstanceName, readOnly, ADConstants.PageSize);
51+
// Note: IsamInstance constructor throws AccessDenied Exception when the path does not end with a backslash.
52+
this.instance = new IsamInstance(AddPathSeparator(checkpointDirectoryPath), AddPathSeparator(this.DatabaseLogFilesPath), tempDatabasePath, ADConstants.EseBaseName, JetInstanceName, readOnly, ADConstants.PageSize);
5453
try
5554
{
5655
var isamParameters = this.instance.IsamSystemParameters;
5756

57+
if(EsentVersion.SupportsWindows10Features)
58+
{
59+
try
60+
{
61+
// Required for Windows Server 2022 compatibility, as it limits the transaction log file format to 8920.
62+
// Note: Usage of JET_efvUsePersistedFormat still causes minor DB format upgrade.
63+
isamParameters.EngineFormatVersion = 0x40000002; // JET_efvUsePersistedFormat: Instructs the engine to use the minimal Engine Format Version of all loaded log and DB files.
64+
}
65+
catch (EsentInvalidParameterException)
66+
{
67+
// JET_efvUsePersistedFormat should be supported since Windows Server 2016.
68+
// Just continue even if it is not supported on the current Windows build.
69+
}
70+
}
71+
5872
// Set the size of the transaction log files to AD defaults.
5973
isamParameters.LogFileSize = ADConstants.EseLogFileSize;
6074

6175
// Delete the log files that are not matching (generation wise) during soft recovery.
6276
isamParameters.DeleteOutOfRangeLogs = true;
6377

6478
// Check the database for indexes over Unicode key columns that were built using an older version of the NLS library.
65-
isamParameters.EnableIndexChecking = true;
79+
isamParameters.EnableIndexChecking2 = true;
6680

6781
// Automatically clean up indexes over Unicode key columns as necessary to avoid database format changes caused by changes to the NLS library.
6882
isamParameters.EnableIndexCleanup = true;
@@ -73,8 +87,27 @@ public DirectoryContext(string dbFilePath, bool readOnly, string logDirectoryPat
7387
// Disable all database engine callbacks to application provided functions. This enables us to open Win2016 DBs on non-DC systems.
7488
isamParameters.DisableCallbacks = true;
7589

76-
// TODO: Configure additional ISAM parameters
77-
// this.instance.IsamSystemParameters.EnableOnlineDefrag = false;
90+
// Increase the limit of maximum open tables.
91+
isamParameters.MaxOpenTables = ADConstants.EseMaxOpenTables;
92+
93+
// Enable backwards compatibility with the file naming conventions of earlier releases of the database engine.
94+
isamParameters.LegacyFileNames = ADConstants.EseLegacyFileNames;
95+
96+
// Set EN-US to be used by any index over a Unicode key column.
97+
isamParameters.UnicodeIndexDefault = new JET_UNICODEINDEX()
98+
{
99+
lcid = ADConstants.EseIndexDefaultLocale,
100+
dwMapFlags = ADConstants.EseIndexDefaultCompareOptions
101+
};
102+
103+
// Force crash recovery to look for the database referenced in the transaction log in the specified folder.
104+
isamParameters.AlternateDatabaseRecoveryPath = this.DSAWorkingDirectory;
105+
106+
if (!readOnly)
107+
{
108+
// Delete obsolete log files.
109+
isamParameters.DeleteOldLogs = true;
110+
}
78111

79112
this.session = this.instance.CreateSession();
80113
this.session.AttachDatabase(this.DSADatabaseFile);
@@ -234,7 +267,6 @@ protected virtual void Dispose(bool disposing)
234267

235268
private static string AddPathSeparator(string path)
236269
{
237-
// TODO: Newer version of ISAM should implemet this
238270
if (string.IsNullOrEmpty(path) || path.EndsWith(Path.DirectorySeparatorChar.ToString()))
239271
{
240272
// No need to add path separator
@@ -246,7 +278,7 @@ private static string AddPathSeparator(string path)
246278
}
247279
}
248280

249-
private static void ValidateDatabaseState(string dbFilePath)
281+
public static void ValidateDatabaseState(string dbFilePath)
250282
{
251283
// Retrieve info about the DB (Win Version, Page Size, State,...)
252284
JET_DBINFOMISC dbInfo;
@@ -255,7 +287,6 @@ private static void ValidateDatabaseState(string dbFilePath)
255287
if (dbInfo.dbstate != JET_dbstate.CleanShutdown)
256288
{
257289
// Database might be inconsistent
258-
// TODO: Extract message as a recource
259290
throw new InvalidDatabaseStateException("The database is not in a clean state. Try to recover it first by running the 'esentutl /r edb /d' command.", dbFilePath);
260291
}
261292
}

Src/DSInternals.DataStore/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// set of attributes. Change these attribute values to modify the information
66
// associated with an assembly.
77
[assembly: AssemblyTitle("DSInternals DataStore Library")]
8-
[assembly: AssemblyVersion("4.5")]
9-
[assembly: AssemblyFileVersion("4.5")]
8+
[assembly: AssemblyVersion("4.6")]
9+
[assembly: AssemblyFileVersion("4.6")]
1010
[assembly: AssemblyDescription("")]
1111
[assembly: AssemblyConfiguration("")]
1212
[assembly: AssemblyCompany("")]

Src/DSInternals.PowerShell/Chocolatey/dsinternals-psmodule.nuspec

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
44
<metadata>
55
<id>DSInternals-PSModule</id>
6-
<version>4.5</version>
6+
<version>4.6</version>
77
<packageSourceUrl>https://github.com/MichaelGrafnetter/DSInternals/tree/master/Src/DSInternals.PowerShell/Chocolatey</packageSourceUrl>
88
<owners>MichaelGrafnetter</owners>
99
<title>DSInternals PowerShell Module</title>
@@ -37,18 +37,15 @@
3737
## Disclaimer
3838
Features exposed through these tools are not supported by Microsoft. Improper use might cause irreversible damage to domain controllers or negatively impact domain security.</description>
3939
<releaseNotes>
40-
* Added support for ntds.dit files with conflicting defunct attributes.
41-
* Fixed the detection of default computer passwords.
42-
* Improved parsing of roaming CNG private keys.
43-
* Updated the target .NET Framework to 4.7.2.
40+
* Added Windows Server 2022 support.
4441
</releaseNotes>
4542
<dependencies>
4643
<!-- Windows Management Framework 3+. For OS prior to Windows 8 and Windows Server 2012. -->
4744
<dependency id="powershell" version="3.0.20121027" />
4845
<!-- Universal C Runtime. For RTM OS prior to Windows 10 and Windows Server 2016. -->
4946
<dependency id="kb2999226" version="1.0.20181019" />
50-
<!-- .NET Framework 4.7+. For RTM OS prior to Windows 10 1703 and Windows Server 1709. -->
51-
<dependency id="dotnetfx" version="4.7.0.0" />
47+
<!-- .NET Framework 4.7.2+. For RTM OS prior to Windows 10 1703 and Windows Server 1709. -->
48+
<dependency id="dotnetfx" version="4.7.2.0" />
5249
</dependencies>
5350
</metadata>
5451
<files>

Src/DSInternals.PowerShell/DSInternals.psd1

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
RootModule = 'DSInternals.Bootstrap.psm1'
99

1010
# Version number of this module.
11-
ModuleVersion = '4.5'
11+
ModuleVersion = '4.6'
1212

1313
# Supported PSEditions
1414
# CompatiblePSEditions = 'Desktop'
@@ -36,7 +36,7 @@ DISCLAIMER: Features exposed through this module are not supported by Microsoft
3636
PowerShellVersion = '3.0'
3737

3838
# Minimum version of Microsoft .NET Framework required by this module
39-
DotNetFrameworkVersion = '4.7' # This requirement is not enforced by older versions of PS.
39+
DotNetFrameworkVersion = '4.7.2' # This requirement is not enforced by older versions of PS.
4040

4141
# Minimum version of the common language runtime (CLR) required by this module
4242
CLRVersion = '4.0.30319.42000' # Corresponds to .NET Framework 4.6 and later
@@ -141,10 +141,7 @@ PrivateData = @{
141141

142142
# ReleaseNotes of this module
143143
ReleaseNotes = @"
144-
- Added support for ntds.dit files with conflicting defunct attributes.
145-
- Fixed the detection of default computer passwords.
146-
- Improved parsing of roaming CNG private keys.
147-
- Updated the target .NET Framework to 4.7.2.
144+
- Added Windows Server 2022 support.
148145
"@
149146
} # End of PSData hashtable
150147

Src/DSInternals.PowerShell/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// set of attributes. Change these attribute values to modify the information
66
// associated with an assembly.
77
[assembly: AssemblyTitle("DSInternals PowerShell Commands")]
8-
[assembly: AssemblyVersion("4.5")]
9-
[assembly: AssemblyFileVersion("4.5")]
8+
[assembly: AssemblyVersion("4.6")]
9+
[assembly: AssemblyFileVersion("4.6")]
1010
[assembly: AssemblyDescription("")]
1111
[assembly: AssemblyConfiguration("")]
1212
[assembly: AssemblyCompany("")]

0 commit comments

Comments
 (0)