Replies: 2 comments
-
I tried to reproduce the problem, but failed. ssh2.c
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi,
My application was (*) multi threading, C++, running on a non stop (depending on a bool variable) loop.
Perhaps the issue is related to multi threading. At the time I did not address any issue on my multi threading implementation.
(*) because I no longer work on this code but I still have it.
Simon
Il mercoledì 2 agosto 2023 alle ore 05:03:31 CEST, ren mingshuai ***@***.***> ha scritto:
I tried to reproduce the problem, but failed.
My reproduction is as follows:
The Client: ssh2.c (The source code is below)
The Server: sshd from openSSH
gdb sshd and make it stop when it recives SSH_MSG_KEXINIT message which is send by ssh2.
ssh2 is executing libssh2_session_handshake and waiting for the response from sshd now.
I pressed Ctrl-C and the programe stoped as expected.
Maybe I misunderstood the bug you described.
Please provide detailed reproduction steps to help us quickly solve the problem.
ssh2.c
#include <libssh2.h>
#include <sys/socket.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
static const char *pubkey = ".ssh/id_rsa.pub";
static const char *privkey = ".ssh/id_rsa";
static const char *username = "username";
static const char *password = "password";
int main(int argc, char *argv[])
{
uint32_t hostaddr;
libssh2_socket_t sock;
int i, auth_pw = 0;
struct sockaddr_in sin;
const char *fingerprint;
char *userauthlist;
int rc;
LIBSSH2_SESSION *session = NULL;
LIBSSH2_CHANNEL *channel;
#ifdef WIN32
WSADATA wsadata;
rc = WSAStartup(MAKEWORD(2, 0), &wsadata);
if(rc) {
fprintf(stderr, "WSAStartup failed with error: %d\n", rc);
return 1;
}
#endif
if(argc > 1) {
hostaddr = inet_addr(argv[1]);
}
else {
hostaddr = htonl(0x7F000001);
}
if(argc > 2) {
username = argv[2];
}
if(argc > 3) {
password = argv[3];
}
rc = libssh2_init(0);
if(rc) {
fprintf(stderr, "libssh2 initialization failed (%d)\n", rc);
return 1;
}
/* Ultra basic "connect to port 22 on localhost". Your code is
* responsible for creating the socket establishing the connection
*/
sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock == LIBSSH2_INVALID_SOCKET) {
fprintf(stderr, "failed to create socket.\n");
rc = 1;
goto shutdown;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(22);
sin.sin_addr.s_addr = hostaddr;
fprintf(stderr, "Connecting to %s:%d as user %s\n",
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), username);
if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) {
fprintf(stderr, "failed to connect.\n");
goto shutdown;
}
/* Create a session instance and start it up. This will trade welcome
* banners, exchange keys, and setup crypto, compression, and MAC layers
*/
session = libssh2_session_init();
if(!session) {
fprintf(stderr, "Could not initialize SSH session.\n");
goto shutdown;
}
/* Enable all debugging when libssh2 was built with debugging enabled */
libssh2_trace(session, ~0);
signal(SIGINT, SIG_DFL);
rc = libssh2_session_handshake(session, sock);
if(rc) {
fprintf(stderr, "Failure establishing SSH session: %d\n", rc);
goto shutdown;
}
shutdown:
if(session) {
libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session);
}
if(sock != LIBSSH2_INVALID_SOCKET) {
shutdown(sock, 2);
#ifdef WIN32
closesocket(sock);
#else
close(sock);
#endif
}
fprintf(stderr, "all done\n");
libssh2_exit();
return rc;
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
On Linux, catching
SIGINT
signal whilelibssh2_session_handshake
is in execution causes the software to remain stuck.To Reproduce
Implement a small code that uses
signal
function to catchSIGINT
and pressCtrl-C
whilelibssh2_session_handshake
is in execution.Expected behavior
The the execution of
libssh2_session_handshake
, and than the program itself should stop as well.Version (please complete the following information):
Beta Was this translation helpful? Give feedback.
All reactions