Files
libssh/tests/ssh_ping.c
Gauravsingh Sisodia c1aab9903f feat: add null hostkey for server
fix: skip gssapi tests in fips mode

fix: skip gssapi_key_exchange_null test on ubuntu and tumbleweed

fix: return early when rc != 0 to show error

tests: replace int asserts by ssh return code asserts

fix: add fatal error when hostkeys are not found and gssapi kex is not enabled

ci: add comment linking gssapi null kex bug in ubuntu and tumbleweed

fix: don't specify hostkeys in config instead of deleting files

tests: assert kex method was null

refactor: remove redundant include

refactor: better error message

fix: check null before accessing in gssapi.c

fix: allow setting no hostkeys
Signed-off-by: Gauravsingh Sisodia <xaerru@gmail.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2026-01-05 12:24:13 +01:00

109 lines
2.5 KiB
C

/* ssh_ping.c */
/*
Copyright 2018 Red Hat, Inc
Author: Jakub Jelen <jjelen@redhat.com>
This file is part of the SSH Library
You are free to copy this file, modify it in any way, consider it being public
domain. This does not apply to the rest of the library though, but it is
allowed to cut-and-paste working code from this file to any license of
program.
The goal is to show the API in action. It's not a reference on how terminal
clients must be made or how a client should react.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <libssh/libssh.h>
#include <libssh/kex.h>
int main(int argc, char **argv)
{
const char *banner = NULL;
ssh_session session = NULL;
const char *hostkeys = NULL;
const char *kex = NULL;
int rc = 1;
#ifdef WITH_GSSAPI
bool t = true;
#endif /* WITH_GSSAPI */
bool process_config = false;
if (argc < 1 || argv[1] == NULL) {
fprintf(stderr, "Error: Need an argument (hostname)\n");
goto out;
}
ssh_init();
session = ssh_new();
if (session == NULL) {
goto out;
}
rc = ssh_options_set(session, SSH_OPTIONS_HOST, argv[1]);
if (rc < 0) {
goto out;
}
/* The automatic username is not available under uid wrapper */
rc = ssh_options_set(session, SSH_OPTIONS_USER, "ping");
if (rc < 0) {
goto out;
}
/* Ignore system-wide configurations when simply trying to reach host */
rc = ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &process_config);
if (rc < 0) {
goto out;
}
/* Enable all supported algorithms */
hostkeys = ssh_get_supported_methods(SSH_HOSTKEYS);
rc = ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, hostkeys);
if (rc < 0) {
goto out;
}
/* Enable all supported kex algorithms */
kex = ssh_get_supported_methods(SSH_KEX);
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, kex);
if (rc < 0) {
goto out;
}
#ifdef WITH_GSSAPI
rc = ssh_options_set(session, SSH_OPTIONS_GSSAPI_KEY_EXCHANGE, &t);
if (rc < 0) {
goto out;
}
#endif /* WITH_GSSAPI */
rc = ssh_connect(session);
if (rc != SSH_OK) {
fprintf(stderr, "Connection failed : %s\n", ssh_get_error(session));
goto out;
}
banner = ssh_get_serverbanner(session);
if (banner == NULL) {
fprintf(stderr, "Did not receive SSH banner\n");
goto out;
}
printf("OK: %s\n", banner);
rc = 0;
out:
ssh_free(session);
ssh_finalize();
return rc;
}