OpenSshConfig(File h, File cfg) { configFile = new OpenSshConfigFile(h, cfg, SshSessionFactory.getLocalUserName()); }
port = positive(entry.getValue(SshConstants.PORT)); connectionAttempts = positive( entry.getValue(SshConstants.CONNECTION_ATTEMPTS)); strictHostKeyChecking = entry .getValue(SshConstants.STRICT_HOST_KEY_CHECKING); batchMode = Boolean.valueOf(OpenSshConfigFile .flag(entry.getValue(SshConstants.BATCH_MODE))); preferredAuthentications = entry .getValue(SshConstants.PREFERRED_AUTHENTICATIONS);
/** * Locate the configuration for a specific host request. * * @param 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. * @return r configuration for the requested name. Never null. */ public Host lookup(String hostName) { HostEntry entry = configFile.lookup(hostName, -1, null); return new Host(entry, hostName, configFile.getLocalUserName()); }
String keyword = dequote(parts[0].trim()); for (String name : parseList(argValue)) { if (name == null || name.isEmpty()) { List<String> args = validate(keyword, parseList(argValue)); for (HostEntry entry : current) { entry.setValue(keyword, args); argValue = validate(keyword, dequote(argValue)); for (HostEntry entry : current) { entry.setValue(keyword, argValue);
public HostEntry lookup(@NonNull String hostName, int port, String userName) { final State cache = refresh(); String cacheKey = toCacheKey(hostName, port, userName); HostEntry h = cache.hosts.get(cacheKey); if (h != null) { for (Map.Entry<String, HostEntry> e : cache.entries.entrySet()) { String pattern = e.getKey(); if (isHostMatch(pattern, hostName)) { fullConfig.merge(e.getValue());
@Override public HostConfigEntry resolveEffectiveHost(String host, int port, String username) throws IOException { HostEntry entry = configFile.lookup(host, port, username); JGitHostConfigEntry config = new JGitHostConfigEntry(); : entry.getValue(SshConstants.USER); if (user == null || user.isEmpty()) { user = configFile.getLocalUserName(); int p = port >= 0 ? port : positive(entry.getValue(SshConstants.PORT)); config.setPort(p >= 0 ? p : SshConstants.SSH_DEFAULT_PORT); config.setProperty(SshConstants.PORT, config.setIdentities(entry.getValues(SshConstants.IDENTITY_FILE)); config.setIdentitiesOnly( flag(entry.getValue(SshConstants.IDENTITIES_ONLY))); return config;
void substitute(String originalHostName, int port, String userName, String localUserName, File home) { int p = port >= 0 ? port : positive(getValue(SshConstants.PORT)); if (p < 0) { p = SshConstants.SSH_DEFAULT_PORT;
@Override public String getValue(String key) { // See com.jcraft.jsch.OpenSSHConfig.MyConfig.getValue() // for this special case. if (key.equals("compression.s2c") //$NON-NLS-1$ || key.equals("compression.c2s")) { //$NON-NLS-1$ if (!OpenSshConfigFile.flag( Host.this.entry.getValue(mapKey(key)))) { return "none,zlib@openssh.com,zlib"; //$NON-NLS-1$ } return "zlib@openssh.com,zlib,none"; //$NON-NLS-1$ } return Host.this.entry.getValue(mapKey(key)); }
private static boolean isHostMatch(String pattern, String name) { if (pattern.startsWith("!")) { //$NON-NLS-1$ return !patternMatchesHost(pattern.substring(1), name); } else { return patternMatchesHost(pattern, name); } }
private synchronized State refresh() { final long mtime = configFile.lastModified(); if (mtime != lastModified) { State newState = new State(); try (BufferedReader br = Files .newBufferedReader(configFile.toPath(), UTF_8)) { newState.entries = parse(br); } catch (IOException | RuntimeException none) { // Ignore -- we'll set and return an empty state } lastModified = mtime; state = newState; } return state; }
public HostEntry lookup(@NonNull String hostName, int port, String userName) { final State cache = refresh(); String cacheKey = toCacheKey(hostName, port, userName); HostEntry h = cache.hosts.get(cacheKey); if (h != null) { for (Map.Entry<String, HostEntry> e : cache.entries.entrySet()) { String pattern = e.getKey(); if (isHostMatch(pattern, hostName)) { fullConfig.merge(e.getValue());
String keyword = dequote(parts[0].trim()); for (String name : parseList(argValue)) { if (name == null || name.isEmpty()) { List<String> args = validate(keyword, parseList(argValue)); for (HostEntry entry : current) { entry.setValue(keyword, args); argValue = validate(keyword, dequote(argValue)); for (HostEntry entry : current) { entry.setValue(keyword, argValue);
private int getNumberOfPasswordPrompts(HostConfigEntry hostConfig) { String prompts = hostConfig .getProperty(SshConstants.NUMBER_OF_PASSWORD_PROMPTS); if (prompts != null) { prompts = prompts.trim(); int value = positive(prompts); if (value > 0) { return value; } log.warn(format(SshdText.get().configInvalidPositive, SshConstants.NUMBER_OF_PASSWORD_PROMPTS, prompts)); } // Default for NumberOfPasswordPrompts according to // https://man.openbsd.org/ssh_config return 3; }
@Override public String getValue(String key) { // See com.jcraft.jsch.OpenSSHConfig.MyConfig.getValue() // for this special case. if (key.equals("compression.s2c") //$NON-NLS-1$ || key.equals("compression.c2s")) { //$NON-NLS-1$ if (!OpenSshConfigFile.flag( Host.this.entry.getValue(mapKey(key)))) { return "none,zlib@openssh.com,zlib"; //$NON-NLS-1$ } return "zlib@openssh.com,zlib,none"; //$NON-NLS-1$ } return Host.this.entry.getValue(mapKey(key)); }
private static boolean isHostMatch(String pattern, String name) { if (pattern.startsWith("!")) { //$NON-NLS-1$ return !patternMatchesHost(pattern.substring(1), name); } else { return patternMatchesHost(pattern, name); } }
private synchronized State refresh() { final long mtime = configFile.lastModified(); if (mtime != lastModified) { State newState = new State(); try (BufferedReader br = Files .newBufferedReader(configFile.toPath(), UTF_8)) { newState.entries = parse(br); } catch (IOException | RuntimeException none) { // Ignore -- we'll set and return an empty state } lastModified = mtime; state = newState; } return state; }
/** * Locate the configuration for a specific host request. * * @param 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. * @return r configuration for the requested name. Never null. */ public Host lookup(String hostName) { HostEntry entry = configFile.lookup(hostName, -1, null); return new Host(entry, hostName, configFile.getLocalUserName()); }
port = positive(entry.getValue(SshConstants.PORT)); connectionAttempts = positive( entry.getValue(SshConstants.CONNECTION_ATTEMPTS)); strictHostKeyChecking = entry .getValue(SshConstants.STRICT_HOST_KEY_CHECKING); batchMode = Boolean.valueOf(OpenSshConfigFile .flag(entry.getValue(SshConstants.BATCH_MODE))); preferredAuthentications = entry .getValue(SshConstants.PREFERRED_AUTHENTICATIONS);
OpenSshConfig(File h, File cfg) { configFile = new OpenSshConfigFile(h, cfg, SshSessionFactory.getLocalUserName()); }
void substitute(String originalHostName, int port, String userName, String localUserName, File home) { int p = port >= 0 ? port : positive(getValue(SshConstants.PORT)); if (p < 0) { p = SshConstants.SSH_DEFAULT_PORT;