From 564763116949a6400cba7cf0670012ad56dfebc5 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 21 Sep 2024 16:15:11 +0200 Subject: [PATCH] fix(sshd_config): Overall improvements --- .../sshd_config/fields/match-parser/Match.g4 | 30 +---- .../fields/match-parser/parser/Match.interp | 16 +-- .../fields/match-parser/parser/Match.tokens | 15 +-- .../match-parser/parser/MatchLexer.interp | 23 +--- .../match-parser/parser/MatchLexer.tokens | 15 +-- .../fields/match-parser/parser/match_lexer.go | 69 +++-------- .../match-parser/parser/match_parser.go | 115 ++++++------------ handlers/sshd_config/handlers/formatting.go | 6 +- .../sshd_config/handlers/formatting_nodes.go | 23 +++- 9 files changed, 86 insertions(+), 226 deletions(-) diff --git a/handlers/sshd_config/fields/match-parser/Match.g4 b/handlers/sshd_config/fields/match-parser/Match.g4 index 10aa6eb..3db90cd 100644 --- a/handlers/sshd_config/fields/match-parser/Match.g4 +++ b/handlers/sshd_config/fields/match-parser/Match.g4 @@ -13,7 +13,7 @@ separator ; criteria - : (USER | GROUP | HOST| LOCALADDRESS | LOCALPORT | RDOMAIN | ADDRESS) + : STRING ; values @@ -24,34 +24,6 @@ value : STRING ; -USER - : ('U'|'u') ('S'|'s') ('E'|'e') ('R'|'r') - ; - -GROUP - : ('G'|'g') ('R'|'r') ('O'|'o') ('U'|'u') ('P'|'p') - ; - -HOST - : ('H'|'h') ('O'|'o') ('S'|'s') ('T'|'t') - ; - -LOCALADDRESS - : ('L'|'l') ('O'|'o') ('C'|'c') ('A'|'a') ('L'|'l') ('A'|'a') ('D'|'d') ('D'|'d') ('R'|'r') ('E'|'e') ('S'|'s') ('S'|'s') - ; - -LOCALPORT - : ('L'|'l') ('O'|'o') ('C'|'c') ('A'|'a') ('L'|'l') ('P'|'p') ('O'|'o') ('R'|'r') ('T'|'t') - ; - -RDOMAIN - : ('R'|'r') ('D'|'d') ('O'|'o') ('M'|'m') ('A'|'a') ('I'|'i') ('N'|'n') - ; - -ADDRESS - : ('A'|'a') ('D'|'d') ('D'|'d') ('R'|'r') ('E'|'e') ('S'|'s') ('S'|'s') - ; - COMMA : ',' ; diff --git a/handlers/sshd_config/fields/match-parser/parser/Match.interp b/handlers/sshd_config/fields/match-parser/parser/Match.interp index d188f93..491bdd3 100644 --- a/handlers/sshd_config/fields/match-parser/parser/Match.interp +++ b/handlers/sshd_config/fields/match-parser/parser/Match.interp @@ -1,25 +1,11 @@ token literal names: null -null -null -null -null -null -null -null ',' null null token symbolic names: null -USER -GROUP -HOST -LOCALADDRESS -LOCALPORT -RDOMAIN -ADDRESS COMMA STRING WHITESPACE @@ -34,4 +20,4 @@ value atn: -[4, 1, 10, 52, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, 20, 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 3, 4, 39, 8, 4, 1, 4, 1, 4, 3, 4, 43, 8, 4, 5, 4, 45, 8, 4, 10, 4, 12, 4, 48, 9, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 1, 7, 53, 0, 13, 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 38, 1, 0, 0, 0, 10, 49, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 10, 0, 0, 16, 18, 3, 2, 1, 0, 17, 16, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 15, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, 1, 1, 0, 0, 0, 26, 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 10, 0, 0, 34, 5, 1, 0, 0, 0, 35, 36, 7, 0, 0, 0, 36, 7, 1, 0, 0, 0, 37, 39, 3, 10, 5, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 46, 1, 0, 0, 0, 40, 42, 5, 8, 0, 0, 41, 43, 3, 10, 5, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 45, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, 50, 5, 9, 0, 0, 50, 11, 1, 0, 0, 0, 8, 13, 17, 21, 28, 31, 38, 42, 46] \ No newline at end of file +[4, 1, 3, 52, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, 20, 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 3, 4, 39, 8, 4, 1, 4, 1, 4, 3, 4, 43, 8, 4, 5, 4, 45, 8, 4, 10, 4, 12, 4, 48, 9, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 0, 53, 0, 13, 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 38, 1, 0, 0, 0, 10, 49, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 3, 0, 0, 16, 18, 3, 2, 1, 0, 17, 16, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 15, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, 1, 1, 0, 0, 0, 26, 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 3, 0, 0, 34, 5, 1, 0, 0, 0, 35, 36, 5, 2, 0, 0, 36, 7, 1, 0, 0, 0, 37, 39, 3, 10, 5, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 46, 1, 0, 0, 0, 40, 42, 5, 1, 0, 0, 41, 43, 3, 10, 5, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 45, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, 50, 5, 2, 0, 0, 50, 11, 1, 0, 0, 0, 8, 13, 17, 21, 28, 31, 38, 42, 46] \ No newline at end of file diff --git a/handlers/sshd_config/fields/match-parser/parser/Match.tokens b/handlers/sshd_config/fields/match-parser/parser/Match.tokens index 21f2b73..9172656 100644 --- a/handlers/sshd_config/fields/match-parser/parser/Match.tokens +++ b/handlers/sshd_config/fields/match-parser/parser/Match.tokens @@ -1,11 +1,4 @@ -USER=1 -GROUP=2 -HOST=3 -LOCALADDRESS=4 -LOCALPORT=5 -RDOMAIN=6 -ADDRESS=7 -COMMA=8 -STRING=9 -WHITESPACE=10 -','=8 +COMMA=1 +STRING=2 +WHITESPACE=3 +','=1 diff --git a/handlers/sshd_config/fields/match-parser/parser/MatchLexer.interp b/handlers/sshd_config/fields/match-parser/parser/MatchLexer.interp index 590b1bb..90a8247 100644 --- a/handlers/sshd_config/fields/match-parser/parser/MatchLexer.interp +++ b/handlers/sshd_config/fields/match-parser/parser/MatchLexer.interp @@ -1,37 +1,16 @@ token literal names: null -null -null -null -null -null -null -null ',' null null token symbolic names: null -USER -GROUP -HOST -LOCALADDRESS -LOCALPORT -RDOMAIN -ADDRESS COMMA STRING WHITESPACE rule names: -USER -GROUP -HOST -LOCALADDRESS -LOCALPORT -RDOMAIN -ADDRESS COMMA STRING WHITESPACE @@ -44,4 +23,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 10, 88, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 4, 8, 80, 8, 8, 11, 8, 12, 8, 81, 1, 9, 4, 9, 85, 8, 9, 11, 9, 12, 9, 86, 0, 0, 10, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 1, 0, 18, 2, 0, 85, 85, 117, 117, 2, 0, 83, 83, 115, 115, 2, 0, 69, 69, 101, 101, 2, 0, 82, 82, 114, 114, 2, 0, 71, 71, 103, 103, 2, 0, 79, 79, 111, 111, 2, 0, 80, 80, 112, 112, 2, 0, 72, 72, 104, 104, 2, 0, 84, 84, 116, 116, 2, 0, 76, 76, 108, 108, 2, 0, 67, 67, 99, 99, 2, 0, 65, 65, 97, 97, 2, 0, 68, 68, 100, 100, 2, 0, 77, 77, 109, 109, 2, 0, 73, 73, 105, 105, 2, 0, 78, 78, 110, 110, 5, 0, 9, 10, 13, 13, 32, 32, 35, 35, 44, 44, 2, 0, 9, 9, 32, 32, 89, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 1, 21, 1, 0, 0, 0, 3, 26, 1, 0, 0, 0, 5, 32, 1, 0, 0, 0, 7, 37, 1, 0, 0, 0, 9, 50, 1, 0, 0, 0, 11, 60, 1, 0, 0, 0, 13, 68, 1, 0, 0, 0, 15, 76, 1, 0, 0, 0, 17, 79, 1, 0, 0, 0, 19, 84, 1, 0, 0, 0, 21, 22, 7, 0, 0, 0, 22, 23, 7, 1, 0, 0, 23, 24, 7, 2, 0, 0, 24, 25, 7, 3, 0, 0, 25, 2, 1, 0, 0, 0, 26, 27, 7, 4, 0, 0, 27, 28, 7, 3, 0, 0, 28, 29, 7, 5, 0, 0, 29, 30, 7, 0, 0, 0, 30, 31, 7, 6, 0, 0, 31, 4, 1, 0, 0, 0, 32, 33, 7, 7, 0, 0, 33, 34, 7, 5, 0, 0, 34, 35, 7, 1, 0, 0, 35, 36, 7, 8, 0, 0, 36, 6, 1, 0, 0, 0, 37, 38, 7, 9, 0, 0, 38, 39, 7, 5, 0, 0, 39, 40, 7, 10, 0, 0, 40, 41, 7, 11, 0, 0, 41, 42, 7, 9, 0, 0, 42, 43, 7, 11, 0, 0, 43, 44, 7, 12, 0, 0, 44, 45, 7, 12, 0, 0, 45, 46, 7, 3, 0, 0, 46, 47, 7, 2, 0, 0, 47, 48, 7, 1, 0, 0, 48, 49, 7, 1, 0, 0, 49, 8, 1, 0, 0, 0, 50, 51, 7, 9, 0, 0, 51, 52, 7, 5, 0, 0, 52, 53, 7, 10, 0, 0, 53, 54, 7, 11, 0, 0, 54, 55, 7, 9, 0, 0, 55, 56, 7, 6, 0, 0, 56, 57, 7, 5, 0, 0, 57, 58, 7, 3, 0, 0, 58, 59, 7, 8, 0, 0, 59, 10, 1, 0, 0, 0, 60, 61, 7, 3, 0, 0, 61, 62, 7, 12, 0, 0, 62, 63, 7, 5, 0, 0, 63, 64, 7, 13, 0, 0, 64, 65, 7, 11, 0, 0, 65, 66, 7, 14, 0, 0, 66, 67, 7, 15, 0, 0, 67, 12, 1, 0, 0, 0, 68, 69, 7, 11, 0, 0, 69, 70, 7, 12, 0, 0, 70, 71, 7, 12, 0, 0, 71, 72, 7, 3, 0, 0, 72, 73, 7, 2, 0, 0, 73, 74, 7, 1, 0, 0, 74, 75, 7, 1, 0, 0, 75, 14, 1, 0, 0, 0, 76, 77, 5, 44, 0, 0, 77, 16, 1, 0, 0, 0, 78, 80, 8, 16, 0, 0, 79, 78, 1, 0, 0, 0, 80, 81, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 18, 1, 0, 0, 0, 83, 85, 7, 17, 0, 0, 84, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 20, 1, 0, 0, 0, 3, 0, 81, 86, 0] \ No newline at end of file +[4, 0, 3, 19, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 1, 4, 1, 11, 8, 1, 11, 1, 12, 1, 12, 1, 2, 4, 2, 16, 8, 2, 11, 2, 12, 2, 17, 0, 0, 3, 1, 1, 3, 2, 5, 3, 1, 0, 2, 5, 0, 9, 10, 13, 13, 32, 32, 35, 35, 44, 44, 2, 0, 9, 9, 32, 32, 20, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 1, 7, 1, 0, 0, 0, 3, 10, 1, 0, 0, 0, 5, 15, 1, 0, 0, 0, 7, 8, 5, 44, 0, 0, 8, 2, 1, 0, 0, 0, 9, 11, 8, 0, 0, 0, 10, 9, 1, 0, 0, 0, 11, 12, 1, 0, 0, 0, 12, 10, 1, 0, 0, 0, 12, 13, 1, 0, 0, 0, 13, 4, 1, 0, 0, 0, 14, 16, 7, 1, 0, 0, 15, 14, 1, 0, 0, 0, 16, 17, 1, 0, 0, 0, 17, 15, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 6, 1, 0, 0, 0, 3, 0, 12, 17, 0] \ No newline at end of file diff --git a/handlers/sshd_config/fields/match-parser/parser/MatchLexer.tokens b/handlers/sshd_config/fields/match-parser/parser/MatchLexer.tokens index 21f2b73..9172656 100644 --- a/handlers/sshd_config/fields/match-parser/parser/MatchLexer.tokens +++ b/handlers/sshd_config/fields/match-parser/parser/MatchLexer.tokens @@ -1,11 +1,4 @@ -USER=1 -GROUP=2 -HOST=3 -LOCALADDRESS=4 -LOCALPORT=5 -RDOMAIN=6 -ADDRESS=7 -COMMA=8 -STRING=9 -WHITESPACE=10 -','=8 +COMMA=1 +STRING=2 +WHITESPACE=3 +','=1 diff --git a/handlers/sshd_config/fields/match-parser/parser/match_lexer.go b/handlers/sshd_config/fields/match-parser/parser/match_lexer.go index 0c61e79..361c298 100644 --- a/handlers/sshd_config/fields/match-parser/parser/match_lexer.go +++ b/handlers/sshd_config/fields/match-parser/parser/match_lexer.go @@ -43,58 +43,26 @@ func matchlexerLexerInit() { "DEFAULT_MODE", } staticData.LiteralNames = []string{ - "", "", "", "", "", "", "", "", "','", + "", "','", } staticData.SymbolicNames = []string{ - "", "USER", "GROUP", "HOST", "LOCALADDRESS", "LOCALPORT", "RDOMAIN", - "ADDRESS", "COMMA", "STRING", "WHITESPACE", + "", "COMMA", "STRING", "WHITESPACE", } staticData.RuleNames = []string{ - "USER", "GROUP", "HOST", "LOCALADDRESS", "LOCALPORT", "RDOMAIN", "ADDRESS", "COMMA", "STRING", "WHITESPACE", } staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 0, 10, 88, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, - 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, - 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, - 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, - 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, - 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 4, 8, 80, 8, 8, - 11, 8, 12, 8, 81, 1, 9, 4, 9, 85, 8, 9, 11, 9, 12, 9, 86, 0, 0, 10, 1, - 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 1, 0, 18, - 2, 0, 85, 85, 117, 117, 2, 0, 83, 83, 115, 115, 2, 0, 69, 69, 101, 101, - 2, 0, 82, 82, 114, 114, 2, 0, 71, 71, 103, 103, 2, 0, 79, 79, 111, 111, - 2, 0, 80, 80, 112, 112, 2, 0, 72, 72, 104, 104, 2, 0, 84, 84, 116, 116, - 2, 0, 76, 76, 108, 108, 2, 0, 67, 67, 99, 99, 2, 0, 65, 65, 97, 97, 2, - 0, 68, 68, 100, 100, 2, 0, 77, 77, 109, 109, 2, 0, 73, 73, 105, 105, 2, - 0, 78, 78, 110, 110, 5, 0, 9, 10, 13, 13, 32, 32, 35, 35, 44, 44, 2, 0, - 9, 9, 32, 32, 89, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, - 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, - 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 1, 21, 1, 0, - 0, 0, 3, 26, 1, 0, 0, 0, 5, 32, 1, 0, 0, 0, 7, 37, 1, 0, 0, 0, 9, 50, 1, - 0, 0, 0, 11, 60, 1, 0, 0, 0, 13, 68, 1, 0, 0, 0, 15, 76, 1, 0, 0, 0, 17, - 79, 1, 0, 0, 0, 19, 84, 1, 0, 0, 0, 21, 22, 7, 0, 0, 0, 22, 23, 7, 1, 0, - 0, 23, 24, 7, 2, 0, 0, 24, 25, 7, 3, 0, 0, 25, 2, 1, 0, 0, 0, 26, 27, 7, - 4, 0, 0, 27, 28, 7, 3, 0, 0, 28, 29, 7, 5, 0, 0, 29, 30, 7, 0, 0, 0, 30, - 31, 7, 6, 0, 0, 31, 4, 1, 0, 0, 0, 32, 33, 7, 7, 0, 0, 33, 34, 7, 5, 0, - 0, 34, 35, 7, 1, 0, 0, 35, 36, 7, 8, 0, 0, 36, 6, 1, 0, 0, 0, 37, 38, 7, - 9, 0, 0, 38, 39, 7, 5, 0, 0, 39, 40, 7, 10, 0, 0, 40, 41, 7, 11, 0, 0, - 41, 42, 7, 9, 0, 0, 42, 43, 7, 11, 0, 0, 43, 44, 7, 12, 0, 0, 44, 45, 7, - 12, 0, 0, 45, 46, 7, 3, 0, 0, 46, 47, 7, 2, 0, 0, 47, 48, 7, 1, 0, 0, 48, - 49, 7, 1, 0, 0, 49, 8, 1, 0, 0, 0, 50, 51, 7, 9, 0, 0, 51, 52, 7, 5, 0, - 0, 52, 53, 7, 10, 0, 0, 53, 54, 7, 11, 0, 0, 54, 55, 7, 9, 0, 0, 55, 56, - 7, 6, 0, 0, 56, 57, 7, 5, 0, 0, 57, 58, 7, 3, 0, 0, 58, 59, 7, 8, 0, 0, - 59, 10, 1, 0, 0, 0, 60, 61, 7, 3, 0, 0, 61, 62, 7, 12, 0, 0, 62, 63, 7, - 5, 0, 0, 63, 64, 7, 13, 0, 0, 64, 65, 7, 11, 0, 0, 65, 66, 7, 14, 0, 0, - 66, 67, 7, 15, 0, 0, 67, 12, 1, 0, 0, 0, 68, 69, 7, 11, 0, 0, 69, 70, 7, - 12, 0, 0, 70, 71, 7, 12, 0, 0, 71, 72, 7, 3, 0, 0, 72, 73, 7, 2, 0, 0, - 73, 74, 7, 1, 0, 0, 74, 75, 7, 1, 0, 0, 75, 14, 1, 0, 0, 0, 76, 77, 5, - 44, 0, 0, 77, 16, 1, 0, 0, 0, 78, 80, 8, 16, 0, 0, 79, 78, 1, 0, 0, 0, - 80, 81, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 18, 1, - 0, 0, 0, 83, 85, 7, 17, 0, 0, 84, 83, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, - 84, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 20, 1, 0, 0, 0, 3, 0, 81, 86, 0, + 4, 0, 3, 19, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, + 1, 4, 1, 11, 8, 1, 11, 1, 12, 1, 12, 1, 2, 4, 2, 16, 8, 2, 11, 2, 12, 2, + 17, 0, 0, 3, 1, 1, 3, 2, 5, 3, 1, 0, 2, 5, 0, 9, 10, 13, 13, 32, 32, 35, + 35, 44, 44, 2, 0, 9, 9, 32, 32, 20, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, + 0, 5, 1, 0, 0, 0, 1, 7, 1, 0, 0, 0, 3, 10, 1, 0, 0, 0, 5, 15, 1, 0, 0, + 0, 7, 8, 5, 44, 0, 0, 8, 2, 1, 0, 0, 0, 9, 11, 8, 0, 0, 0, 10, 9, 1, 0, + 0, 0, 11, 12, 1, 0, 0, 0, 12, 10, 1, 0, 0, 0, 12, 13, 1, 0, 0, 0, 13, 4, + 1, 0, 0, 0, 14, 16, 7, 1, 0, 0, 15, 14, 1, 0, 0, 0, 16, 17, 1, 0, 0, 0, + 17, 15, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 6, 1, 0, 0, 0, 3, 0, 12, 17, + 0, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -135,14 +103,7 @@ func NewMatchLexer(input antlr.CharStream) *MatchLexer { // MatchLexer tokens. const ( - MatchLexerUSER = 1 - MatchLexerGROUP = 2 - MatchLexerHOST = 3 - MatchLexerLOCALADDRESS = 4 - MatchLexerLOCALPORT = 5 - MatchLexerRDOMAIN = 6 - MatchLexerADDRESS = 7 - MatchLexerCOMMA = 8 - MatchLexerSTRING = 9 - MatchLexerWHITESPACE = 10 + MatchLexerCOMMA = 1 + MatchLexerSTRING = 2 + MatchLexerWHITESPACE = 3 ) diff --git a/handlers/sshd_config/fields/match-parser/parser/match_parser.go b/handlers/sshd_config/fields/match-parser/parser/match_parser.go index ae15253..58bd86d 100644 --- a/handlers/sshd_config/fields/match-parser/parser/match_parser.go +++ b/handlers/sshd_config/fields/match-parser/parser/match_parser.go @@ -33,38 +33,37 @@ var MatchParserStaticData struct { func matchParserInit() { staticData := &MatchParserStaticData staticData.LiteralNames = []string{ - "", "", "", "", "", "", "", "", "','", + "", "','", } staticData.SymbolicNames = []string{ - "", "USER", "GROUP", "HOST", "LOCALADDRESS", "LOCALPORT", "RDOMAIN", - "ADDRESS", "COMMA", "STRING", "WHITESPACE", + "", "COMMA", "STRING", "WHITESPACE", } staticData.RuleNames = []string{ "root", "matchEntry", "separator", "criteria", "values", "value", } staticData.PredictionContextCache = antlr.NewPredictionContextCache() staticData.serializedATN = []int32{ - 4, 1, 10, 52, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, - 4, 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, - 20, 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, - 1, 1, 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 3, 4, 39, 8, 4, - 1, 4, 1, 4, 3, 4, 43, 8, 4, 5, 4, 45, 8, 4, 10, 4, 12, 4, 48, 9, 4, 1, - 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 1, 7, 53, 0, 13, - 1, 0, 0, 0, 2, 26, 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, - 38, 1, 0, 0, 0, 10, 49, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, - 0, 13, 14, 1, 0, 0, 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 10, 0, 0, 16, 18, - 3, 2, 1, 0, 17, 16, 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, - 19, 15, 1, 0, 0, 0, 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, - 0, 0, 0, 22, 24, 1, 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, - 1, 1, 0, 0, 0, 26, 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, - 0, 28, 29, 1, 0, 0, 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, - 1, 0, 0, 0, 31, 32, 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 10, 0, 0, - 34, 5, 1, 0, 0, 0, 35, 36, 7, 0, 0, 0, 36, 7, 1, 0, 0, 0, 37, 39, 3, 10, - 5, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 46, 1, 0, 0, 0, 40, 42, - 5, 8, 0, 0, 41, 43, 3, 10, 5, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, - 43, 45, 1, 0, 0, 0, 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, - 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, - 50, 5, 9, 0, 0, 50, 11, 1, 0, 0, 0, 8, 13, 17, 21, 28, 31, 38, 42, 46, + 4, 1, 3, 52, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, + 2, 5, 7, 5, 1, 0, 3, 0, 14, 8, 0, 1, 0, 1, 0, 3, 0, 18, 8, 0, 5, 0, 20, + 8, 0, 10, 0, 12, 0, 23, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 29, 8, 1, 1, + 1, 3, 1, 32, 8, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 3, 4, 39, 8, 4, 1, 4, + 1, 4, 3, 4, 43, 8, 4, 5, 4, 45, 8, 4, 10, 4, 12, 4, 48, 9, 4, 1, 5, 1, + 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 0, 53, 0, 13, 1, 0, 0, 0, 2, 26, + 1, 0, 0, 0, 4, 33, 1, 0, 0, 0, 6, 35, 1, 0, 0, 0, 8, 38, 1, 0, 0, 0, 10, + 49, 1, 0, 0, 0, 12, 14, 3, 2, 1, 0, 13, 12, 1, 0, 0, 0, 13, 14, 1, 0, 0, + 0, 14, 21, 1, 0, 0, 0, 15, 17, 5, 3, 0, 0, 16, 18, 3, 2, 1, 0, 17, 16, + 1, 0, 0, 0, 17, 18, 1, 0, 0, 0, 18, 20, 1, 0, 0, 0, 19, 15, 1, 0, 0, 0, + 20, 23, 1, 0, 0, 0, 21, 19, 1, 0, 0, 0, 21, 22, 1, 0, 0, 0, 22, 24, 1, + 0, 0, 0, 23, 21, 1, 0, 0, 0, 24, 25, 5, 0, 0, 1, 25, 1, 1, 0, 0, 0, 26, + 28, 3, 6, 3, 0, 27, 29, 3, 4, 2, 0, 28, 27, 1, 0, 0, 0, 28, 29, 1, 0, 0, + 0, 29, 31, 1, 0, 0, 0, 30, 32, 3, 8, 4, 0, 31, 30, 1, 0, 0, 0, 31, 32, + 1, 0, 0, 0, 32, 3, 1, 0, 0, 0, 33, 34, 5, 3, 0, 0, 34, 5, 1, 0, 0, 0, 35, + 36, 5, 2, 0, 0, 36, 7, 1, 0, 0, 0, 37, 39, 3, 10, 5, 0, 38, 37, 1, 0, 0, + 0, 38, 39, 1, 0, 0, 0, 39, 46, 1, 0, 0, 0, 40, 42, 5, 1, 0, 0, 41, 43, + 3, 10, 5, 0, 42, 41, 1, 0, 0, 0, 42, 43, 1, 0, 0, 0, 43, 45, 1, 0, 0, 0, + 44, 40, 1, 0, 0, 0, 45, 48, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, + 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 49, 50, 5, 2, 0, 0, 50, + 11, 1, 0, 0, 0, 8, 13, 17, 21, 28, 31, 38, 42, 46, } deserializer := antlr.NewATNDeserializer(nil) staticData.atn = deserializer.Deserialize(staticData.serializedATN) @@ -102,17 +101,10 @@ func NewMatchParser(input antlr.TokenStream) *MatchParser { // MatchParser tokens. const ( - MatchParserEOF = antlr.TokenEOF - MatchParserUSER = 1 - MatchParserGROUP = 2 - MatchParserHOST = 3 - MatchParserLOCALADDRESS = 4 - MatchParserLOCALPORT = 5 - MatchParserRDOMAIN = 6 - MatchParserADDRESS = 7 - MatchParserCOMMA = 8 - MatchParserSTRING = 9 - MatchParserWHITESPACE = 10 + MatchParserEOF = antlr.TokenEOF + MatchParserCOMMA = 1 + MatchParserSTRING = 2 + MatchParserWHITESPACE = 3 ) // MatchParser rules. @@ -261,7 +253,7 @@ func (p *MatchParser) Root() (localctx IRootContext) { } _la = p.GetTokenStream().LA(1) - if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&254) != 0 { + if _la == MatchParserSTRING { { p.SetState(12) p.MatchEntry() @@ -291,7 +283,7 @@ func (p *MatchParser) Root() (localctx IRootContext) { } _la = p.GetTokenStream().LA(1) - if (int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&254) != 0 { + if _la == MatchParserSTRING { { p.SetState(16) p.MatchEntry() @@ -594,13 +586,7 @@ type ICriteriaContext interface { GetParser() antlr.Parser // Getter signatures - USER() antlr.TerminalNode - GROUP() antlr.TerminalNode - HOST() antlr.TerminalNode - LOCALADDRESS() antlr.TerminalNode - LOCALPORT() antlr.TerminalNode - RDOMAIN() antlr.TerminalNode - ADDRESS() antlr.TerminalNode + STRING() antlr.TerminalNode // IsCriteriaContext differentiates from other interfaces. IsCriteriaContext() @@ -638,32 +624,8 @@ func NewCriteriaContext(parser antlr.Parser, parent antlr.ParserRuleContext, inv func (s *CriteriaContext) GetParser() antlr.Parser { return s.parser } -func (s *CriteriaContext) USER() antlr.TerminalNode { - return s.GetToken(MatchParserUSER, 0) -} - -func (s *CriteriaContext) GROUP() antlr.TerminalNode { - return s.GetToken(MatchParserGROUP, 0) -} - -func (s *CriteriaContext) HOST() antlr.TerminalNode { - return s.GetToken(MatchParserHOST, 0) -} - -func (s *CriteriaContext) LOCALADDRESS() antlr.TerminalNode { - return s.GetToken(MatchParserLOCALADDRESS, 0) -} - -func (s *CriteriaContext) LOCALPORT() antlr.TerminalNode { - return s.GetToken(MatchParserLOCALPORT, 0) -} - -func (s *CriteriaContext) RDOMAIN() antlr.TerminalNode { - return s.GetToken(MatchParserRDOMAIN, 0) -} - -func (s *CriteriaContext) ADDRESS() antlr.TerminalNode { - return s.GetToken(MatchParserADDRESS, 0) +func (s *CriteriaContext) STRING() antlr.TerminalNode { + return s.GetToken(MatchParserSTRING, 0) } func (s *CriteriaContext) GetRuleContext() antlr.RuleContext { @@ -689,18 +651,13 @@ func (s *CriteriaContext) ExitRule(listener antlr.ParseTreeListener) { func (p *MatchParser) Criteria() (localctx ICriteriaContext) { localctx = NewCriteriaContext(p, p.GetParserRuleContext(), p.GetState()) p.EnterRule(localctx, 6, MatchParserRULE_criteria) - var _la int - p.EnterOuterAlt(localctx, 1) { p.SetState(35) - _la = p.GetTokenStream().LA(1) - - if !((int64(_la) & ^0x3f) == 0 && ((int64(1)<<_la)&254) != 0) { - p.GetErrorHandler().RecoverInline(p) - } else { - p.GetErrorHandler().ReportMatch(p) - p.Consume() + p.Match(MatchParserSTRING) + if p.HasError() { + // Recognition error - abort rule + goto errorExit } } diff --git a/handlers/sshd_config/handlers/formatting.go b/handlers/sshd_config/handlers/formatting.go index 4fcc2de..38aa0e4 100644 --- a/handlers/sshd_config/handlers/formatting.go +++ b/handlers/sshd_config/handlers/formatting.go @@ -26,7 +26,11 @@ func FormatDocument( switch entry.(type) { case *ast.SSHDOption: option := entry.(*ast.SSHDOption) - edits = append(edits, formatSSHDOption(option, options)...) + edits = append(edits, formatSSHDOption( + option, + options, + optionTemplate, + )...) case *ast.SSHDMatchBlock: matchBlock := entry.(*ast.SSHDMatchBlock) diff --git a/handlers/sshd_config/handlers/formatting_nodes.go b/handlers/sshd_config/handlers/formatting_nodes.go index 02c148e..bb0b7cd 100644 --- a/handlers/sshd_config/handlers/formatting_nodes.go +++ b/handlers/sshd_config/handlers/formatting_nodes.go @@ -14,10 +14,17 @@ import ( var optionTemplate = formatting.FormatTemplate( "%s /!'%s/!'", ) +var matchTemplate = formatting.FormatTemplate( + "%s %s", +) +var matchOptionTemplate = formatting.FormatTemplate( + " %s /!'%s/!'", +) func formatSSHDOption( option *ast.SSHDOption, options protocol.FormattingOptions, + template formatting.FormatTemplate, ) []protocol.TextEdit { var key string @@ -38,7 +45,7 @@ func formatSSHDOption( return []protocol.TextEdit{ { Range: option.ToLSPRange(), - NewText: optionTemplate.Format(options, key, value), + NewText: template.Format(options, key, value), }, } } @@ -50,15 +57,23 @@ func formatSSHDMatchBlock( edits := make([]protocol.TextEdit, 0) edits = append(edits, protocol.TextEdit{ - Range: matchBlock.ToLSPRange(), - NewText: optionTemplate.Format(options, matchBlock.MatchEntry.Key.Key, formatMatchToString(matchBlock.MatchValue)), + Range: matchBlock.MatchEntry.ToLSPRange(), + NewText: matchTemplate.Format( + options, + matchBlock.MatchEntry.Key.Key, + formatMatchToString(matchBlock.MatchValue), + ), }) it := matchBlock.Options.Iterator() for it.Next() { option := it.Value().(*ast.SSHDOption) - edits = append(edits, formatSSHDOption(option, options)...) + edits = append(edits, formatSSHDOption( + option, + options, + matchOptionTemplate, + )...) } return edits