aboutsummaryrefslogtreecommitdiff
path: root/tests/torture.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-02-06 11:15:05 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-02-06 11:15:05 +0100
commit05cd7296ba9a27d2eb4a9d1ecea8230ecb75a35e (patch)
treebd99ab4a33e666c20e1fcf9de1f01dd6db7cb035 /tests/torture.c
parent93a2d794591ba8bc21bde28e0d95b5c7505a322c (diff)
downloadlibssh-05cd7296ba9a27d2eb4a9d1ecea8230ecb75a35e.tar.gz
libssh-05cd7296ba9a27d2eb4a9d1ecea8230ecb75a35e.tar.xz
libssh-05cd7296ba9a27d2eb4a9d1ecea8230ecb75a35e.zip
tests: Added a torture_ssh_session().
Diffstat (limited to 'tests/torture.c')
-rw-r--r--tests/torture.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/torture.c b/tests/torture.c
index 62f52ef..c2b173f 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -4,10 +4,93 @@
static int verbosity = 0;
+static int torture_auth_kbdint(ssh_session session,
+ const char *password) {
+ const char *prompt;
+ char echo;
+ int err;
+
+ if (session == NULL || password == NULL) {
+ return SSH_AUTH_ERROR;
+ }
+
+ err = ssh_userauth_kbdint(session, NULL, NULL);
+
+ prompt = ssh_userauth_kbdint_getprompt(session, 0, &echo);
+ if (prompt == NULL) {
+ return SSH_AUTH_ERROR;
+ }
+
+ if (password && strstr(prompt, "Password:")) {
+ if (ssh_userauth_kbdint_setanswer(session, 0, password) < 0) {
+ return SSH_AUTH_ERROR;
+ }
+ }
+ err = ssh_userauth_kbdint(session, NULL, NULL);
+
+ return err;
+}
+
int torture_libssh_verbosity(void){
return verbosity;
}
+ssh_session torture_ssh_session(const char *host,
+ const char *user,
+ const char *password) {
+ ssh_session session;
+
+ if (host == NULL) {
+ return NULL;
+ }
+
+ session = ssh_new();
+ if (session == NULL) {
+ return NULL;
+ }
+
+ if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) {
+ goto failed;
+ }
+
+ if (user != NULL) {
+ if (ssh_options_set(session, SSH_OPTIONS_USER, user) < 0) {
+ goto failed;
+ }
+ }
+
+ if (ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity) < 0) {
+ goto failed;
+ }
+
+ if (ssh_connect(session)) {
+ goto failed;
+ }
+
+ /* We are in testing mode, so consinder the hostkey as verified ;) */
+
+ if (password != NULL) {
+ int err = torture_auth_kbdint(session, password);
+ if (err == SSH_AUTH_ERROR) {
+ goto failed;
+ }
+ } else {
+ int err = ssh_userauth_autopubkey(session, NULL);
+ if (err == SSH_AUTH_ERROR) {
+ goto failed;
+ }
+ }
+
+ return session;
+failed:
+ if (ssh_is_connected(session)) {
+ ssh_disconnect(session);
+ }
+ ssh_free(session);
+
+ return NULL;
+}
+
int main(int argc, char **argv) {
struct argument_s arguments;
@@ -17,3 +100,5 @@ int main(int argc, char **argv) {
return torture_run_tests();
}
+
+/* vim: set ts=4 sw=4 et cindent syntax=c.doxygen: */