You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

  1. From acb0e4f401440ca325e441064d2cb4b896fb9a3d Mon Sep 17 00:00:00 2001
  2. From: Andreas Schneider <asn@cryptomilk.org>
  3. Date: Wed, 17 Oct 2018 17:32:54 +0200
  4. Subject: [PATCH 5/8] examples: Explicitly track auth state in
  5. samplesshd-kbdint
  6. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
  7. (cherry picked from commit 0ff566b6dde5cd27653aa35280feceefad5d5224)
  8. Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
  9. ---
  10. examples/samplesshd-kbdint.c | 20 ++++++++++++++++----
  11. 1 file changed, 16 insertions(+), 4 deletions(-)
  12. --- a/examples/samplesshd-kbdint.c
  13. +++ b/examples/samplesshd-kbdint.c
  14. @@ -23,6 +23,7 @@ clients must be made or how a client sho
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. +#include <stdbool.h>
  19. #define SSHD_USER "libssh"
  20. #define SSHD_PASSWORD "libssh"
  21. @@ -36,6 +37,7 @@ clients must be made or how a client sho
  22. #endif
  23. static int port = 22;
  24. +static bool authenticated = false;
  25. #ifdef WITH_PCAP
  26. static const char *pcap_file = "debug.server.pcap";
  27. @@ -61,11 +63,20 @@ static void cleanup_pcap(void) {
  28. #endif
  29. -static int auth_password(const char *user, const char *password){
  30. - if(strcmp(user, SSHD_USER))
  31. +static int auth_password(const char *user, const char *password)
  32. +{
  33. + int cmp;
  34. +
  35. + cmp = strcmp(user, SSHD_USER);
  36. + if (cmp != 0) {
  37. return 0;
  38. - if(strcmp(password, SSHD_PASSWORD))
  39. + }
  40. + cmp = strcmp(password, SSHD_PASSWORD);
  41. + if (cmp != 0) {
  42. return 0;
  43. + }
  44. +
  45. + authenticated = true;
  46. return 1; // authenticated
  47. }
  48. #ifdef HAVE_ARGP_H
  49. @@ -200,6 +211,7 @@ static int kbdint_check_response(ssh_ses
  50. return 0;
  51. }
  52. + authenticated = true;
  53. return 1;
  54. }
  55. @@ -328,7 +340,7 @@ int main(int argc, char **argv){
  56. /* proceed to authentication */
  57. auth = authenticate(session);
  58. - if(!auth){
  59. + if (!auth || !authenticated) {
  60. printf("Authentication error: %s\n", ssh_get_error(session));
  61. ssh_disconnect(session);
  62. return 1;