public class OpenSshConfigFile extends Object
Both JSch 0.1.54 and Apache MINA sshd 2.1.0 have parsers for this, but both are buggy. Therefore we implement our own parser to read an openssh configuration file.
Limitations compared to the full openssh 7.5 parser:
Note that openssh's readconf.c is a validating parser; this parser does not validate entries.
This config does %-substitutions for the following tokens:
lookup(String, int, String)
lookup(String, int, String)
replaced only if set in the config
lookup(String, int, String)
replaced only if set in the config
%i is not handled; Java has no concept of a "user ID". %T is always replaced by NONE.
Modifier and Type | Class and Description |
---|---|
static class |
OpenSshConfigFile.HostEntry
A host entry from the ssh config file.
|
Constructor and Description |
---|
OpenSshConfigFile(File home,
File config,
String localUserName)
Creates a new
OpenSshConfigFile that will read the config from
file config use the given file home as "home" directory. |
Modifier and Type | Method and Description |
---|---|
static boolean |
flag(String value)
Converts a ssh config flag value (yes/true/on - no/false/off) into an
boolean . |
String |
getLocalUserName()
Retrieves the local user name as given in the constructor.
|
OpenSshConfigFile.HostEntry |
lookup(String hostName,
int port,
String userName)
Locate the configuration for a specific host request.
|
static int |
positive(String value)
Converts a positive value into an
int . |
String |
toString() |
protected List<String> |
validate(String key,
List<String> value)
Hook to perform validation on values, or to sanitize them.
|
protected String |
validate(String key,
String value)
Hook to perform validation on a single value, or to sanitize it.
|
public OpenSshConfigFile(@NonNull File home, @NonNull File config, @NonNull String localUserName)
OpenSshConfigFile
that will read the config from
file config
use the given file home
as "home" directory.home
- user's home directory for the purpose of ~ replacementconfig
- file to load.localUserName
- user name of the current user on the local host OS@NonNull public OpenSshConfigFile.HostEntry lookup(@NonNull String hostName, int port, String userName)
hostName
- the name the user has supplied to the SSH tool. This may be a
real host name, or it may just be a "Host" block in the
configuration file.port
- the user supplied; <= 0 if noneuserName
- the user supplied, may be null
or empty if none givenprotected String validate(String key, String value)
key
- of the entryvalue
- as read from the config fileprotected List<String> validate(String key, List<String> value)
key
- of the entryvalue
- list of arguments as read from the config fileList
of values, possibly empty and possibly containing
empty elements, but not containing null
public static int positive(String value)
int
.value
- to convertpublic static boolean flag(String value)
boolean
.value
- to converttrue
if value
is "yes", "on", or "true";
false
otherwisepublic String getLocalUserName()
Copyright © 2020 Eclipse JGit Project. All rights reserved.