summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2020-05-21 13:11:23 +0200
committerJakub Jelen <jjelen@redhat.com>2020-05-21 13:34:23 +0200
commit866e4442b529e14290db98e3f353caa92c96cc73 (patch)
treeb79ebae2227508ac99ffbd3fd3b2252b2800dc4d
parent39bb93a53b77c9362a9ffa804ed49f47ab73108e (diff)
downloadlibssh-866e4442b529e14290db98e3f353caa92c96cc73.tar.gz
libssh-866e4442b529e14290db98e3f353caa92c96cc73.tar.xz
libssh-866e4442b529e14290db98e3f353caa92c96cc73.zip
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>
-rw-r--r--tests/authentication.c74
-rw-r--r--tests/connection.c31
-rw-r--r--tests/sftp_stress/main.c174
-rw-r--r--tests/test_exec.c62
-rw-r--r--tests/test_pcap.c50
-rw-r--r--tests/test_ssh_bind_accept_fd.c147
-rw-r--r--tests/test_tunnel.c76
-rw-r--r--tests/tests.h8
8 files changed, 0 insertions, 622 deletions
diff --git a/tests/authentication.c b/tests/authentication.c
deleted file mode 100644
index 248b646f..00000000
--- a/tests/authentication.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/connection.c b/tests/connection.c
deleted file mode 100644
index 889c5117..00000000
--- a/tests/connection.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/sftp_stress/main.c b/tests/sftp_stress/main.c
deleted file mode 100644
index ac3f8bb4..00000000
--- a/tests/sftp_stress/main.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/test_exec.c b/tests/test_exec.c
deleted file mode 100644
index 352cc837..00000000
--- a/tests/test_exec.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/test_pcap.c b/tests/test_pcap.c
deleted file mode 100644
index 01aa714a..00000000
--- a/tests/test_pcap.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/test_ssh_bind_accept_fd.c b/tests/test_ssh_bind_accept_fd.c
deleted file mode 100644
index 5aa8211a..00000000
--- a/tests/test_ssh_bind_accept_fd.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/test_tunnel.c b/tests/test_tunnel.c
deleted file mode 100644
index 952c73e1..00000000
--- a/tests/test_tunnel.c
+++ /dev/null
@@ -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;
-}
diff --git a/tests/tests.h b/tests/tests.h
deleted file mode 100644
index dd001f1f..00000000
--- a/tests/tests.h
+++ /dev/null
@@ -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);
-