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

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