Error executing interactive prompt commands on OpenBSD 4.7

0 votes
asked Feb 28, 2011 by David R. Pinheiro (120 points)
edited Mar 29, 2011

I'm trying Rebex SSH Pack to write an application that executes a lot of interactive commands on many linuces and unices platforms.

While testing prompt interactions with Rebex.TerminalEmulation.Shell objects, an error executing a "su -" command interaction on OpenBSD 4.7 occurs. I think there is a problem related with the prompt options.

The following code is OK on Linux, Solaris and HP-UX.

Rebex.Net.Ssh ssh;
Rebex.TerminalEmulation.Shell shell;
String terminalScreen;
String host;
String username;
String password;
String rootPassword;
String[] promptQuestions;

try
{
    host = "XXX.XXX.XXX.XXX";
    username = "user";
    password = "password";
    rootPassword = "rootpassword";
    promptQuestions = new String[] { "Password:", "Password: " };


    ssh = new Rebex.Net.Ssh();
    ssh.LogWriter = new Rebex.FileLogWriter(@"C:\temp\rebex.txt", Rebex.LogLevel.Debug);
    ssh.Connect(host);
    ssh.Login(username, password);
    ssh.Timeout = 5000;

    //shell = ssh.StartShell(Rebex.TerminalEmulation.ShellMode.Prompt);
    //shell.Prompt = "regex:[$#] $";

    shell = ssh.StartShell(Rebex.TerminalEmulation.ShellMode.WellKnownShell);

    shell.SendCommand("su -");
    while (shell.IsRunning)
    {
        terminalScreen = shell.ReadAll(promptQuestions);
        foreach(String promptQuestion in promptQuestions)
          if (terminalScreen.Contains(promptQuestion))
          {
              shell.SendCommand(rootPassword, true);
              break;
           }
    }
}
catch (Exception e)
{
}

The text above describes two error scenarios with the ssh log attached.

ShellMode.Prompt
shell.Prompt = "regex:[$#] $";
Error:
code: shell.SendCommand("su -");
message: Unable do process command

2011-02-28 15:45:31.995 Opening log file.
2011-02-28 15:45:42.542 DEBUG Ssh(1) Info: Received 514 bytes of data.
2011-02-28 15:45:42.542 DEBUG Ssh(1) Info: Sent 5 bytes of data.
2011-02-28 15:45:42.542 DEBUG Ssh(1) Info: Received 7 bytes of data.
2011-02-28 15:46:35.166 Opening log file.
2011-02-28 15:46:35.791 INFO Ssh(1) Info: Connecting to XX.XX.XX.XX:22 using Ssh 1.0.4060.0 (trial version).
2011-02-28 15:46:35.838 DEBUG Ssh(1) SSH: Server is 'SSH-2.0-OpenSSH_5.5'.
2011-02-28 15:46:35.838 DEBUG Ssh(1) SSH: Negotiation started.
2011-02-28 15:46:35.869 DEBUG Ssh(1) SSH: Group exchange.
2011-02-28 15:46:35.869 DEBUG Ssh(1) SSH: Negotiating key.
2011-02-28 15:46:36.026 DEBUG Ssh(1) SSH: Validating signature.
2011-02-28 15:46:36.057 DEBUG Ssh(1) SSH: Negotiation finished.
2011-02-28 15:46:36.057 INFO Ssh(1) Info: Server: SSH-2.0-OpenSSH_5.5
2011-02-28 15:46:36.057 INFO Ssh(1) Info: Fingerprint: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
2011-02-28 15:46:36.057 INFO Ssh(1) Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA1, DSS, aes256-ctr/aes256-ctr, SHA1/SHA1
2011-02-28 15:46:36.916 DEBUG Ssh(1) SSH: Allowed authentication methods: publickey, password, keyboard-interactive.
2011-02-28 15:46:36.916 DEBUG Ssh(1) SSH: Trying password authentication for 'user'.
2011-02-28 15:46:36.948 DEBUG Ssh(1) SSH: Authentication successful.
2011-02-28 15:46:37.573 DEBUG Ssh(1) SSH: Requesting pseudoterminal 'vt100' (80x25).
2011-02-28 15:46:37.573 DEBUG Ssh(1) SSH: Requesting shell.
2011-02-28 15:46:38.588 DEBUG Ssh(1) Info: Received 514 bytes of data.
2011-02-28 15:46:38.588 DEBUG Ssh(1) Info: Sent 5 bytes of data.
2011-02-28 15:46:38.588 DEBUG Ssh(1) Info: Received 7 bytes of data.

