Bonsoir,
J'essaie d'ourir une session ssh au travers d'un programme en C. Effet j'arrive à établir la connexion, mais le problème est que je n'arrive pas à exécuter une commande. Je me demande même si la création du cannal s'est bien faite.
j'ai le message suisvant quand je l'exécute:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 int main(){ ssh_session session; int verbosity = SSH_LOG_PROTOCOL; int port = 22; char* password = "root"; int rc; session = ssh_new(); if (session == NULL) return(-1); //Set options for SSH connection ssh_options_set(session,SSH_OPTIONS_HOST,"90.12.34.44"); ssh_options_set(session,SSH_OPTIONS_LOG_VERBOSITY,&verbosity); ssh_options_set(session,SSH_OPTIONS_PORT,&port); ssh_options_set(session,SSH_OPTIONS_USER,"root"); //Connect to server rc = ssh_connect(session); if (rc != SSH_OK){ fprintf(stderr,"Error connecting to host %s\n",ssh_get_error(session)); ssh_free(session); return(-1); } rc = ssh_userauth_password(session,NULL,password); if ( rc == SSH_AUTH_SUCCESS){ printf("Authenticated correctly"); } ssh_channel channel; channel = ssh_channel_new(session); if(channel == NULL) return SSH_ERROR; rc = ssh_channel_open_session(channel); if (rc != SSH_OK){ ssh_channel_free(channel); return rc; } rc = ssh_channel_request_exec(channel,"date"); if (rc != SSH_OK){ ssh_channel_close(channel); ssh_channel_free(channel); return rc; } char buffer[256]; unsigned int nbytes; nbytes = ssh_channel_read(channel,buffer,sizeof(buffer),0); while(nbytes > 0){ if(fwrite(buffer,1,nbytes,stdout)){ ssh_channel_close(channel); ssh_channel_free(channel); return SSH_ERROR; } nbytes = ssh_channel_read(channel,buffer,sizeof(buffer),0); if (nbytes < 0){ ssh_channel_close(channel); ssh_channel_free(channel); return SSH_ERROR; } return 0; } }
Le programme ne rend pas la main par la suite.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 [2016/01/10 18:37:36.208930, 2] ssh_socket_connect: Nonblocking connection socket: 3 [2016/01/10 18:37:36.208953, 2] ssh_connect: Socket connecting, now waiting for the callbacks to work [2016/01/10 18:37:36.209172, 1] socket_callback_connected: Socket connection callback: 1 (0) [2016/01/10 18:37:36.214088, 1] ssh_client_connection_callback: SSH server banner: SSH-2.0-OpenSSH_6.9p1 Debian-2+b1 [2016/01/10 18:37:36.214130, 1] ssh_analyze_banner: Analyzing banner: SSH-2.0-OpenSSH_6.9p1 Debian-2+b1 [2016/01/10 18:37:36.214155, 1] ssh_analyze_banner: We are talking to an OpenSSH client version: 6.9 (60900) [2016/01/10 18:37:36.263338, 2] ssh_packet_dh_reply: Received SSH_KEXDH_REPLY [2016/01/10 18:37:36.266653, 2] ssh_client_curve25519_reply: SSH_MSG_NEWKEYS sent [2016/01/10 18:37:36.266671, 2] ssh_packet_newkeys: Received SSH_MSG_NEWKEYS [2016/01/10 18:37:36.266999, 2] ssh_packet_newkeys: Signature verified and valid [2016/01/10 18:37:36.267033, 2] channel_open: Creating a channel 43 with 64000 window and 32768 max packet [2016/01/10 18:37:36.304042, 1] ssh_packet_unimplemented: Received SSH_MSG_UNIMPLEMENTED (sequence number 3)
Avec quelques printf j'ai vu que ça bloquait au niveau de la création du cannal.
En vous remerciant d'avance pour vos réponses
Partager