Blame SOURCES/0058-Make-the-max-number-of-bind-retries-tunable.patch

bd689f
From be7c2d639127dd8af0139caf94f8c29f431d3753 Mon Sep 17 00:00:00 2001
bd689f
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
bd689f
Date: Mon, 18 Jun 2018 10:13:48 +0200
bd689f
Subject: [PATCH 58/59] Make the max number of bind retries tunable
bd689f
bd689f
Resolves: rhbz#1318198
bd689f
---
bd689f
 parseconf.c   | 1 +
bd689f
 privops.c     | 8 ++++++--
bd689f
 tunables.c    | 2 ++
bd689f
 tunables.h    | 1 +
bd689f
 vsftpd.conf.5 | 5 +++++
bd689f
 5 files changed, 15 insertions(+), 2 deletions(-)
bd689f
bd689f
diff --git a/parseconf.c b/parseconf.c
bd689f
index aeb401a..3cfe7da 100644
bd689f
--- a/parseconf.c
bd689f
+++ b/parseconf.c
bd689f
@@ -143,6 +143,7 @@ parseconf_uint_array[] =
bd689f
   { "delay_successful_login", &tunable_delay_successful_login },
bd689f
   { "max_login_fails", &tunable_max_login_fails },
bd689f
   { "chown_upload_mode", &tunable_chown_upload_mode },
bd689f
+  { "bind_retries", &tunable_bind_retries },
bd689f
   { 0, 0 }
bd689f
 };
bd689f
 
bd689f
diff --git a/privops.c b/privops.c
bd689f
index 010d28d..83b25c7 100644
bd689f
--- a/privops.c
bd689f
+++ b/privops.c
bd689f
@@ -120,8 +120,8 @@ unsigned short
bd689f
 vsf_privop_pasv_listen(struct vsf_session* p_sess)
bd689f
 {
bd689f
   static struct vsf_sysutil_sockaddr* s_p_sockaddr;
bd689f
-  int bind_retries = 10;
bd689f
-  unsigned short the_port;
bd689f
+  int bind_retries = tunable_bind_retries + 1;
bd689f
+  unsigned short the_port = 0;
bd689f
   /* IPPORT_RESERVED */
bd689f
   unsigned short min_port = 1024;
bd689f
   unsigned short max_port = 65535;
bd689f
@@ -131,6 +131,10 @@ vsf_privop_pasv_listen(struct vsf_session* p_sess)
bd689f
     die("listed fd already active");
bd689f
   }
bd689f
 
bd689f
+  if (bind_retries < 2)
bd689f
+  {
bd689f
+    bind_retries = 2;
bd689f
+  }
bd689f
   if (tunable_pasv_min_port > min_port && tunable_pasv_min_port <= max_port)
bd689f
   {
bd689f
     min_port = (unsigned short) tunable_pasv_min_port;
bd689f
diff --git a/tunables.c b/tunables.c
bd689f
index 63de8e6..a7ce9c8 100644
bd689f
--- a/tunables.c
bd689f
+++ b/tunables.c
bd689f
@@ -115,6 +115,7 @@ unsigned int tunable_delay_failed_login;
bd689f
 unsigned int tunable_delay_successful_login;
bd689f
 unsigned int tunable_max_login_fails;
bd689f
 unsigned int tunable_chown_upload_mode;
bd689f
+unsigned int tunable_bind_retries;
bd689f
 
bd689f
 const char* tunable_secure_chroot_dir;
bd689f
 const char* tunable_ftp_username;
bd689f
@@ -268,6 +269,7 @@ tunables_load_defaults()
bd689f
   tunable_max_login_fails = 3;
bd689f
   /* -rw------- */
bd689f
   tunable_chown_upload_mode = 0600;
bd689f
+  tunable_bind_retries = 9;
bd689f
 
bd689f
   install_str_setting("/usr/share/empty", &tunable_secure_chroot_dir);
bd689f
   install_str_setting("ftp", &tunable_ftp_username);
bd689f
diff --git a/tunables.h b/tunables.h
bd689f
index 8a4b8b2..029d645 100644
bd689f
--- a/tunables.h
bd689f
+++ b/tunables.h
bd689f
@@ -120,6 +120,7 @@ extern unsigned int tunable_delay_failed_login;
bd689f
 extern unsigned int tunable_delay_successful_login;
bd689f
 extern unsigned int tunable_max_login_fails;
bd689f
 extern unsigned int tunable_chown_upload_mode;
bd689f
+extern unsigned int tunable_bind_retries;
bd689f
 
bd689f
 /* String defines */
bd689f
 extern const char* tunable_secure_chroot_dir;
bd689f
diff --git a/vsftpd.conf.5 b/vsftpd.conf.5
bd689f
index f246906..ce3fba3 100644
bd689f
--- a/vsftpd.conf.5
bd689f
+++ b/vsftpd.conf.5
bd689f
@@ -760,6 +760,11 @@ value will be treated as a base 10 integer!
bd689f
 
bd689f
 Default: 077
bd689f
 .TP
bd689f
+.B bind_retries
bd689f
+Maximum number of attempts to find a free listening port in passive mode.
bd689f
+
bd689f
+Default: 9
bd689f
+.TP
bd689f
 .B chown_upload_mode
bd689f
 The file mode to force for chown()ed anonymous uploads. (Added in v2.0.6).
bd689f
 
bd689f
-- 
bd689f
2.14.4
bd689f