Subject: Fail to login with libshh2

Fail to login with libshh2

From: SIFE Abdelrazak <sife_php_at_yahoo.com>
Date: Wed, 27 Oct 2010 03:29:29 -0700 (PDT)

I write this piece of code but when I try to connect to server I get "Invalid password":
#include<stdio.h> #include<stdlib.h> #include<libssh2.h> #include<sys/socket.h> #include<netinet/in.h> #include<sys/types.h> #define PORT 22 main() { int ss, sshsock, lstat; char *ulogin = "tst"; char *password = "pass"; char *ADDR = "127.0.0.1"; struct sockaddr_in sin; LIBSSH2_SESSION *session; sshsock = socket(AF_INET, SOCK_STREAM, 0); sin.sin_family = AF_INET; sin.sin_port = htons(PORT); sin.sin_addr.s_addr = inet_addr(ADDR); connect(sshsock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)); session = libssh2_session_init(); if(session == NULL) { printf("Fail to initial SSH session\n"); exit(0); } ss = libssh2_session_startup(session, sshsock); if(ss < 0) { printf("Fail to startup SSH session\n"); exit(0); } lstat = libssh2_userauth_password_ex(session, ulogin, strlen(ulogin), password, strlen(password), NULL); if(lstat == 0) printf("Login successed\n"); else printf("Invalid password\n"); /* disconnect from ssh server */ libssh2_session_disconnect(session, 0); /* free ssh session */ libssh2_session_free(session); /* exit from libssh2 */ libssh2_exit(); /* close descriptor of socket */ close(sshsock); return 0; }
gcc -o sshc sshc.c -I/usr/local/include -L/usr/local/lib -lssh2

                                  

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-10-27