dsccommunity / DnsServerDsc

This module contains DSC resources for the management and configuration of Windows Server DNS Server.
MIT License
65 stars 54 forks source link

002.DnsRecordPtr.ps1 - expandIPv6String only working in edge cases #255

Closed Nabsku closed 3 years ago

Nabsku commented 3 years ago

Hi,

started using your Dsc module to automate our Ptr deployment via ansible and I found a pretty severe bug/issue that I'd like to point out.

https://github.com/dsccommunity/DnsServerDsc/blob/b17d68fa8188b6bd4c24ae875f510aa3529b1e54/source/Classes/002.DnsRecordPtr.ps1#L142-L146

This logic does not work when you're using an IPv6 like 2a1f:2786:9:1::11. All it does is add zeroes between segments 2a1f and 2787.

I've hotfixed the issue in our own infrastructure and I'd like to share it with you guys so you can include a similar fix in your own code.

    $segments = [System.Collections.ArrayList]::new($string -split ':')

    $newSegments  = [System.Collections.ArrayList]::new()

    $blankSegmentCount = 8 - $segments.count

    foreach($segment in $segments){
        if([string]::IsNullOrEmpty($segment)){
            for ($i = 0; $i -le $blankSegmentCount; $i++)
            {
                $newSegments.Add('0000')
            }
        } else {
            $newSegments.Add($segment)
        }
    }

    # Insert missing segments
    #for ($i = 0; $i -lt $blankSegmentCount; $i++)
    #{
    #    $segments.Insert(1, '0000')
    #}

    # Pad out all segments with leading zeros
    $paddedSegments = $newSegments | ForEach-Object {
        $_.PadLeft(4, '0')
    }

    return ($paddedSegments -join ':')
johlju commented 3 years ago

Thanks for the submitting the issue and providing a fix. 😄

johlju commented 3 years ago

@Sudman1 do you have time to look over the provided hotfix above?

Sudman1 commented 3 years ago

I'll take a look at this tonight.

johlju commented 3 years ago

@Sudman1 thank for fixing this, and thank you @Nabsku for reporting it and providing a solution.

johlju commented 3 years ago

To the community: If you are in need of the fix for this issue, then please use the latest preview version of v3.0.0. The fix was released in preview version https://www.powershellgallery.com/packages/DnsServerDsc/3.0.0-preview0003.

johlju commented 3 years ago

The full release v3.0.0 is now out.