Paul Thomas | 8 Sep 2007 19:51
Picon

Interacting with a shell how?

So I've been reading through the docs and I've got a working example that can get to the point where it can open up a shell on a pty, but after that suceeds what do I do now?

The guides all say
    /* At this point the shell can be interacted with using
     * libssh2_channel_read()
     * libssh2_channel_read_stderr()
     * libssh2_channel_write()
     * libssh2_channel_write_stderr()

Thats nice, but I expected that after I requested a shell that there would be some data on the socket ready to be read that contained something like:
   paul <at> computerName ~ $

What am I missing here? I've been unable to find much help online in the form of docs talking about ssh with the exception of the RFCs and these talk about the protocol, not what do do when its already connected.

Help? Advice?
Paul

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@...
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Paul Thomas | 10 Sep 2007 18:51
Picon

Re: (no subject)

So I take it no one out there has any idea how to actually get things going with this library? I can create the shell..now what? Why isn't there a bash like prompt being sent back to me over the socket?

On 9/9/07, Paul Thomas <thomaspu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
The problem that I have isn't that I don't know how to read and write stuff to my ssh connection, its that after setting up a shell, I don't get anything over the socket.

        if (libssh2_channel_request_pty(m_channel, "vt100")) {
            log( "Failed requesting pty");
        }

        if (libssh2_channel_shell(m_channel)) {
            log( "Unable to request shell on allocated pty");
        }

        if ( libssh2_poll_channel_read(m_channel, 0) )
            log("hey, theres data");

        libssh2_channel_write(m_channel, "/bin/bash\r\n", strlen("/bin/bash\r\n"));

        if ( libssh2_poll_channel_read(m_channel, 0) )
            log("hey, theres data");

So after getting a shell on a pty, I'd expect that there be some data waiting to be read from the socket.. like the prompt:
   user <at> computername $
But there's nothing. So I tried to startup a terminal and then read from the channel and still no data. How do I tell it to fire up a terminal on the remote end? Or how do I get the default prompt?

Thanks,
Paul


On 9/9/07, Mark Erikson < mark-h27JknMdrUSttCpgsWEBFlaTQe2KTcn/@public.gmane.org> wrote:
> From: "Paul Thomas" <thomaspu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Subject: [libssh2] Interacting with a shell how?
>
> So I've been reading through the docs and I've got a working example that
> can get to the point where it can open up a shell on a pty, but after that
> suceeds what do I do now?
>
> The guides all say
>     /* At this point the shell can be interacted with using
>      * libssh2_channel_read()
>      * libssh2_channel_read_stderr()
>      * libssh2_channel_write()
>      * libssh2_channel_write_stderr()
>
> Thats nice, but I expected that after I requested a shell that there would
> be some data on the socket ready to be read that contained something like:
>    paul <at> computerName ~ $
>
> What am I missing here? I've been unable to find much help online in the
> form of docs talking about ssh with the exception of the RFCs and these talk
> about the protocol, not what do do when its already connected.
>
> Help? Advice?
> Paul

I've also been working on a project which uses libssh2 to create a
shell.  I don't have a good, simple example to give you, since it's a
GUI program that contains code adapted from several different sources,
and things are ugly right now.  But, let me see if I can give an
overview of how I've got things working.

I have an SSHConnection class that encapsulates the socket IO.  Whenever
the socket reports that there's input available, I call
SSHConnection->Read(void * buffer, uint nbytes).  Read() does some
calculations to figure out exactly how much to read from the channel,
does a libssh2_poll() to confirm that it's ready to read, then creates a
new char[] buffer and calls libssh2_channel_read(channel, buffer,
actualNBytes).  From there, you should be able to do whatever you want
with the data.

Writing's pretty simple.  Whenever the user types, I call
SSHConnection->Write(char* data, int len), which passes it on to
libssh2_channel_write(channel, data, len).

My project is still pretty much a throwaway test with a lot of glitches,
so I don't claim to have this perfected.  Still, hopefully that will
give you a bit of an idea where to head.

Mark Erikson
http://www.isquaredsoftware.com

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/libssh2-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@...
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Daniel Stenberg | 10 Sep 2007 22:14
Picon
Favicon
Gravatar

Re: (no subject)

On Mon, 10 Sep 2007, Paul Thomas wrote:

> So I take it no one out there has any idea how to actually get things going 
> with this library? I can create the shell..now what? Why isn't there a bash 
> like prompt being sent back to me over the socket?

Given the silence, I would say that we either don't know or don't have the 
time to respond/investigate.

Feel free to check out the source and compare with the protocol definitions to 
see if you can figure it out.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Dan Fandrich | 10 Sep 2007 23:09
Favicon

Re: (no subject)

On Mon, Sep 10, 2007 at 12:51:37PM -0400, Paul Thomas wrote:
> So I take it no one out there has any idea how to actually get things going
> with this library? I can create the shell..now what? Why isn't there a bash
> like prompt being sent back to me over the socket?

It is--but it's begin sent encrypted so you need to use libssh2 to read it.

>         > can get to the point where it can open up a shell on a pty, but after
>         that
>         > suceeds what do I do now?
>         >
>         > The guides all say
>         >     /* At this point the shell can be interacted with using
>         >      * libssh2_channel_read()
>         >      * libssh2_channel_read_stderr()
>         >      * libssh2_channel_write()
>         >      * libssh2_channel_write_stderr()
>         >
>         > Thats nice, but I expected that after I requested a shell that there
>         would
>         > be some data on the socket ready to be read that contained something
>         like:
>         >    paul <at> computerName ~ $

The documentation for those function describes how to use them.  The following
brute-force hack to the ssh2 example program will display the first bit
of data sent by the remote server after a shell connect just to prove that
it's possible:

--- libssh2/example/simple/ssh2.c   Wed Aug  8 18:10:11 2007
+++ ./ssh2.c    Mon Sep 10 13:56:56 2007
 <at>  <at>  -217,6 +217,15  <at>  <at> 
      * A channel can be closed with: libssh2_channel_close()
      * A channel can be freed with: libssh2_channel_free()
      */
