1
1

Removed old, 10 years unused test files

They do not build anymore and I believe most of their functionality is already
covered by new testst.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Jakub Jelen 2020-05-21 13:11:23 +02:00
родитель 39bb93a53b
Коммит 866e4442b5
8 изменённых файлов: 0 добавлений и 622 удалений

Просмотреть файл

@ -1,74 +0,0 @@
/*
This file is distributed in public domain. You can do whatever you want
with its content.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <libssh/libssh.h>
#include "tests.h"
static int auth_kbdint(SSH_SESSION *session){
int err=ssh_userauth_kbdint(session,NULL,NULL);
char *name,*instruction,*prompt,*ptr;
char buffer[128];
int i,n;
char echo;
while (err==SSH_AUTH_INFO){
name=ssh_userauth_kbdint_getname(session);
instruction=ssh_userauth_kbdint_getinstruction(session);
n=ssh_userauth_kbdint_getnprompts(session);
if(strlen(name)>0)
printf("%s\n",name);
if(strlen(instruction)>0)
printf("%s\n",instruction);
for(i=0;i<n;++i){
prompt=ssh_userauth_kbdint_getprompt(session,i,&echo);
if(echo){
printf("%s",prompt);
fgets(buffer,sizeof(buffer),stdin);
buffer[sizeof(buffer)-1]=0;
if((ptr=strchr(buffer,'\n')))
*ptr=0;
ssh_userauth_kbdint_setanswer(session,i,buffer);
memset(buffer,0,strlen(buffer));
} else {
ptr=getpass(prompt);
ssh_userauth_kbdint_setanswer(session,i,ptr);
}
}
err=ssh_userauth_kbdint(session,NULL,NULL);
}
return err;
}
int authenticate (SSH_SESSION *session){
int auth=ssh_userauth_autopubkey(session, NULL);
char *password;
if(auth==SSH_AUTH_ERROR){
fprintf(stderr,"Authenticating with pubkey: %s\n",ssh_get_error(session));
return auth;
}
if(auth!=SSH_AUTH_SUCCESS){
auth=auth_kbdint(session);
if(auth==SSH_AUTH_ERROR){
fprintf(stderr,"authenticating with keyb-interactive: %s\n",
ssh_get_error(session));
return auth;
}
}
if(auth!=SSH_AUTH_SUCCESS){
password=getpass("Password : ");
auth = ssh_userauth_password(session,NULL,password);
memset(password,0,strlen(password));
if (auth==SSH_AUTH_ERROR){
fprintf(stderr,"Authentication with password failed: %s\n",ssh_get_error(session));
return auth;
}
}
return auth;
}

Просмотреть файл

@ -1,31 +0,0 @@
/*
This file is distributed in public domain. You can do whatever you want
with its content.
*/
#include <libssh/libssh.h>
#include <stdio.h>
#include "tests.h"
SSH_OPTIONS *set_opts(int argc, char **argv){
SSH_OPTIONS *options=ssh_options_new();
char *host=NULL;
if(ssh_options_getopt(options,&argc, argv)){
fprintf(stderr,"error parsing command line :%s\n",ssh_get_error(options));
return NULL;
}
int i;
while((i=getopt(argc,argv,""))!=-1){
switch(i){
default:
fprintf(stderr,"unknown option %c\n",optopt);
}
}
if(optind < argc)
host=argv[optind++];
if(host==NULL){
fprintf(stderr,"must provide an host name\n");
return NULL;
}
ssh_options_set_host(options,host);
return options;
}

Просмотреть файл

