Blame SOURCES/0056-Log-die-calls-to-syslog.patch

bd689f
From ee6af258e8cb1a7fada5e6d3e54429b89f12b158 Mon Sep 17 00:00:00 2001
bd689f
From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= <olysonek@redhat.com>
bd689f
Date: Fri, 15 Jun 2018 12:02:21 +0200
bd689f
Subject: [PATCH 56/59] Log die() calls to syslog
bd689f
bd689f
Pass messages given to die(), die2() and bug() to syslog. Currently this
bd689f
functionality requires waiting for a short amount of time (1 second is
bd689f
used) after logging the message and before exiting. This is a workaround
bd689f
for the following systemd bug:
bd689f
https://github.com/systemd/systemd/issues/2913
bd689f
bd689f
The need for this workaround is the main reason why I decided not to
bd689f
enable this functionality by default.
bd689f
bd689f
Resolves: rhbz#1318198
bd689f
Resolves: rhbz#1582672
bd689f
---
bd689f
 logging.c     | 13 +++++++++----
bd689f
 logging.h     |  2 ++
bd689f
 main.c        |  4 ++++
bd689f
 parseconf.c   |  1 +
bd689f
 tcpwrap.c     |  3 ---
bd689f
 tunables.c    |  2 ++
bd689f
 tunables.h    |  2 ++
bd689f
 utility.c     | 11 +++++++++++
bd689f
 vsftpd.conf.5 | 10 ++++++++++
bd689f
 9 files changed, 41 insertions(+), 7 deletions(-)
bd689f
bd689f
diff --git a/logging.c b/logging.c
bd689f
index c4461f7..9e86808 100644
bd689f
--- a/logging.c
bd689f
+++ b/logging.c
bd689f
@@ -30,10 +30,6 @@ static void vsf_log_do_log_to_file(int fd, struct mystr* p_str);
bd689f
 void
bd689f
 vsf_log_init(struct vsf_session* p_sess)
bd689f
 {
bd689f
-  if (tunable_syslog_enable || tunable_tcp_wrappers)
bd689f
-  {
bd689f
-    vsf_sysutil_openlog(0);
bd689f
-  }
bd689f
   if (!tunable_xferlog_enable && !tunable_dual_log_enable)
bd689f
   {
bd689f
     return;
bd689f
@@ -389,3 +385,12 @@ vsf_log_do_log_vsftpd_format(struct vsf_session* p_sess, struct mystr* p_str,
bd689f
   }
bd689f
 }
bd689f
 
bd689f
+void
bd689f
+vsf_log_die(const char* p_text)
bd689f
+{
bd689f
+  struct mystr log_str = INIT_MYSTR;
bd689f
+
bd689f
+  str_append_text(&log_str, "ERROR: ");
bd689f
+  str_append_text(&log_str, p_text);
bd689f
+  str_syslog(&log_str, 1);
bd689f
+}
bd689f
diff --git a/logging.h b/logging.h
bd689f
index 1ff57d1..75f06c1 100644
bd689f
--- a/logging.h
bd689f
+++ b/logging.h
bd689f
@@ -91,5 +91,7 @@ void vsf_log_line(struct vsf_session* p_sess, enum EVSFLogEntryType what,
bd689f
 void vsf_log_failed_line(struct vsf_session* p_sess, enum EVSFLogEntryType what,
bd689f
                   struct mystr* p_str);
bd689f
 
bd689f
+void vsf_log_die(const char* p_text);
bd689f
+
bd689f
 #endif /* VSF_LOGGING_H */
bd689f
 
bd689f
diff --git a/main.c b/main.c
bd689f
index f039081..1178d44 100644
bd689f
--- a/main.c
bd689f
+++ b/main.c
bd689f
@@ -120,6 +120,10 @@ main(int argc, const char* argv[])
bd689f
     }
bd689f
     vsf_sysutil_free(p_statbuf);
bd689f
   }
bd689f
+  if (tunable_log_die || tunable_syslog_enable || tunable_tcp_wrappers)
bd689f
+  {
bd689f
+    vsf_sysutil_openlog(0);
bd689f
+  }
bd689f
   /* Resolve pasv_address if required */
bd689f
   if (tunable_pasv_address && tunable_pasv_addr_resolve)
bd689f
   {
bd689f
diff --git a/parseconf.c b/parseconf.c
bd689f
index 47b54f1..aeb401a 100644
bd689f
--- a/parseconf.c
bd689f
+++ b/parseconf.c
bd689f
@@ -112,6 +112,7 @@ parseconf_bool_array[] =
bd689f
   { "seccomp_sandbox", &tunable_seccomp_sandbox },
bd689f
   { "allow_writeable_chroot", &tunable_allow_writeable_chroot },
bd689f
   { "better_stou", &tunable_better_stou },
bd689f
+  { "log_die", &tunable_log_die },
bd689f
   { 0, 0 }
bd689f
 };
bd689f
 
