@Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } });
private SshServer defaultSshServer() { SshServer sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(randomPort()); ClassLoadableResourceKeyPairProvider fileKeyPairProvider = new ClassLoadableResourceKeyPairProvider(hostkey); sshServer.setKeyPairProvider(fileKeyPairProvider); sshServer.setPasswordAuthenticator(new PasswordAuthenticator() { @Override public boolean authenticate(String username, String password, ServerSession session) { return username.equals(password); } }); sshServer.setGSSAuthenticator(new BogusGSSAuthenticator()); sshServer.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory())); ScpCommandFactory commandFactory = new ScpCommandFactory(); commandFactory.setDelegateCommandFactory(new CommandFactory() { @Override public Command createCommand(String command) { return new ProcessShellFactory(command.split(" ")).create(); } }); sshServer.setCommandFactory(commandFactory); sshServer.setShellFactory(new ProcessShellFactory("ls")); return sshServer; }
@Override public Command create() { return new InvertedShellWrapper(createInvertedShell()); }
@Override public synchronized void start(Environment env) throws IOException { // TODO propagate the Environment itself and support signal sending. shell.start(env); shellIn = shell.getInputStream(); shellOut = shell.getOutputStream(); shellErr = shell.getErrorStream(); executor.execute(this::pumpStreams); }
@Override public void write(int c) throws IOException { if (c == '\r') { handleCR(); } else if (c == '\n') { handleLF(); } else { writeRawOutput(c); } }
protected InvertedShell createInvertedShell() { return new ProcessShell(resolveEffectiveCommand(getCommand())); }
@Override public synchronized int read() throws IOException { int c = readRawInput(); if (c == -1) { return c; } if (c == '\r') { c = handleCR(); } else if (c == '\n') { c = handleLF(); } lastChar = c; return c; }
@Override public String toString() { return getMessage(); } }
@Override public Command createCommand(String command) { return new UnknownCommand(command); } }
protected void handleCR() throws IOException { if (ttyOptions.contains(PtyMode.ICRNL)) { writeRawOutput('\n'); // Map CR to NL on input } else if (ttyOptions.contains(PtyMode.IGNCR)) { // Ignore CR on input return; } else { writeRawOutput('\r'); } }
protected int handleLF() throws IOException { // Map NL to CR-NL. if ((ttyOptions.contains(PtyMode.ONLCR) || ttyOptions.contains(PtyMode.ONOCR)) && (lastChar != '\r')) { buffer = insertCharacter(buffer, '\n'); return '\r'; } else if (ttyOptions.contains(PtyMode.ONLRET)) { // Newline performs a carriage return return '\r'; } else { return '\n'; } }
public synchronized void write(byte[] buf, int off, int len) { if (len == 1) { write(buf[off] & 0xFF); } else { buffer.putBytes(buf, off, len); } }
sshd.setCommandFactory(new CommandFactory() { public Command createCommand(String command) { return new ProcessShellFactory(" ")).create(); } });
@Override public synchronized void start(Environment env) throws IOException { // TODO propagate the Environment itself and support signal sending. shell.start(env); shellIn = shell.getInputStream(); shellOut = shell.getOutputStream(); shellErr = shell.getErrorStream(); executor.execute(this::pumpStreams); }
@Override public void write(int c) throws IOException { if (c == '\r') { handleCR(); } else if (c == '\n') { handleLF(); } else { writeRawOutput(c); } }
protected InvertedShell createInvertedShell() { return new ProcessShell(resolveEffectiveCommand(getCommand())); }
@Override public synchronized int read() throws IOException { int c = readRawInput(); if (c == -1) { return c; } if (c == '\r') { c = handleCR(); } else if (c == '\n') { c = handleLF(); } lastChar = c; return c; }
@Override public Command create() { return new InvertedShellWrapper(createInvertedShell()); }
@Override public String toString() { return getMessage(); } }
@Override public Command createCommand(String command) { return new UnknownCommand(command); } }