@ -1,174 +0,0 @@
/*
* main.c
*
* Created on: 22 juin 2009
* Author: aris
*/
#include <stdio.h>
#include <libssh/libssh.h>
#include <libssh/sftp.h>
#include <time.h>
#include <stdlib.h>
#include <fcntl.h>
#include <signal.h>
#include <pthread.h>
#define TEST_READ 1
#define TEST_WRITE 2
#define NTHREADS 3
#define FILESIZE 100000
unsigned char samplefile[FILESIZE];
volatile int stop=0;
const char* hosts[]={"localhost","barebone"};
void signal_stop(){
stop=1;
printf("Stopping...\n");
}
SSH_SESSION *connect_host(const char *hostname);
int sftp_test(SSH_SESSION *session, int test);
int docycle(const char *host, int test){
SSH_SESSION *session=connect_host(host);
int ret=SSH_ERROR;
if(!session){
printf("connect failed\n");
} else {
printf("Connected\n");
ret=sftp_test(session,test);
if(ret != SSH_OK){
printf("Error in sftp\n");
}
ssh_disconnect(session);
}
return ret;
}
int thread(){
while(docycle(hosts[rand()%2],TEST_WRITE) == SSH_OK)
if(stop)
break;
return 0;
}
int main(int argc, char **argv){
int i;
pthread_t threads[NTHREADS];
ssh_init();
srand(time(NULL));
for(i=0;i<FILESIZE;++i)
samplefile[i]=rand() & 0xff;
signal(SIGTERM,signal_stop);
signal(SIGINT,signal_stop);
for(i=0;i<NTHREADS;++i){
srand(i);
pthread_create(&threads[i],NULL,(void *) thread, NULL);
}
for(i=0;i<NTHREADS;++i){
pthread_join(threads[i],NULL);
}
ssh_finalize();
printf("Ended\n");
return 0;
}
SSH_SESSION *connect_host(const char *hostname){
SSH_SESSION *session;
SSH_OPTIONS *options;
int auth=0;
int state;
options=ssh_options_new();
ssh_options_set_host(options,hostname);
session=ssh_new();
ssh_set_options(session,options);
if(ssh_connect(session)){
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
ssh_disconnect(session);
return NULL;
}
state = ssh_session_is_known_server(session);
switch(state){
case SSH_SERVER_KNOWN_OK:
break; /* ok */
case SSH_SERVER_KNOWN_CHANGED:
fprintf(stderr,"Host key for server changed : server's one is now :\n");
fprintf(stderr,"For security reason, connection will be stopped\n");
ssh_disconnect(session);
ssh_finalize();
return NULL;
case SSH_SERVER_FOUND_OTHER:
fprintf(stderr,"The host key for this server was not found but an other type of key exists.\n");
fprintf(stderr,"An attacker might change the default server key to confuse your client"
"into thinking the key does not exist\n"
"We advise you to rerun the client with -d or -r for more safety.\n");
ssh_disconnect(session);
ssh_finalize();
return NULL;
case SSH_SERVER_NOT_KNOWN:
fprintf(stderr,"The server is unknown. Leaving now");
ssh_disconnect(session);
return NULL;
case SSH_SERVER_ERROR:
fprintf(stderr,"%s",ssh_get_error(session));
ssh_disconnect(session);
return NULL;
}
ssh_userauth_none(session, NULL);
auth=ssh_userauth_autopubkey(session, NULL);
if(auth==SSH_AUTH_ERROR){
fprintf(stderr,"Authenticating with pubkey: %s\n",ssh_get_error(session));
ssh_disconnect(session);
return NULL;
}
if(auth!=SSH_AUTH_SUCCESS){
fprintf(stderr,"Authentication failed: %s\n",ssh_get_error(session));
ssh_disconnect(session);
return NULL;
}
ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success");
return session;
}
int sftp_test(SSH_SESSION *session, int test){
SFTP_SESSION *sftp=sftp_new(session);
SFTP_FILE *file;
int wrote=0;
char name[128];
if(sftp == NULL)
return SSH_ERROR;
if(sftp_init(sftp)<0){
printf("problem initializing sftp : %s\n",ssh_get_error(session));
return SSH_ERROR;
}
if(test==TEST_WRITE){
snprintf(name,sizeof(name),"/tmp/libsshstress%d",rand());
file=sftp_open(sftp,name,O_RDWR|O_CREAT,0777);
if(!file){
printf("Failed to open file : %s\n",ssh_get_error(session));
sftp_free(sftp);
return SSH_ERROR;
}
while(wrote<FILESIZE){
int max=FILESIZE-wrote;
int towrite=rand()%max + 1;
int ret=sftp_write(file,&samplefile[wrote],towrite);
if(ret<=0){
printf("Problem while writing : %s\n",ssh_get_error(session));
sftp_free(sftp);
return SSH_ERROR;
}
if(ret != towrite){
printf("Asked to write %d, wrote %d\n",towrite,ret);
}
wrote += ret;
}
sftp_close(file);
}
sftp_free(sftp);
return SSH_OK;
}

Просмотреть файл

