diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-11-07 17:23:06 +0100 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-11-07 17:23:06 +0100 |
commit | 272a4d1e4596a505d2ca7f3631827855a3bd98f1 (patch) | |
tree | 33edb4d31acf15ae5da24f2ce5aa0251e3e69e23 /examples/knownhosts.c | |
parent | 3a95ecfe74ee770f6c0045768abe16faf29ca1aa (diff) | |
download | libssh-272a4d1e4596a505d2ca7f3631827855a3bd98f1.tar.gz libssh-272a4d1e4596a505d2ca7f3631827855a3bd98f1.tar.xz libssh-272a4d1e4596a505d2ca7f3631827855a3bd98f1.zip |
Refactorize sample.c
Diffstat (limited to 'examples/knownhosts.c')
-rw-r--r-- | examples/knownhosts.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/examples/knownhosts.c b/examples/knownhosts.c index bee9c91..d57ad45 100644 --- a/examples/knownhosts.c +++ b/examples/knownhosts.c @@ -37,9 +37,7 @@ int verify_knownhost(ssh_session session){ hlen = ssh_get_pubkey_hash(session, &hash); if (hlen < 0) { - ssh_disconnect(session); - ssh_finalize(); - return 1; + return -1; } switch(state){ case SSH_SERVER_KNOWN_OK: @@ -49,17 +47,13 @@ int verify_knownhost(ssh_session session){ ssh_print_hexa("Public key hash",hash, hlen); free(hash); fprintf(stderr,"For security reason, connection will be stopped\n"); - ssh_disconnect(session); - ssh_finalize(); - exit(-1); + return -1; 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(); - exit(-1); + return -1; case SSH_SERVER_FILE_NOT_FOUND: fprintf(stderr,"Could not find known host file. If you accept the host key here,\n"); fprintf(stderr,"the file will be automatically created.\n"); @@ -71,8 +65,7 @@ int verify_knownhost(ssh_session session){ free(hexa); fgets(buf,sizeof(buf),stdin); if(strncasecmp(buf,"yes",3)!=0){ - ssh_disconnect(session); - exit(-1); + return -1; } fprintf(stderr,"This new key will be written on disk for further usage. do you agree ?\n"); fgets(buf,sizeof(buf),stdin); @@ -80,7 +73,7 @@ int verify_knownhost(ssh_session session){ if (ssh_write_knownhost(session) < 0) { free(hash); fprintf(stderr, "error %s\n", strerror(errno)); - exit(-1); + return -1; } } @@ -88,9 +81,7 @@ int verify_knownhost(ssh_session session){ case SSH_SERVER_ERROR: free(hash); fprintf(stderr,"%s",ssh_get_error(session)); - ssh_disconnect(session); - ssh_finalize(); - exit(-1); + return -1; } free(hash); return 0; |