fix(server): Improve ssh handlers

Signed-off-by: Myzel394 <github.7a2op@simplelogin.co>
This commit is contained in:
Myzel394 2025-05-29 15:34:21 +02:00
parent fa45351ec5
commit 9a1686a7d8
No known key found for this signature in database
GPG Key ID: 3B955307C2FC2F11
8 changed files with 47 additions and 28 deletions

12
flake.lock generated
View File

@ -26,11 +26,11 @@
]
},
"locked": {
"lastModified": 1742209644,
"narHash": "sha256-jMy1XqXqD0/tJprEbUmKilTkvbDY/C0ZGSsJJH4TNCE=",
"lastModified": 1745875161,
"narHash": "sha256-0YkWCS13jpoo3+sX/3kcgdxBNt1VZTmvF+FhZb4rFKI=",
"owner": "tweag",
"repo": "gomod2nix",
"rev": "8f3534eb8f6c5c3fce799376dc3b91bae6b11884",
"rev": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0",
"type": "github"
},
"original": {
@ -41,11 +41,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1742669843,
"narHash": "sha256-G5n+FOXLXcRx+3hCJ6Rt6ZQyF1zqQ0DL0sWAMn2Nk0w=",
"lastModified": 1748026106,
"narHash": "sha256-6m1Y3/4pVw1RWTsrkAK2VMYSzG4MMIj7sqUy7o8th1o=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1e5b653dff12029333a6546c11e108ede13052eb",
"rev": "063f43f2dbdef86376cc29ad646c45c46e93234c",
"type": "github"
},
"original": {

View File

@ -28,14 +28,14 @@
inherit system;
overlays = [
(final: prev: {
go = prev.go_1_22;
buildGoModule = prev.buildGo122Module;
go = prev.go_1_24;
buildGoModule = prev.buildGo124Module;
})
gomod2nix.overlays.default
];
};
inputs = [
pkgs.go_1_22
pkgs.go_1_24
];
serverUncompressed = pkgs.buildGoModule {
nativeBuildInputs = inputs;
@ -133,7 +133,7 @@
};
devShells.default = let
version = "0.16.2";
version = "0.18.1";
ourGopls = pkgs.buildGoModule {
pname = "gopls";
inherit version;

View File

@ -21,12 +21,12 @@ func (e PathInvalidError) Error() string {
type PathType uint8
const (
PathTypeExistenceOptional PathType = 0
PathTypeFile PathType = 1
PathTypeDirectory PathType = 2
)
type PathValue struct {
IsOptional bool
RequiredType PathType
}
@ -34,30 +34,31 @@ func (v PathValue) GetTypeDescription() []string {
hints := make([]string, 0)
switch v.RequiredType {
case PathTypeExistenceOptional:
hints = append(hints, "Optional")
break
case PathTypeFile:
hints = append(hints, "File")
case PathTypeDirectory:
hints = append(hints, "Directory")
}
if v.IsOptional {
hints = append(hints, "Optional")
}
return []string{strings.Join(hints, ", ")}
}
func (v PathValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
if v.RequiredType == PathTypeExistenceOptional {
return nil
}
if !utils.DoesPathExist(value) {
if v.IsOptional {
return nil
} else {
return []*InvalidValue{{
Err: PathDoesNotExistError{},
Start: 0,
End: uint32(len(value)),
}}
}
}
isValid := false
@ -77,8 +78,7 @@ func (v PathValue) DeprecatedCheckIsValid(value string) []*InvalidValue {
Err: PathInvalidError{},
Start: 0,
End: uint32(len(value)),
},
}
}}
}
func (v PathValue) DeprecatedFetchCompletions(line string, cursor uint32) []protocol.CompletionItem {

View File

@ -15,6 +15,7 @@ var UserDeclaration = "`user`"
var PathField = docvalues.DocumentationValue{
Documentation: "Append messages to file, specified by its absolute pathname",
Value: docvalues.PathValue{
IsOptional: true,
RequiredType: docvalues.PathTypeFile,
},
}
@ -40,6 +41,7 @@ var EmailDeclaration = "`user-part@domain-part`"
var IncludeField = docvalues.DocumentationValue{
Documentation: "Include any definitions in file as alias entries. The format of the file is identical to this one.",
Value: docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
}

View File

@ -16,7 +16,8 @@ var LabelField = docvalues.RegexValue{
var SpecField = docvalues.OrValue{
Values: []docvalues.DeprecatedValue{
docvalues.PathValue{
RequiredType: docvalues.PathTypeExistenceOptional,
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
docvalues.KeyEnumAssignmentValue{
Separator: "=",

View File

@ -139,6 +139,7 @@ rsa-sha2-512,rsa-sha2-256
Arguments to CertificateFile may use the tilde syntax to refer to a user's home directory, the tokens described in the TOKENS section and environment variables as described in the ENVIRONMENT VARIABLES section.
It is possible to have multiple certificate files specified in configuration files; these certificates will be tried in sequence. Multiple CertificateFile directives will add to the list of certificates used for authentication.`,
Value: docvalues.PathValue{
IsOptional: true,
RequiredType: docvalues.PathTypeFile,
},
},
@ -366,6 +367,7 @@ aes128-gcm@openssh.com,aes256-gcm@openssh.com
DuplicatesExtractor: &docvalues.SimpleDuplicatesExtractor,
RespectQuotes: true,
SubValue: docvalues.PathValue{
IsOptional: true,
RequiredType: docvalues.PathTypeFile,
},
},
@ -834,6 +836,7 @@ rsa-sha2-512,rsa-sha2-256
Documentation: `Specifies a path to a library that will be used when loading any FIDO authenticator-hosted keys, overriding the default of using the built-in USB HID support.
If the specified value begins with a $ character, then it will be treated as an environment variable containing the path to the library.`,
Value: docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
},
@ -963,6 +966,7 @@ rsa-sha2-512,rsa-sha2-256
DuplicatesExtractor: &docvalues.SimpleDuplicatesExtractor,
RespectQuotes: true,
SubValue: docvalues.PathValue{
IsOptional: true,
RequiredType: docvalues.PathTypeFile,
},
},
@ -986,6 +990,7 @@ rsa-sha2-512,rsa-sha2-256
"xauthlocation": {
Documentation: `Specifies the full pathname of the xauth(1) program. The default is /usr/X11R6/bin/xauth.`,
Value: docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
},

View File

@ -155,6 +155,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
Values: []docvalues.DeprecatedValue{
docvalues.SingleEnumValue("none"),
docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
},
@ -166,6 +167,7 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
Values: []docvalues.DeprecatedValue{
docvalues.SingleEnumValue("none"),
docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
},
@ -358,13 +360,19 @@ See PATTERNS in ssh_config(5) for more information on patterns. This keyword may
},
"hostcertificate": {
Documentation: `Specifies a file containing a public host certificate. The certificate's public key must match a private host key already specified by HostKey. The default behaviour of sshd(8) is not to load any certificates.`,
Value: docvalues.PathValue{},
Value: docvalues.PathValue{
IsOptional: true,
RequiredType: docvalues.PathTypeFile,
},
},
"hostkey": {
Documentation: `Specifies a file containing a private host key used by SSH. The defaults are /etc/ssh/ssh_host_ecdsa_key, /etc/ssh/ssh_host_ed25519_key and /etc/ssh/ssh_host_rsa_key.
Note that sshd(8) will refuse to use a file if it is group/world-accessible and that the HostKeyAlgorithms option restricts which of the keys are actually used by sshd(8).
It is possible to have multiple host key files. It is also possible to specify public host key files instead. In this case operations on the private key will be delegated to an ssh-agent(1).`,
Value: docvalues.PathValue{},
Value: docvalues.PathValue{
IsOptional: true,
RequiredType: docvalues.PathTypeFile,
},
},
"hostkeyagent": {
Documentation: `Identifies the UNIX-domain socket used to communicate with an agent that has access to the private host keys. If the string "SSH_AUTH_SOCK" is specified, the location of the socket will be read from the SSH_AUTH_SOCK environment variable.`,
@ -609,6 +617,7 @@ Only a subset of keywords may be used on the lines following a Match keyword. Av
"modulifile": {
Documentation: `Specifies the moduli(5) file that contains the Diffie-Hellman groups used for the “diffie-hellman-group-exchange-sha1” and “diffie-hellman-group-exchange-sha256” key exchange methods. The default is /etc/moduli.`,
Value: docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
},
@ -874,6 +883,7 @@ Only a subset of keywords may be used on the lines following a Match keyword. Av
"securitykeyprovider": {
Documentation: `Specifies a path to a library that will be used when loading FIDO authenticator-hosted keys, overriding the default of using the built-in USB HID support.`,
Value: docvalues.PathValue{
IsOptional: false,
RequiredType: docvalues.PathTypeFile,
},
},

View File

@ -24,6 +24,7 @@ func TextDocumentCompletion(context *glsp.Context, params *protocol.CompletionPa
entry, matchBlock := d.Config.FindOption(line)
if entry == nil ||
entry.Separator == nil ||
entry.Key == nil ||