@ -1,62 +0,0 @@
/*
This file is distributed in public domain. You can do whatever you want
with its content.
*/
#include <libssh/libssh.h>
#include <stdio.h>
#include <string.h>
#include "tests.h"
void do_connect(SSH_SESSION *session) {
char buf[4096] = {0};
CHANNEL *channel;
int error = ssh_connect(session);
if (error != SSH_OK) {
fprintf(stderr,"Error at connection: %s\n", ssh_get_error(session));
return;
}
printf("Connected\n");
ssh_session_is_known_server(session);
error = authenticate(session);
if(error != SSH_AUTH_SUCCESS) {
fprintf(stderr,"Error at authentication: %s\n", ssh_get_error(session));
return;
}
printf("Authenticated\n");
channel = ssh_channel_new(session);
ssh_channel_open_session(channel);
printf("Execute 'ls' on the channel\n");
error = ssh_channel_request_exec(channel, "ls");
if(error != SSH_OK){
fprintf(stderr, "Error executing command: %s\n", ssh_get_error(session));
return;
}
printf("--------------------output----------------------\n");
while (ssh_channel_read(channel, buf, sizeof(buf), 0)) {
printf("%s", buf);
}
printf("\n");
printf("---------------------end------------------------\n");
ssh_channel_send_eof(channel);
fprintf(stderr, "Exit status: %d\n", ssh_channel_get_exit_status(channel));
printf("\nChannel test finished\n");
ssh_channel_close(channel);
ssh_channel_free(channel);
}
int main(int argc, char **argv){
SSH_OPTIONS *options=set_opts(argc, argv);
SSH_SESSION *session=ssh_new();
if(options==NULL){
return 1;
}
ssh_set_options(session,options);
do_connect(session);
ssh_disconnect(session);
ssh_finalize();
return 0;
}

Просмотреть файл

@ -1,50 +0,0 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
/* Simple test for the pcap functions */
#include <libssh/libssh.h>
#include <libssh/pcap.h>
#include <libssh/buffer.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv){
ssh_pcap_file pcap;
ssh_pcap_context ctx;
ssh_buffer buffer=ssh_buffer_new();
char *str="Hello, this is a test string to test the capabilities of the"
"pcap file writer.";
printf("Simple pcap tester\n");
pcap=ssh_pcap_file_new();
if(ssh_pcap_file_open(pcap,"test.cap") != SSH_OK){
printf("error happened\n");
return EXIT_FAILURE;
}
buffer_add_data(buffer,str,strlen(str));
ctx=ssh_pcap_context_new(NULL);
ssh_pcap_context_set_file(ctx,pcap);
ssh_pcap_context_write(ctx,SSH_PCAP_DIR_OUT,str,strlen(str),strlen(str));
return EXIT_SUCCESS;
}

Просмотреть файл

