forked from ParallelSSH/ssh2-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_agent_forward_succeeds.c
More file actions
51 lines (41 loc) · 1.35 KB
/
test_agent_forward_succeeds.c
File metadata and controls
51 lines (41 loc) · 1.35 KB
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
#include "session_fixture.h"
#include <libssh2.h>
#include <stdio.h>
const char *USERNAME = "libssh2"; /* set in Dockerfile */
const char *KEY_FILE_PRIVATE = "key_rsa";
const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */
int test(LIBSSH2_SESSION *session)
{
int rc;
LIBSSH2_CHANNEL *channel;
const char *userauth_list =
libssh2_userauth_list(session, USERNAME, strlen(USERNAME));
if(userauth_list == NULL) {
print_last_session_error("libssh2_userauth_list");
return 1;
}
if(strstr(userauth_list, "publickey") == NULL) {
fprintf(stderr, "'publickey' was expected in userauth list: %s\n",
userauth_list);
return 1;
}
rc = libssh2_userauth_publickey_fromfile_ex(
session, USERNAME, strlen(USERNAME), KEY_FILE_PUBLIC, KEY_FILE_PRIVATE,
NULL);
if(rc != 0) {
print_last_session_error("libssh2_userauth_publickey_fromfile_ex");
return 1;
}
channel = libssh2_channel_open_session(session);
/* if(channel == NULL) { */
/* printf("Error opening channel\n"); */
/* return 1; */
/* } */
rc = libssh2_channel_request_auth_agent(channel);
if(rc != 0) {
fprintf(stderr, "Auth agent request for agent forwarding failed, "
"error code %d\n", rc);
return 1;
}
return 0;
}