bd689f
diff --git a/tcpwrap.c b/tcpwrap.c
bd689f
index 5bf57d3..132b771 100644
bd689f
--- a/tcpwrap.c
bd689f
+++ b/tcpwrap.c
bd689f
@@ -27,15 +27,12 @@ int
bd689f
 vsf_tcp_wrapper_ok(int remote_fd)
bd689f
 {
bd689f
   struct request_info req;
bd689f
-  vsf_sysutil_openlog(0);
bd689f
   request_init(&req, RQ_DAEMON, "vsftpd", RQ_FILE, remote_fd, 0);
bd689f
   fromhost(&req;;
bd689f
   if (!hosts_access(&req))
bd689f
   {
bd689f
-    vsf_sysutil_closelog();
bd689f
     return 0;
bd689f
   }
bd689f
-  vsf_sysutil_closelog();
bd689f
   return 1;
bd689f
 }
bd689f
 
bd689f
diff --git a/tunables.c b/tunables.c
bd689f
index 5ec2bdc..63de8e6 100644
bd689f
--- a/tunables.c
bd689f
+++ b/tunables.c
bd689f
@@ -93,6 +93,7 @@ int tunable_http_enable;
bd689f
 int tunable_seccomp_sandbox;
bd689f
 int tunable_allow_writeable_chroot;
bd689f
 int tunable_better_stou;
bd689f
+int tunable_log_die;
bd689f
 
bd689f
 unsigned int tunable_accept_timeout;
bd689f
 unsigned int tunable_connect_timeout;
bd689f
@@ -241,6 +242,7 @@ tunables_load_defaults()
bd689f
   tunable_seccomp_sandbox = 0;
bd689f
   tunable_allow_writeable_chroot = 0;
bd689f
   tunable_better_stou = 0;
bd689f
+  tunable_log_die = 0;
bd689f
 
bd689f
   tunable_accept_timeout = 60;
bd689f
   tunable_connect_timeout = 60;
bd689f
diff --git a/tunables.h b/tunables.h
bd689f
index 85ea1a8..8a4b8b2 100644
bd689f
--- a/tunables.h
bd689f
+++ b/tunables.h
bd689f
@@ -96,6 +96,8 @@ extern int tunable_allow_writeable_chroot;    /* Allow misconfiguration */
bd689f
 extern int tunable_better_stou;               /* Use better file name generation
bd689f
                                                * algorithm for the STOU command
bd689f
 					       */
bd689f
+extern int tunable_log_die;                   /* Log calls to die(), die2()
bd689f
+                                               * and bug() */
bd689f
 
bd689f
 /* Integer/numeric defines */
bd689f
 extern unsigned int tunable_accept_timeout;
bd689f
diff --git a/utility.c b/utility.c
bd689f
index 5fd714d..75e5bdd 100644
bd689f
--- a/utility.c
bd689f
+++ b/utility.c
bd689f
@@ -9,6 +9,8 @@
bd689f
 #include "sysutil.h"
bd689f
 #include "str.h"
bd689f
 #include "defs.h"
bd689f
+#include "logging.h"
bd689f
+#include "tunables.h"
bd689f
 
bd689f
 #define DIE_DEBUG
bd689f
 
bd689f
@@ -41,11 +43,20 @@ void
bd689f
 bug(const char* p_text)
bd689f
 {
bd689f
   /* Rats. Try and write the reason to the network for diagnostics */
bd689f
+  if (tunable_log_die)
bd689f
+  {
bd689f
+    vsf_log_die(p_text);
bd689f
+  }
bd689f
   vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD);
bd689f
   (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "500 OOPS: ", 10);
bd689f
   (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text,
bd689f
                                 vsf_sysutil_strlen(p_text));
bd689f
   (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2);
bd689f
+  if (tunable_log_die)
bd689f
+  {
bd689f
+    /* Workaround for https://github.com/systemd/systemd/issues/2913 */
bd689f
+    vsf_sysutil_sleep(1.0);
bd689f
+  }
bd689f
   vsf_sysutil_exit(2);
bd689f
 }
bd689f
 
bd689f
diff --git a/vsftpd.conf.5 b/vsftpd.conf.5
bd689f
index e9ae474..f246906 100644
bd689f
--- a/vsftpd.conf.5
bd689f
+++ b/vsftpd.conf.5
bd689f
@@ -358,6 +358,16 @@ wanting to e.g. append a file.
bd689f
 
bd689f
 Default: YES
bd689f
 .TP
bd689f
+.B log_die
bd689f
+Log an error to syslog when some error condition occurs and vsftpd decides
bd689f
+to quit. Internally, the error messages given to the functions die(), die2()
bd689f
+and bug() are passed to syslog. Currently this functionality requires waiting
bd689f
+for a short amount of time (1 second is used) after logging the message and
bd689f
+before exiting. This is a workaround for the following systemd bug:
bd689f
+https://github.com/systemd/systemd/issues/2913
bd689f
+
bd689f
+Default: NO
bd689f
+.TP
bd689f
 .B log_ftp_protocol
bd689f
 When enabled, all FTP requests and responses are logged, providing the option
bd689f
 xferlog_std_format is not enabled. Useful for debugging.
bd689f
-- 
bd689f
2.14.4
bd689f