Blame tests/torture.h

Packit Service 31306d
/*
Packit Service 31306d
 * torture.c - torture library for testing libssh
Packit Service 31306d
 *
Packit Service 31306d
 * This file is part of the SSH Library
Packit Service 31306d
 *
Packit Service 31306d
 * Copyright (c) 2008-2009 by Andreas Schneider <asn@cryptomilk.org>
Packit Service 31306d
 *
Packit Service 31306d
 * The SSH Library is free software; you can redistribute it and/or modify
Packit Service 31306d
 * it under the terms of the GNU Lesser General Public License as published by
Packit Service 31306d
 * the Free Software Foundation; either version 2.1 of the License, or (at your
Packit Service 31306d
 * option) any later version.
Packit Service 31306d
 *
Packit Service 31306d
 * The SSH Library is distributed in the hope that it will be useful, but
Packit Service 31306d
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit Service 31306d
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
Packit Service 31306d
 * License for more details.
Packit Service 31306d
 *
Packit Service 31306d
 * You should have received a copy of the GNU Lesser General Public License
Packit Service 31306d
 * along with the SSH Library; see the file COPYING.  If not, write to
Packit Service 31306d
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
Packit Service 31306d
 * MA 02111-1307, USA.
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
#ifndef _TORTURE_H
Packit Service 31306d
#define _TORTURE_H
Packit Service 31306d
Packit Service 31306d
#ifndef _GNU_SOURCE
Packit Service 31306d
#define _GNU_SOURCE
Packit Service 31306d
#endif
Packit Service 31306d
Packit Service 31306d
#include <stdio.h>
Packit Service 31306d
#include <stdlib.h>
Packit Service 31306d
#include <stdarg.h>
Packit Service 31306d
#include <stddef.h>
Packit Service 31306d
#include <setjmp.h>
Packit Service 31306d
Packit Service 31306d
#include "libssh/priv.h"
Packit Service 31306d
#include "libssh/server.h"
Packit Service 31306d
#include "libssh/sftp.h"
Packit Service 31306d
Packit Service 31306d
#include <cmocka.h>
Packit Service 31306d
Packit Service 31306d
#include "torture_cmocka.h"
Packit Service 31306d
Packit Service 31306d
#ifndef assert_return_code
Packit Service 31306d
/* hack for older versions of cmocka */
Packit Service 31306d
#define assert_return_code(code, errno) \
Packit Service 31306d
    assert_true(code >= 0)
Packit Service 31306d
#endif /* assert_return_code */
Packit Service 31306d
Packit Service 31306d
#define TORTURE_SSH_SERVER "127.0.0.10"
Packit Service 31306d
#define TORTURE_SSH_USER_BOB "bob"
Packit Service 31306d
#define TORTURE_SSH_USER_BOB_PASSWORD "secret"
Packit Service 31306d
Packit Service 31306d
#define TORTURE_SSH_USER_ALICE "alice"
Packit Service 31306d
Packit Service 31306d
/* Used by main to communicate with parse_opt. */
Packit Service 31306d
struct argument_s {
Packit Service 31306d
  const char *pattern;
Packit Service 31306d
  int verbose;
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
struct torture_sftp {
Packit Service 31306d
    ssh_session ssh;
Packit Service 31306d
    sftp_session sftp;
Packit Service 31306d
    char *testdir;
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
struct torture_state {
Packit Service 31306d
    char *socket_dir;
Packit Service 31306d
    char *pcap_file;
Packit Service 31306d
    char *srv_pidfile;
Packit Service 31306d
    char *srv_config;
Packit Service 31306d
    bool srv_pam;
Packit Service 31306d
    char *srv_additional_config;
Packit Service 31306d
    struct {
Packit Service 31306d
        ssh_session session;
Packit Service 31306d
        struct torture_sftp *tsftp;
Packit Service 31306d
    } ssh;
Packit Service 31306d
#ifdef WITH_PCAP
Packit Service 31306d
    ssh_pcap_file plain_pcap;
Packit Service 31306d
#endif
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
#ifndef ZERO_STRUCT
Packit Service 31306d
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
Packit Service 31306d
#endif
Packit Service 31306d
Packit Service 31306d
void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments);
Packit Service 31306d
Packit Service 31306d
int torture_rmdirs(const char *path);
Packit Service 31306d
int torture_isdir(const char *path);
Packit Service 31306d
Packit Service 31306d
int torture_terminate_process(const char *pidfile);
Packit Service 31306d
Packit Service 31306d
/*
Packit Service 31306d
 * Returns the verbosity level asked by user
Packit Service 31306d
 */
Packit Service 31306d
int torture_libssh_verbosity(void);
Packit Service 31306d
Packit Service 31306d
ssh_session torture_ssh_session(struct torture_state *s,
Packit Service 31306d
                                const char *host,
Packit Service 31306d
                                const unsigned int *port,
Packit Service 31306d
                                const char *user,
Packit Service 31306d
                                const char *password);
Packit Service 31306d
Packit Service 31306d
ssh_bind torture_ssh_bind(const char *addr,
Packit Service 31306d
                          const unsigned int port,
Packit Service 31306d
                          enum ssh_keytypes_e key_type,
Packit Service 31306d
                          const char *private_key_file);
Packit Service 31306d
Packit Service 31306d
struct torture_sftp *torture_sftp_session(ssh_session session);
Packit Service 31306d
void torture_sftp_close(struct torture_sftp *t);
Packit Service 31306d
Packit Service 31306d
void torture_write_file(const char *filename, const char *data);
Packit Service 31306d
Packit Service 31306d
#define torture_filter_tests(tests) _torture_filter_tests(tests, sizeof(tests) / sizeof(tests)[0])
Packit Service 31306d
void _torture_filter_tests(struct CMUnitTest *tests, size_t ntests);
Packit Service 31306d
Packit Service 31306d
const char *torture_server_address(int domain);
Packit Service 31306d
int torture_server_port(void);
Packit Service 31306d
Packit Service 31306d
void torture_setup_socket_dir(void **state);
Packit Service 31306d
void torture_setup_sshd_server(void **state, bool pam);
Packit Service 31306d
Packit Service 31306d
void torture_teardown_socket_dir(void **state);
Packit Service 31306d
void torture_teardown_sshd_server(void **state);
Packit Service 31306d
Packit Service 31306d
int torture_update_sshd_config(void **state, const char *config);
Packit Service 31306d
Packit Service 31306d
void torture_reset_config(ssh_session session);
Packit Service 31306d
Packit Service 31306d
/*
Packit Service 31306d
 * This function must be defined in every unit test file.
Packit Service 31306d
 */
Packit Service 31306d
int torture_run_tests(void);
Packit Service 31306d
Packit Service 31306d
char *torture_make_temp_dir(const char *template);
Packit Service 31306d
char *torture_create_temp_file(const char *template);
Packit Service 31306d
Packit Service 31306d
char *torture_get_current_working_dir(void);
Packit Service 31306d
int torture_change_dir(char *path);
Packit Service 31306d
Packit Service 31306d
#endif /* _TORTURE_H */