[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Create SSH server in Windows with libssh


Hi,

I need to use libssh to create an SSH server that allows me to connect to
it and have a normal SSH session (executing commands in the SSH server,
autocomplete...).

I've seen code in the examples folder to do that in Linux but nothing to do
so in windows. I've written some code that works fine creating a SSH sever
listening in a port, I create a new thread to handle every incoming
connection but I don't know how to follow to create a fully interactive
connection.

The creation of the SSH server works fine but I don't know how to handle
the incoming connections to get a shell when logged in.

Here is some code I've used:

[...]
ssh_init();
ssh_event event;/* Create and configure the ssh session. */auto
sshbind = ssh_bind_new();
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, ip);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
"C:\\Users\\user\\Desktop\\priv_key.txt");

/* Listen on `port' for connections. */if (ssh_bind_listen(sshbind) < 0) {
    printf("Error listening to socket: %s\n", ssh_get_error(sshbind));
    return -1;}if (true) { printf("Listening on port %d.\n", port); }
/* Loop forever, waiting for and handling connection attempts. */while (1) {

    ssh_session session = ssh_new();
    if (ssh_bind_accept(sshbind, session) == SSH_ERROR) {
        fprintf(stderr, "Error accepting a connection: %s'.\n",
ssh_get_error(sshbind));
        return -1;
    }
    if (true) { printf("Accepted a connection.\n"); }
    event = ssh_event_new();
    std::thread(sessionHandler, event, session).detach();


But I need to properly implement the sessionHandler function

Any help?

Thanks

-- 
Alberto García Illera

GPG Public Key <https://goo.gl/yshdwh>

Follow-Ups:
Re: Create SSH server in Windows with libsshAlberto Garcia <agarciaillera@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org