1
1
libssh/tests/ssh_ping.c
Anderson Toshiyuki Sasaki 3aea2ad53f ssh_ping: Ignore system-wide configuration
Ignore the system-wide configuration when simply trying to reach the
host.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2020-03-29 10:00:57 +02:00

77 строки
1.8 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 <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <libssh/libssh.h>
int main(int argc, char **argv)
{
const char *banner = NULL;
ssh_session session = NULL;
int rc = 1;
bool process_config = false;
if (argc < 1 || argv[1] == NULL) {
fprintf(stderr, "Error: Need an argument (hostname)\n");
goto out;
}
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;
}
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);
return rc;
}