geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.4 KiB

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