@ -1,147 +0,0 @@
/* Test the ability to use ssh_bind_accept_fd.
*
* Expected behavior: Prints "SUCCESS!"
*
* Faulty behavior observed before change: Connection timeout
*/
#include <arpa/inet.h>
#include <err.h>
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <netinet/in.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
struct options {
const char *server_keyfile;
} options;
const char HOST[] = "127.0.0.1";
const int PORT = 3333;
int get_connection() {
int rc, server_socket, client_conn = -1;
struct sockaddr_in server_socket_addr;
struct sockaddr_storage client_conn_addr;
socklen_t client_conn_addr_size = sizeof(client_conn_addr);
server_socket = socket(PF_INET, SOCK_STREAM, 0);
if (server_socket < 0) {
goto out;
}
server_socket_addr.sin_family = AF_INET;
server_socket_addr.sin_port = htons(PORT);
if (inet_pton(AF_INET, HOST, &server_socket_addr.sin_addr) != 1) {
goto out;
}
rc = bind(server_socket, (struct sockaddr *)&server_socket_addr,
sizeof(server_socket_addr));
if (rc < 0) {
goto out;
}
if (listen(server_socket, 0) < 0) {
goto out;
}
client_conn = accept(server_socket,
(struct sockaddr *)&client_conn_addr,
&client_conn_addr_size);
out:
return client_conn;
}
void ssh_server() {
ssh_bind bind;
ssh_session session;
int client_conn = get_connection();
if (client_conn < 0) {
err(1, "get_connection");
}
bind = ssh_bind_new();
if (!bind) {
errx(1, "ssh_bind_new");
}
#ifdef HAVE_DSA
/*TODO mbedtls this is probably required */
if (ssh_bind_options_set(bind, SSH_BIND_OPTIONS_DSAKEY,
options.server_keyfile) != SSH_OK) {
errx(1, "ssh_bind_options_set(SSH_BIND_OPTIONS_DSAKEY");
}
#else
if (ssh_bind_options_set(bind, SSH_BIND_OPTIONS_RSAKEY,
options.server_keyfile) != SSH_OK) {
errx(1, "ssh_bind_options_set(SSH_BIND_OPTIONS_RSAKEY");
}
#endif
session = ssh_new();
if (!session) {
errx(1, "ssh_new");
}
if (ssh_bind_accept_fd(bind, session, client_conn) != SSH_OK) {
errx(1, "ssh_bind_accept: %s", ssh_get_error(bind));
}
if (ssh_handle_key_exchange(session) != SSH_OK) {
errx(1, "ssh_handle_key_exchange: %s", ssh_get_error(session));
}
printf("SUCCESS!\n");
}
void ssh_client() {
ssh_session session;
session = ssh_new();
if (!session) {
errx(1, "ssh_new");
}
if (ssh_options_set(session, SSH_OPTIONS_HOST, HOST) < 0) {
errx(1, "ssh_options_set(SSH_OPTIONS_HOST)");
}
if (ssh_options_set(session, SSH_OPTIONS_PORT, &PORT) < 0) {
errx(1, "ssh_options_set(SSH_OPTIONS_PORT)");
}
if (ssh_connect(session) != SSH_OK) {
errx(1, "ssh_connect: %s", ssh_get_error(session));
}
}
int main(int argc, const char *argv[]) {
if (argc != 2) {
printf("Usage: %s <private key file>\n", argv[0]);
exit(1);
}
options.server_keyfile = argv[1];
pid_t pid = fork();
if (pid < 0) {
errx(1, "fork");
}
if (pid == 0) {
/* Allow the server to get set up */
sleep(3);
ssh_client();
} else {
ssh_server();
}
return 0;
}

Просмотреть файл

@ -1,76 +0,0 @@
/*
This file is distributed in public domain. You can do whatever you want
with its content.
*/
#include <libssh/libssh.h>
#include <stdio.h>
#include <string.h>
#include "tests.h"
#define ECHO_PORT 7
void do_connect(SSH_SESSION *session){
int error=ssh_connect(session);
if(error != SSH_OK){
fprintf(stderr,"Error at connection :%s\n",ssh_get_error(session));
return;
}
printf("Connected\n");
ssh_session_is_known_server(session);
// we don't care what happens here
error=authenticate(session);
if(error != SSH_AUTH_SUCCESS){
fprintf(stderr,"Error at authentication :%s\n",ssh_get_error(session));
return;
}
printf("Authenticated\n");
CHANNEL *channel=ssh_channel_new(session);
error=ssh_channel_open_forward(channel,"localhost",ECHO_PORT,"localhost",42);
if(error!=SSH_OK){
fprintf(stderr,"Error when opening forward:%s\n",ssh_get_error(session));
return;
}
printf("Forward opened\n");
int i=0;
char string[20];
char buffer[20];
for(i=0;i<2000;++i){
sprintf(string,"%d\n",i);
ssh_channel_write(channel,string,strlen(string));
do {
error=ssh_channel_poll(channel,0);
//if(error < strlen(string))
//usleep(10);
} while(error < strlen(string) && error >= 0);
if(error>0){
error=ssh_channel_read_nonblocking(channel,buffer,strlen(string),0);
if(error>=0){
if(memcmp(buffer,string,strlen(string))!=0){
fprintf(stderr,"Problem with answer: wanted %s got %s\n",string,buffer);
} else {
printf(".");
fflush(stdout);
}
}
}
if(error==-1){
fprintf(stderr,"Channel reading error : %s\n",ssh_get_error(session));
break;
}
}
printf("\nChannel test finished\n");
ssh_channel_close(channel);
ssh_channel_free(channel);
}
int main(int argc, char **argv){
SSH_OPTIONS *options=set_opts(argc, argv);
SSH_SESSION *session=ssh_new();
if(options==NULL){
return 1;
}
ssh_set_options(session,options);
do_connect(session);
ssh_disconnect(session);
ssh_finalize();
return 0;
}

Просмотреть файл

@ -1,8 +0,0 @@
/*
This file is distributed in public domain. You can do whatever you want
with its content.
*/
#include <libssh/libssh.h>
int authenticate (SSH_SESSION *session);
SSH_OPTIONS *set_opts(int argc, char **argv);