ShellMode.WellKnownShell
error:
code: terminalScreen = shell.ReadAll(promptQuestions);
message: Response reading timeout
terminal error message: "tset: standard error: Inappropriate ioctl for device"

2011-02-28 15:53:43.051 Opening log file.
2011-02-28 15:53:43.176 INFO Ssh(1) Info: Connecting to XX.XX.XX.XX:22 using Ssh 1.0.4060.0 (trial version).
2011-02-28 15:53:43.208 DEBUG Ssh(1) SSH: Server is 'SSH-2.0-OpenSSH_5.5'.
2011-02-28 15:53:43.208 DEBUG Ssh(1) SSH: Negotiation started.
2011-02-28 15:53:43.239 DEBUG Ssh(1) SSH: Group exchange.
2011-02-28 15:53:43.239 DEBUG Ssh(1) SSH: Negotiating key.
2011-02-28 15:53:43.395 DEBUG Ssh(1) SSH: Validating signature.
2011-02-28 15:53:43.426 DEBUG Ssh(1) SSH: Negotiation finished.
2011-02-28 15:53:43.426 INFO Ssh(1) Info: Server: SSH-2.0-OpenSSH_5.5
2011-02-28 15:53:43.426 INFO Ssh(1) Info: Fingerprint: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
2011-02-28 15:53:43.426 INFO Ssh(1) Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA1, DSS, aes256-ctr/aes256-ctr, SHA1/SHA1
2011-02-28 15:53:43.614 DEBUG Ssh(1) SSH: Allowed authentication methods: publickey, password, keyboard-interactive.
2011-02-28 15:53:43.614 DEBUG Ssh(1) SSH: Trying password authentication for 'user'.
2011-02-28 15:53:43.645 DEBUG Ssh(1) SSH: Authentication successful.
2011-02-28 15:53:43.645 DEBUG Ssh(1) SSH: Requesting shell.
2011-02-28 15:53:43.661 DEBUG Ssh(1) Info: Sent 21 bytes of data.
2011-02-28 15:53:43.661 DEBUG Ssh(1) Info: Received 16 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 30 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 17 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 31 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 20 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 34 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 15 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 39 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Received 15 bytes of data.
2011-02-28 15:53:43.676 DEBUG Ssh(1) Info: Sent 33 bytes of data.
2011-02-28 15:53:43.692 DEBUG Ssh(1) Info: Received 9 bytes of data.
2011-02-28 15:53:43.786 DEBUG Ssh(1) Info: Sent 13 bytes of data.
2011-02-28 15:53:43.833 DEBUG Ssh(1) Info: Received 54 bytes of data.

I would appreciate some help. Thank you.

1 Answer

0 votes
answered Mar 1, 2011 by Lukas Pokorny (124,570 points)
edited Mar 1, 2011

It looks like ShellMode.Prompt mode isn't quite compatible with *BSD platforms at the moment - we were able to reproduce the same error with FreeBSD as well. I just sent a link to the current build of Rebex SSH Shell to your e-mail. Please give it a try and let us know whether it helps.


ShellMode.WellKnownShell is most likely an entirely different issue. Most Unix platforms only allow the "su" command to be run in a session with a real terminal or pseudo-terminal, which is not the case with WellKnownShell. Are you actually able to run your code in this mode against any of the platforms mentioned?

Attempts to run "su" on non-terminal sessions produce all kinds of errors such as "su: must be run from a terminal", so I guess the one you got is related as well. The "tset" command is used to initialize the terminal (it might be called by "su" itself), which doesn't work if no terminal is available.

...