+    {
+       int len = 0;
+       while (len == 0) {
+           char buf[1024];
+           len = libssh2_channel_read(channel, buf, sizeof(buf));
+           printf("%*s", len, buf);
+       }
+    }
+

   skip_shell:
     if (channel) {

A real implementation would be built on libssh2_poll instead of this
dumb busy loop.

It would probably be a good idea to update the ssh2 example program to
actually behave more like OpenSSH's ssh and allow an actual interactive
login session.

>>> Dan
--

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Dan Fandrich | 10 Sep 2007 23:22
Favicon

Re: (no subject)

On Mon, Sep 10, 2007 at 12:51:37PM -0400, Paul Thomas wrote:
> On 9/9/07, Paul Thomas <thomaspu@...> wrote:
> 
>     The problem that I have isn't that I don't know how to read and write stuff
>     to my ssh connection, its that after setting up a shell, I don't get
>     anything over the socket.
> 
>             if (libssh2_channel_request_pty(m_channel, "vt100")) {
>                 log( "Failed requesting pty");
>             }
> 
>             if (libssh2_channel_shell(m_channel)) {
>                 log( "Unable to request shell on allocated pty");
>             }
> 
>             if ( libssh2_poll_channel_read(m_channel, 0) )
>                 log("hey, theres data");
> 
>             libssh2_channel_write(m_channel, "/bin/bash\r\n", strlen("/bin/bash
>     \r\n"));
> 
>             if ( libssh2_poll_channel_read(m_channel, 0) )
>                 log("hey, theres data");

Sorry, I deleted your code before even looking at it!  I suspect what's
happening is that you're not giving the server time to respond. 
libssh2_poll_channel_read() returns a value based on what data has already
been received--it doesn't block and wait for it.  The polling loop around
the libssh2_channel_read() in my last message gets around that, as would
a call to libssh_poll().

>>> Dan
--

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
SourceForge.net | 13 Sep 2007 09:16
Picon
Favicon

[ libssh2-Bugs-1772505 ] Visual Studio project files are corrupt

Bugs item #1772505, was opened at 2007-08-11 20:48
Message generated for change (Comment added) made by nobody
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1772505&group_id=125852

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: misc
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: Visual Studio project files are corrupt

Initial Comment:
I downloaded the tar.gz files for both versions 0.16 and 0.17 and the Visual Studio project files under the
win32 directory are all corrupt. Attempting to open up the Visual Studio 6 workspace or project file(s)
from Visual Studio 2005 or 2008 gives this error:

"Cannot load the project due to a corrupt project file"

I'm able to open up the project files from the 0.15 tar.gz file just fine. I did a diff on the 0.15 and the 0.17
versions of one of the project files and didn't find anything different. However, I found that if I opened
up the project file with something like wordpad, saved it and re-opened it that I was able to then open that
project file. Looks like the line endings were probably not saved in a windows-friendly fashion.

Paul

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2007-09-13 00:16

Message:
Logged In: NO 

Pull it from CVS. That's okay.

Karsten

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1772505&group_id=125852

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
roberto pulvirenti | 13 Sep 2007 10:13
Picon
Favicon

looking for memory leak

Hello guys,

Have you ever used valgrind or any other similar tool for detecting memory leak on the last release of libssh2?
I have used libssh2 under HP-UX (aCC as compiler) and I'm not finding a good tool (my free licence of Purify has expired) for HP.

Your experience, if positive (even if on other operating system/compiler), could give me enough confidence that libssh2 is a good choice.

Thanks in advance.

Roberto

L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@...
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Daniel Stenberg | 13 Sep 2007 10:16
Picon
Favicon
Gravatar

Re: looking for memory leak

On Thu, 13 Sep 2007, roberto pulvirenti wrote:

> Have you ever used valgrind or any other similar tool for detecting memory 
> leak on the last release of libssh2?

Yes. I've used valgrind on it on occasion.

> Your experience, if positive (even if on other operating system/compiler), 
> could give me enough confidence that libssh2 is a good choice.

libssh2 is still not very widely used and lots of changes have been done in it 
during the last year so there's of course a risk that there are remaining 
problems and leaks in there. The library has a rather extensive API so various 
applications are likely to use it in new and different ways that might provoke 
different problems.

But as this is open source, everyone is free and invited to dive in and fix 
and improve.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Guenter Knauf | 14 Sep 2007 05:48
Picon

Re: [ libssh2-Bugs-1772505 ] Visual Studio project files arecorrupt

Hi Daniel,
> Bugs item #1772505, was opened at 2007-08-11 20:48
> Summary: Visual Studio project files are corrupt

> Initial Comment:
> I downloaded the tar.gz files for both versions 0.16 and 0.17 and the
> Visual Studio project files under the win32 directory are all corrupt.

I guess I broke these at some time when I updated the *.ds? files;
I've just checked with both commandline CVS and TortoiseCVS, and I get always proper files back;
however when I check out on Linux I see that the files come out in Unix format; so seems to me that they are
stored as lf in CVS, and the Win32 tools do the conversion to crlf...
how can we properly overcome this issue? How do you do it with libcurl? did you check them into CVS as crlf, and
then a 'cvs admin -kb' ??
I can see with libcurl that the curllib.dsw is in crlf format when I open it on Linux...

greets, Guen.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Daniel Stenberg | 14 Sep 2007 09:06
Picon
Favicon
Gravatar

Re: [ libssh2-Bugs-1772505 ] Visual Studio project files arecorrupt

On Fri, 14 Sep 2007, Guenter Knauf wrote:

> I guess I broke these at some time when I updated the *.ds? files; I've just 
> checked with both commandline CVS and TortoiseCVS, and I get always proper 
> files back; however when I check out on Linux I see that the files come out 
> in Unix format; so seems to me that they are stored as lf in CVS, and the 
> Win32 tools do the conversion to crlf... how can we properly overcome this 
> issue? How do you do it with libcurl? did you check them into CVS as crlf, 
> and then a 'cvs admin -kb' ?? I can see with libcurl that the curllib.dsw is 
> in crlf format when I open it on Linux...

Yes, I believe they have to be set as binary (-kb) for CVS as otherwise it'll 
play fun tricks on the newlines...

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

Gmane