1 #include "session_fixture.h"
2
3 #include <libssh2.h>
4
5 #include <stdio.h>
6
7 const char *USERNAME = "libssh2"; /* set in Dockerfile */
8 const char *KEY_FILE_PRIVATE = "key_rsa";
9 const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */
10
test(LIBSSH2_SESSION * session)11 int test(LIBSSH2_SESSION *session)
12 {
13 int rc;
14 LIBSSH2_CHANNEL *channel;
15
16 const char *userauth_list =
17 libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
18 if(userauth_list == NULL) {
19 print_last_session_error("libssh2_userauth_list");
20 return 1;
21 }
22
23 if(strstr(userauth_list, "publickey") == NULL) {
24 fprintf(stderr, "'publickey' was expected in userauth list: %s\n",
25 userauth_list);
26 return 1;
27 }
28
29 rc = libssh2_userauth_publickey_fromfile_ex(
30 session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE,
31 NULL);
32 if(rc != 0) {
33 print_last_session_error("libssh2_userauth_publickey_fromfile_ex");
34 return 1;
35 }
36
37 channel = libssh2_channel_open_session(session);
38 /* if(channel == NULL) { */
39 /* printf("Error opening channel\n"); */
40 /* return 1; */
41 /* } */
42
43 rc = libssh2_channel_request_auth_agent(channel);
44 if(rc != 0) {
45 fprintf(stderr, "Auth agent request for agent forwarding failed, "
46 "error code %d\n", rc);
47 return 1;
48 }
49
50 return 0;
51 }
52