$ gcc -o agent_auth -Wall -I/usr/include -I. -lssh2 ssh2_agent.c ssh2_agent.c: In function 'main': ssh2_agent.c:99: warning: implicit declaration of function 'libssh2_session_handshake' /home/andrey/tmp/ccmczn2V.o: In function `main': ssh2_agent.c:(.text+0x1a8): undefined reference to `libssh2_session_handshake' collect2: ld returned 1 exit status
$ gcc -o agent_auth -Wall -I$PWD/libssh2/include -I. -L$PWD/libssh2/lib -lssh2 ssh2_agent.c
$ LD_LIBRARY_PATH=$PWD/libssh2/lib ./agent-auth localhost andrey failed to connect! zsh: segmentation fault ./agent_auth localhost andrey
munmap(0xb7813000, 4096) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3 connect(3, {sa_family=AF_INET, sin_port=htons(22), sin_addr=inet_addr("255.255.255.255")}, 16) = -1 ENETUNREACH (Network is unreachable) write(2, "failed to connect!\n", 19failed to connect! ) = 19 --- SIGSEGV (Segmentation fault) @ 0 (0) --- +++ killed by SIGSEGV +++ zsh: segmentation fault strace -f ./agent_auth localhost username
--- ssh2_agent.c.orig 2011-12-08 23:53:41.000000000 +0300 +++ ssh2_agent.c 2011-12-09 00:02:10.000000000 +0300 @@ -231,10 +231,12 @@ int main(int argc, char *argv[]) */ shutdown: - - libssh2_agent_disconnect(agent); - libssh2_agent_free(agent); + if (agent) { + libssh2_agent_disconnect(agent); + + libssh2_agent_free(agent); + } if(session) {
$ gcc -o agent_auth -Wall -I$PWD/libssh2/include -I. -L$PWD/libssh2/lib -lssh2 ssh2_agent.c $ LD_LIBRARY_PATH=$PWD/libssh2/lib ./agent_auth localhost andrey failed to connect!
if (argc > 1) { hostaddr = inet_addr(argv[1]); } else { hostaddr = htonl(0x7F000001); }
$ LD_LIBRARY_PATH=$PWD/libssh2/lib ./agent_auth 127.0.0.1 andrey Fingerprint: FA F3 92 9E C4 AE 14 B4 FC BE ED 2A E8 33 0C 1E 34 09 9F B3 Authentication methods: publickey,password Authentication with username andrey and public key /home/andrey/.ssh/id_rsa failed! Authentication with username andrey and public key /home/andrey/.ssh/id_dsa succeeded! all done!
Source: https://habr.com/ru/post/134307/
All Articles