Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dsc/tests/dsc_sshdconfig.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ resources:
$out.resources.count | Should -Be 1
$out.resources[0].properties | Should -Not -BeNullOrEmpty
$out.resources[0].properties.port | Should -BeNullOrEmpty
$out.resources[0].properties.passwordAuthentication | Should -Be 'no'
$out.resources[0].properties.passwordAuthentication | Should -Be $false
$out.resources[0].properties._inheritedDefaults | Should -BeNullOrEmpty
} else {
$out.results.count | Should -Be 1
$out.results.result.actualState | Should -Not -BeNullOrEmpty
$out.results.result.actualState.port[0] | Should -Be 22
$out.results.result.actualState.passwordAuthentication | Should -Be 'no'
$out.results.result.actualState.passwordAuthentication | Should -Be $false
$out.results.result.actualState._inheritedDefaults | Should -Contain 'port'
}
}
Expand All @@ -69,7 +69,7 @@ resources:
$LASTEXITCODE | Should -Be 0
$out.resources.count | Should -Be 1
($out.resources[0].properties.psobject.properties | Measure-Object).count | Should -Be 1
$out.resources[0].properties.passwordAuthentication | Should -Be 'no'
$out.resources[0].properties.passwordAuthentication | Should -Be $false
}

It '<command> with _includeDefaults specified works' -TestCases @(
Expand Down Expand Up @@ -128,7 +128,7 @@ resources:
$out.results.count | Should -Be 1
$out.results.result.actualState | Should -Not -BeNullOrEmpty
$out.results.result.actualState.port | Should -Be 22
$out.results.result.actualState.passwordAuthentication | Should -Be 'yes'
$out.results.result.actualState.passwordAuthentication | Should -Be $true
$out.results.result.actualState._inheritedDefaults | Should -Not -Contain 'port'
}
}
Expand Down
4 changes: 2 additions & 2 deletions grammars/tree-sitter-ssh-server-config/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ module.exports = grammar({
),

criteria: $ => seq(
field('criteria', $.alpha),
field('keyword', $.alpha),
choice(seq(/[ \t]/, optional('=')), '='),
field('argument', $._argument)
field('argument', alias($._argument, $.argument))
),

_argument: $ => choice($.boolean, $.number, $.string, $._commaSeparatedString, $._doublequotedString, $._singlequotedString),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ authorizedkeysfile "path to authorized keys file"
(match
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
Expand All @@ -53,7 +54,8 @@ authorizedkeysfile "path to authorized keys file"
(match
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
Expand Down Expand Up @@ -229,15 +231,17 @@ passwordauthentication yes
(match
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
(boolean))))
(match
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
Expand Down Expand Up @@ -307,7 +311,8 @@ passwordauthentication yes
(match
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
Expand All @@ -320,7 +325,8 @@ passwordauthentication yes
(match
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
Expand Down Expand Up @@ -412,11 +418,13 @@ passwordauthentication no
(match
(criteria
(alpha)
(argument
(string)
(string))
(string)))
(criteria
(alpha)
(string))
(argument
(string)))
(keyword
(alphanumeric)
(arguments
Expand Down
10 changes: 6 additions & 4 deletions resources/sshdconfig/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ parser = "Parser"
parseInt = "Parse Integer"
persist = "Persist"
registry = "Registry"
stringUtf8 = "String UTF-8"

[get]
debugSetting = "Get setting:"
Expand All @@ -35,17 +36,18 @@ set = "Set command: '%{input}'"
[parser]
failedToParse = "failed to parse: '%{input}'"
failedToParseAsArray = "value is not an array"
failedToParseChildNode = "failed to parse child node: '%{input}'"
failedToParseNode = "failed to parse '%{input}'"
failedToParseRoot = "failed to parse root: '%{input}'"
invalidConfig = "invalid config: '%{input}'"
invalidMultiArgNode = "multi-arg node '%{input}' is not valid"
invalidValue = "operator is an invalid value for node"
keyNotFound = "key '%{key}' not found"
keyNotRepeatable = "key '%{key}' is not repeatable"
keywordDebug = "Parsing keyword: '%{text}'"
missingValueInChildNode = "missing value in child node: '%{input}'"
missingCriteriaInMatch = "missing criteria field in match block: '%{input}'"
missingKeyInChildNode = "missing key in child node: '%{input}'"
missingKeyInCriteria = "missing key in criteria node: '%{input}'"
missingValueInCriteria = "missing value in criteria node: '%{input}'"
missingValueInChildNode = "missing value in child node: '%{input}'"
noArgumentsFound = "no arguments found in node: '%{input}'"
valueDebug = "Parsed argument value:"
unknownNode = "unknown node: '%{kind}'"
unknownNodeType = "unknown node type: '%{node}'"
Expand Down
6 changes: 4 additions & 2 deletions resources/sshdconfig/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use thiserror::Error;
pub enum SshdConfigError {
#[error("{t}: {0}", t = t!("error.command"))]
CommandError(String),
#[error("{t}: {0}", t = t!("error.envVar"))]
EnvVarError(#[from] std::env::VarError),
#[error("{t}: {0}", t = t!("error.fmt"))]
FmtError(#[from] std::fmt::Error),
#[error("{t}: {0}", t = t!("error.invalidInput"))]
Expand All @@ -28,6 +30,6 @@ pub enum SshdConfigError {
#[cfg(windows)]
#[error("{t}: {0}", t = t!("error.registry"))]
RegistryError(#[from] dsc_lib_registry::error::RegistryError),
#[error("{t}: {0}", t = t!("error.envVar"))]
EnvVarError(#[from] std::env::VarError),
#[error("{t}: {0}", t = t!("error.stringUtf8"))]
StringUtf8Error(#[from] std::str::Utf8Error),
}
13 changes: 9 additions & 4 deletions resources/sshdconfig/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

// keywords that can have multiple arguments per line but cannot be repeated over multiple lines,
// as subsequent entries are ignored, should be represented as arrays
pub const MULTI_ARG_KEYWORDS: [&str; 17] = [
// note that it is possible for a keyword to be in one, neither, or both of the multi-arg and repeatable lists below.

// keywords that can have multiple comma-separated arguments per line and should be represented as arrays.
pub const MULTI_ARG_KEYWORDS: [&str; 22] = [
"acceptenv",
"allowgroups",
"allowusers",
"authenticationmethods",
"authorizedkeysfile",
"casignaturealgorithms",
"channeltimeout",
"ciphers",
"denygroups",
"denyusers",
"hostbasedacceptedalgorithms",
"hostkeyalgorithms",
"ipqos",
Expand All @@ -24,7 +30,6 @@ pub const MULTI_ARG_KEYWORDS: [&str; 17] = [
];

// keywords that can be repeated over multiple lines and should be represented as arrays.
// note that some keywords can be both multi-arg and repeatable, in which case they only need to be listed here
pub const REPEATABLE_KEYWORDS: [&str; 12] = [
"acceptenv",
"allowgroups",
Expand Down
Loading