[Libssh] Implementing a SSH server
Jan Willamowius
jan at willamowius.de
Tue Dec 30 15:34:33 CET 2008
Hi Aris,
using ssh_bind_accept with a file descriptor in to-be-accepted state
work better indeed.
I didn't think of this, because ssh_bind_set_fd() is missing, but I
wrote my fd directly into ssh_bind->bindfd and that works fine.
Thanks for your help,
Jan
PS: To implement a server, one still needs to include priv.h and it
would be great if you would accept the patch I submitted to add "extern
C" declarations.
Aris Adamantiadis wrote:
> Hello,
>
> after reading server.c source, it seems that what you want to do is not
> possible using only the external API. So I understand why you got out
> some code from ssh_bind_accept() into your own code.
> Your code has the two lines:
> session->dsa_key = dsa;
> session->rsa_key = rsa;
> How did you define the variables dsa and rsa ? You will have to set them
> as explained in ssh_bind_accept().
>
> It's really ugly but it might work as expected.
> Something possible would be changing your app a little to use
> ssh_bind_accept by giving it a file descriptor in the to-be-accepted state.
>
> I agree it lacks a function like
> ssh_accept_fd(SSH_OPTIONS options, int fd);
>
> Maybe in 0.3
>
> Regards,
>
> Aris
>
> Jan Willamowius a écrit :
> > Hi,
> >
> > I'm trying to use libssh to replace a telent server in a C++ application
> > with a ssh server. I'm sticking as close to the samplesshd as I can,
> > but I have to pass in the file descriptor for the socket.
> >
> > When running under valgrind, I can see that my code throws a lot of
> > errors in ssh_accept() about crypto variables not being initialized,
> > while samplesshd doesn't.
> >
> > My code looks like this:
> >
> > session = ssh_new();
> > session->server = 1;
> > session->version = 2;
> > SSH_OPTIONS *options = ssh_options_new();
> > ssh_options_set_dsa_server_key(options, "ssh_host_dsa_key");
> > ssh_options_set_rsa_server_key(options, "ssh_host_rsa_key");
> > // ... read keys ...
> > ssh_socket_free(session->socket);
> > session->socket = ssh_socket_new(session);
> > ssh_socket_set_fd(session->socket, NEW_HANDLE);
> > ssh_options_set_fd(options, NEW_HANDLE);
> > ssh_set_options(session, options);
> > session->dsa_key = dsa;
> > session->rsa_key = rsa;
> >
> > if(ssh_accept(session)) {
> > return false;
> > }
> >
> > What else do i need to initialize before calling ssh_accept() ?
> >
> > Thanks,
> > Jan
--
Jan Willamowius, jan at willamowius.de, http://www.willamowius.de/
More information about the Libssh
mailing list