010-runtime-maxauthtries.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. From 46b22e57d91e33a591d0fba97da52672af4d6ed2 Mon Sep 17 00:00:00 2001
  2. From: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
  3. Date: Mon, 29 May 2017 10:25:09 +0100
  4. Subject: [PATCH] dropbear server: support -T max auth tries
  5. Add support for '-T n' for a run-time specification for maximum number
  6. of authentication attempts where 'n' is between 1 and compile time
  7. option MAX_AUTH_TRIES.
  8. A default number of tries can be specified at compile time using
  9. 'DEFAULT_AUTH_TRIES' which itself defaults to MAX_AUTH_TRIES for
  10. backwards compatibility.
  11. Signed-off-by: Kevin Darbyshire-Bryant <kevin@darbyshire-bryant.me.uk>
  12. ---
  13. options.h | 7 +++++++
  14. runopts.h | 1 +
  15. svr-auth.c | 2 +-
  16. svr-runopts.c | 17 +++++++++++++++++
  17. 4 files changed, 26 insertions(+), 1 deletion(-)
  18. diff --git a/options.h b/options.h
  19. index 0c51bb1..4d22704 100644
  20. --- a/options.h
  21. +++ b/options.h
  22. @@ -284,6 +284,13 @@ Homedir is prepended unless path begins with / */
  23. #define MAX_AUTH_TRIES 10
  24. #endif
  25. +/* Default maximum number of failed authentication tries.
  26. + * defaults to MAX_AUTH_TRIES */
  27. +
  28. +#ifndef DEFAULT_AUTH_TRIES
  29. +#define DEFAULT_AUTH_TRIES MAX_AUTH_TRIES
  30. +#endif
  31. +
  32. /* The default file to store the daemon's process ID, for shutdown
  33. scripts etc. This can be overridden with the -P flag */
  34. #ifndef DROPBEAR_PIDFILE
  35. diff --git a/runopts.h b/runopts.h
  36. index f7c869d..2f7da63 100644
  37. --- a/runopts.h
  38. +++ b/runopts.h
  39. @@ -96,6 +96,7 @@ typedef struct svr_runopts {
  40. int noauthpass;
  41. int norootpass;
  42. int allowblankpass;
  43. + unsigned int maxauthtries;
  44. #ifdef ENABLE_SVR_REMOTETCPFWD
  45. int noremotetcp;
  46. diff --git a/svr-auth.c b/svr-auth.c
  47. index 577ea88..6a7ce0b 100644
  48. --- a/svr-auth.c
  49. +++ b/svr-auth.c
  50. @@ -362,7 +362,7 @@ void send_msg_userauth_failure(int partial, int incrfail) {
  51. ses.authstate.failcount++;
  52. }
  53. - if (ses.authstate.failcount >= MAX_AUTH_TRIES) {
  54. + if (ses.authstate.failcount >= svr_opts.maxauthtries) {
  55. char * userstr;
  56. /* XXX - send disconnect ? */
  57. TRACE(("Max auth tries reached, exiting"))
  58. diff --git a/svr-runopts.c b/svr-runopts.c
  59. index 8f60059..1e7440f 100644
  60. --- a/svr-runopts.c
  61. +++ b/svr-runopts.c
  62. @@ -73,6 +73,7 @@ static void printhelp(const char * progname) {
  63. "-g Disable password logins for root\n"
  64. "-B Allow blank password logins\n"
  65. #endif
  66. + "-T <1 to %d> Maximum authentication tries (default %d)\n"
  67. #ifdef ENABLE_SVR_LOCALTCPFWD
  68. "-j Disable local port forwarding\n"
  69. #endif
  70. @@ -106,6 +107,7 @@ static void printhelp(const char * progname) {
  71. #ifdef DROPBEAR_ECDSA
  72. ECDSA_PRIV_FILENAME,
  73. #endif
  74. + MAX_AUTH_TRIES, DEFAULT_AUTH_TRIES,
  75. DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT, DROPBEAR_PIDFILE,
  76. DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);
  77. }
  78. @@ -118,6 +120,7 @@ void svr_getopts(int argc, char ** argv) {
  79. char* recv_window_arg = NULL;
  80. char* keepalive_arg = NULL;
  81. char* idle_timeout_arg = NULL;
  82. + char* maxauthtries_arg = NULL;
  83. char* keyfile = NULL;
  84. char c;
  85. @@ -130,6 +133,7 @@ void svr_getopts(int argc, char ** argv) {
  86. svr_opts.noauthpass = 0;
  87. svr_opts.norootpass = 0;
  88. svr_opts.allowblankpass = 0;
  89. + svr_opts.maxauthtries = DEFAULT_AUTH_TRIES;
  90. svr_opts.inetdmode = 0;
  91. svr_opts.portcount = 0;
  92. svr_opts.hostkey = NULL;
  93. @@ -234,6 +238,9 @@ void svr_getopts(int argc, char ** argv) {
  94. case 'I':
  95. next = &idle_timeout_arg;
  96. break;
  97. + case 'T':
  98. + next = &maxauthtries_arg;
  99. + break;
  100. #if defined(ENABLE_SVR_PASSWORD_AUTH) || defined(ENABLE_SVR_PAM_AUTH)
  101. case 's':
  102. svr_opts.noauthpass = 1;
  103. @@ -330,6 +337,16 @@ void svr_getopts(int argc, char ** argv) {
  104. dropbear_exit("Bad recv window '%s'", recv_window_arg);
  105. }
  106. }
  107. +
  108. + if (maxauthtries_arg) {
  109. + unsigned int val = 0;
  110. + if (m_str_to_uint(maxauthtries_arg, &val) == DROPBEAR_FAILURE ||
  111. + val == 0 || val > MAX_AUTH_TRIES) {
  112. + dropbear_exit("Bad maxauthtries '%s'", maxauthtries_arg);
  113. + }
  114. + svr_opts.maxauthtries = val;
  115. + }
  116. +
  117. if (keepalive_arg) {
  118. unsigned int val;
  119. --
  120. 2.7.4