Module/Rule.SqlServerConfiguration/Convert/Methods.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#region Method Functions
<#
    .SYNOPSIS
        Retrieves the SqlServerConfiguration OptionName from the check-content element in the xccdf
 
    .PARAMETER CheckContent
        Specifies the check-content element in the xccdf
#>

function Get-OptionName
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $CheckContent
    )

    switch ($checkcontent) 
    {
        {$PSItem -Match "(?<=EXEC SP_CONFIGURE\s').+?(?=')"}
        {
            $optionName = ($PSItem | Select-String -Pattern "(?<=EXEC SP_CONFIGURE\s').+?(?=')" -AllMatches).Matches[1]
        }
        {$PSItem -Match "WHERE name = 'common criteria compliance enabled'"}
        {
            $optionName = "common criteria compliance enabled"
        }
        {$PSItem -Match "EXEC sp_configure 'filestream access level'"}
        {
            $optionName = "filestream access level"
        }       
    }

    return $optionName
}

<#
    .SYNOPSIS
        Sets the SqlServerConfiguration OptionValue from the check-content element in the xccdf
 
    .PARAMETER CheckContent
        Specifies the check-content element in the xccdf
#>

function Set-OptionValue
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $CheckContent
    )

    # STIG guidance states most configuration options should be disabled unless required. Default state is set to disable.

    switch ($checkContent)
    {
        {$PSItem -Match "WHERE name = 'common criteria compliance enabled'"}
        {
            $optionValue = "1"
        }
        default
        {
            $optionValue = "0"
        }
    }

    return $optionValue
}