aboutsummaryrefslogtreecommitdiff
path: root/examples/samplesshd-kbdint.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-10-17 17:32:54 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-10-19 12:31:04 +0200
commit0ff566b6dde5cd27653aa35280feceefad5d5224 (patch)
tree0c6039dc4e295c8c824c456057078cd6e9f764e7 /examples/samplesshd-kbdint.c
parent9c200d3ef4f62d724d3bae2563b81c38cc31e215 (diff)
downloadlibssh-0ff566b6dde5cd27653aa35280feceefad5d5224.tar.gz
libssh-0ff566b6dde5cd27653aa35280feceefad5d5224.tar.xz
libssh-0ff566b6dde5cd27653aa35280feceefad5d5224.zip
examples: Explicitly track auth state in samplesshd-kbdint
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'examples/samplesshd-kbdint.c')
-rw-r--r--examples/samplesshd-kbdint.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/examples/samplesshd-kbdint.c b/examples/samplesshd-kbdint.c
index 5c2c461e..522aebd6 100644
--- a/examples/samplesshd-kbdint.c
+++ b/examples/samplesshd-kbdint.c
@@ -23,6 +23,7 @@ clients must be made or how a client should react.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <stdbool.h>
#define SSHD_USER "libssh"
#define SSHD_PASSWORD "libssh"
@@ -36,6 +37,7 @@ clients must be made or how a client should react.
#endif
static int port = 22;
+static bool authenticated = false;
#ifdef WITH_PCAP
static const char *pcap_file = "debug.server.pcap";
@@ -61,11 +63,20 @@ static void cleanup_pcap(void) {
#endif
-static int auth_password(const char *user, const char *password){
- if(strcmp(user, SSHD_USER))
+static int auth_password(const char *user, const char *password)
+{
+ int cmp;
+
+ cmp = strcmp(user, SSHD_USER);
+ if (cmp != 0) {
return 0;
- if(strcmp(password, SSHD_PASSWORD))
+ }
+ cmp = strcmp(password, SSHD_PASSWORD);
+ if (cmp != 0) {
return 0;
+ }
+
+ authenticated = true;
return 1; // authenticated
}
#ifdef HAVE_ARGP_H
@@ -200,6 +211,7 @@ static int kbdint_check_response(ssh_session session) {
return 0;
}
+ authenticated = true;
return 1;
}
@@ -328,7 +340,7 @@ int main(int argc, char **argv){
/* proceed to authentication */
auth = authenticate(session);
- if(!auth){
+ if (!auth || !authenticated) {
printf("Authentication error: %s\n", ssh_get_error(session));
ssh_disconnect(session);
return 1;