Skip to content

Commit

Permalink
Merge pull request #2240 from microsoft/lusassl-ianatimezoneissuedete…
Browse files Browse the repository at this point in the history
…ction

Check for invalid IanaTimeZoneMappings.xml added
  • Loading branch information
dpaulson45 authored Dec 3, 2024
2 parents 24ca159 + 836a619 commit e2f7408
Show file tree
Hide file tree
Showing 7 changed files with 1,250 additions and 1 deletion.
1 change: 1 addition & 0 deletions .build/cspell-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ hostnames
HRESULT
hsts
httperr
iana
ietf
imap
inetsrv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

. $PSScriptRoot\Add-AnalyzedResultInformation.ps1
. $PSScriptRoot\Get-DisplayResultsGroupingKey.ps1
. $PSScriptRoot\Test-IanaTimeZoneMapping.ps1
. $PSScriptRoot\..\..\..\Shared\CompareExchangeBuildLevel.ps1
. $PSScriptRoot\..\..\..\Shared\ErrorMonitorFunctions.ps1
function Invoke-AnalyzerFrequentConfigurationIssues {
[CmdletBinding()]
param(
Expand Down Expand Up @@ -244,6 +246,41 @@ function Invoke-AnalyzerFrequentConfigurationIssues {
}
}

if ($null -ne $exchangeInformation.IanaTimeZoneMappingsRaw) {

try {
[xml]$ianaTimeZoneMappingXml = $exchangeInformation.IanaTimeZoneMappingsRaw

# Test IanaTimeZoneMapping.xml content to ensure it doesn't contain invalid or duplicate entries
$ianaTimeZoneMappingStatus = Test-IanaTimeZoneMapping -IanaMappingFile $ianaTimeZoneMappingXml

$ianaTimeZoneStatusMissingAttributes = $ianaTimeZoneMappingStatus.NodeMissingAttributes
$ianaTimeZoneStatusDuplicateEntries = $ianaTimeZoneMappingStatus.DuplicateEntries

$ianaTimeZoneInvalidEntriesList = New-Object System.Collections.Generic.List[string]

foreach ($invalid in $ianaTimeZoneStatusMissingAttributes) {
$ianaTimeZoneInvalidEntriesList.Add("Invalid entry - IANA: $($invalid.IANA) Win: $($invalid.Win)")
}

foreach ($dupe in $ianaTimeZoneStatusDuplicateEntries) {
$ianaTimeZoneInvalidEntriesList.Add("Duplicate entry - IANA: $($dupe.IANA) Win: $($dupe.Win)")
}

if ($ianaTimeZoneInvalidEntriesList.Count -ge 1) {
$params = $baseParams + @{
Name = "IanaTimeZoneMappings.xml invalid"
Details = "`r`n`t`t$([System.String]::Join("`r`n`t`t", $ianaTimeZoneInvalidEntriesList))`r`n`t`tMore information: https://aka.ms/ExchangeIanaTimeZoneIssue"
DisplayWriteType = "Red"
}
Add-AnalyzedResultInformation @params
}
} catch {
Write-Verbose "Unable to convert IanaTimeZoneMappings.xml to Xml - Exception: $_"
Invoke-CatchActions
}
}

$displayWriteType = "Yellow"
$displayValue = "Unknown - Unable to run Get-AcceptedDomain"
$additionalDisplayValue = [string]::Empty
Expand Down
79 changes: 79 additions & 0 deletions Diagnostics/HealthChecker/Analyzer/Test-IanaTimeZoneMapping.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. $PSScriptRoot\..\..\..\Shared\ErrorMonitorFunctions.ps1

function Test-IanaTimeZoneMapping {
[CmdletBinding(DefaultParameterSetName = "FilePath")]
param(
[Parameter(Mandatory = $true, ParameterSetName = "FilePath")]
[string]$FilePath,

[Parameter(Mandatory = $true, ParameterSetName = "MappingFile")]
[System.Xml.XmlNode]$IanaMappingFile
)

begin {
$xmlMap = New-Object System.Collections.Generic.HashSet[string]
$xmlMissingAttributesList = New-Object System.Collections.Generic.HashSet[object]
$xmlDuplicateEntriesList = New-Object System.Collections.Generic.List[object]
} process {

if ($PSCmdlet.ParameterSetName -eq "FilePath") {
if ((Test-Path -Path $FilePath) -eq $false) {
Write-Verbose "Path: $FilePath doesn't exist"

return
}

try {
[xml]$IanaMappingFile = Get-Content -Path $FilePath -ErrorAction Stop
} catch {
Write-Verbose "Exception while trying to import file: $FilePath - Exception: $_"
Invoke-CatchActions
}
}

try {
$nodeList = $IanaMappingFile.SelectNodes("//Map")

if ($null -eq $nodeList) {
Write-Verbose "Failed to process XML file"

return
}

foreach ($node in $nodeList) {

[string]$iana = $node.Attributes["IANA"].Value
[string]$win = $node.Attributes["Win"].Value
$xmlMapKey = "$iana|$win"

if ([System.String]::IsNullOrEmpty($iana) -or
[System.String]::IsNullOrEmpty($win)) {
Write-Verbose "Map node missing required attribute: $xmlMapKey"
$xmlMissingAttributesList.Add($node)

continue
}

if ($xmlMap -contains $xmlMapKey) {
Write-Verbose "Duplicate entry found: $xmlMapKey"
$xmlDuplicateEntriesList.Add($node)

continue
}

[void]$xmlMap.Add($xmlMapKey)
}
} catch {
Write-Verbose "Exception while processing content of the IanaTimeZoneMapping file - Exception: $_"
Invoke-CatchActions
}
} end {
return [PSCustomObject]@{
NodeMissingAttributes = $xmlMissingAttributesList
DuplicateEntries = $xmlDuplicateEntriesList
}
}
}
Loading

0 comments on commit e2f7408

Please sign in to comment.