File: torture.h

package info (click to toggle)
libssh 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,804 kB
  • sloc: ansic: 124,224; cpp: 421; xml: 226; sh: 206; makefile: 26; python: 9
file content (202 lines) | stat: -rw-r--r-- 6,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * torture.c - torture library for testing libssh
 *
 * This file is part of the SSH Library
 *
 * Copyright (c) 2008-2009 by Andreas Schneider <asn@cryptomilk.org>
 *
 * 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.
 */

#ifndef _TORTURE_H
#define _TORTURE_H

#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#include "libssh/priv.h"
#include "libssh/server.h"
#include "libssh/sftp.h"

#include <cmocka.h>

#include "tests_config.h"
#include "torture_cmocka.h"

#ifndef assert_return_code
/* hack for older versions of cmocka */
#define assert_return_code(code, errno) assert_true(code >= 0)
#endif /* assert_return_code */

#define TORTURE_SSH_SERVER "127.0.0.10"
#define TORTURE_SSH_SERVER_IP6 "fd00::5357:5f0a"
#define TORTURE_SSH_USER_BOB "bob"
#define TORTURE_SSH_USER_BOB_PASSWORD "secret"

#define TORTURE_SSH_USER_ALICE "alice"
#define TORTURE_SSH_USER_CHARLIE "charlie"

/* Used by main to communicate with parse_opt. */
struct argument_s {
    const char *pattern;
    int verbose;
};

struct torture_sftp {
    ssh_session ssh;
    sftp_session sftp;
    char *testdir;
};

struct torture_ssh {
    ssh_session session;
    void *cb_state;  /* For storing callback state */
    void *callbacks; /* For storing callbacks */
};

struct torture_state {
    char *socket_dir;
    char *gss_dir;
    char *pcap_file;
    char *log_file;
    char *srv_pidfile;
    char *srv_config;
    char *srv1_pidfile;
    char *srv1_config;
    bool srv_pam;
    bool disable_hostkeys;
    char *srv_additional_config;
    struct {
        ssh_session session;
        struct torture_sftp *tsftp;
        struct torture_ssh ssh;
    } ssh;
#ifdef WITH_PCAP
    ssh_pcap_file plain_pcap;
#endif
    void *private_data;
};

#ifndef ZERO_STRUCT
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
#endif

void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments);

int torture_rmdirs(const char *path);
int torture_isdir(const char *path);

int torture_terminate_process(const char *pidfile);

/*
 * Returns the verbosity level asked by user
 */
int torture_libssh_verbosity(void);

ssh_session torture_ssh_session(struct torture_state *s,
                                const char *host,
                                const unsigned int *port,
                                const char *user,
                                const char *password);

ssh_session torture_ssh_session_proxyjump(void);

ssh_bind torture_ssh_bind(const char *addr,
                          const unsigned int port,
                          enum ssh_keytypes_e key_type,
                          const char *private_key_file);

struct torture_sftp *torture_sftp_session(ssh_session session);
struct torture_sftp *torture_sftp_session_channel(ssh_session session,
                                                  ssh_channel channel);
void torture_sftp_close(struct torture_sftp *t);

void torture_write_file(const char *filename, const char *data);

#define torture_filter_tests(tests) \
    _torture_filter_tests(tests, sizeof(tests) / sizeof(tests)[0])
void _torture_filter_tests(struct CMUnitTest *tests, size_t ntests);

const char *torture_server_address(int domain);
const char *torture_server1_address(int domain);
int torture_server_port(void);

int torture_wait_for_daemon(unsigned int seconds);

#ifdef SSHD_EXECUTABLE
void torture_setup_socket_dir(void **state);
void torture_setup_sshd_server(void **state, bool pam);
void torture_setup_sshd_servers(void **state, bool pam);

void torture_teardown_socket_dir(void **state);
void torture_teardown_sshd_server(void **state);
void torture_teardown_sshd_server1(void **state);

int torture_update_sshd_config(void **state, const char *config);
#endif /* SSHD_EXECUTABLE */

#ifdef WITH_PKCS11_URI
void torture_setup_tokens(const char *temp_dir,
                          const char *filename,
                          const char object_name[],
                          const char *load_public);
void torture_cleanup_tokens(const char *temp_dir);
#endif /* WITH_PKCS11_URI */

void torture_reset_config(ssh_session session);

void torture_setup_create_libssh_config(void **state);

void torture_setup_libssh_server(void **state, const char *server_path);

#ifdef WITH_GSSAPI
void torture_setup_kdc_server(void **state,
                              const char *kadmin_script,
                              const char *kinit_script);
void torture_teardown_kdc_server(void **state);
void torture_set_kdc_env_str(const char *gss_dir, char *env, size_t size);
void torture_set_env_from_str(const char *env);
#endif /* WITH_GSSAPI */

#if defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED)
__attribute__((weak)) int torture_run_tests(void);
#else
/*
 * This function must be defined in every unit test file.
 */
int torture_run_tests(void);
#endif

void torture_free_state(struct torture_state *s);

char *torture_make_temp_dir(const char *template);
char *torture_create_temp_file(const char *template);

char *torture_get_current_working_dir(void);
int torture_change_dir(char *path);

void torture_setenv(char const *variable, char const *value);
void torture_unsetenv(char const *variable);

int torture_setup_ssh_agent(struct torture_state *s, const char *add_key);
int torture_cleanup_ssh_agent(void);

void torture_finalize(void);

#endif /* _TORTURE_H */